Debian Codegraph @

tests/tst-dlopen.c

raw
1 /*
2 Copyright (C) Nalin Dahyabhai <[email protected]> 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 <stdlib.h>
17 #include <sys/stat.h>
18 #include "basics.h"
19
20 /* Simple program to see if dlopen() would succeed. */
21 int main(int argc, char **argv)
22 {
23 int i;
24 int rc;
25 struct stat st;
26 _cleanup_(freep) char *buf = NULL;
27
28 for (i = 1; i < argc; i++) {
29 if (dlopen(argv[i], RTLD_NOW)) {
30 fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
31 argv[i]);
32 } else {
33 rc = asprintf(&buf, "./%s", argv[i]);
34 if (rc >= 0 && (stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
35 fprintf(stdout, "dlopen() of \"./%s\" "
36 "succeeded.\n", argv[i]);
37 } else {
38 fprintf(stdout, "dlopen() of \"%s\" failed: "
39 "%s\n", argv[i], dlerror());
40 return 1;
41 }
42 }
43 }
44 return 0;
45 }