dlopen.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. tempdir=`mktemp -d /tmp/dlopenXXXXXX`
  3. test -n "$tempdir" || exit 1
  4. cat >> $tempdir/dlopen.c << _EOF
  5. #include <dlfcn.h>
  6. #include <stdio.h>
  7. #include <limits.h>
  8. #include <sys/stat.h>
  9. /* Simple program to see if dlopen() would succeed. */
  10. int main(int argc, char **argv)
  11. {
  12. int i;
  13. struct stat st;
  14. char buf[PATH_MAX];
  15. for (i = 1; i < argc; i++) {
  16. if (dlopen(argv[i], RTLD_NOW)) {
  17. fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
  18. argv[i]);
  19. } else {
  20. snprintf(buf, sizeof(buf), "./%s", argv[i]);
  21. if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
  22. fprintf(stdout, "dlopen() of \"./%s\" "
  23. "succeeded.\n", argv[i]);
  24. } else {
  25. fprintf(stdout, "dlopen() of \"%s\" failed: "
  26. "%s\n", argv[i], dlerror());
  27. return 1;
  28. }
  29. }
  30. }
  31. return 0;
  32. }
  33. _EOF
  34. for arg in $@ ; do
  35. case "$arg" in
  36. "")
  37. ;;
  38. -I*|-D*|-f*|-m*|-g*|-O*|-W*)
  39. cflags="$cflags $arg"
  40. ;;
  41. -l*|-L*)
  42. ldflags="$ldflags $arg"
  43. ;;
  44. /*)
  45. modules="$modules $arg"
  46. ;;
  47. *)
  48. modules="$modules $arg"
  49. ;;
  50. esac
  51. done
  52. ${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags -ldl
  53. retval=0
  54. for module in $modules ; do
  55. case "$module" in
  56. "")
  57. ;;
  58. /*)
  59. $tempdir/dlopen "$module"
  60. retval=$?
  61. ;;
  62. *)
  63. $tempdir/dlopen ./"$module"
  64. retval=$?
  65. ;;
  66. esac
  67. done
  68. rm -f $tempdir/dlopen $tempdir/dlopen.c
  69. rmdir $tempdir
  70. exit $retval