testModule.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * testModule.c : a small tester program for xmlModule
  3. *
  4. * See Copyright for the status of this software.
  5. *
  6. * joelwreed@comcast.net
  7. */
  8. #include <stdio.h>
  9. #include <libxml/xmlversion.h>
  10. #ifdef LIBXML_MODULES_ENABLED
  11. #include <limits.h>
  12. #include <string.h>
  13. #include <stdarg.h>
  14. #include <libxml/xmlmemory.h>
  15. #include <libxml/debugXML.h>
  16. #include <libxml/xmlmodule.h>
  17. #ifdef _WIN32
  18. #define MODULE_PATH "."
  19. #include <stdlib.h> /* for _MAX_PATH */
  20. #ifndef __MINGW32__
  21. #define PATH_MAX _MAX_PATH
  22. #endif
  23. #else
  24. #define MODULE_PATH ".libs"
  25. #endif
  26. /* Used for SCO Openserver*/
  27. #ifndef PATH_MAX
  28. #ifdef _POSIX_PATH_MAX
  29. #define PATH_MAX _POSIX_PATH_MAX
  30. #else
  31. #define PATH_MAX 4096
  32. #endif
  33. #endif
  34. typedef int (*hello_world_t)(void);
  35. int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
  36. xmlChar filename[PATH_MAX];
  37. xmlModulePtr module = NULL;
  38. hello_world_t hello_world = NULL;
  39. /* build the module filename, and confirm the module exists */
  40. xmlStrPrintf(filename, sizeof(filename),
  41. "%s/testdso%s",
  42. (const xmlChar*)MODULE_PATH,
  43. (const xmlChar*)LIBXML_MODULE_EXTENSION);
  44. module = xmlModuleOpen((const char*)filename, 0);
  45. if (module == NULL) {
  46. fprintf(stderr, "Failed to open module\n");
  47. return(1);
  48. }
  49. if (xmlModuleSymbol(module, "hello_world", (void **) &hello_world)) {
  50. fprintf(stderr, "Failure to lookup\n");
  51. return(1);
  52. }
  53. if (hello_world == NULL) {
  54. fprintf(stderr, "Lookup returned NULL\n");
  55. return(1);
  56. }
  57. (*hello_world)();
  58. xmlModuleClose(module);
  59. return(0);
  60. }
  61. #else
  62. int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
  63. printf("%s : Module support not compiled in\n", argv[0]);
  64. return(0);
  65. }
  66. #endif /* LIBXML_SCHEMAS_ENABLED */