tst-origin.c 722 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dlfcn.h>
  5. #ifdef __UCLIBC__
  6. extern void _dlinfo(void);
  7. #endif
  8. int main(int argc, char **argv) {
  9. void *h1, *h2;
  10. int (*mydltest)(const char *s);
  11. char *error;
  12. h1 = dlopen ("libtest31.so", RTLD_LAZY);
  13. if (!h1) {
  14. fprintf(stderr, "Could not open libtest31.so: %s\n", dlerror());
  15. exit(1);
  16. }
  17. h2 = dlopen ("libtest31.so", RTLD_NOLOAD);
  18. if (!h2) {
  19. fprintf(stderr, "Could not open libtest31.so(RTLD_NOLOAD): %s\n", dlerror());
  20. exit(1);
  21. }
  22. mydltest = dlsym(h1, "dltest");
  23. if ((error = dlerror()) != NULL) {
  24. fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
  25. exit(1);
  26. }
  27. dlclose(h2);
  28. dlclose(h1);
  29. return EXIT_SUCCESS;
  30. }