Fixed some minor annoyances with dlsym

- Added missing newline character to "File not found" message
 - Now properly handles relative file paths
This commit is contained in:
Scott Ehlert 2007-03-21 20:24:01 +00:00
parent 118b002ee8
commit 68beb4b1a3
2 changed files with 6 additions and 3 deletions

Binary file not shown.

View File

@ -5,26 +5,29 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <limits.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char *file=NULL; char *file=NULL;
void *dl= NULL; void *dl= NULL;
FILE *fp = NULL; FILE *fp = NULL;
char path[PATH_MAX];
if (argc != 2) if (argc != 2)
{ {
printf("Usage: dlsym <file>\n"); printf("Usage: dlsym <file>\n");
exit(0); exit(0);
} }
file = argv[1]; file = argv[1];
fp = fopen(file, "rb"); realpath(file, path);
fp = fopen(path, "rb");
if (!fp) if (!fp)
{ {
printf("File not found."); printf("File not found.\n");
exit(0); exit(0);
} }
dl = dlopen(file, RTLD_NOW); dl = dlopen(path, RTLD_NOW);
if (dl) if (dl)
{ {