diff options
author | Patrick Monnerat <pm@datasphere.ch> | 2014-03-04 17:11:02 +0100 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2014-10-04 21:13:47 +0800 |
commit | 6e4d870336a3d892bf5833dc7685c11d64f1d008 (patch) | |
tree | dbe98fb8384d559a20f04cebce505a53e14e7688 /os400 | |
parent | 5621c81b49cf2c2eb7b110d862f4b52b916f82b2 (diff) | |
download | android_external_libxml2-6e4d870336a3d892bf5833dc7685c11d64f1d008.tar.gz android_external_libxml2-6e4d870336a3d892bf5833dc7685c11d64f1d008.tar.bz2 android_external_libxml2-6e4d870336a3d892bf5833dc7685c11d64f1d008.zip |
OS400: UTF8<-->EBCDIC wrappers for system and external library calls
Diffstat (limited to 'os400')
-rw-r--r-- | os400/wrappers.c | 170 | ||||
-rw-r--r-- | os400/wrappers.h | 70 |
2 files changed, 240 insertions, 0 deletions
diff --git a/os400/wrappers.c b/os400/wrappers.c new file mode 100644 index 00000000..9f592b79 --- /dev/null +++ b/os400/wrappers.c @@ -0,0 +1,170 @@ +/** +*** UTF-8/EBCDIC wrappers to system and C library procedures. +*** +*** See Copyright for the status of this software. +*** +*** Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A. +**/ + +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <stdlib.h> +#include <dlfcn.h> +#include <netdb.h> +#include <errno.h> + +#include "config.h" + +#include "libxml/xmlmemory.h" + +#include "transcode.h" + + +static const char * lxdles = NULL; + + +int +_lx_getaddrinfo(const char * node, const char * service, + const struct addrinfo * hints, struct addrinfo * * res) + +{ + xmlDictPtr d = NULL; + int i; + + i = getaddrinfo(xmlTranscodeResult(node, NULL, &d, NULL), + xmlTranscodeResult(service, NULL, &d, NULL), hints, res); + xmlZapDict(&d); + return i; +} + + +const char * +_lx_inet_ntop(int af, const void * src, char * dst, socklen_t size) + +{ + const char * cp1 = inet_ntop(af, src, dst, size); + char const * cp2; + int i; + + if (!cp1) + return cp1; + + if (!(cp2 = xmlTranscodeString(cp1, NULL, NULL))) + return cp2; + + i = strlen(cp2); + + if (i >= size) { + xmlFree((char *) cp2); + errno = ENOSPC; + return (const char *) NULL; + } + + memcpy(dst, cp2, i + 1); + xmlFree((char *) cp2); + return dst; +} + + +void * +_lx_dlopen(const char * filename, int flag) + +{ + xmlDictPtr d = NULL; + void * result; + + result = dlopen(xmlTranscodeResult(filename, NULL, &d, NULL), flag); + xmlZapDict(&d); + return result; +} + + +void * +_lx_dlsym(void * handle, const char * symbol) + +{ + xmlDictPtr d = NULL; + void * result; + + result = dlsym(handle, xmlTranscodeResult(symbol, NULL, &d, NULL)); + xmlZapDict(&d); + return result; +} + + +char * +_lx_dlerror(void) + +{ + char * cp1 = (char *) dlerror(); + + if (!cp1) + return cp1; + + if (lxdles) + xmlFree((char *) lxdles); + + lxdles = (const char *) xmlTranscodeString(cp1, NULL, NULL); + return (char *) lxdles; +} + + +#ifdef HAVE_ZLIB_H +#include <zlib.h> + +gzFile +_lx_gzopen(const char * path, const char * mode) + +{ + xmlDictPtr d = NULL; + gzFile f; + + f = gzopen(xmlTranscodeResult(path, NULL, &d, NULL), + xmlTranscodeResult(mode, NULL, &d, NULL)); + xmlZapDict(&d); + return f; +} + + +gzFile +_lx_gzdopen(int fd, const char * mode) + +{ + xmlDictPtr d = NULL; + gzFile f; + + f = gzdopen(fd, xmlTranscodeResult(mode, NULL, &d, NULL)); + xmlZapDict(&d); + return f; +} + +int +_lx_inflateInit2_(z_streamp strm, int windowBits, + const char * version, int stream_size) + +{ + xmlDictPtr d = NULL; + int r; + + r = inflateInit2_(strm, windowBits, + xmlTranscodeResult(version, NULL, &d, NULL), stream_size); + xmlZapDict(&d); + return r; +} + +int +_lx_deflateInit2_(z_streamp strm, int level, int method, int windowBits, + int memLevel, int strategy, const char * version, int stream_size) + +{ + xmlDictPtr d = NULL; + int r; + + r = deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + xmlTranscodeResult(version, NULL, &d, NULL), stream_size); + xmlZapDict(&d); + return r; +} + +#endif diff --git a/os400/wrappers.h b/os400/wrappers.h new file mode 100644 index 00000000..388ec8c2 --- /dev/null +++ b/os400/wrappers.h @@ -0,0 +1,70 @@ +/** +*** Replace system/C library calls by EBCDIC wrappers. +*** This is a layer inserted between libxml2 itself and the EBCDIC +*** environment. +*** +*** See Copyright for the status of this software. +*** +*** Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A. +**/ + +#ifndef __WRAPPERS_H_ +#define __WRAPPERS_H_ + +/** +*** OS/400 specific defines. +**/ + +#define __cplusplus__strings__ + +/** +*** Force header inclusions before renaming procedures to UTF-8 wrappers. +**/ + +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netdb.h> + +#include "dlfcn.h" + + +/** +*** UTF-8 wrappers prototypes. +**/ + +extern int _lx_getaddrinfo(const char * node, const char * service, + const struct addrinfo * hints, struct addrinfo * * res); +extern const char * + _lx_inet_ntop(int af, + const void * src, char * dst, socklen_t size); +extern void * _lx_dlopen(const char * filename, int flag); +extern void * _lx_dlsym(void * handle, const char * symbol); +extern char * _lx_dlerror(void); + + +#ifdef HAVE_ZLIB_H + +#include <zlib.h> + +extern gzFile _lx_gzopen(const char * path, const char * mode); +extern gzFile _lx_gzdopen(int fd, const char * mode); + +#endif + + +/** +*** Rename data/procedures to UTF-8 wrappers. +**/ + +#define getaddrinfo _lx_getaddrinfo +#define inet_ntop _lx_inet_ntop +#define dlopen _lx_dlopen +#define dlsym _lx_dlsym +#define dlerror _lx_dlerror +#define gzopen _lx_gzopen +#define gzdopen _lx_gzdopen +#define inflateInit2_ _lx_inflateInit2_ +#define deflateInit2_ _lx_deflateInit2_ + +#endif |