dl.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef _DL_H
  2. #define _DL_H
  3. #include "common.h"
  4. #include <dlfcn.h>
  5. #include <bdlib/src/String.h>
  6. #include <bdlib/src/HashTable.h>
  7. extern const char *dlsym_error;
  8. #define DLSYM(_handle, x) \
  9. dlerror(); \
  10. x##_t x; \
  11. *(void **) (&x) = dlsym(_handle, #x); \
  12. dlsym_error = dlerror(); \
  13. if (dlsym_error) { \
  14. sdprintf("%s", dlsym_error); \
  15. return(1); \
  16. }
  17. #define DLSYM_GLOBAL_FWDCOMPAT(_handle, x) do { \
  18. dlerror(); \
  19. if ((dl_symbol_table[#x] = (FunctionPtr) ((x##_t) dlsym(_handle, #x))) == \
  20. NULL) { \
  21. if ((dl_symbol_table[#x] = \
  22. (FunctionPtr) ((x##_t) dlsym(NULL, "_" #x))) == NULL) { \
  23. dlsym_error = dlerror(); \
  24. if (dlsym_error) { \
  25. fprintf(stderr, "%s", dlsym_error); \
  26. return(1); \
  27. } \
  28. } \
  29. } else { \
  30. my_symbols << #x; \
  31. } \
  32. } while (0)
  33. #define DLSYM_GLOBAL(_handle, x) do { \
  34. dlerror(); \
  35. dl_symbol_table[#x] = (FunctionPtr) ((x##_t) dlsym(_handle, #x)); \
  36. dlsym_error = dlerror(); \
  37. if (dlsym_error) { \
  38. fprintf(stderr, "%s", dlsym_error); \
  39. return(1); \
  40. } \
  41. my_symbols << #x; \
  42. } while (0)
  43. #define DLSYM_GLOBAL_SIMPLE(_handle, x) ( \
  44. dl_symbol_table[#x] = (FunctionPtr) ((x##_t) dlsym(_handle, #x)), \
  45. dl_symbol_table[#x] \
  46. )
  47. #define DLSYM_VAR(x) ((x##_t)dl_symbol_table[#x])
  48. extern bd::HashTable<bd::String, FunctionPtr> dl_symbol_table;
  49. #ifdef GENERATE_DEFS
  50. #undef DLSYM_GLOBAL
  51. #undef DLSYM_GLOBAL_FWDCOMPAT
  52. #endif
  53. #endif /* !_DL_H_ */