oculus1

annotate libovr/Src/Kernel/OVR_Std.h @ 29:9a973ef0e2a3

fixed the performance issue under MacOSX by replacing glutSolidTeapot (which uses glEvalMesh) with my own teapot generator.
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 27 Oct 2013 06:31:18 +0200
parents e2f9e4603129
children
rev   line source
nuclear@3 1 /************************************************************************************
nuclear@3 2
nuclear@3 3 PublicHeader: OVR.h
nuclear@3 4 Filename : OVR_Std.h
nuclear@3 5 Content : Standard C function interface
nuclear@3 6 Created : September 19, 2012
nuclear@3 7 Notes :
nuclear@3 8
nuclear@3 9 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
nuclear@3 10
nuclear@3 11 Use of this software is subject to the terms of the Oculus license
nuclear@3 12 agreement provided at the time of installation or download, or which
nuclear@3 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@3 14
nuclear@3 15 ************************************************************************************/
nuclear@3 16
nuclear@3 17 #ifndef OVR_Std_h
nuclear@3 18 #define OVR_Std_h
nuclear@3 19
nuclear@3 20 #include "OVR_Types.h"
nuclear@3 21 #include <stdarg.h> // for va_list args
nuclear@3 22 #include <string.h>
nuclear@3 23 #include <stdio.h>
nuclear@3 24 #include <stdlib.h>
nuclear@3 25 #include <ctype.h>
nuclear@3 26
nuclear@3 27 #if !defined(OVR_OS_WINCE) && defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400)
nuclear@3 28 #define OVR_MSVC_SAFESTRING
nuclear@3 29 #include <errno.h>
nuclear@3 30 #endif
nuclear@3 31
nuclear@3 32 // Wide-char funcs
nuclear@3 33 #include <wchar.h>
nuclear@3 34 #include <wctype.h>
nuclear@3 35
nuclear@3 36 namespace OVR {
nuclear@3 37
nuclear@3 38 #if defined(OVR_OS_WIN32)
nuclear@3 39 inline char* OVR_CDECL OVR_itoa(int val, char *dest, UPInt destsize, int radix)
nuclear@3 40 {
nuclear@3 41 #if defined(OVR_MSVC_SAFESTRING)
nuclear@3 42 _itoa_s(val, dest, destsize, radix);
nuclear@3 43 return dest;
nuclear@3 44 #else
nuclear@3 45 OVR_UNUSED(destsize);
nuclear@3 46 return itoa(val, dest, radix);
nuclear@3 47 #endif
nuclear@3 48 }
nuclear@3 49 #else // OVR_OS_WIN32
nuclear@3 50 inline char* OVR_itoa(int val, char* dest, unsigned int len, int radix)
nuclear@3 51 {
nuclear@3 52 if (val == 0)
nuclear@3 53 {
nuclear@3 54 if (len > 1)
nuclear@3 55 {
nuclear@3 56 dest[0] = '0';
nuclear@3 57 dest[1] = '\0';
nuclear@3 58 }
nuclear@3 59 return dest;
nuclear@3 60 }
nuclear@3 61
nuclear@3 62 int cur = val;
nuclear@3 63 unsigned int i = 0;
nuclear@3 64 unsigned int sign = 0;
nuclear@3 65
nuclear@3 66 if (val < 0)
nuclear@3 67 {
nuclear@3 68 val = -val;
nuclear@3 69 sign = 1;
nuclear@3 70 }
nuclear@3 71
nuclear@3 72 while ((val != 0) && (i < (len - 1 - sign)))
nuclear@3 73 {
nuclear@3 74 cur = val % radix;
nuclear@3 75 val /= radix;
nuclear@3 76
nuclear@3 77 if (radix == 16)
nuclear@3 78 {
nuclear@3 79 switch(cur)
nuclear@3 80 {
nuclear@3 81 case 10:
nuclear@3 82 dest[i] = 'a';
nuclear@3 83 break;
nuclear@3 84 case 11:
nuclear@3 85 dest[i] = 'b';
nuclear@3 86 break;
nuclear@3 87 case 12:
nuclear@3 88 dest[i] = 'c';
nuclear@3 89 break;
nuclear@3 90 case 13:
nuclear@3 91 dest[i] = 'd';
nuclear@3 92 break;
nuclear@3 93 case 14:
nuclear@3 94 dest[i] = 'e';
nuclear@3 95 break;
nuclear@3 96 case 15:
nuclear@3 97 dest[i] = 'f';
nuclear@3 98 break;
nuclear@3 99 default:
nuclear@3 100 dest[i] = (char)('0' + cur);
nuclear@3 101 break;
nuclear@3 102 }
nuclear@3 103 }
nuclear@3 104 else
nuclear@3 105 {
nuclear@3 106 dest[i] = (char)('0' + cur);
nuclear@3 107 }
nuclear@3 108 ++i;
nuclear@3 109 }
nuclear@3 110
nuclear@3 111 if (sign)
nuclear@3 112 {
nuclear@3 113 dest[i++] = '-';
nuclear@3 114 }
nuclear@3 115
nuclear@3 116 for (unsigned int j = 0; j < i / 2; ++j)
nuclear@3 117 {
nuclear@3 118 char tmp = dest[j];
nuclear@3 119 dest[j] = dest[i - 1 - j];
nuclear@3 120 dest[i - 1 - j] = tmp;
nuclear@3 121 }
nuclear@3 122 dest[i] = '\0';
nuclear@3 123
nuclear@3 124 return dest;
nuclear@3 125 }
nuclear@3 126
nuclear@3 127 #endif
nuclear@3 128
nuclear@3 129
nuclear@3 130 // String functions
nuclear@3 131
nuclear@3 132 inline UPInt OVR_CDECL OVR_strlen(const char* str)
nuclear@3 133 {
nuclear@3 134 return strlen(str);
nuclear@3 135 }
nuclear@3 136
nuclear@3 137 inline char* OVR_CDECL OVR_strcpy(char* dest, UPInt destsize, const char* src)
nuclear@3 138 {
nuclear@3 139 #if defined(OVR_MSVC_SAFESTRING)
nuclear@3 140 strcpy_s(dest, destsize, src);
nuclear@3 141 return dest;
nuclear@3 142 #else
nuclear@3 143 OVR_UNUSED(destsize);
nuclear@3 144 return strcpy(dest, src);
nuclear@3 145 #endif
nuclear@3 146 }
nuclear@3 147
nuclear@3 148 inline char* OVR_CDECL OVR_strncpy(char* dest, UPInt destsize, const char* src, UPInt count)
nuclear@3 149 {
nuclear@3 150 #if defined(OVR_MSVC_SAFESTRING)
nuclear@3 151 strncpy_s(dest, destsize, src, count);
nuclear@3 152 return dest;
nuclear@3 153 #else
nuclear@3 154 OVR_UNUSED(destsize);
nuclear@3 155 return strncpy(dest, src, count);
nuclear@3 156 #endif
nuclear@3 157 }
nuclear@3 158
nuclear@3 159 inline char * OVR_CDECL OVR_strcat(char* dest, UPInt destsize, const char* src)
nuclear@3 160 {
nuclear@3 161 #if defined(OVR_MSVC_SAFESTRING)
nuclear@3 162 strcat_s(dest, destsize, src);
nuclear@3 163 return dest;
nuclear@3 164 #else
nuclear@3 165 OVR_UNUSED(destsize);
nuclear@3 166 return strcat(dest, src);
nuclear@3 167 #endif
nuclear@3 168 }
nuclear@3 169
nuclear@3 170 inline int OVR_CDECL OVR_strcmp(const char* dest, const char* src)
nuclear@3 171 {
nuclear@3 172 return strcmp(dest, src);
nuclear@3 173 }
nuclear@3 174
nuclear@3 175 inline const char* OVR_CDECL OVR_strchr(const char* str, char c)
nuclear@3 176 {
nuclear@3 177 return strchr(str, c);
nuclear@3 178 }
nuclear@3 179
nuclear@3 180 inline char* OVR_CDECL OVR_strchr(char* str, char c)
nuclear@3 181 {
nuclear@3 182 return strchr(str, c);
nuclear@3 183 }
nuclear@3 184
nuclear@3 185 inline const char* OVR_strrchr(const char* str, char c)
nuclear@3 186 {
nuclear@3 187 UPInt len = OVR_strlen(str);
nuclear@3 188 for (UPInt i=len; i>0; i--)
nuclear@3 189 if (str[i]==c)
nuclear@3 190 return str+i;
nuclear@3 191 return 0;
nuclear@3 192 }
nuclear@3 193
nuclear@3 194 inline const UByte* OVR_CDECL OVR_memrchr(const UByte* str, UPInt size, UByte c)
nuclear@3 195 {
nuclear@3 196 for (SPInt i = (SPInt)size - 1; i >= 0; i--)
nuclear@3 197 {
nuclear@3 198 if (str[i] == c)
nuclear@3 199 return str + i;
nuclear@3 200 }
nuclear@3 201 return 0;
nuclear@3 202 }
nuclear@3 203
nuclear@3 204 inline char* OVR_CDECL OVR_strrchr(char* str, char c)
nuclear@3 205 {
nuclear@3 206 UPInt len = OVR_strlen(str);
nuclear@3 207 for (UPInt i=len; i>0; i--)
nuclear@3 208 if (str[i]==c)
nuclear@3 209 return str+i;
nuclear@3 210 return 0;
nuclear@3 211 }
nuclear@3 212
nuclear@3 213
nuclear@3 214 double OVR_CDECL OVR_strtod(const char* string, char** tailptr);
nuclear@3 215
nuclear@3 216 inline long OVR_CDECL OVR_strtol(const char* string, char** tailptr, int radix)
nuclear@3 217 {
nuclear@3 218 return strtol(string, tailptr, radix);
nuclear@3 219 }
nuclear@3 220
nuclear@3 221 inline long OVR_CDECL OVR_strtoul(const char* string, char** tailptr, int radix)
nuclear@3 222 {
nuclear@3 223 return strtoul(string, tailptr, radix);
nuclear@3 224 }
nuclear@3 225
nuclear@3 226 inline int OVR_CDECL OVR_strncmp(const char* ws1, const char* ws2, UPInt size)
nuclear@3 227 {
nuclear@3 228 return strncmp(ws1, ws2, size);
nuclear@3 229 }
nuclear@3 230
nuclear@3 231 inline UInt64 OVR_CDECL OVR_strtouq(const char *nptr, char **endptr, int base)
nuclear@3 232 {
nuclear@3 233 #if defined(OVR_CC_MSVC) && !defined(OVR_OS_WINCE)
nuclear@3 234 return _strtoui64(nptr, endptr, base);
nuclear@3 235 #else
nuclear@3 236 return strtoull(nptr, endptr, base);
nuclear@3 237 #endif
nuclear@3 238 }
nuclear@3 239
nuclear@3 240 inline SInt64 OVR_CDECL OVR_strtoq(const char *nptr, char **endptr, int base)
nuclear@3 241 {
nuclear@3 242 #if defined(OVR_CC_MSVC) && !defined(OVR_OS_WINCE)
nuclear@3 243 return _strtoi64(nptr, endptr, base);
nuclear@3 244 #else
nuclear@3 245 return strtoll(nptr, endptr, base);
nuclear@3 246 #endif
nuclear@3 247 }
nuclear@3 248
nuclear@3 249
nuclear@3 250 inline SInt64 OVR_CDECL OVR_atoq(const char* string)
nuclear@3 251 {
nuclear@3 252 #if defined(OVR_CC_MSVC) && !defined(OVR_OS_WINCE)
nuclear@3 253 return _atoi64(string);
nuclear@3 254 #else
nuclear@3 255 return atoll(string);
nuclear@3 256 #endif
nuclear@3 257 }
nuclear@3 258
nuclear@3 259 inline UInt64 OVR_CDECL OVR_atouq(const char* string)
nuclear@3 260 {
nuclear@3 261 return OVR_strtouq(string, NULL, 10);
nuclear@3 262 }
nuclear@3 263
nuclear@3 264
nuclear@3 265 // Implemented in GStd.cpp in platform-specific manner.
nuclear@3 266 int OVR_CDECL OVR_stricmp(const char* dest, const char* src);
nuclear@3 267 int OVR_CDECL OVR_strnicmp(const char* dest, const char* src, UPInt count);
nuclear@3 268
nuclear@3 269 inline UPInt OVR_CDECL OVR_sprintf(char *dest, UPInt destsize, const char* format, ...)
nuclear@3 270 {
nuclear@3 271 va_list argList;
nuclear@3 272 va_start(argList,format);
nuclear@3 273 UPInt ret;
nuclear@3 274 #if defined(OVR_CC_MSVC)
nuclear@3 275 #if defined(OVR_MSVC_SAFESTRING)
nuclear@3 276 ret = _vsnprintf_s(dest, destsize, _TRUNCATE, format, argList);
nuclear@3 277 OVR_ASSERT(ret != -1);
nuclear@3 278 #else
nuclear@3 279 OVR_UNUSED(destsize);
nuclear@3 280 ret = _vsnprintf(dest, destsize - 1, format, argList); // -1 for space for the null character
nuclear@3 281 OVR_ASSERT(ret != -1);
nuclear@3 282 dest[destsize-1] = 0;
nuclear@3 283 #endif
nuclear@3 284 #else
nuclear@3 285 OVR_UNUSED(destsize);
nuclear@3 286 ret = vsprintf(dest, format, argList);
nuclear@3 287 OVR_ASSERT(ret < destsize);
nuclear@3 288 #endif
nuclear@3 289 va_end(argList);
nuclear@3 290 return ret;
nuclear@3 291 }
nuclear@3 292
nuclear@3 293 inline UPInt OVR_CDECL OVR_vsprintf(char *dest, UPInt destsize, const char * format, va_list argList)
nuclear@3 294 {
nuclear@3 295 UPInt ret;
nuclear@3 296 #if defined(OVR_CC_MSVC)
nuclear@3 297 #if defined(OVR_MSVC_SAFESTRING)
nuclear@3 298 dest[0] = '\0';
nuclear@3 299 int rv = vsnprintf_s(dest, destsize, _TRUNCATE, format, argList);
nuclear@3 300 if (rv == -1)
nuclear@3 301 {
nuclear@3 302 dest[destsize - 1] = '\0';
nuclear@3 303 ret = destsize - 1;
nuclear@3 304 }
nuclear@3 305 else
nuclear@3 306 ret = (UPInt)rv;
nuclear@3 307 #else
nuclear@3 308 OVR_UNUSED(destsize);
nuclear@3 309 int rv = _vsnprintf(dest, destsize - 1, format, argList);
nuclear@3 310 OVR_ASSERT(rv != -1);
nuclear@3 311 ret = (UPInt)rv;
nuclear@3 312 dest[destsize-1] = 0;
nuclear@3 313 #endif
nuclear@3 314 #else
nuclear@3 315 OVR_UNUSED(destsize);
nuclear@3 316 ret = (UPInt)vsprintf(dest, format, argList);
nuclear@3 317 OVR_ASSERT(ret < destsize);
nuclear@3 318 #endif
nuclear@3 319 return ret;
nuclear@3 320 }
nuclear@3 321
nuclear@3 322 // Returns the number of characters in the formatted string.
nuclear@3 323 inline UPInt OVR_CDECL OVR_vscprintf(const char * format, va_list argList)
nuclear@3 324 {
nuclear@3 325 UPInt ret;
nuclear@3 326 #if defined(OVR_CC_MSVC)
nuclear@3 327 ret = (UPInt) _vscprintf(format, argList);
nuclear@3 328 #else
nuclear@3 329 ret = (UPInt) vsnprintf(NULL, 0, format, argList);
nuclear@3 330 #endif
nuclear@3 331 return ret;
nuclear@3 332 }
nuclear@3 333
nuclear@3 334
nuclear@3 335 wchar_t* OVR_CDECL OVR_wcscpy(wchar_t* dest, UPInt destsize, const wchar_t* src);
nuclear@3 336 wchar_t* OVR_CDECL OVR_wcsncpy(wchar_t* dest, UPInt destsize, const wchar_t* src, UPInt count);
nuclear@3 337 wchar_t* OVR_CDECL OVR_wcscat(wchar_t* dest, UPInt destsize, const wchar_t* src);
nuclear@3 338 UPInt OVR_CDECL OVR_wcslen(const wchar_t* str);
nuclear@3 339 int OVR_CDECL OVR_wcscmp(const wchar_t* a, const wchar_t* b);
nuclear@3 340 int OVR_CDECL OVR_wcsicmp(const wchar_t* a, const wchar_t* b);
nuclear@3 341
nuclear@3 342 inline int OVR_CDECL OVR_wcsicoll(const wchar_t* a, const wchar_t* b)
nuclear@3 343 {
nuclear@3 344 #if defined(OVR_OS_WIN32)
nuclear@3 345 #if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400)
nuclear@3 346 return ::_wcsicoll(a, b);
nuclear@3 347 #else
nuclear@3 348 return ::wcsicoll(a, b);
nuclear@3 349 #endif
nuclear@3 350 #else
nuclear@3 351 // not supported, use regular wcsicmp
nuclear@3 352 return OVR_wcsicmp(a, b);
nuclear@3 353 #endif
nuclear@3 354 }
nuclear@3 355
nuclear@3 356 inline int OVR_CDECL OVR_wcscoll(const wchar_t* a, const wchar_t* b)
nuclear@3 357 {
nuclear@3 358 #if defined(OVR_OS_WIN32) || defined(OVR_OS_LINUX)
nuclear@3 359 return wcscoll(a, b);
nuclear@3 360 #else
nuclear@3 361 // not supported, use regular wcscmp
nuclear@3 362 return OVR_wcscmp(a, b);
nuclear@3 363 #endif
nuclear@3 364 }
nuclear@3 365
nuclear@3 366 #ifndef OVR_NO_WCTYPE
nuclear@3 367
nuclear@3 368 inline int OVR_CDECL UnicodeCharIs(const UInt16* table, wchar_t charCode)
nuclear@3 369 {
nuclear@3 370 unsigned offset = table[charCode >> 8];
nuclear@3 371 if (offset == 0) return 0;
nuclear@3 372 if (offset == 1) return 1;
nuclear@3 373 return (table[offset + ((charCode >> 4) & 15)] & (1 << (charCode & 15))) != 0;
nuclear@3 374 }
nuclear@3 375
nuclear@3 376 extern const UInt16 UnicodeAlnumBits[];
nuclear@3 377 extern const UInt16 UnicodeAlphaBits[];
nuclear@3 378 extern const UInt16 UnicodeDigitBits[];
nuclear@3 379 extern const UInt16 UnicodeSpaceBits[];
nuclear@3 380 extern const UInt16 UnicodeXDigitBits[];
nuclear@3 381
nuclear@3 382 // Uncomment if necessary
nuclear@3 383 //extern const UInt16 UnicodeCntrlBits[];
nuclear@3 384 //extern const UInt16 UnicodeGraphBits[];
nuclear@3 385 //extern const UInt16 UnicodeLowerBits[];
nuclear@3 386 //extern const UInt16 UnicodePrintBits[];
nuclear@3 387 //extern const UInt16 UnicodePunctBits[];
nuclear@3 388 //extern const UInt16 UnicodeUpperBits[];
nuclear@3 389
nuclear@3 390 inline int OVR_CDECL OVR_iswalnum (wchar_t charCode) { return UnicodeCharIs(UnicodeAlnumBits, charCode); }
nuclear@3 391 inline int OVR_CDECL OVR_iswalpha (wchar_t charCode) { return UnicodeCharIs(UnicodeAlphaBits, charCode); }
nuclear@3 392 inline int OVR_CDECL OVR_iswdigit (wchar_t charCode) { return UnicodeCharIs(UnicodeDigitBits, charCode); }
nuclear@3 393 inline int OVR_CDECL OVR_iswspace (wchar_t charCode) { return UnicodeCharIs(UnicodeSpaceBits, charCode); }
nuclear@3 394 inline int OVR_CDECL OVR_iswxdigit(wchar_t charCode) { return UnicodeCharIs(UnicodeXDigitBits, charCode); }
nuclear@3 395
nuclear@3 396 // Uncomment if necessary
nuclear@3 397 //inline int OVR_CDECL OVR_iswcntrl (wchar_t charCode) { return UnicodeCharIs(UnicodeCntrlBits, charCode); }
nuclear@3 398 //inline int OVR_CDECL OVR_iswgraph (wchar_t charCode) { return UnicodeCharIs(UnicodeGraphBits, charCode); }
nuclear@3 399 //inline int OVR_CDECL OVR_iswlower (wchar_t charCode) { return UnicodeCharIs(UnicodeLowerBits, charCode); }
nuclear@3 400 //inline int OVR_CDECL OVR_iswprint (wchar_t charCode) { return UnicodeCharIs(UnicodePrintBits, charCode); }
nuclear@3 401 //inline int OVR_CDECL OVR_iswpunct (wchar_t charCode) { return UnicodeCharIs(UnicodePunctBits, charCode); }
nuclear@3 402 //inline int OVR_CDECL OVR_iswupper (wchar_t charCode) { return UnicodeCharIs(UnicodeUpperBits, charCode); }
nuclear@3 403
nuclear@3 404 int OVR_CDECL OVR_towupper(wchar_t charCode);
nuclear@3 405 int OVR_CDECL OVR_towlower(wchar_t charCode);
nuclear@3 406
nuclear@3 407 #else // OVR_NO_WCTYPE
nuclear@3 408
nuclear@3 409 inline int OVR_CDECL OVR_iswspace(wchar_t c)
nuclear@3 410 {
nuclear@3 411 return iswspace(c);
nuclear@3 412 }
nuclear@3 413
nuclear@3 414 inline int OVR_CDECL OVR_iswdigit(wchar_t c)
nuclear@3 415 {
nuclear@3 416 return iswdigit(c);
nuclear@3 417 }
nuclear@3 418
nuclear@3 419 inline int OVR_CDECL OVR_iswxdigit(wchar_t c)
nuclear@3 420 {
nuclear@3 421 return iswxdigit(c);
nuclear@3 422 }
nuclear@3 423
nuclear@3 424 inline int OVR_CDECL OVR_iswalpha(wchar_t c)
nuclear@3 425 {
nuclear@3 426 return iswalpha(c);
nuclear@3 427 }
nuclear@3 428
nuclear@3 429 inline int OVR_CDECL OVR_iswalnum(wchar_t c)
nuclear@3 430 {
nuclear@3 431 return iswalnum(c);
nuclear@3 432 }
nuclear@3 433
nuclear@3 434 inline wchar_t OVR_CDECL OVR_towlower(wchar_t c)
nuclear@3 435 {
nuclear@3 436 return (wchar_t)towlower(c);
nuclear@3 437 }
nuclear@3 438
nuclear@3 439 inline wchar_t OVR_towupper(wchar_t c)
nuclear@3 440 {
nuclear@3 441 return (wchar_t)towupper(c);
nuclear@3 442 }
nuclear@3 443
nuclear@3 444 #endif // OVR_NO_WCTYPE
nuclear@3 445
nuclear@3 446 // ASCII versions of tolower and toupper. Don't use "char"
nuclear@3 447 inline int OVR_CDECL OVR_tolower(int c)
nuclear@3 448 {
nuclear@3 449 return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c;
nuclear@3 450 }
nuclear@3 451
nuclear@3 452 inline int OVR_CDECL OVR_toupper(int c)
nuclear@3 453 {
nuclear@3 454 return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
nuclear@3 455 }
nuclear@3 456
nuclear@3 457
nuclear@3 458
nuclear@3 459 inline double OVR_CDECL OVR_wcstod(const wchar_t* string, wchar_t** tailptr)
nuclear@3 460 {
nuclear@3 461 #if defined(OVR_OS_OTHER)
nuclear@3 462 OVR_UNUSED(tailptr);
nuclear@3 463 char buffer[64];
nuclear@3 464 char* tp = NULL;
nuclear@3 465 UPInt max = OVR_wcslen(string);
nuclear@3 466 if (max > 63) max = 63;
nuclear@3 467 unsigned char c = 0;
nuclear@3 468 for (UPInt i=0; i < max; i++)
nuclear@3 469 {
nuclear@3 470 c = (unsigned char)string[i];
nuclear@3 471 buffer[i] = ((c) < 128 ? (char)c : '!');
nuclear@3 472 }
nuclear@3 473 buffer[max] = 0;
nuclear@3 474 return OVR_strtod(buffer, &tp);
nuclear@3 475 #else
nuclear@3 476 return wcstod(string, tailptr);
nuclear@3 477 #endif
nuclear@3 478 }
nuclear@3 479
nuclear@3 480 inline long OVR_CDECL OVR_wcstol(const wchar_t* string, wchar_t** tailptr, int radix)
nuclear@3 481 {
nuclear@3 482 #if defined(OVR_OS_OTHER)
nuclear@3 483 OVR_UNUSED(tailptr);
nuclear@3 484 char buffer[64];
nuclear@3 485 char* tp = NULL;
nuclear@3 486 UPInt max = OVR_wcslen(string);
nuclear@3 487 if (max > 63) max = 63;
nuclear@3 488 unsigned char c = 0;
nuclear@3 489 for (UPInt i=0; i < max; i++)
nuclear@3 490 {
nuclear@3 491 c = (unsigned char)string[i];
nuclear@3 492 buffer[i] = ((c) < 128 ? (char)c : '!');
nuclear@3 493 }
nuclear@3 494 buffer[max] = 0;
nuclear@3 495 return strtol(buffer, &tp, radix);
nuclear@3 496 #else
nuclear@3 497 return wcstol(string, tailptr, radix);
nuclear@3 498 #endif
nuclear@3 499 }
nuclear@3 500
nuclear@3 501 } // OVR
nuclear@3 502
nuclear@3 503 #endif // OVR_Std_h