defaultmod2.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. extern int found_in_mod1 (void);
  4. int
  5. found_in_mod1 (void)
  6. {
  7. return 1;
  8. }
  9. extern int found_in_mod2 (void);
  10. int
  11. found_in_mod2 (void)
  12. {
  13. return 2;
  14. }
  15. extern int test_in_mod2 (int (*mainp)(int, char **));
  16. int
  17. test_in_mod2 (int (*mainp)(int, char **))
  18. {
  19. int (*ifp) (void);
  20. void *p;
  21. int result = 0;
  22. /* Find function `main'. */
  23. p = dlsym (RTLD_DEFAULT, "main");
  24. if (p == NULL)
  25. {
  26. printf ("%s: main not found\n", __FILE__);
  27. result = 1;
  28. }
  29. else if ((int (*)(int, char **))p != mainp)
  30. {
  31. printf ("%s: wrong address returned for main\n", __FILE__);
  32. result = 1;
  33. }
  34. else
  35. printf ("%s: main correctly found\n", __FILE__);
  36. ifp = dlsym (RTLD_DEFAULT, "found_in_mod1");
  37. if ((void *) ifp == NULL)
  38. {
  39. printf ("%s: found_in_mod1 not found\n", __FILE__);
  40. result = 1;
  41. }
  42. else if (ifp () != 1)
  43. {
  44. printf ("%s: wrong address returned for found_in_mod1\n", __FILE__);
  45. result = 1;
  46. }
  47. else
  48. printf ("%s: found_in_mod1 correctly found\n", __FILE__);
  49. ifp = dlsym (RTLD_DEFAULT, "found_in_mod2");
  50. if ((void *) ifp == NULL)
  51. {
  52. printf ("%s: found_in_mod2 not found\n", __FILE__);
  53. result = 1;
  54. }
  55. else if (ifp () != 2)
  56. {
  57. printf ("%s: wrong address returned for found_in_mod2\n", __FILE__);
  58. result = 1;
  59. }
  60. else
  61. printf ("%s: found_in_mod2 correctly found\n", __FILE__);
  62. return result;
  63. }