1 /**
2 *** UTF-8/EBCDIC wrappers to system and C library procedures.
3 ***
4 *** See Copyright for the status of this software.
5 ***
6 *** Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
7 **/
8
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <arpa/inet.h>
12 #include <stdlib.h>
13 #include <dlfcn.h>
14 #include <netdb.h>
15 #include <errno.h>
16
17 #include "config.h"
18
19 #include "libxml/xmlmemory.h"
20
21 #include "transcode.h"
22
23
24 static const char * lxdles = NULL;
25
26
27 int
_lx_getaddrinfo(const char * node,const char * service,const struct addrinfo * hints,struct addrinfo ** res)28 _lx_getaddrinfo(const char * node, const char * service,
29 const struct addrinfo * hints, struct addrinfo * * res)
30
31 {
32 xmlDictPtr d = NULL;
33 int i;
34
35 i = getaddrinfo(xmlTranscodeResult(node, NULL, &d, NULL),
36 xmlTranscodeResult(service, NULL, &d, NULL), hints, res);
37 xmlZapDict(&d);
38 return i;
39 }
40
41
42 const char *
_lx_inet_ntop(int af,const void * src,char * dst,socklen_t size)43 _lx_inet_ntop(int af, const void * src, char * dst, socklen_t size)
44
45 {
46 const char * cp1 = inet_ntop(af, src, dst, size);
47 char const * cp2;
48 int i;
49
50 if (!cp1)
51 return cp1;
52
53 if (!(cp2 = xmlTranscodeString(cp1, NULL, NULL)))
54 return cp2;
55
56 i = strlen(cp2);
57
58 if (i >= size) {
59 xmlFree((char *) cp2);
60 errno = ENOSPC;
61 return (const char *) NULL;
62 }
63
64 memcpy(dst, cp2, i + 1);
65 xmlFree((char *) cp2);
66 return dst;
67 }
68
69
70 void *
_lx_dlopen(const char * filename,int flag)71 _lx_dlopen(const char * filename, int flag)
72
73 {
74 xmlDictPtr d = NULL;
75 void * result;
76
77 result = dlopen(xmlTranscodeResult(filename, NULL, &d, NULL), flag);
78 xmlZapDict(&d);
79 return result;
80 }
81
82
83 void *
_lx_dlsym(void * handle,const char * symbol)84 _lx_dlsym(void * handle, const char * symbol)
85
86 {
87 xmlDictPtr d = NULL;
88 void * result;
89
90 result = dlsym(handle, xmlTranscodeResult(symbol, NULL, &d, NULL));
91 xmlZapDict(&d);
92 return result;
93 }
94
95
96 char *
_lx_dlerror(void)97 _lx_dlerror(void)
98
99 {
100 char * cp1 = (char *) dlerror();
101
102 if (!cp1)
103 return cp1;
104
105 if (lxdles)
106 xmlFree((char *) lxdles);
107
108 lxdles = (const char *) xmlTranscodeString(cp1, NULL, NULL);
109 return (char *) lxdles;
110 }
111
112
113 #ifdef LIBXML_ZLIB_ENABLED
114 #include <zlib.h>
115
116 gzFile
_lx_gzopen(const char * path,const char * mode)117 _lx_gzopen(const char * path, const char * mode)
118
119 {
120 xmlDictPtr d = NULL;
121 gzFile f;
122
123 f = gzopen(xmlTranscodeResult(path, NULL, &d, NULL),
124 xmlTranscodeResult(mode, NULL, &d, NULL));
125 xmlZapDict(&d);
126 return f;
127 }
128
129
130 gzFile
_lx_gzdopen(int fd,const char * mode)131 _lx_gzdopen(int fd, const char * mode)
132
133 {
134 xmlDictPtr d = NULL;
135 gzFile f;
136
137 f = gzdopen(fd, xmlTranscodeResult(mode, NULL, &d, NULL));
138 xmlZapDict(&d);
139 return f;
140 }
141
142 int
_lx_inflateInit2_(z_streamp strm,int windowBits,const char * version,int stream_size)143 _lx_inflateInit2_(z_streamp strm, int windowBits,
144 const char * version, int stream_size)
145
146 {
147 xmlDictPtr d = NULL;
148 int r;
149
150 r = inflateInit2_(strm, windowBits,
151 xmlTranscodeResult(version, NULL, &d, NULL), stream_size);
152 xmlZapDict(&d);
153 return r;
154 }
155
156 int
_lx_deflateInit2_(z_streamp strm,int level,int method,int windowBits,int memLevel,int strategy,const char * version,int stream_size)157 _lx_deflateInit2_(z_streamp strm, int level, int method, int windowBits,
158 int memLevel, int strategy, const char * version, int stream_size)
159
160 {
161 xmlDictPtr d = NULL;
162 int r;
163
164 r = deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
165 xmlTranscodeResult(version, NULL, &d, NULL), stream_size);
166 xmlZapDict(&d);
167 return r;
168 }
169
170 #endif
171