File: tst-dlopen.c

package info (click to toggle)
pam 1.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,084 kB
  • sloc: ansic: 31,022; xml: 21,835; sh: 12,645; makefile: 1,606; perl: 904; yacc: 408; lex: 72; sed: 16
file content (43 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
   Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <dlfcn.h>
#include <stdio.h>
#include <limits.h>
#include <sys/stat.h>

/* Simple program to see if dlopen() would succeed. */
int main(int argc, char **argv)
{
  int i;
  struct stat st;
  char buf[PATH_MAX];

  for (i = 1; i < argc; i++) {
    if (dlopen(argv[i], RTLD_NOW)) {
      fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
              argv[i]);
    } else {
      snprintf(buf, sizeof(buf), "./%s", argv[i]);
      if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
        fprintf(stdout, "dlopen() of \"./%s\" "
                "succeeded.\n", argv[i]);
      } else {
        fprintf(stdout, "dlopen() of \"%s\" failed: "
                "%s\n", argv[i], dlerror());
        return 1;
      }
    }
  }
  return 0;
}