oculus1

annotate libovr/Src/Kernel/OVR_Std.h @ 1:e2f9e4603129

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