tst-dlopen.c 1.1 KB

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