blob: 50ed666af7843309261733065d49857a49d8575a [file] [log] [blame]
Daniel Veillardce1648b2005-01-04 15:10:22 +00001/*
Daniel Veillardf6b71bd2005-01-04 17:50:14 +00002 * xmlmodule.c : basic API for dynamic module loading added 2.6.17
Daniel Veillardce1648b2005-01-04 15:10:22 +00003 *
4 * See Copyright for the status of this software.
5 *
6 * joelwreed@comcast.net
Daniel Veillardbe076e92005-01-04 20:18:14 +00007 *
8 * http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html
Daniel Veillardce1648b2005-01-04 15:10:22 +00009 */
10
11#define IN_LIBXML
12#include "libxml.h"
13
14#include <string.h>
15#include <libxml/xmlmemory.h>
16#include <libxml/xmlerror.h>
17#include <libxml/xmlmodule.h>
18#include <libxml/globals.h>
19
20#ifdef LIBXML_MODULES_ENABLED
21
22struct _xmlModule {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000023 unsigned char *name;
24 void *handle;
Daniel Veillardce1648b2005-01-04 15:10:22 +000025};
26
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000027static void *xmlModulePlatformOpen(const char *name);
28static int xmlModulePlatformClose(void *handle);
Daniel Veillardbe076e92005-01-04 20:18:14 +000029static int xmlModulePlatformSymbol(void *handle, const char *name, void **result);
Daniel Veillardce1648b2005-01-04 15:10:22 +000030
31/************************************************************************
32 * *
Daniel Veillardf8e3db02012-09-11 13:26:36 +080033 * module memory error handler *
Daniel Veillardce1648b2005-01-04 15:10:22 +000034 * *
35 ************************************************************************/
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000036
Daniel Veillardce1648b2005-01-04 15:10:22 +000037/**
38 * xmlModuleErrMemory:
39 * @extra: extra information
40 *
41 * Handle an out of memory condition
42 */
43static void
44xmlModuleErrMemory(xmlModulePtr module, const char *extra)
45{
46 const char *name = NULL;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000047
Daniel Veillardce1648b2005-01-04 15:10:22 +000048 if (module != NULL) {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000049 name = (const char *) module->name;
Daniel Veillardce1648b2005-01-04 15:10:22 +000050 }
51
52 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
53 XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
54 name, NULL, 0, 0,
55 "Memory allocation failed : %s\n", extra);
56}
57
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000058/**
59 * xmlModuleOpen:
60 * @name: the module name
Daniel Veillard48df9612005-01-04 21:50:05 +000061 * @options: a set of xmlModuleOption
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000062 *
63 * Opens a module/shared library given its name or path
Patrick Gansterer5a82e482012-08-13 17:39:06 +080064 * NOTE: that due to portability issues, behaviour can only be
65 * guaranteed with @name using ASCII. We canot guarantee that
66 * an UTF-8 string would work, which is why name is a const char *
67 * and not a const xmlChar * .
Daniel Veillard48df9612005-01-04 21:50:05 +000068 * TODO: options are not yet implemented.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000069 *
70 * Returns a handle for the module or NULL in case of error
71 */
72xmlModulePtr
Daniel Veillard48df9612005-01-04 21:50:05 +000073xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED)
Daniel Veillardce1648b2005-01-04 15:10:22 +000074{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000075 xmlModulePtr module;
Daniel Veillardce1648b2005-01-04 15:10:22 +000076
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000077 module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule));
78 if (module == NULL) {
79 xmlModuleErrMemory(NULL, "creating module");
80 return (NULL);
81 }
Daniel Veillardce1648b2005-01-04 15:10:22 +000082
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000083 memset(module, 0, sizeof(xmlModule));
Daniel Veillardce1648b2005-01-04 15:10:22 +000084
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000085 module->handle = xmlModulePlatformOpen(name);
Daniel Veillardce1648b2005-01-04 15:10:22 +000086
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000087 if (module->handle == NULL) {
88 xmlFree(module);
89 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
90 XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
91 name, NULL, 0, 0, "failed to open %s\n", name);
Daniel Veillard24505b02005-07-28 23:49:35 +000092 return(NULL);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000093 }
94
95 module->name = xmlStrdup((const xmlChar *) name);
96 return (module);
97}
98
99/**
100 * xmlModuleSymbol:
101 * @module: the module
102 * @name: the name of the symbol
Daniel Veillardbe076e92005-01-04 20:18:14 +0000103 * @symbol: the resulting symbol address
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000104 *
105 * Lookup for a symbol address in the given module
Patrick Gansterer5a82e482012-08-13 17:39:06 +0800106 * NOTE: that due to portability issues, behaviour can only be
107 * guaranteed with @name using ASCII. We canot guarantee that
108 * an UTF-8 string would work, which is why name is a const char *
109 * and not a const xmlChar * .
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000110 *
Daniel Veillardbe076e92005-01-04 20:18:14 +0000111 * Returns 0 if the symbol was found, or -1 in case of error
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000112 */
Daniel Veillardbe076e92005-01-04 20:18:14 +0000113int
114xmlModuleSymbol(xmlModulePtr module, const char *name, void **symbol)
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000115{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000116 int rc = -1;
Daniel Veillardf8e3db02012-09-11 13:26:36 +0800117
Gaurav085b9972014-02-18 11:47:43 +0800118 if ((NULL == module) || (symbol == NULL) || (name == NULL)) {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000119 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
120 XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000121 NULL, NULL, 0, 0, "null parameter\n");
122 return rc;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000123 }
124
Daniel Veillardbe076e92005-01-04 20:18:14 +0000125 rc = xmlModulePlatformSymbol(module->handle, name, symbol);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000126
Daniel Veillardbe076e92005-01-04 20:18:14 +0000127 if (rc == -1) {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000128 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
129 XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000130 name, NULL, 0, 0,
131 "failed to find symbol: %s\n",
132 (name == NULL ? "NULL" : name));
133 return rc;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000134 }
135
Daniel Veillardbe076e92005-01-04 20:18:14 +0000136 return rc;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000137}
138
139/**
140 * xmlModuleClose:
141 * @module: the module handle
142 *
143 * The close operations unload the associated module and free the
144 * data associated to the module.
145 *
146 * Returns 0 in case of success, -1 in case of argument error and -2
147 * if the module could not be closed/unloaded.
148 */
149int
150xmlModuleClose(xmlModulePtr module)
151{
152 int rc;
153
154 if (NULL == module) {
155 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000156 XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
157 NULL, NULL, 0, 0, "null module pointer\n");
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000158 return -1;
159 }
160
161 rc = xmlModulePlatformClose(module->handle);
162
163 if (rc != 0) {
164 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000165 XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000166 (const char *) module->name, NULL, 0, 0,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000167 "failed to close: %s\n", module->name);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000168 return -2;
169 }
170
171 rc = xmlModuleFree(module);
172 return (rc);
173}
174
175/**
176 * xmlModuleFree:
177 * @module: the module handle
178 *
179 * The free operations free the data associated to the module
180 * but does not unload the associated shared library which may still
181 * be in use.
182 *
183 * Returns 0 in case of success, -1 in case of argument error
184 */
185int
186xmlModuleFree(xmlModulePtr module)
187{
188 if (NULL == module) {
189 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
Daniel Veillard24505b02005-07-28 23:49:35 +0000190 XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000191 NULL, NULL, 0, 0, "null module pointer\n");
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000192 return -1;
193 }
194
195 xmlFree(module->name);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000196 xmlFree(module);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000197
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000198 return (0);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000199}
200
Daniel Veillard643fb5d2008-02-08 10:49:46 +0000201#if defined(HAVE_DLOPEN) && !defined(_WIN32)
Daniel Veillarddcd93902005-01-13 11:25:15 +0000202#ifdef HAVE_DLFCN_H
Daniel Veillardce1648b2005-01-04 15:10:22 +0000203#include <dlfcn.h>
Daniel Veillarddcd93902005-01-13 11:25:15 +0000204#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +0000205
Daniel Veillard9b693b42005-10-28 14:54:17 +0000206#ifndef RTLD_GLOBAL /* For Tru64 UNIX 4.0 */
207#define RTLD_GLOBAL 0
208#endif
209
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000210/**
Daniel Veillardce1648b2005-01-04 15:10:22 +0000211 * xmlModulePlatformOpen:
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000212 * @name: path to the module
213 *
Daniel Veillardce1648b2005-01-04 15:10:22 +0000214 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000215 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000216
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000217static void *
218xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000219{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000220 return dlopen(name, RTLD_GLOBAL | RTLD_NOW);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000221}
222
223/*
224 * xmlModulePlatformClose:
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000225 * @handle: handle to the module
226 *
Daniel Veillardce1648b2005-01-04 15:10:22 +0000227 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000228 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000229
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000230static int
231xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000232{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000233 return dlclose(handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000234}
235
236/*
237 * xmlModulePlatformSymbol:
Daniel Veillardbe076e92005-01-04 20:18:14 +0000238 * http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
239 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000240 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000241
Daniel Veillardbe076e92005-01-04 20:18:14 +0000242static int
243xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000244{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000245 *symbol = dlsym(handle, name);
246 if (dlerror() != NULL) {
247 return -1;
248 }
249 return 0;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000250}
251
Daniel Veillardff4c1852005-03-10 10:37:28 +0000252#else /* ! HAVE_DLOPEN */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000253
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000254#ifdef HAVE_SHLLOAD /* HAVE_SHLLOAD */
Daniel Veillarddcd93902005-01-13 11:25:15 +0000255#ifdef HAVE_DL_H
256#include <dl.h>
257#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +0000258/*
259 * xmlModulePlatformOpen:
260 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000261 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000262
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000263static void *
264xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000265{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000266 return shl_load(name, BIND_IMMEDIATE, 0L);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000267}
268
269/*
270 * xmlModulePlatformClose:
271 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000272 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000273
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000274static int
275xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000276{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000277 return shl_unload(handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000278}
279
280/*
281 * xmlModulePlatformSymbol:
Daniel Veillardbe076e92005-01-04 20:18:14 +0000282 * http://docs.hp.com/en/B2355-90683/shl_load.3X.html
283 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000284 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000285
Daniel Veillardbe076e92005-01-04 20:18:14 +0000286static int
287xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000288{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000289 int rc;
290
291 errno = 0;
Daniel Veillard9b693b42005-10-28 14:54:17 +0000292 rc = shl_findsym(&handle, name, TYPE_UNDEFINED, symbol);
Daniel Veillardbe076e92005-01-04 20:18:14 +0000293 return rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000294}
295
296#endif /* HAVE_SHLLOAD */
Daniel Veillardff4c1852005-03-10 10:37:28 +0000297#endif /* ! HAVE_DLOPEN */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000298
299#ifdef _WIN32
300
301#include <windows.h>
302
303/*
304 * xmlModulePlatformOpen:
305 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000306 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000307
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000308static void *
309xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000310{
Patrick Gansterer5a82e482012-08-13 17:39:06 +0800311 return LoadLibraryA(name);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000312}
313
314/*
315 * xmlModulePlatformClose:
316 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000317 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000318
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000319static int
320xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000321{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000322 int rc;
323
324 rc = FreeLibrary(handle);
325 return (0 == rc);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000326}
327
328/*
329 * xmlModulePlatformSymbol:
Daniel Veillardbe076e92005-01-04 20:18:14 +0000330 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocaddress.asp
331 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000332 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000333
Daniel Veillardbe076e92005-01-04 20:18:14 +0000334static int
335xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000336{
Daniel Veillarddfc0aa02012-08-17 11:04:24 +0800337#ifdef _WIN32_WCE
338 /*
339 * GetProcAddressA seems only available on WinCE
340 */
Patrick Gansterer5a82e482012-08-13 17:39:06 +0800341 *symbol = GetProcAddressA(handle, name);
Daniel Veillarddfc0aa02012-08-17 11:04:24 +0800342#else
343 *symbol = GetProcAddress(handle, name);
344#endif
Daniel Veillardbe076e92005-01-04 20:18:14 +0000345 return (NULL == *symbol) ? -1 : 0;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000346}
347
348#endif /* _WIN32 */
349
350#ifdef HAVE_BEOS
351
352#include <kernel/image.h>
353
354/*
355 * xmlModulePlatformOpen:
356 * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html
357 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000358 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000359
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000360static void *
361xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000362{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000363 return (void *) load_add_on(name);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000364}
365
366/*
367 * xmlModulePlatformClose:
368 * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html
369 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000370 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000371
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000372static int
373xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000374{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000375 status_t rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000376
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000377 rc = unload_add_on((image_id) handle);
378
379 if (rc == B_OK)
380 return 0;
381 else
382 return -1;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000383}
384
385/*
386 * xmlModulePlatformSymbol:
387 * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html
Daniel Veillardbe076e92005-01-04 20:18:14 +0000388 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000389 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000390
Daniel Veillardbe076e92005-01-04 20:18:14 +0000391static int
392xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000393{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000394 status_t rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000395
Daniel Veillardbe076e92005-01-04 20:18:14 +0000396 rc = get_image_symbol((image_id) handle, name, B_SYMBOL_TYPE_ANY, symbol);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000397
Daniel Veillardbe076e92005-01-04 20:18:14 +0000398 return (rc == B_OK) ? 0 : -1;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000399}
400
401#endif /* HAVE_BEOS */
402
403#ifdef HAVE_OS2
404
405#include <os2.h>
406
407/*
408 * xmlModulePlatformOpen:
409 * os2 api info: http://www.edm2.com/os2api/Dos/DosLoadModule.html
410 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000411 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000412
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000413static void *
414xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000415{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000416 char errbuf[256];
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000417 void *handle;
418 int rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000419
Daniel Veillardbe076e92005-01-04 20:18:14 +0000420 rc = DosLoadModule(errbuf, sizeof(errbuf) - 1, name, &handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000421
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000422 if (rc)
423 return 0;
424 else
425 return (handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000426}
427
428/*
429 * xmlModulePlatformClose:
430 * os2 api info: http://www.edm2.com/os2api/Dos/DosFreeModule.html
431 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000432 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000433
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000434static int
435xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000436{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000437 return DosFreeModule(handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000438}
439
440/*
441 * xmlModulePlatformSymbol:
442 * os2 api info: http://www.edm2.com/os2api/Dos/DosQueryProcAddr.html
Daniel Veillardbe076e92005-01-04 20:18:14 +0000443 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000444 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000445
Daniel Veillardbe076e92005-01-04 20:18:14 +0000446static int
447xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000448{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000449 int rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000450
Daniel Veillardbe076e92005-01-04 20:18:14 +0000451 rc = DosQueryProcAddr(handle, 0, name, symbol);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000452
Daniel Veillardbe076e92005-01-04 20:18:14 +0000453 return (rc == NO_ERROR) ? 0 : -1;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000454}
455
456#endif /* HAVE_OS2 */
457
Daniel Veillard5d4644e2005-04-01 13:11:58 +0000458#define bottom_xmlmodule
459#include "elfgcchack.h"
Daniel Veillardce1648b2005-01-04 15:10:22 +0000460#endif /* LIBXML_MODULES_ENABLED */