Imported Upstream version 1.1.6
[platform/upstream/pam.git] / tests / tst-dlopen.c
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 #ifdef PAM_STATIC
23   return 77;
24 #else
25   int i;
26   struct stat st;
27   char buf[PATH_MAX];
28
29   for (i = 1; i < argc; i++) {
30     if (dlopen(argv[i], RTLD_NOW)) {
31       fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
32               argv[i]);
33     } else {
34       snprintf(buf, sizeof(buf), "./%s", argv[i]);
35       if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
36         fprintf(stdout, "dlopen() of \"./%s\" "
37                 "succeeded.\n", argv[i]);
38       } else {
39         fprintf(stdout, "dlopen() of \"%s\" failed: "
40                 "%s\n", argv[i], dlerror());
41         return 1;
42       }
43     }
44   }
45   return 0;
46 #endif
47 }