Mercurial > sdl-ios-xcode
diff src/stdlib/SDL_string.c @ 1456:84de7511f79f
Fixed a bunch of 64-bit compatibility problems
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Mar 2006 09:43:47 +0000 |
parents | d910939febfa |
children | 73dc5d39bbf8 |
line wrap: on
line diff
--- a/src/stdlib/SDL_string.c Mon Feb 27 22:14:40 2006 +0000 +++ b/src/stdlib/SDL_string.c Wed Mar 01 09:43:47 2006 +0000 @@ -69,7 +69,7 @@ } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) { const char *textstart = text; @@ -100,6 +100,37 @@ } #endif +#ifndef HAVE_SSCANF +static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep) +{ + const char *textstart = text; + uintptr_t value = 0; + + if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { + text += 2; + } + for ( ; ; ) { + int v; + if ( SDL_isdigit(*text) ) { + v = *text - '0'; + } else if ( radix == 16 && SDL_isupperhex(*text) ) { + v = 10 + (*text - 'A'); + } else if ( radix == 16 && SDL_islowerhex(*text) ) { + v = 10 + (*text - 'a'); + } else { + break; + } + value *= radix; + value += v; + ++text; + } + if ( valuep ) { + *valuep = value; + } + return (text - textstart); +} +#endif + #ifdef SDL_HAS_64BIT_TYPE #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep) @@ -141,7 +172,7 @@ } #endif -#ifndef HAVE_SSCANF +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep) { const char *textstart = text; @@ -488,6 +519,20 @@ } #endif +#ifndef HAVE_STRTOUL +unsigned long SDL_strtoul(const char *string, char **endp, int base) +{ + size_t len; + unsigned long value; + + len = SDL_ScanUnsignedLong(string, base ? base : 10, &value); + if ( endp ) { + *endp = (char *)string + len; + } + return value; +} +#endif + #ifdef SDL_HAS_64BIT_TYPE #ifndef HAVE__I64TOA @@ -556,6 +601,20 @@ } #endif +#ifndef HAVE_STRTOULL +Uint64 SDL_strtoull(const char *string, char **endp, int base) +{ + size_t len; + Uint64 value; + + len = SDL_ScanUnsignedLongLong(string, base ? base : 10, &value); + if ( endp ) { + *endp = (char *)string + len; + } + return value; +} +#endif + #endif /* SDL_HAS_64BIT_TYPE */ #ifndef HAVE_STRTOD @@ -817,8 +876,8 @@ break; case 'p': { - unsigned long value; - text += SDL_ScanUnsignedLong(text, 16, &value); + uintptr_t value; + text += SDL_ScanUintPtrT(text, 16, &value); if ( ! suppress ) { void** valuep = va_arg(ap, void**); *valuep = (void*)value; @@ -1003,7 +1062,7 @@ } return (text - textstart); } -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { char *textstart = text; if ( maxlen <= 0 ) {