blob: a95ab66acdfd799e7446d36f181d334e33d30c8b [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
Stéphane Michaut454e3972017-08-28 14:30:43 +020011/* In order RTLD_GLOBAL and RTLD_NOW to be defined on zOS */
12#if defined(__MVS__)
13#define _UNIX03_SOURCE
14#endif
15
Daniel Veillardce1648b2005-01-04 15:10:22 +000016#define IN_LIBXML
17#include "libxml.h"
18
19#include <string.h>
20#include <libxml/xmlmemory.h>
21#include <libxml/xmlerror.h>
22#include <libxml/xmlmodule.h>
23#include <libxml/globals.h>
24
25#ifdef LIBXML_MODULES_ENABLED
26
27struct _xmlModule {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000028 unsigned char *name;
29 void *handle;
Daniel Veillardce1648b2005-01-04 15:10:22 +000030};
31
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000032static void *xmlModulePlatformOpen(const char *name);
33static int xmlModulePlatformClose(void *handle);
Daniel Veillardbe076e92005-01-04 20:18:14 +000034static int xmlModulePlatformSymbol(void *handle, const char *name, void **result);
Daniel Veillardce1648b2005-01-04 15:10:22 +000035
36/************************************************************************
37 * *
Daniel Veillardf8e3db02012-09-11 13:26:36 +080038 * module memory error handler *
Daniel Veillardce1648b2005-01-04 15:10:22 +000039 * *
40 ************************************************************************/
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000041
Daniel Veillardce1648b2005-01-04 15:10:22 +000042/**
43 * xmlModuleErrMemory:
44 * @extra: extra information
45 *
46 * Handle an out of memory condition
47 */
48static void
49xmlModuleErrMemory(xmlModulePtr module, const char *extra)
50{
51 const char *name = NULL;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000052
Daniel Veillardce1648b2005-01-04 15:10:22 +000053 if (module != NULL) {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000054 name = (const char *) module->name;
Daniel Veillardce1648b2005-01-04 15:10:22 +000055 }
56
57 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
58 XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
59 name, NULL, 0, 0,
60 "Memory allocation failed : %s\n", extra);
61}
62
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000063/**
64 * xmlModuleOpen:
65 * @name: the module name
Daniel Veillard48df9612005-01-04 21:50:05 +000066 * @options: a set of xmlModuleOption
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000067 *
68 * Opens a module/shared library given its name or path
Patrick Gansterer5a82e482012-08-13 17:39:06 +080069 * NOTE: that due to portability issues, behaviour can only be
70 * guaranteed with @name using ASCII. We canot guarantee that
71 * an UTF-8 string would work, which is why name is a const char *
72 * and not a const xmlChar * .
Daniel Veillard48df9612005-01-04 21:50:05 +000073 * TODO: options are not yet implemented.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000074 *
75 * Returns a handle for the module or NULL in case of error
76 */
77xmlModulePtr
Daniel Veillard48df9612005-01-04 21:50:05 +000078xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED)
Daniel Veillardce1648b2005-01-04 15:10:22 +000079{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000080 xmlModulePtr module;
Daniel Veillardce1648b2005-01-04 15:10:22 +000081
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000082 module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule));
83 if (module == NULL) {
84 xmlModuleErrMemory(NULL, "creating module");
85 return (NULL);
86 }
Daniel Veillardce1648b2005-01-04 15:10:22 +000087
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000088 memset(module, 0, sizeof(xmlModule));
Daniel Veillardce1648b2005-01-04 15:10:22 +000089
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000090 module->handle = xmlModulePlatformOpen(name);
Daniel Veillardce1648b2005-01-04 15:10:22 +000091
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000092 if (module->handle == NULL) {
93 xmlFree(module);
94 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
95 XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
96 name, NULL, 0, 0, "failed to open %s\n", name);
Daniel Veillard24505b02005-07-28 23:49:35 +000097 return(NULL);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +000098 }
99
100 module->name = xmlStrdup((const xmlChar *) name);
101 return (module);
102}
103
104/**
105 * xmlModuleSymbol:
106 * @module: the module
107 * @name: the name of the symbol
Daniel Veillardbe076e92005-01-04 20:18:14 +0000108 * @symbol: the resulting symbol address
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000109 *
110 * Lookup for a symbol address in the given module
Patrick Gansterer5a82e482012-08-13 17:39:06 +0800111 * NOTE: that due to portability issues, behaviour can only be
112 * guaranteed with @name using ASCII. We canot guarantee that
113 * an UTF-8 string would work, which is why name is a const char *
114 * and not a const xmlChar * .
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000115 *
Daniel Veillardbe076e92005-01-04 20:18:14 +0000116 * Returns 0 if the symbol was found, or -1 in case of error
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000117 */
Daniel Veillardbe076e92005-01-04 20:18:14 +0000118int
119xmlModuleSymbol(xmlModulePtr module, const char *name, void **symbol)
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000120{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000121 int rc = -1;
Daniel Veillardf8e3db02012-09-11 13:26:36 +0800122
Gaurav085b9972014-02-18 11:47:43 +0800123 if ((NULL == module) || (symbol == NULL) || (name == NULL)) {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000124 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
125 XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000126 NULL, NULL, 0, 0, "null parameter\n");
127 return rc;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000128 }
129
Daniel Veillardbe076e92005-01-04 20:18:14 +0000130 rc = xmlModulePlatformSymbol(module->handle, name, symbol);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000131
Daniel Veillardbe076e92005-01-04 20:18:14 +0000132 if (rc == -1) {
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000133 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
134 XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000135 name, NULL, 0, 0,
136 "failed to find symbol: %s\n",
137 (name == NULL ? "NULL" : name));
138 return rc;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000139 }
140
Daniel Veillardbe076e92005-01-04 20:18:14 +0000141 return rc;
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000142}
143
144/**
145 * xmlModuleClose:
146 * @module: the module handle
147 *
148 * The close operations unload the associated module and free the
149 * data associated to the module.
150 *
151 * Returns 0 in case of success, -1 in case of argument error and -2
152 * if the module could not be closed/unloaded.
153 */
154int
155xmlModuleClose(xmlModulePtr module)
156{
157 int rc;
158
159 if (NULL == module) {
160 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000161 XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
162 NULL, NULL, 0, 0, "null module pointer\n");
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000163 return -1;
164 }
165
166 rc = xmlModulePlatformClose(module->handle);
167
168 if (rc != 0) {
169 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000170 XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000171 (const char *) module->name, NULL, 0, 0,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000172 "failed to close: %s\n", module->name);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000173 return -2;
174 }
175
176 rc = xmlModuleFree(module);
177 return (rc);
178}
179
180/**
181 * xmlModuleFree:
182 * @module: the module handle
183 *
184 * The free operations free the data associated to the module
185 * but does not unload the associated shared library which may still
186 * be in use.
187 *
188 * Returns 0 in case of success, -1 in case of argument error
189 */
190int
191xmlModuleFree(xmlModulePtr module)
192{
193 if (NULL == module) {
194 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
Daniel Veillard24505b02005-07-28 23:49:35 +0000195 XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL,
Daniel Veillardbe076e92005-01-04 20:18:14 +0000196 NULL, NULL, 0, 0, "null module pointer\n");
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000197 return -1;
198 }
199
200 xmlFree(module->name);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000201 xmlFree(module);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000202
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000203 return (0);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000204}
205
Daniel Veillard643fb5d2008-02-08 10:49:46 +0000206#if defined(HAVE_DLOPEN) && !defined(_WIN32)
Daniel Veillarddcd93902005-01-13 11:25:15 +0000207#ifdef HAVE_DLFCN_H
Daniel Veillardce1648b2005-01-04 15:10:22 +0000208#include <dlfcn.h>
Daniel Veillarddcd93902005-01-13 11:25:15 +0000209#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +0000210
Daniel Veillard9b693b42005-10-28 14:54:17 +0000211#ifndef RTLD_GLOBAL /* For Tru64 UNIX 4.0 */
212#define RTLD_GLOBAL 0
213#endif
214
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000215/**
Daniel Veillardce1648b2005-01-04 15:10:22 +0000216 * xmlModulePlatformOpen:
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000217 * @name: path to the module
218 *
Daniel Veillardce1648b2005-01-04 15:10:22 +0000219 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000220 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000221
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000222static void *
223xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000224{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000225 return dlopen(name, RTLD_GLOBAL | RTLD_NOW);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000226}
227
228/*
229 * xmlModulePlatformClose:
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000230 * @handle: handle to the module
231 *
Daniel Veillardce1648b2005-01-04 15:10:22 +0000232 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000233 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000234
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000235static int
236xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000237{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000238 return dlclose(handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000239}
240
241/*
242 * xmlModulePlatformSymbol:
Daniel Veillardbe076e92005-01-04 20:18:14 +0000243 * http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
244 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000245 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000246
Daniel Veillardbe076e92005-01-04 20:18:14 +0000247static int
248xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000249{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000250 *symbol = dlsym(handle, name);
251 if (dlerror() != NULL) {
252 return -1;
253 }
254 return 0;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000255}
256
Daniel Veillardff4c1852005-03-10 10:37:28 +0000257#else /* ! HAVE_DLOPEN */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000258
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000259#ifdef HAVE_SHLLOAD /* HAVE_SHLLOAD */
Daniel Veillarddcd93902005-01-13 11:25:15 +0000260#ifdef HAVE_DL_H
261#include <dl.h>
262#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +0000263/*
264 * xmlModulePlatformOpen:
265 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000266 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000267
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000268static void *
269xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000270{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000271 return shl_load(name, BIND_IMMEDIATE, 0L);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000272}
273
274/*
275 * xmlModulePlatformClose:
276 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000277 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000278
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000279static int
280xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000281{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000282 return shl_unload(handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000283}
284
285/*
286 * xmlModulePlatformSymbol:
Daniel Veillardbe076e92005-01-04 20:18:14 +0000287 * http://docs.hp.com/en/B2355-90683/shl_load.3X.html
288 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000289 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000290
Daniel Veillardbe076e92005-01-04 20:18:14 +0000291static int
292xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000293{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000294 int rc;
295
296 errno = 0;
Daniel Veillard9b693b42005-10-28 14:54:17 +0000297 rc = shl_findsym(&handle, name, TYPE_UNDEFINED, symbol);
Daniel Veillardbe076e92005-01-04 20:18:14 +0000298 return rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000299}
300
301#endif /* HAVE_SHLLOAD */
Daniel Veillardff4c1852005-03-10 10:37:28 +0000302#endif /* ! HAVE_DLOPEN */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000303
Nick Wellnhofere3890542017-10-09 00:20:01 +0200304#if defined(_WIN32) && !defined(__CYGWIN__)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000305
Nick Wellnhofere3890542017-10-09 00:20:01 +0200306#define WIN32_LEAN_AND_MEAN
Daniel Veillardce1648b2005-01-04 15:10:22 +0000307#include <windows.h>
308
309/*
310 * xmlModulePlatformOpen:
311 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000312 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000313
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000314static void *
315xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000316{
Patrick Gansterer5a82e482012-08-13 17:39:06 +0800317 return LoadLibraryA(name);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000318}
319
320/*
321 * xmlModulePlatformClose:
322 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000323 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000324
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000325static int
326xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000327{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000328 int rc;
329
330 rc = FreeLibrary(handle);
331 return (0 == rc);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000332}
333
334/*
335 * xmlModulePlatformSymbol:
Daniel Veillardbe076e92005-01-04 20:18:14 +0000336 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocaddress.asp
337 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000338 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000339
Daniel Veillardbe076e92005-01-04 20:18:14 +0000340static int
341xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000342{
Nick Wellnhofer13acadb2017-11-12 17:28:12 +0100343XML_IGNORE_PEDANTIC_WARNINGS
Daniel Veillarddfc0aa02012-08-17 11:04:24 +0800344#ifdef _WIN32_WCE
345 /*
346 * GetProcAddressA seems only available on WinCE
347 */
Patrick Gansterer5a82e482012-08-13 17:39:06 +0800348 *symbol = GetProcAddressA(handle, name);
Daniel Veillarddfc0aa02012-08-17 11:04:24 +0800349#else
350 *symbol = GetProcAddress(handle, name);
351#endif
Daniel Veillardbe076e92005-01-04 20:18:14 +0000352 return (NULL == *symbol) ? -1 : 0;
Nick Wellnhofer13acadb2017-11-12 17:28:12 +0100353XML_POP_WARNINGS
Daniel Veillardce1648b2005-01-04 15:10:22 +0000354}
355
356#endif /* _WIN32 */
357
358#ifdef HAVE_BEOS
359
360#include <kernel/image.h>
361
362/*
363 * xmlModulePlatformOpen:
364 * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html
365 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000366 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000367
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000368static void *
369xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000370{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000371 return (void *) load_add_on(name);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000372}
373
374/*
375 * xmlModulePlatformClose:
376 * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html
377 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000378 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000379
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000380static int
381xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000382{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000383 status_t rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000384
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000385 rc = unload_add_on((image_id) handle);
386
387 if (rc == B_OK)
388 return 0;
389 else
390 return -1;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000391}
392
393/*
394 * xmlModulePlatformSymbol:
395 * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html
Daniel Veillardbe076e92005-01-04 20:18:14 +0000396 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000397 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000398
Daniel Veillardbe076e92005-01-04 20:18:14 +0000399static int
400xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000401{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000402 status_t rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000403
Daniel Veillardbe076e92005-01-04 20:18:14 +0000404 rc = get_image_symbol((image_id) handle, name, B_SYMBOL_TYPE_ANY, symbol);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000405
Daniel Veillardbe076e92005-01-04 20:18:14 +0000406 return (rc == B_OK) ? 0 : -1;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000407}
408
409#endif /* HAVE_BEOS */
410
411#ifdef HAVE_OS2
412
413#include <os2.h>
414
415/*
416 * xmlModulePlatformOpen:
417 * os2 api info: http://www.edm2.com/os2api/Dos/DosLoadModule.html
418 * returns a handle on success, and zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000419 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000420
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000421static void *
422xmlModulePlatformOpen(const char *name)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000423{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000424 char errbuf[256];
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000425 void *handle;
426 int rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000427
Daniel Veillardbe076e92005-01-04 20:18:14 +0000428 rc = DosLoadModule(errbuf, sizeof(errbuf) - 1, name, &handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000429
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000430 if (rc)
431 return 0;
432 else
433 return (handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000434}
435
436/*
437 * xmlModulePlatformClose:
438 * os2 api info: http://www.edm2.com/os2api/Dos/DosFreeModule.html
439 * returns 0 on success, and non-zero on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000440 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000441
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000442static int
443xmlModulePlatformClose(void *handle)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000444{
Daniel Veillardbe076e92005-01-04 20:18:14 +0000445 return DosFreeModule(handle);
Daniel Veillardce1648b2005-01-04 15:10:22 +0000446}
447
448/*
449 * xmlModulePlatformSymbol:
450 * os2 api info: http://www.edm2.com/os2api/Dos/DosQueryProcAddr.html
Daniel Veillardbe076e92005-01-04 20:18:14 +0000451 * returns 0 on success and the loaded symbol in result, and -1 on error.
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000452 */
Daniel Veillardce1648b2005-01-04 15:10:22 +0000453
Daniel Veillardbe076e92005-01-04 20:18:14 +0000454static int
455xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
Daniel Veillardce1648b2005-01-04 15:10:22 +0000456{
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000457 int rc;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000458
Daniel Veillardbe076e92005-01-04 20:18:14 +0000459 rc = DosQueryProcAddr(handle, 0, name, symbol);
Daniel Veillardf6b71bd2005-01-04 17:50:14 +0000460
Daniel Veillardbe076e92005-01-04 20:18:14 +0000461 return (rc == NO_ERROR) ? 0 : -1;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000462}
463
464#endif /* HAVE_OS2 */
465
Daniel Veillard5d4644e2005-04-01 13:11:58 +0000466#define bottom_xmlmodule
467#include "elfgcchack.h"
Daniel Veillardce1648b2005-01-04 15:10:22 +0000468#endif /* LIBXML_MODULES_ENABLED */