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