os2, geniconv: replaced many uses of libc calls with SDL_ counterparts. FIXME: figure out a way to handle errno checks properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
diff --git a/src/core/os2/geniconv/makefile b/src/core/os2/geniconv/makefile
index 7dffd30..566c13d 100644
--- a/src/core/os2/geniconv/makefile
+++ b/src/core/os2/geniconv/makefile
@@ -11,7 +11,7 @@ LIBFILE = geniconv.lib
all: $(LIBFILE) test.exe .symbolic
-CFLAGS = -I$(%WATCOM)/h/os2 -I$(%WATCOM)/h -I. -bt=os2 -q -d0 -w2
+CFLAGS = -I$(%WATCOM)/h/os2 -I$(%WATCOM)/h -I. -bt=os2 -q -d0 -w2 -DGENICONV_STANDALONE=1
SRCS = geniconv.c os2cp.c os2iconv.c
SRCS+= sys2utf8.c
diff --git a/src/core/os2/geniconv/os2cp.c b/src/core/os2/geniconv/os2cp.c
index 3566f68..3e571f8 100644
--- a/src/core/os2/geniconv/os2cp.c
+++ b/src/core/os2/geniconv/os2cp.c
@@ -22,11 +22,21 @@
#define INCL_DOSNLS
#define INCL_DOSERRORS
#include <os2.h>
-#include <string.h>
-#include <ctype.h>
#include "os2cp.h"
+#ifndef GENICONV_STANDALONE
+#include "../../../SDL_internal.h"
+#else
+#include <string.h>
+#include <ctype.h>
+#define SDL_isspace isspace
+#define SDL_strchr strchr
+#define SDL_memcpy memcpy
+#define SDL_strupr strupr
+#define SDL_strcmp strcmp
+#endif
+
typedef struct _CP2NAME {
ULONG ulCode;
PSZ pszName;
@@ -354,28 +364,28 @@ unsigned long os2cpFromName(char *cp)
return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
}
- while (isspace(*cp))
+ while (SDL_isspace(*cp))
cp++;
- pcEnd = strchr(cp, ' ');
+ pcEnd = SDL_strchr(cp, ' ');
if (pcEnd == NULL)
- pcEnd = strchr(cp, '\0');
+ pcEnd = SDL_strchr(cp, '\0');
ulNext = pcEnd - cp;
if (ulNext >= sizeof(acBuf))
return 0;
- memcpy(acBuf, cp, ulNext);
+ SDL_memcpy(acBuf, cp, ulNext);
acBuf[ulNext] = '\0';
- strupr(acBuf);
+ SDL_strupr(acBuf);
- lCmp = strcmp(aName2CP[0].pszName, acBuf);
+ lCmp = SDL_strcmp(aName2CP[0].pszName, acBuf);
if (lCmp > 0)
return 0;
else if (lCmp == 0)
return aName2CP[0].ulCode;
- lCmp = strcmp(aName2CP[ulHi].pszName, acBuf);
+ lCmp = SDL_strcmp(aName2CP[ulHi].pszName, acBuf);
if (lCmp < 0)
return 0;
else if (lCmp == 0)
@@ -384,7 +394,7 @@ unsigned long os2cpFromName(char *cp)
while ((ulHi - ulLo) > 1) {
ulNext = (ulLo + ulHi) / 2;
- lCmp = strcmp(aName2CP[ulNext].pszName, acBuf);
+ lCmp = SDL_strcmp(aName2CP[ulNext].pszName, acBuf);
if (lCmp < 0)
ulLo = ulNext;
else if (lCmp > 0)
diff --git a/src/core/os2/geniconv/os2iconv.c b/src/core/os2/geniconv/os2iconv.c
index c48aa0c..2aed47f 100644
--- a/src/core/os2/geniconv/os2iconv.c
+++ b/src/core/os2/geniconv/os2iconv.c
@@ -31,19 +31,30 @@
#define _ULS_CALLCONV_
#define CALLCONV _System
#include <uconv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#ifdef ICONV_THREAD_SAFE
#define INCL_DOSSEMAPHORES
#define INCL_DOSERRORS
#include <os2.h>
#endif
+
#include "os2cp.h"
+#ifndef GENICONV_STANDALONE
+#include "../../../SDL_internal.h"
+#else
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#if !defined(min)
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
+#define SDL_min min
+#define SDL_strcasecmp stricmp
+#define SDL_snprintf _snprintf
+#define SDL_malloc malloc
+#define SDL_free free
+#define SDL_memcpy memcpy
+#endif
#define MAX_CP_NAME_LEN 64
@@ -82,7 +93,7 @@ static int uconv_open(const char *code, UconvObject *uobj)
{
int rc;
- if (!stricmp(code, "UTF-16")) {
+ if (!SDL_strcasecmp(code, "UTF-16")) {
*uobj = NULL;
return ULS_SUCCESS;
}
@@ -92,7 +103,7 @@ static int uconv_open(const char *code, UconvObject *uobj)
unsigned long cp = os2cpFromName((char *)code);
char cp_name[16];
- if (cp != 0 && _snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0)
+ if (cp != 0 && SDL_snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0)
rc = _createUconvObj(cp_name, uobj);
}
@@ -113,7 +124,7 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
if (fromcode == NULL)
fromcode = "";
- if (stricmp(tocode, fromcode) != 0) {
+ if (SDL_strcasecmp(tocode, fromcode) != 0) {
rc = uconv_open(fromcode, &uo_fromcode);
if (rc != ULS_SUCCESS) {
errno = EINVAL;
@@ -131,7 +142,7 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
uo_fromcode = NULL;
}
- iuobj = (iuconv_obj *) malloc(sizeof(iuconv_obj));
+ iuobj = (iuconv_obj *) SDL_malloc(sizeof(iuconv_obj));
iuobj->uo_tocode = uo_tocode;
iuobj->uo_fromcode = uo_fromcode;
iuobj->buf_len = 0;
@@ -158,8 +169,8 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
size_t ret = (size_t)(-1);
if (uo_tocode == NULL && uo_fromcode == NULL) {
- uc_buf_len = min(*inbytesleft, *outbytesleft);
- memcpy(*outbuf, *inbuf, uc_buf_len);
+ uc_buf_len = SDL_min(*inbytesleft, *outbytesleft);
+ SDL_memcpy(*outbuf, *inbuf, uc_buf_len);
*inbytesleft -= uc_buf_len;
*outbytesleft -= uc_buf_len;
outbuf += uc_buf_len;
@@ -174,9 +185,9 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
if (uo_tocode && uo_fromcode &&
(((iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
if (((iuconv_obj *)cd)->buf != NULL)
- free(((iuconv_obj *)cd)->buf);
+ SDL_free(((iuconv_obj *)cd)->buf);
((iuconv_obj *)cd)->buf_len = *inbytesleft << 1;
- ((iuconv_obj *)cd)->buf = (UniChar *)malloc(((iuconv_obj *)cd)->buf_len);
+ ((iuconv_obj *)cd)->buf = (UniChar *)SDL_malloc(((iuconv_obj *)cd)->buf_len);
}
if (uo_fromcode) {
@@ -260,9 +271,9 @@ int _System os2_iconv_close(iconv_t cd)
UniFreeUconvObject(((iuconv_obj *)cd)->uo_fromcode);
if (((iuconv_obj *)cd)->buf != NULL)
- free(((iuconv_obj *)cd)->buf);
+ SDL_free(((iuconv_obj *)cd)->buf);
- free(cd);
+ SDL_free(cd);
return 0;
}
diff --git a/src/core/os2/geniconv/sys2utf8.c b/src/core/os2/geniconv/sys2utf8.c
index c3f4883..fb96430 100644
--- a/src/core/os2/geniconv/sys2utf8.c
+++ b/src/core/os2/geniconv/sys2utf8.c
@@ -20,7 +20,15 @@
*/
#include "geniconv.h"
+
+#ifndef GENICONV_STANDALONE
+#include "../../../SDL_internal.h"
+#else
#include <stdlib.h>
+#define SDL_malloc malloc
+#define SDL_realloc realloc
+#define SDL_free free
+#endif
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
{
@@ -83,25 +91,25 @@ int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr)
{
int cbNewStr = (((cbStr > 4)? cbStr : 4) + 1) * 2;
- char *pszNewStr = (char *) malloc(cbNewStr);
+ char *pszNewStr = (char *) SDL_malloc(cbNewStr);
if (pszNewStr == NULL)
return NULL;
cbNewStr = StrUTF8(fToUTF8, pszNewStr, cbNewStr, pcStr, cbStr);
if (cbNewStr != -1) {
- pcStr = (char *) realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
+ pcStr = (char *) SDL_realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
if (pcStr)
return pcStr;
}
- free(pszNewStr);
+ SDL_free(pszNewStr);
return NULL;
}
void StrUTF8Free(char *pszStr)
{
- free(pszStr);
+ SDL_free(pszStr);
}
/* vi: set ts=4 sw=4 expandtab: */