dladdr.c 656 B

12345678910111213141516171819202122232425
  1. #include <dlfcn.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. int main(int argc, char **argv)
  6. {
  7. Dl_info info;
  8. int res = 0;
  9. memset(&info, '\0', sizeof(Dl_info));
  10. res = dladdr((void *)1, &info);
  11. if (res != 0) {
  12. fprintf(stderr, "dladdr() should fail\n");
  13. fprintf(stderr, "dli_fname = %s\n", info.dli_fname);
  14. fprintf(stderr, "dli_fbase = 0x%08x\n", (unsigned int)info.dli_fbase);
  15. fprintf(stderr, "dli_sname = %s\n", info.dli_sname);
  16. fprintf(stderr, "dli_saddr = 0x%08x\n", (unsigned int)info.dli_saddr);
  17. exit(1);
  18. }
  19. fprintf(stderr, "dladdr() failed as expected\n");
  20. return EXIT_SUCCESS;
  21. }