src/stdlib/SDL_string.c
changeset 1456 84de7511f79f
parent 1402 d910939febfa
child 1501 73dc5d39bbf8
     1.1 --- a/src/stdlib/SDL_string.c	Mon Feb 27 22:14:40 2006 +0000
     1.2 +++ b/src/stdlib/SDL_string.c	Wed Mar 01 09:43:47 2006 +0000
     1.3 @@ -69,7 +69,7 @@
     1.4  }
     1.5  #endif
     1.6  
     1.7 -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
     1.8 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
     1.9  static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
    1.10  {
    1.11      const char *textstart = text;
    1.12 @@ -100,6 +100,37 @@
    1.13  }
    1.14  #endif
    1.15  
    1.16 +#ifndef HAVE_SSCANF
    1.17 +static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
    1.18 +{
    1.19 +    const char *textstart = text;
    1.20 +    uintptr_t value = 0;
    1.21 +
    1.22 +    if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
    1.23 +        text += 2;
    1.24 +    }
    1.25 +    for ( ; ; ) {
    1.26 +        int v;
    1.27 +        if ( SDL_isdigit(*text) ) {
    1.28 +            v = *text - '0';
    1.29 +        } else if ( radix == 16 && SDL_isupperhex(*text) ) {
    1.30 +            v = 10 + (*text - 'A');
    1.31 +        } else if ( radix == 16 && SDL_islowerhex(*text) ) {
    1.32 +            v = 10 + (*text - 'a');
    1.33 +        } else {
    1.34 +            break;
    1.35 +        }
    1.36 +        value *= radix;
    1.37 +        value += v;
    1.38 +        ++text;
    1.39 +    }
    1.40 +    if ( valuep ) {
    1.41 +        *valuep = value;
    1.42 +    }
    1.43 +    return (text - textstart);
    1.44 +}
    1.45 +#endif
    1.46 +
    1.47  #ifdef SDL_HAS_64BIT_TYPE
    1.48  #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
    1.49  static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
    1.50 @@ -141,7 +172,7 @@
    1.51  }
    1.52  #endif
    1.53  
    1.54 -#ifndef HAVE_SSCANF
    1.55 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
    1.56  static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep)
    1.57  {
    1.58      const char *textstart = text;
    1.59 @@ -488,6 +519,20 @@
    1.60  }
    1.61  #endif
    1.62  
    1.63 +#ifndef HAVE_STRTOUL
    1.64 +unsigned long SDL_strtoul(const char *string, char **endp, int base)
    1.65 +{
    1.66 +    size_t len;
    1.67 +    unsigned long value;
    1.68 +
    1.69 +    len = SDL_ScanUnsignedLong(string, base ? base : 10, &value);
    1.70 +    if ( endp ) {
    1.71 +        *endp = (char *)string + len;
    1.72 +    }
    1.73 +    return value;
    1.74 +}
    1.75 +#endif
    1.76 +
    1.77  #ifdef SDL_HAS_64BIT_TYPE
    1.78  
    1.79  #ifndef HAVE__I64TOA
    1.80 @@ -556,6 +601,20 @@
    1.81  }
    1.82  #endif
    1.83  
    1.84 +#ifndef HAVE_STRTOULL
    1.85 +Uint64 SDL_strtoull(const char *string, char **endp, int base)
    1.86 +{
    1.87 +    size_t len;
    1.88 +    Uint64 value;
    1.89 +
    1.90 +    len = SDL_ScanUnsignedLongLong(string, base ? base : 10, &value);
    1.91 +    if ( endp ) {
    1.92 +        *endp = (char *)string + len;
    1.93 +    }
    1.94 +    return value;
    1.95 +}
    1.96 +#endif
    1.97 +
    1.98  #endif /* SDL_HAS_64BIT_TYPE */
    1.99  
   1.100  #ifndef HAVE_STRTOD
   1.101 @@ -817,8 +876,8 @@
   1.102                          break;
   1.103                      case 'p':
   1.104                          {
   1.105 -                            unsigned long value;
   1.106 -                            text += SDL_ScanUnsignedLong(text, 16, &value);
   1.107 +                            uintptr_t value;
   1.108 +                            text += SDL_ScanUintPtrT(text, 16, &value);
   1.109                              if ( ! suppress ) {
   1.110                                  void** valuep = va_arg(ap, void**);
   1.111                                  *valuep = (void*)value;
   1.112 @@ -1003,7 +1062,7 @@
   1.113      }
   1.114      return (text - textstart);
   1.115  }
   1.116 -int  SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
   1.117 +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
   1.118  {
   1.119      char *textstart = text;
   1.120      if ( maxlen <= 0 ) {