1 /*
2 Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 */
9
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13
14 #include <dlfcn.h>
15 #include <stdio.h>
16 #include <limits.h>
17 #include <sys/stat.h>
18
19 /* Simple program to see if dlopen() would succeed. */
20 int main(int argc, char **argv)
21 {
22 int i;
23 struct stat st;
24 char buf[PATH_MAX];
25
26 for (i = 1; i < argc; i++) {
27 if (dlopen(argv[i], RTLD_NOW)) {
28 fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
29 argv[i]);
30 } else {
31 snprintf(buf, sizeof(buf), "./%s", argv[i]);
32 if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
33 fprintf(stdout, "dlopen() of \"./%s\" "
34 "succeeded.\n", argv[i]);
35 } else {
36 fprintf(stdout, "dlopen() of \"%s\" failed: "
37 "%s\n", argv[i], dlerror());
38 return 1;
39 }
40 }
41 }
42 return 0;
43 }