28 #define ICONV_THREAD_SAFE 1
31 #define _ULS_CALLCONV_
32 #define CALLCONV _System
37 #ifdef ICONV_THREAD_SAFE
38 #define INCL_DOSSEMAPHORES
39 #define INCL_DOSERRORS
45 #define min(a, b) (((a) < (b)) ? (a) : (b))
48 #define MAX_CP_NAME_LEN 64
55 #ifdef ICONV_THREAD_SAFE
65 const char *ch = code;
71 uc_code[
i] = (
unsigned short)*ch;
78 return UniCreateUconvObject(uc_code, uobj);
81 static int uconv_open(
const char *code, UconvObject *uobj)
85 if (!stricmp(code,
"UTF-16")) {
91 if (rc != ULS_SUCCESS) {
95 if (
cp != 0 && _snprintf(cp_name,
sizeof(cp_name),
"IBM-%u",
cp) > 0)
105 UconvObject uo_tocode;
106 UconvObject uo_fromcode;
113 if (fromcode ==
NULL)
116 if (stricmp(tocode, fromcode) != 0) {
118 if (rc != ULS_SUCCESS) {
124 if (rc != ULS_SUCCESS) {
125 UniFreeUconvObject(uo_fromcode);
139 #ifdef ICONV_THREAD_SAFE
148 char* * outbuf,
size_t *outbytesleft)
150 UconvObject uo_tocode = ((
iuconv_obj *)(cd))->uo_tocode;
151 UconvObject uo_fromcode = ((
iuconv_obj *)(cd))->uo_fromcode;
152 size_t nonIdenticalConv = 0;
158 size_t ret = (
size_t)(-1);
160 if (uo_tocode ==
NULL && uo_fromcode ==
NULL) {
161 uc_buf_len =
min(*inbytesleft, *outbytesleft);
162 memcpy(*outbuf, *inbuf, uc_buf_len);
163 *inbytesleft -= uc_buf_len;
164 *outbytesleft -= uc_buf_len;
165 outbuf += uc_buf_len;
170 #ifdef ICONV_THREAD_SAFE
171 DosRequestMutexSem(((
iuconv_obj *)(cd))->hMtx, SEM_INDEFINITE_WAIT);
174 if (uo_tocode && uo_fromcode &&
175 (((
iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
178 ((
iuconv_obj *)cd)->buf_len = *inbytesleft << 1;
188 uc_str = (UniChar **)outbuf;
189 uc_buf_len = *outbytesleft;
191 uc_buf_len = uc_buf_len >> 1;
192 uc_str_len = &uc_buf_len;
193 rc = UniUconvToUcs(uo_fromcode, (
void **)inbuf, inbytesleft,
194 uc_str, uc_str_len, &nonIdenticalConv);
195 uc_buf_len = uc_buf_len << 1;
197 *outbytesleft = uc_buf_len;
199 if (rc != ULS_SUCCESS) {
202 }
else if (*inbytesleft && !*uc_str_len) {
208 return nonIdenticalConv;
211 uc_buf_len = ((
iuconv_obj *)cd)->buf_len - uc_buf_len;
213 uc_str_len = &uc_buf_len;
215 uc_str = (UniChar **)inbuf;
216 uc_str_len = inbytesleft;
219 *uc_str_len = *uc_str_len>>1;
220 rc = UniUconvFromUcs(uo_tocode, uc_str, uc_str_len, (
void **)outbuf,
221 outbytesleft, &nonIdenticalConv);
222 if (rc != ULS_SUCCESS) {
227 case ULS_ILLEGALSEQUENCE:
235 }
else if (*uc_str_len && !*outbytesleft) {
240 ret = nonIdenticalConv;
244 #ifdef ICONV_THREAD_SAFE
254 #ifdef ICONV_THREAD_SAFE
258 UniFreeUconvObject(((
iuconv_obj *)cd)->uo_tocode);
260 UniFreeUconvObject(((
iuconv_obj *)cd)->uo_fromcode);
GLenum GLuint GLenum GLsizei const GLchar * buf
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
unsigned long os2cpFromName(char *cp)
int _System os2_iconv_close(iconv_t cd)
static int uconv_open(const char *code, UconvObject *uobj)
iconv_t _System os2_iconv_open(const char *tocode, const char *fromcode)
size_t _System os2_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
static int _createUconvObj(const char *code, UconvObject *uobj)