failtest.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. /* Number of rounds we perform the test. */
  4. #define TEST_ROUNDS 10
  5. static const char unknown[] = "a-file-with-this-name-does-not-exist";
  6. static const char exists[] = "failtestmod.so";
  7. int
  8. main (void)
  9. {
  10. int i;
  11. setvbuf (stdout, NULL, _IONBF, 0);
  12. for (i = 0; i < TEST_ROUNDS; ++i)
  13. {
  14. void *dsc;
  15. printf ("Round %d: Try loading \"%s\"\n", i, unknown);
  16. dsc = dlopen (unknown, RTLD_NOW);
  17. if (dsc != NULL)
  18. {
  19. printf ("We found a file of name \"%s\": this should not happen\n",
  20. unknown);
  21. return 1;
  22. }
  23. printf ("Round %d: loading \"%s\" failed\n", i, unknown);
  24. /* Don't use `dlerror', just load an existing file. */
  25. dsc = dlopen (exists, RTLD_NOW);
  26. if (dsc == NULL)
  27. {
  28. printf ("Could not load \"%s\": %s\n", exists, dlerror ());
  29. return 1;
  30. }
  31. printf ("Round %d: Loaded \"%s\"\n", i, exists);
  32. dlclose (dsc);
  33. printf ("Round %d: Unloaded \"%s\"\n", i, exists);
  34. }
  35. return 0;
  36. }
  37. extern void foo (void);
  38. void
  39. foo (void)
  40. {
  41. }