Debian Codegraph @

liblastlog2/src/tests/tst_dlopen.c

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