testModule.c 1.8 KB

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