Removed the inline functions from SDL_stdinc.h
authorSam Lantinga <slouken@libsdl.org>
Fri, 05 Jul 2013 23:57:19 -0700
changeset 7351668a3dc28361
parent 7350 302af2a46a66
child 7352 de96caa46c09
Removed the inline functions from SDL_stdinc.h
Having the SDL functions inline is causing build issues, and in the case of malloc(), etc. causing malloc/free mismatches, if the application build environment differs from the SDL build environment.

In the interest of safety and consistency, the functions will always be in the SDL library and will only be redirected to the C library there, if they are available.

See the following threads on the SDL mailing list for the gruesome details:
* SDL_stdinc.h inlines problematic when application not compiled in exact same feature environment
* Error compiling program against SDL2 with -std=c++11 g++ flag
include/SDL_stdinc.h
src/libm/math_libm.h
src/libm/math_private.h
src/stdlib/SDL_getenv.c
src/stdlib/SDL_malloc.c
src/stdlib/SDL_qsort.c
src/stdlib/SDL_stdlib.c
src/stdlib/SDL_string.c
src/video/SDL_RLEaccel.c
     1.1 --- a/include/SDL_stdinc.h	Fri Jul 05 21:37:27 2013 -0700
     1.2 +++ b/include/SDL_stdinc.h	Fri Jul 05 23:57:19 2013 -0700
     1.3 @@ -227,76 +227,17 @@
     1.4  #define SDL_stack_free(data)            SDL_free(data)
     1.5  #endif
     1.6  
     1.7 -
     1.8 -/* SDL stdinc inline functions:
     1.9 -
    1.10 -   The theory here is that by default we forcibly inline what we can, and your
    1.11 -   app will use the inline version by default. However we expose a non-inline
    1.12 -   version too, so the symbol is always available in the library even if your app
    1.13 -   bypassed the inline version. The SDL_*_inline versions aren't guaranteed to
    1.14 -   exist, so never call them directly; use SDL_* instead, and trust the system
    1.15 -   to give you the right thing.
    1.16 -
    1.17 -   The benefit here is that you can dlsym() these functions, which you
    1.18 -   couldn't if you had macros, you can link against a foreign build of SDL
    1.19 -   even if you configured differently, and you can drop the unconfigured SDL
    1.20 -   headers into a project without #defining HAVE_MALLOC (etc) and still link.
    1.21 -
    1.22 -   If you want to disable the inline functions and just use SDL's functions,
    1.23 -   you can define SDL_STDINC_NO_INLINES before including this file.
    1.24 -*/
    1.25 -
    1.26  extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
    1.27 -#if defined(HAVE_MALLOC) && !defined(SDL_STDINC_NO_INLINES)
    1.28 -SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); }
    1.29 -#define SDL_malloc SDL_malloc_inline
    1.30 -#endif
    1.31 -
    1.32  extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
    1.33 -#if defined(HAVE_CALLOC) && !defined(SDL_STDINC_NO_INLINES)
    1.34 -SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); }
    1.35 -#define SDL_calloc SDL_calloc_inline
    1.36 -#endif
    1.37 -
    1.38  extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
    1.39 -#if defined(HAVE_REALLOC) && !defined(SDL_STDINC_NO_INLINES)
    1.40 -SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); }
    1.41 -#define SDL_realloc SDL_realloc_inline
    1.42 -#endif
    1.43 -
    1.44  extern DECLSPEC void SDLCALL SDL_free(void *mem);
    1.45 -#if defined(HAVE_FREE) && !defined(SDL_STDINC_NO_INLINES)
    1.46 -SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); }
    1.47 -#define SDL_free SDL_free_inline
    1.48 -#endif
    1.49  
    1.50  extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
    1.51 -#if defined(HAVE_GETENV) && !defined(SDL_STDINC_NO_INLINES)
    1.52 -SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); }
    1.53 -#define SDL_getenv SDL_getenv_inline
    1.54 -#endif
    1.55 -
    1.56  extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
    1.57 -#if defined(HAVE_SETENV) && !defined(SDL_STDINC_NO_INLINES)
    1.58 -SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); }
    1.59 -#define SDL_setenv SDL_setenv_inline
    1.60 -#endif
    1.61  
    1.62  extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
    1.63 -#if defined(HAVE_QSORT) && !defined(SDL_STDINC_NO_INLINES)
    1.64 -SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { qsort(base, nmemb, size, compare); }
    1.65 -#define SDL_qsort SDL_qsort_inline
    1.66 -#endif
    1.67  
    1.68  extern DECLSPEC int SDLCALL SDL_abs(int x);
    1.69 -#ifndef SDL_STDINC_NO_INLINES
    1.70 -#ifdef HAVE_ABS
    1.71 -SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); }
    1.72 -#else
    1.73 -SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); }
    1.74 -#endif
    1.75 -#define SDL_abs SDL_abs_inline
    1.76 -#endif /* !SDL_STDINC_NO_INLINES */
    1.77  
    1.78  /* !!! FIXME: these have side effects. You probably shouldn't use them. */
    1.79  /* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
    1.80 @@ -307,35 +248,14 @@
    1.81  extern DECLSPEC int SDLCALL SDL_isspace(int x);
    1.82  extern DECLSPEC int SDLCALL SDL_toupper(int x);
    1.83  extern DECLSPEC int SDLCALL SDL_tolower(int x);
    1.84 -#ifndef SDL_STDINC_NO_INLINES
    1.85 -#ifdef HAVE_CTYPE_H
    1.86 -SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); }
    1.87 -SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); }
    1.88 -SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); }
    1.89 -SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); }
    1.90 -#else
    1.91 -SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); }
    1.92 -SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
    1.93 -SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
    1.94 -SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
    1.95 -#endif
    1.96 -#define SDL_isdigit SDL_isdigit_inline
    1.97 -#define SDL_isspace SDL_isspace_inline
    1.98 -#define SDL_toupper SDL_toupper_inline
    1.99 -#define SDL_tolower SDL_tolower_inline
   1.100 -#endif /* !SDL_STDINC_NO_INLINES */
   1.101  
   1.102  extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   1.103 -#if defined(HAVE_MEMSET) && !defined(SDL_STDINC_NO_INLINES)
   1.104 -SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); }
   1.105 -#define SDL_memset SDL_memset_inline
   1.106 -#endif
   1.107  
   1.108  #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
   1.109  #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
   1.110  
   1.111 -/* !!! FIXME: does this _really_ beat memset() on any modern platform? */
   1.112 -SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len)
   1.113 +/* Note that the semantics are different from memset() in that this is a 32-bit assignment */
   1.114 +SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t dwords)
   1.115  {
   1.116  #if defined(__GNUC__) && defined(i386)
   1.117      int u0, u1, u2;
   1.118 @@ -343,17 +263,16 @@
   1.119          "cld \n\t"
   1.120          "rep ; stosl \n\t"
   1.121          : "=&D" (u0), "=&a" (u1), "=&c" (u2)
   1.122 -        : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))
   1.123 +        : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
   1.124          : "memory"
   1.125      );
   1.126 -/* !!! FIXME: amd64? */
   1.127  #else
   1.128 -    size_t _n = (len + 3) / 4;
   1.129 +    size_t _n = (dwords + 3) / 4;
   1.130      Uint32 *_p = SDL_static_cast(Uint32 *, dst);
   1.131      Uint32 _val = (val);
   1.132 -    if (len == 0)
   1.133 +    if (dwords == 0)
   1.134          return;
   1.135 -    switch (len % 4)
   1.136 +    switch (dwords % 4)
   1.137      {
   1.138          case 0: do {    *_p++ = _val;
   1.139          case 3:         *_p++ = _val;
   1.140 @@ -366,323 +285,54 @@
   1.141  
   1.142  
   1.143  extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
   1.144 -#if !defined(SDL_STDINC_NO_INLINES)
   1.145 -#if defined(__MACOSX__) && defined(HAVE_MEMCPY)
   1.146 -SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.147 -{
   1.148 -    /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   1.149 -    return memcpy(dst, src, len);
   1.150 -}
   1.151 -#define SDL_memcpy SDL_memcpy_inline
   1.152 -#elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   1.153 -SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.154 -{
   1.155 -    /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   1.156 -    /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   1.157 -    /* !!! FIXME: amd64? */
   1.158 -    int u0, u1, u2;
   1.159 -    __asm__ __volatile__ (
   1.160 -        "cld \n\t"
   1.161 -        "rep ; movsl \n\t"
   1.162 -        "testb $2,%b4 \n\t"
   1.163 -        "je 1f \n\t"
   1.164 -        "movsw \n"
   1.165 -        "1:\ttestb $1,%b4 \n\t"
   1.166 -        "je 2f \n\t"
   1.167 -        "movsb \n"
   1.168 -        "2:"
   1.169 -        : "=&c" (u0), "=&D" (u1), "=&S" (u2)
   1.170 -        : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src)
   1.171 -        : "memory"
   1.172 -    );
   1.173 -    return dst;
   1.174 -}
   1.175 -#define SDL_memcpy SDL_memcpy_inline
   1.176 -#elif defined(HAVE_MEMCPY)
   1.177 -SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.178 -{
   1.179 -    return memcpy(dst, src, len);
   1.180 -}
   1.181 -#define SDL_memcpy SDL_memcpy_inline
   1.182 -#elif defined(HAVE_BCOPY)  /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */
   1.183 -SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.184 -{
   1.185 -    bcopy(src, dst, len);
   1.186 -    return dst;
   1.187 -}
   1.188 -#define SDL_memcpy SDL_memcpy_inline
   1.189 -#endif
   1.190 -#endif /* !SDL_STDINC_NO_INLINES */
   1.191 -
   1.192  
   1.193  SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
   1.194  {
   1.195 -#if defined(__GNUC__) && defined(i386)
   1.196 -    /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   1.197 -    /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   1.198 -    int ecx, edi, esi;
   1.199 -    __asm__ __volatile__ (
   1.200 -        "cld \n\t"
   1.201 -        "rep ; movsl \n\t"
   1.202 -        : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
   1.203 -        : "0" (SDL_static_cast(unsigned, dwords)), "1" (dst), "2" (src)
   1.204 -        : "memory"
   1.205 -    );
   1.206 -    return dst;
   1.207 -#else
   1.208      return SDL_memcpy(dst, src, dwords * 4);
   1.209 -#endif
   1.210  }
   1.211  
   1.212  extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
   1.213 -#if defined(HAVE_MEMMOVE) && !defined(SDL_STDINC_NO_INLINES)
   1.214 -SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); }
   1.215 -#define SDL_memmove SDL_memmove_inline
   1.216 -#endif
   1.217 -
   1.218  extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   1.219 -#if defined(HAVE_MEMCMP) && !defined(SDL_STDINC_NO_INLINES)
   1.220 -SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
   1.221 -#define SDL_memcmp SDL_memcmp_inline
   1.222 -#endif
   1.223 -
   1.224 -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   1.225 -#if defined(HAVE_STRLEN) && !defined(SDL_STDINC_NO_INLINES)
   1.226 -SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
   1.227 -#define SDL_strlen SDL_strlen_inline
   1.228 -#endif
   1.229  
   1.230  extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   1.231 -#if defined(HAVE_WCSLEN) && !defined(SDL_STDINC_NO_INLINES)
   1.232 -SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
   1.233 -#define SDL_wcslen SDL_wcslen_inline
   1.234 -#endif
   1.235 +extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.236 +extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.237  
   1.238 -extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.239 -#if defined(HAVE_WCSLCPY) && !defined(SDL_STDINC_NO_INLINES)
   1.240 -SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
   1.241 -#define SDL_wcslcpy SDL_wcslcpy_inline
   1.242 -#endif
   1.243 -
   1.244 -extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.245 -#if defined(HAVE_WCSLCAT) && !defined(SDL_STDINC_NO_INLINES)
   1.246 -SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
   1.247 -#define SDL_wcslcat SDL_wcslcat_inline
   1.248 -#endif
   1.249 -
   1.250 +extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   1.251  extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   1.252 -#if defined(HAVE_STRLCPY) && !defined(SDL_STDINC_NO_INLINES)
   1.253 -SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
   1.254 -#define SDL_strlcpy SDL_strlcpy_inline
   1.255 -#else
   1.256 -#endif
   1.257 -
   1.258  extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
   1.259 -
   1.260  extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   1.261 -#if defined(HAVE_STRLCAT) && !defined(SDL_STDINC_NO_INLINES)
   1.262 -SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
   1.263 -#define SDL_strlcat SDL_strlcat_inline
   1.264 -#endif
   1.265 -
   1.266  extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
   1.267 -#if defined(HAVE_STRDUP) && !defined(SDL_STDINC_NO_INLINES)
   1.268 -SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
   1.269 -#define SDL_strdup SDL_strdup_inline
   1.270 -#endif
   1.271 -
   1.272  extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
   1.273 -#if defined(HAVE__STRREV) && !defined(SDL_STDINC_NO_INLINES)
   1.274 -SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
   1.275 -#define SDL_strrev SDL_strrev_inline
   1.276 -#endif
   1.277 -
   1.278  extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
   1.279 -#if defined(HAVE__STRUPR) && !defined(SDL_STDINC_NO_INLINES)
   1.280 -SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
   1.281 -#define SDL_strupr SDL_strupr_inline
   1.282 -#endif
   1.283 -
   1.284  extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
   1.285 -#if defined(HAVE__STRLWR) && !defined(SDL_STDINC_NO_INLINES)
   1.286 -SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
   1.287 -#define SDL_strlwr SDL_strlwr_inline
   1.288 -#endif
   1.289 -
   1.290  extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
   1.291 -#ifndef SDL_STDINC_NO_INLINES
   1.292 -#ifdef HAVE_STRCHR
   1.293 -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,strchr(str, c)); }
   1.294 -#define SDL_strchr SDL_strchr_inline
   1.295 -#elif defined(HAVE_INDEX)  /* !!! FIXME: is there anywhere that has this but not strchr? */
   1.296 -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,index(str, c)); }
   1.297 -#define SDL_strchr SDL_strchr_inline
   1.298 -#endif
   1.299 -#endif /* !SDL_STDINC_NO_INLINES */
   1.300 -
   1.301  extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
   1.302 -#ifndef SDL_STDINC_NO_INLINES
   1.303 -#ifdef HAVE_STRRCHR
   1.304 -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,strrchr(str, c)); }
   1.305 -#define SDL_strrchr SDL_strrchr_inline
   1.306 -#elif defined(HAVE_RINDEX)  /* !!! FIXME: is there anywhere that has this but not strrchr? */
   1.307 -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,rindex(str, c)); }
   1.308 -#define SDL_strrchr SDL_strrchr_inline
   1.309 -#endif
   1.310 -#endif /* !SDL_STDINC_NO_INLINES */
   1.311 -
   1.312  extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
   1.313 -#if defined(HAVE_STRSTR) && !defined(SDL_STDINC_NO_INLINES)
   1.314 -SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return SDL_const_cast(char*,strstr(haystack, needle)); }
   1.315 -#define SDL_strstr SDL_strstr_inline
   1.316 -#endif
   1.317 -
   1.318 -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   1.319 -#if defined(HAVE__LTOA) && !defined(SDL_STDINC_NO_INLINES)
   1.320 -SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
   1.321 -#define SDL_ltoa SDL_ltoa_inline
   1.322 -#endif
   1.323  
   1.324  extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
   1.325 -#ifndef SDL_STDINC_NO_INLINES
   1.326 -#ifdef HAVE_ITOA
   1.327 -SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
   1.328 -#else
   1.329 -SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
   1.330 -#endif
   1.331 -#define SDL_itoa SDL_itoa_inline
   1.332 -#endif /* !SDL_STDINC_NO_INLINES */
   1.333 -
   1.334 +extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   1.335 +extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   1.336  extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
   1.337 -#if defined(HAVE__ULTOA) && !defined(SDL_STDINC_NO_INLINES)
   1.338 -SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
   1.339 -#define SDL_ultoa SDL_ultoa_inline
   1.340 -#endif
   1.341 -
   1.342 -extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   1.343 -#ifndef SDL_STDINC_NO_INLINES
   1.344 -#ifdef HAVE__UITOA
   1.345 -SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
   1.346 -#else
   1.347 -SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
   1.348 -#endif
   1.349 -#define SDL_uitoa SDL_uitoa_inline
   1.350 -#endif /* !SDL_STDINC_NO_INLINES */
   1.351 -
   1.352 -
   1.353 -extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   1.354 -#if defined(HAVE_STRTOL) && !defined(SDL_STDINC_NO_INLINES)
   1.355 -SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
   1.356 -#define SDL_strtol SDL_strtol_inline
   1.357 -#endif
   1.358 -
   1.359 -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   1.360 -#if defined(HAVE_STRTOUL) && !defined(SDL_STDINC_NO_INLINES)
   1.361 -SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
   1.362 -#define SDL_strtoul SDL_strtoul_inline
   1.363 -#endif
   1.364 -
   1.365  extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
   1.366 -#if defined(HAVE__I64TOA) && !defined(SDL_STDINC_NO_INLINES)
   1.367 -SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
   1.368 -#define SDL_lltoa SDL_lltoa_inline
   1.369 -#endif
   1.370 -
   1.371  extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
   1.372 -#if defined(HAVE__UI64TOA) && !defined(SDL_STDINC_NO_INLINES)
   1.373 -SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
   1.374 -#define SDL_ulltoa SDL_ulltoa_inline
   1.375 -#endif
   1.376 -
   1.377 -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   1.378 -#if defined(HAVE_STRTOLL) && !defined(SDL_STDINC_NO_INLINES)
   1.379 -SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
   1.380 -#define SDL_strtoll SDL_strtoll_inline
   1.381 -#endif
   1.382 -
   1.383 -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   1.384 -#if defined(HAVE_STRTOULL) && !defined(SDL_STDINC_NO_INLINES)
   1.385 -SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
   1.386 -#define SDL_strtoull SDL_strtoull_inline
   1.387 -#endif
   1.388 -
   1.389 -extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   1.390 -#if defined(HAVE_STRTOD) && !defined(SDL_STDINC_NO_INLINES)
   1.391 -SDL_FORCE_INLINE double SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
   1.392 -#define SDL_strtod SDL_strtod_inline
   1.393 -#endif
   1.394  
   1.395  extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
   1.396 -#ifndef SDL_STDINC_NO_INLINES
   1.397 -#ifdef HAVE_ATOI
   1.398 -SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
   1.399 -#else
   1.400 -SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
   1.401 -#endif
   1.402 -#define SDL_atoi SDL_atoi_inline
   1.403 -#endif /* !SDL_STDINC_NO_INLINES */
   1.404 -
   1.405  extern DECLSPEC double SDLCALL SDL_atof(const char *str);
   1.406 -#ifndef SDL_STDINC_NO_INLINES
   1.407 -#ifdef HAVE_ATOF
   1.408 -SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
   1.409 -#else
   1.410 -SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
   1.411 -#endif
   1.412 -#define SDL_atof SDL_atof_inline
   1.413 -#endif /* !SDL_STDINC_NO_INLINES */
   1.414 -
   1.415 +extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   1.416 +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   1.417 +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   1.418 +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   1.419 +extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   1.420  
   1.421  extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   1.422 -#if defined(HAVE_STRCMP) && !defined(SDL_STDINC_NO_INLINES)
   1.423 -SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
   1.424 -#define SDL_strcmp SDL_strcmp_inline
   1.425 -#endif
   1.426 -
   1.427  extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   1.428 -#if defined(HAVE_STRNCMP) && !defined(SDL_STDINC_NO_INLINES)
   1.429 -SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
   1.430 -#define SDL_strncmp SDL_strncmp_inline
   1.431 -#endif
   1.432 -
   1.433  extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   1.434 -#ifndef SDL_STDINC_NO_INLINES
   1.435 -#ifdef HAVE_STRCASECMP
   1.436 -SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
   1.437 -#define SDL_strcasecmp SDL_strcasecmp_inline
   1.438 -#elif defined(HAVE__STRICMP)
   1.439 -SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
   1.440 -#define SDL_strcasecmp SDL_strcasecmp_inline
   1.441 -#endif
   1.442 -#endif /* !SDL_STDINC_NO_INLINES */
   1.443 -
   1.444  extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   1.445 -#ifndef SDL_STDINC_NO_INLINES
   1.446 -#ifdef HAVE_STRNCASECMP
   1.447 -SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
   1.448 -#define SDL_strncasecmp SDL_strncasecmp_inline
   1.449 -#elif defined(HAVE__STRNICMP)
   1.450 -SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
   1.451 -#define SDL_strncasecmp SDL_strncasecmp_inline
   1.452 -#endif
   1.453 -#endif /* !SDL_STDINC_NO_INLINES */
   1.454  
   1.455 -/* Not doing SDL_*_inline functions for these, because of the varargs. */
   1.456  extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   1.457 -#ifdef HAVE_SSCANF
   1.458 -#define SDL_sscanf sscanf
   1.459 -#endif
   1.460 -
   1.461  extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   1.462 -#ifdef HAVE_SNPRINTF
   1.463 -#define SDL_snprintf snprintf
   1.464 -#endif
   1.465 -
   1.466  extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   1.467 -#if defined(HAVE_VSNPRINTF) && !defined(SDL_STDINC_NO_INLINES)
   1.468 -SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); }
   1.469 -#define SDL_vsnprintf SDL_vsnprintf_inline
   1.470 -#endif
   1.471  
   1.472  #ifndef HAVE_M_PI
   1.473  #ifndef M_PI
   1.474 @@ -691,100 +341,19 @@
   1.475  #endif
   1.476  
   1.477  extern DECLSPEC double SDLCALL SDL_atan(double x);
   1.478 -#if defined(HAVE_ATAN) && !defined(SDL_STDINC_NO_INLINES)
   1.479 -SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
   1.480 -#define SDL_atan SDL_atan_inline
   1.481 -#endif
   1.482 -
   1.483  extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
   1.484 -#if defined(HAVE_ATAN2) && !defined(SDL_STDINC_NO_INLINES)
   1.485 -SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
   1.486 -#define SDL_atan2 SDL_atan2_inline
   1.487 -#endif
   1.488 -
   1.489  extern DECLSPEC double SDLCALL SDL_ceil(double x);
   1.490 -#ifndef SDL_STDINC_NO_INLINES
   1.491 -#ifdef HAVE_CEIL
   1.492 -SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
   1.493 -#else
   1.494 -SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
   1.495 -#endif
   1.496 -#define SDL_ceil SDL_ceil_inline
   1.497 -#endif /* !SDL_STDINC_NO_INLINES */
   1.498 -
   1.499  extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   1.500 -#if defined(HAVE_COPYSIGN) && !defined(SDL_STDINC_NO_INLINES)
   1.501 -SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
   1.502 -#define SDL_copysign SDL_copysign_inline
   1.503 -#endif
   1.504 -
   1.505  extern DECLSPEC double SDLCALL SDL_cos(double x);
   1.506 -#if defined(HAVE_COS) && !defined(SDL_STDINC_NO_INLINES)
   1.507 -SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
   1.508 -#define SDL_cos SDL_cos_inline
   1.509 -#endif
   1.510 -
   1.511  extern DECLSPEC float SDLCALL SDL_cosf(float x);
   1.512 -#ifndef SDL_STDINC_NO_INLINES
   1.513 -#ifdef HAVE_COSF
   1.514 -SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
   1.515 -#else
   1.516 -SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
   1.517 -#endif
   1.518 -#define SDL_cosf SDL_cosf_inline
   1.519 -#endif /* !SDL_STDINC_NO_INLINES */
   1.520 -
   1.521  extern DECLSPEC double SDLCALL SDL_fabs(double x);
   1.522 -#if defined(HAVE_FABS) && !defined(SDL_STDINC_NO_INLINES)
   1.523 -SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
   1.524 -#define SDL_fabs SDL_fabs_inline
   1.525 -#endif
   1.526 -
   1.527  extern DECLSPEC double SDLCALL SDL_floor(double x);
   1.528 -#if defined(HAVE_FLOOR) && !defined(SDL_STDINC_NO_INLINES)
   1.529 -SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
   1.530 -#define SDL_floor SDL_floor_inline
   1.531 -#endif
   1.532 -
   1.533  extern DECLSPEC double SDLCALL SDL_log(double x);
   1.534 -#if defined(HAVE_LOG) && !defined(SDL_STDINC_NO_INLINES)
   1.535 -SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
   1.536 -#define SDL_log SDL_log_inline
   1.537 -#endif
   1.538 -
   1.539  extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   1.540 -#if defined(HAVE_POW) && !defined(SDL_STDINC_NO_INLINES)
   1.541 -SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
   1.542 -#define SDL_pow SDL_pow_inline
   1.543 -#endif
   1.544 -
   1.545  extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   1.546 -#if defined(HAVE_SCALBN) && !defined(SDL_STDINC_NO_INLINES)
   1.547 -SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
   1.548 -#define SDL_scalbn SDL_scalbn_inline
   1.549 -#endif
   1.550 -
   1.551  extern DECLSPEC double SDLCALL SDL_sin(double x);
   1.552 -#if defined(HAVE_SIN) && !defined(SDL_STDINC_NO_INLINES)
   1.553 -SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
   1.554 -#define SDL_sin SDL_sin_inline
   1.555 -#endif
   1.556 -
   1.557  extern DECLSPEC float SDLCALL SDL_sinf(float x);
   1.558 -#ifndef SDL_STDINC_NO_INLINES
   1.559 -#ifdef HAVE_SINF
   1.560 -SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
   1.561 -#else
   1.562 -SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
   1.563 -#endif
   1.564 -#define SDL_sinf SDL_sinf_inline
   1.565 -#endif /* !SDL_STDINC_NO_INLINES */
   1.566 -
   1.567  extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   1.568 -#if defined(HAVE_SQRT) && !defined(SDL_STDINC_NO_INLINES)
   1.569 -SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
   1.570 -#define SDL_sqrt SDL_sqrt_inline
   1.571 -#endif
   1.572  
   1.573  /* The SDL implementation of iconv() returns these error codes */
   1.574  #define SDL_ICONV_ERROR     (size_t)-1
     2.1 --- a/src/libm/math_libm.h	Fri Jul 05 21:37:27 2013 -0700
     2.2 +++ b/src/libm/math_libm.h	Fri Jul 05 23:57:19 2013 -0700
     2.3 @@ -18,74 +18,19 @@
     2.4       misrepresented as being the original software.
     2.5    3. This notice may not be removed or altered from any source distribution.
     2.6  */
     2.7 -#include "SDL_config.h"
     2.8 -#include "SDL_stdinc.h"
     2.9  
    2.10  /* Math routines from uClibc: http://www.uclibc.org */
    2.11  
    2.12 -#ifdef HAVE_ATAN
    2.13 -#define atan            SDL_uclibc_atan
    2.14 -#else
    2.15 -#define atan            SDL_atan
    2.16 -#endif
    2.17 -double atan(double x);
    2.18 -
    2.19 -#ifndef HAVE_ATAN2
    2.20 -#define __ieee754_atan2 SDL_atan2
    2.21 -#endif
    2.22 -
    2.23 -#ifdef HAVE_COPYSIGN
    2.24 -#define copysign        SDL_uclibc_copysign
    2.25 -#else
    2.26 -#define copysign        SDL_copysign
    2.27 -#endif
    2.28 -double copysign(double x, double y);
    2.29 -
    2.30 -#ifdef HAVE_COS
    2.31 -#define cos             SDL_uclibc_cos
    2.32 -#else
    2.33 -#define cos             SDL_cos
    2.34 -#endif
    2.35 -double cos(double x);
    2.36 -
    2.37 -#ifdef HAVE_FABS
    2.38 -#define fabs            SDL_uclibc_fabs
    2.39 -#else
    2.40 -#define fabs            SDL_fabs
    2.41 -#endif
    2.42 -double fabs(double x);
    2.43 -
    2.44 -#ifdef HAVE_FLOOR
    2.45 -#define floor           SDL_uclibc_floor
    2.46 -#else
    2.47 -#define floor           SDL_floor
    2.48 -#endif
    2.49 -double floor(double x);
    2.50 -
    2.51 -#ifndef HAVE_LOG
    2.52 -#define __ieee754_log   SDL_log
    2.53 -#endif
    2.54 -
    2.55 -#ifndef HAVE_POW
    2.56 -#define __ieee754_pow   SDL_pow
    2.57 -#endif
    2.58 -
    2.59 -#ifdef HAVE_SCALBN
    2.60 -#define scalbn          SDL_uclibc_scalbn
    2.61 -#else
    2.62 -#define scalbn          SDL_scalbn
    2.63 -#endif
    2.64 -double scalbn(double x, int n);
    2.65 -
    2.66 -#ifdef HAVE_SIN
    2.67 -#define sin             SDL_uclibc_sin
    2.68 -#else
    2.69 -#define sin             SDL_sin
    2.70 -#endif
    2.71 -double sin(double x);
    2.72 -
    2.73 -#ifndef HAVE_SQRT
    2.74 -#define __ieee754_sqrt  SDL_sqrt
    2.75 -#endif
    2.76 +double SDL_uclibc_atan(double x);
    2.77 +double SDL_uclibc_atan2(double y, double x);    
    2.78 +double SDL_uclibc_copysign(double x, double y);       
    2.79 +double SDL_uclibc_cos(double x);         
    2.80 +double SDL_uclibc_fabs(double x);        
    2.81 +double SDL_uclibc_floor(double x);
    2.82 +double SDL_uclibc_log(double x);
    2.83 +double SDL_uclibc_pow(double x, double y);    
    2.84 +double SDL_uclibc_scalbn(double x, int n);
    2.85 +double SDL_uclibc_sin(double x);
    2.86 +double SDL_uclibc_sqrt(double x);
    2.87  
    2.88  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/libm/math_private.h	Fri Jul 05 21:37:27 2013 -0700
     3.2 +++ b/src/libm/math_private.h	Fri Jul 05 23:57:19 2013 -0700
     3.3 @@ -27,6 +27,18 @@
     3.4  
     3.5  typedef unsigned int u_int32_t;
     3.6  
     3.7 +#define atan            SDL_uclibc_atan
     3.8 +#define __ieee754_atan2 SDL_uclibc_atan2
     3.9 +#define copysign        SDL_uclibc_copysign
    3.10 +#define cos             SDL_uclibc_cos
    3.11 +#define fabs            SDL_uclibc_fabs
    3.12 +#define floor           SDL_uclibc_floor
    3.13 +#define __ieee754_log   SDL_uclibc_log
    3.14 +#define __ieee754_pow   SDL_uclibc_pow
    3.15 +#define scalbn          SDL_uclibc_scalbn
    3.16 +#define sin             SDL_uclibc_sin
    3.17 +#define __ieee754_sqrt  SDL_uclibc_sqrt
    3.18 +
    3.19  /* The original fdlibm code used statements like:
    3.20  	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
    3.21  	ix0 = *(n0+(int*)&x);			* high word of x *
     4.1 --- a/src/stdlib/SDL_getenv.c	Fri Jul 05 21:37:27 2013 -0700
     4.2 +++ b/src/stdlib/SDL_getenv.c	Fri Jul 05 23:57:19 2013 -0700
     4.3 @@ -31,9 +31,12 @@
     4.4  
     4.5  
     4.6  /* Put a variable into the environment */
     4.7 -#ifdef SDL_setenv
     4.8 -#undef SDL_setenv
     4.9 -int SDL_setenv(const char *name, const char *value, int overwrite) { return SDL_setenv_inline(name, value, overwrite); }
    4.10 +#if defined(HAVE_SETENV)
    4.11 +int
    4.12 +SDL_setenv(const char *name, const char *value, int overwrite)
    4.13 +{
    4.14 +    return setenv(name, value, overwrite);
    4.15 +}
    4.16  #elif defined(__WIN32__)
    4.17  int
    4.18  SDL_setenv(const char *name, const char *value, int overwrite)
    4.19 @@ -143,9 +146,12 @@
    4.20  #endif
    4.21  
    4.22  /* Retrieve a variable named "name" from the environment */
    4.23 -#ifdef SDL_getenv
    4.24 -#undef SDL_getenv
    4.25 -char *SDL_getenv(const char *name) { return SDL_getenv_inline(name); }
    4.26 +#if defined(HAVE_GETENV)
    4.27 +char *
    4.28 +SDL_getenv(const char *name)
    4.29 +{
    4.30 +    return getenv(name);
    4.31 +}
    4.32  #elif defined(__WIN32__)
    4.33  char *
    4.34  SDL_getenv(const char *name)
     5.1 --- a/src/stdlib/SDL_malloc.c	Fri Jul 05 21:37:27 2013 -0700
     5.2 +++ b/src/stdlib/SDL_malloc.c	Fri Jul 05 23:57:19 2013 -0700
     5.3 @@ -24,16 +24,27 @@
     5.4  
     5.5  #include "SDL_stdinc.h"
     5.6  
     5.7 -#ifdef SDL_malloc
     5.8 -/* expose the symbol, but use what we figured out elsewhere. */
     5.9 -#undef SDL_malloc
    5.10 -#undef SDL_calloc
    5.11 -#undef SDL_realloc
    5.12 -#undef SDL_free
    5.13 -void *SDL_malloc(size_t size) { return SDL_malloc_inline(size); }
    5.14 -void *SDL_calloc(size_t nmemb, size_t size) { return SDL_calloc_inline(nmemb, size); }
    5.15 -void *SDL_realloc(void *ptr, size_t size) { return SDL_realloc_inline(ptr, size); }
    5.16 -void SDL_free(void *ptr) { SDL_free_inline(ptr); }
    5.17 +#if defined(HAVE_MALLOC)
    5.18 +
    5.19 +void *SDL_malloc(size_t size)
    5.20 +{
    5.21 +    return malloc(size);
    5.22 +}
    5.23 +
    5.24 +void *SDL_calloc(size_t nmemb, size_t size)
    5.25 +{
    5.26 +    return calloc(nmemb, size);
    5.27 +}
    5.28 +
    5.29 +void *SDL_realloc(void *ptr, size_t size)
    5.30 +{
    5.31 +    return realloc(ptr, size);
    5.32 +}
    5.33 +
    5.34 +void SDL_free(void *ptr)
    5.35 +{
    5.36 +    free(ptr);
    5.37 +}
    5.38  
    5.39  #else  /* the rest of this is a LOT of tapdancing to implement malloc. :) */
    5.40  
     6.1 --- a/src/stdlib/SDL_qsort.c	Fri Jul 05 21:37:27 2013 -0700
     6.2 +++ b/src/stdlib/SDL_qsort.c	Fri Jul 05 23:57:19 2013 -0700
     6.3 @@ -51,12 +51,11 @@
     6.4  #include "SDL_stdinc.h"
     6.5  #include "SDL_assert.h"
     6.6  
     6.7 -#ifdef SDL_qsort
     6.8 -#undef SDL_qsort
     6.9 +#if defined(HAVE_QSORT)
    6.10  void
    6.11  SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *))
    6.12  {
    6.13 -    SDL_qsort_inline(base, nmemb, size, compare);
    6.14 +    qsort(base, nmemb, size, compare);
    6.15  }
    6.16  #else
    6.17  
     7.1 --- a/src/stdlib/SDL_stdlib.c	Fri Jul 05 21:37:27 2013 -0700
     7.2 +++ b/src/stdlib/SDL_stdlib.c	Fri Jul 05 23:57:19 2013 -0700
     7.3 @@ -23,24 +23,169 @@
     7.4  /* This file contains portable stdlib functions for SDL */
     7.5  
     7.6  #include "SDL_stdinc.h"
     7.7 +#include "../libm/math_libm.h"
     7.8  
     7.9 -/* these are always #defined, make them real symbol in the library, too... */
    7.10 -#undef SDL_ceil
    7.11 -#undef SDL_abs
    7.12 -#undef SDL_sinf
    7.13 -#undef SDL_cosf
    7.14 -#undef SDL_isdigit
    7.15 -#undef SDL_isspace
    7.16 -#undef SDL_toupper
    7.17 -#undef SDL_tolower
    7.18 -double SDL_ceil(double x) { return SDL_ceil_inline(x); }
    7.19 -float SDL_cosf(float x) { return SDL_cosf_inline(x); }
    7.20 -float SDL_sinf(float x) { return SDL_sinf_inline(x); }
    7.21 -int SDL_abs(int x) { return SDL_abs_inline(x); }
    7.22 -int SDL_isdigit(int x) { return SDL_isdigit_inline(x); }
    7.23 -int SDL_isspace(int x) { return SDL_isspace_inline(x); }
    7.24 -int SDL_toupper(int x) { return SDL_toupper_inline(x); }
    7.25 -int SDL_tolower(int x) { return SDL_tolower_inline(x); }
    7.26 +
    7.27 +double
    7.28 +SDL_atan(double x)
    7.29 +{
    7.30 +#ifdef HAVE_ATAN
    7.31 +    return atan(x);
    7.32 +#else
    7.33 +    return SDL_uclibc_atan(x);
    7.34 +#endif /* HAVE_ATAN */
    7.35 +}
    7.36 +
    7.37 +double
    7.38 +SDL_atan2(double x, double y)
    7.39 +{
    7.40 +#if defined(HAVE_ATAN2)
    7.41 +    return atan2(x, y);
    7.42 +#else
    7.43 +    return SDL_uclibc_atan2(x, y);
    7.44 +#endif /* HAVE_ATAN2 */
    7.45 +}
    7.46 +
    7.47 +double
    7.48 +SDL_ceil(double x)
    7.49 +{
    7.50 +#ifdef HAVE_CEIL
    7.51 +    return ceil(x);
    7.52 +#else
    7.53 +    return (double)(int)((x)+0.5);
    7.54 +#endif /* HAVE_CEIL */
    7.55 +}
    7.56 +
    7.57 +double
    7.58 +SDL_copysign(double x, double y)
    7.59 +{
    7.60 +#if defined(HAVE_COPYSIGN)
    7.61 +    return copysign(x, y);
    7.62 +#else
    7.63 +    return SDL_uclibc_copysign(x, y);
    7.64 +#endif /* HAVE_COPYSIGN */
    7.65 +}
    7.66 +
    7.67 +double
    7.68 +SDL_cos(double x)
    7.69 +{
    7.70 +#if defined(HAVE_COS)
    7.71 +    return cos(x);
    7.72 +#else
    7.73 +    return SDL_uclibc_cos(x);
    7.74 +#endif /* HAVE_COS */
    7.75 +}
    7.76 +
    7.77 +float
    7.78 +SDL_cosf(float x)
    7.79 +{
    7.80 +#ifdef HAVE_COSF
    7.81 +    return cosf(x);
    7.82 +#else
    7.83 +    return (float)SDL_cos((double)x);
    7.84 +#endif
    7.85 +}
    7.86 +
    7.87 +double
    7.88 +SDL_fabs(double x)
    7.89 +{
    7.90 +#if defined(HAVE_FABS)
    7.91 +    return fabs(x); 
    7.92 +#else
    7.93 +    return SDL_uclibc_fabs(x);
    7.94 +#endif /* HAVE_FABS */
    7.95 +}
    7.96 +
    7.97 +double
    7.98 +SDL_floor(double x)
    7.99 +{
   7.100 +#if defined(HAVE_FLOOR)
   7.101 +    return floor(x);
   7.102 +#else
   7.103 +    return SDL_uclibc_floor(x);
   7.104 +#endif /* HAVE_FLOOR */
   7.105 +}
   7.106 +
   7.107 +double
   7.108 +SDL_log(double x)
   7.109 +{
   7.110 +#if defined(HAVE_LOG)
   7.111 +    return log(x);
   7.112 +#else
   7.113 +    return SDL_uclibc_log(x);
   7.114 +#endif /* HAVE_LOG */
   7.115 +}
   7.116 +
   7.117 +double
   7.118 +SDL_pow(double x, double y)
   7.119 +{
   7.120 +#if defined(HAVE_POW)
   7.121 +    return pow(x, y);
   7.122 +#else
   7.123 +    return SDL_uclibc_pow(x, y);
   7.124 +#endif /* HAVE_POW */
   7.125 +}
   7.126 +
   7.127 +double
   7.128 +SDL_scalbn(double x, int n)
   7.129 +{
   7.130 +#if defined(HAVE_SCALBN)
   7.131 +    return scalbn(x, n);
   7.132 +#else
   7.133 +    return SDL_uclibc_scalbn(x, n);
   7.134 +#endif /* HAVE_SCALBN */
   7.135 +}
   7.136 +
   7.137 +double
   7.138 +SDL_sin(double x)
   7.139 +{
   7.140 +#if defined(HAVE_SIN)
   7.141 +    return sin(x);
   7.142 +#else
   7.143 +    return SDL_uclibc_sin(x);
   7.144 +#endif /* HAVE_SIN */
   7.145 +}
   7.146 +
   7.147 +float 
   7.148 +SDL_sinf(float x)
   7.149 +{
   7.150 +#ifdef HAVE_SINF
   7.151 +    return sinf(x);
   7.152 +#else
   7.153 +    return (float)SDL_sin((double)x);
   7.154 +#endif /* HAVE_SINF */
   7.155 +}
   7.156 +
   7.157 +double
   7.158 +SDL_sqrt(double x)
   7.159 +{
   7.160 +#if defined(HAVE_SQRT)
   7.161 +    return sqrt(x);
   7.162 +#else
   7.163 +    return SDL_uclibc_sqrt(x);
   7.164 +#endif
   7.165 +}
   7.166 +
   7.167 +int SDL_abs(int x)
   7.168 +{
   7.169 +#ifdef HAVE_ABS
   7.170 +    return abs(x);
   7.171 +#else
   7.172 +    return ((x) < 0 ? -(x) : (x));
   7.173 +#endif
   7.174 +}
   7.175 +
   7.176 +#ifdef HAVE_CTYPE_H
   7.177 +int SDL_isdigit(int x) { return isdigit(x); }
   7.178 +int SDL_isspace(int x) { return isspace(x); }
   7.179 +int SDL_toupper(int x) { return toupper(x); }
   7.180 +int SDL_tolower(int x) { return tolower(x); }
   7.181 +#else
   7.182 +int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
   7.183 +int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
   7.184 +int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   7.185 +int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   7.186 +#endif
   7.187  
   7.188  
   7.189  #ifndef HAVE_LIBC
     8.1 --- a/src/stdlib/SDL_string.c	Fri Jul 05 21:37:27 2013 -0700
     8.2 +++ b/src/stdlib/SDL_string.c	Fri Jul 05 23:57:19 2013 -0700
     8.3 @@ -24,17 +24,6 @@
     8.4  
     8.5  #include "SDL_stdinc.h"
     8.6  
     8.7 -/* these are always #defined, make them real symbol in the library, too... */
     8.8 -#undef SDL_itoa
     8.9 -#undef SDL_uitoa
    8.10 -#undef SDL_atoi
    8.11 -#undef SDL_atof
    8.12 -char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); }
    8.13 -char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); }
    8.14 -int SDL_atoi(const char *str) { return SDL_atoi_inline(str); }
    8.15 -double SDL_atof(const char *str) { return SDL_atof_inline(str); }
    8.16 -
    8.17 -
    8.18  
    8.19  #define SDL_isupperhex(X)   (((X) >= 'A') && ((X) <= 'F'))
    8.20  #define SDL_islowerhex(X)   (((X) >= 'a') && ((X) <= 'f'))
    8.21 @@ -54,7 +43,7 @@
    8.22          return 0;
    8.23  }
    8.24  
    8.25 -#if !defined(SDL_sscanf) || !defined(SDL_strtol)
    8.26 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL)
    8.27  static size_t
    8.28  SDL_ScanLong(const char *text, int radix, long *valuep)
    8.29  {
    8.30 @@ -95,7 +84,7 @@
    8.31  }
    8.32  #endif
    8.33  
    8.34 -#if !defined(SDL_sscanf) || !defined(SDL_strtoul) || !defined(SDL_strtod)
    8.35 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
    8.36  static size_t
    8.37  SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
    8.38  {
    8.39 @@ -127,7 +116,7 @@
    8.40  }
    8.41  #endif
    8.42  
    8.43 -#ifndef SDL_sscanf
    8.44 +#ifndef HAVE_SSCANF
    8.45  static size_t
    8.46  SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
    8.47  {
    8.48 @@ -159,7 +148,7 @@
    8.49  }
    8.50  #endif
    8.51  
    8.52 -#if !defined(SDL_sscanf) || !defined(SDL_strtoll)
    8.53 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
    8.54  static size_t
    8.55  SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
    8.56  {
    8.57 @@ -200,7 +189,7 @@
    8.58  }
    8.59  #endif
    8.60  
    8.61 -#if !defined(SDL_sscanf) || !defined(SDL_strtoull)
    8.62 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
    8.63  static size_t
    8.64  SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
    8.65  {
    8.66 @@ -232,7 +221,7 @@
    8.67  }
    8.68  #endif
    8.69  
    8.70 -#if !defined(SDL_sscanf) || !defined(SDL_strtod)
    8.71 +#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
    8.72  static size_t
    8.73  SDL_ScanFloat(const char *text, double *valuep)
    8.74  {
    8.75 @@ -268,14 +257,12 @@
    8.76  }
    8.77  #endif
    8.78  
    8.79 -
    8.80 -#ifdef SDL_memset
    8.81 -#undef SDL_memset
    8.82 -void *SDL_memset(void *dst, int c, size_t len) { return SDL_memset_inline(dst, c, len); }
    8.83 -#else
    8.84  void *
    8.85  SDL_memset(void *dst, int c, size_t len)
    8.86  {
    8.87 +#if defined(HAVE_MEMSET)
    8.88 +    return memset(dst, c, len);
    8.89 +#else
    8.90      size_t left = (len % 4);
    8.91      Uint32 *dstp4;
    8.92      Uint8 *dstp1;
    8.93 @@ -299,14 +286,9 @@
    8.94      }
    8.95  
    8.96      return dst;
    8.97 +#endif /* HAVE_MEMSET */
    8.98  }
    8.99 -#endif
   8.100 -
   8.101  
   8.102 -#ifdef SDL_memcpy
   8.103 -#undef SDL_memcpy
   8.104 -void *SDL_memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy_inline(dst, src, len); }
   8.105 -#else
   8.106  void *
   8.107  SDL_memcpy(void *dst, const void *src, size_t len)
   8.108  {
   8.109 @@ -315,6 +297,11 @@
   8.110         On my machine this is twice as fast as the C code below.
   8.111       */
   8.112      return __builtin_memcpy(dst, src, len);
   8.113 +#elif defined(HAVE_MEMCPY)
   8.114 +    return memcpy(dst, src, len);
   8.115 +#elif defined(HAVE_BCOPY)
   8.116 +    bcopy(src, dst, len);
   8.117 +    return dst;
   8.118  #else
   8.119      /* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
   8.120         using Uint32* pointers, so we need to make sure the pointers are
   8.121 @@ -354,16 +341,13 @@
   8.122      return dst;
   8.123  #endif /* __GNUC__ */
   8.124  }
   8.125 -#endif
   8.126  
   8.127 -
   8.128 -#ifdef SDL_memmove
   8.129 -#undef SDL_memmove
   8.130 -void *SDL_memmove(void *dst, const void *src, size_t len) { return SDL_memmove_inline(dst, src, len); }
   8.131 -#else
   8.132  void *
   8.133  SDL_memmove(void *dst, const void *src, size_t len)
   8.134  {
   8.135 +#if defined(HAVE_MEMMOVE)
   8.136 +    return memmove(dst, src, len);
   8.137 +#else
   8.138      char *srcp = (char *) src;
   8.139      char *dstp = (char *) dst;
   8.140  
   8.141 @@ -379,16 +363,15 @@
   8.142          }
   8.143      }
   8.144      return dst;
   8.145 +#endif /* HAVE_MEMMOVE */
   8.146  }
   8.147 -#endif
   8.148  
   8.149 -#ifdef SDL_memcmp
   8.150 -#undef SDL_memcmp
   8.151 -int SDL_memcmp(const void *s1, const void *s2, size_t len) { return SDL_memcmp_inline(s1, s2, len); }
   8.152 -#else
   8.153  int
   8.154  SDL_memcmp(const void *s1, const void *s2, size_t len)
   8.155  {
   8.156 +#if defined(HAVE_MEMCMP)
   8.157 +    return memcmp(s1, s2, len);
   8.158 +#else
   8.159      char *s1p = (char *) s1;
   8.160      char *s2p = (char *) s2;
   8.161      while (len--) {
   8.162 @@ -399,46 +382,43 @@
   8.163          ++s2p;
   8.164      }
   8.165      return 0;
   8.166 +#endif /* HAVE_MEMCMP */
   8.167  }
   8.168 -#endif
   8.169  
   8.170 -#ifdef SDL_strlen
   8.171 -#undef SDL_strlen
   8.172 -size_t SDL_strlen(const char *string) { return SDL_strlen_inline(string); }
   8.173 -#else
   8.174  size_t
   8.175  SDL_strlen(const char *string)
   8.176  {
   8.177 +#if defined(HAVE_STRLEN)
   8.178 +    return strlen(str);
   8.179 +#else
   8.180      size_t len = 0;
   8.181      while (*string++) {
   8.182          ++len;
   8.183      }
   8.184      return len;
   8.185 +#endif /* HAVE_STRLEN */
   8.186  }
   8.187 -#endif
   8.188  
   8.189 -#ifdef SDL_wcslen
   8.190 -#undef SDL_wcslen
   8.191 -size_t SDL_wcslen(const wchar_t * string) { return SDL_wcslen_inline(string); }
   8.192 -#else
   8.193  size_t
   8.194  SDL_wcslen(const wchar_t * string)
   8.195  {
   8.196 +#if defined(HAVE_WCSLEN)
   8.197 +    return wcslen(wstr);
   8.198 +#else
   8.199      size_t len = 0;
   8.200      while (*string++) {
   8.201          ++len;
   8.202      }
   8.203      return len;
   8.204 +#endif /* HAVE_WCSLEN */
   8.205  }
   8.206 -#endif
   8.207  
   8.208 -#ifdef SDL_wcslcpy
   8.209 -#undef SDL_wcslcpy
   8.210 -size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcpy_inline(dst, src, maxlen); }
   8.211 -#else
   8.212  size_t
   8.213  SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
   8.214  {
   8.215 +#if defined(HAVE_WCSLCPY)
   8.216 +    return wcslcpy(dst, src, maxlen);
   8.217 +#else
   8.218      size_t srclen = SDL_wcslen(src);
   8.219      if (maxlen > 0) {
   8.220          size_t len = SDL_min(srclen, maxlen - 1);
   8.221 @@ -446,32 +426,30 @@
   8.222          dst[len] = '\0';
   8.223      }
   8.224      return srclen;
   8.225 +#endif /* HAVE_WCSLCPY */
   8.226  }
   8.227 -#endif
   8.228  
   8.229 -#ifdef SDL_wcslcat
   8.230 -#undef SDL_wcslcat
   8.231 -size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcat_inline(dst, src, maxlen); }
   8.232 -#else
   8.233  size_t
   8.234  SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
   8.235  {
   8.236 +#if defined(HAVE_WCSLCAT)
   8.237 +    return wcslcat(dst, src, maxlen);
   8.238 +#else
   8.239      size_t dstlen = SDL_wcslen(dst);
   8.240      size_t srclen = SDL_wcslen(src);
   8.241      if (dstlen < maxlen) {
   8.242          SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
   8.243      }
   8.244      return dstlen + srclen;
   8.245 +#endif /* HAVE_WCSLCAT */
   8.246  }
   8.247 -#endif
   8.248  
   8.249 -#ifdef SDL_strlcpy
   8.250 -#undef SDL_strlcpy
   8.251 -size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { return SDL_strlcpy_inline(dst, src, maxlen); }
   8.252 -#else
   8.253  size_t
   8.254  SDL_strlcpy(char *dst, const char *src, size_t maxlen)
   8.255  {
   8.256 +#if defined(HAVE_STRLCPY)
   8.257 +    return strlcpy(dst, src, maxlen);
   8.258 +#else
   8.259      size_t srclen = SDL_strlen(src);
   8.260      if (maxlen > 0) {
   8.261          size_t len = SDL_min(srclen, maxlen - 1);
   8.262 @@ -479,8 +457,8 @@
   8.263          dst[len] = '\0';
   8.264      }
   8.265      return srclen;
   8.266 +#endif /* HAVE_STRLCPY */
   8.267  }
   8.268 -#endif
   8.269  
   8.270  size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
   8.271  {
   8.272 @@ -514,45 +492,42 @@
   8.273      return bytes;
   8.274  }
   8.275  
   8.276 -#ifdef SDL_strlcat
   8.277 -#undef SDL_strlcat
   8.278 -size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { return SDL_strlcat_inline(dst, src, maxlen); }
   8.279 -#else
   8.280  size_t
   8.281  SDL_strlcat(char *dst, const char *src, size_t maxlen)
   8.282  {
   8.283 +#if defined(HAVE_STRLCAT)
   8.284 +    return strlcat(dst, src, maxlen);
   8.285 +#else
   8.286      size_t dstlen = SDL_strlen(dst);
   8.287      size_t srclen = SDL_strlen(src);
   8.288      if (dstlen < maxlen) {
   8.289          SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
   8.290      }
   8.291      return dstlen + srclen;
   8.292 +#endif /* HAVE_STRLCAT */
   8.293  }
   8.294 -#endif
   8.295  
   8.296 -#ifdef SDL_strdup
   8.297 -#undef SDL_strdup
   8.298 -char *SDL_strdup(const char *string) { return SDL_strdup_inline(string); }
   8.299 -#else
   8.300  char *
   8.301  SDL_strdup(const char *string)
   8.302  {
   8.303 +#if defined(HAVE_STRDUP)
   8.304 +    return strdup(str);
   8.305 +#else
   8.306      size_t len = SDL_strlen(string) + 1;
   8.307      char *newstr = SDL_malloc(len);
   8.308      if (newstr) {
   8.309          SDL_strlcpy(newstr, string, len);
   8.310      }
   8.311      return newstr;
   8.312 +#endif /* HAVE_STRDUP */
   8.313  }
   8.314 -#endif
   8.315  
   8.316 -#ifdef SDL_strrev
   8.317 -#undef SDL_strrev
   8.318 -char *SDL_strrev(char *string) { return SDL_strrev_inline(string); }
   8.319 -#else
   8.320  char *
   8.321  SDL_strrev(char *string)
   8.322  {
   8.323 +#if defined(HAVE__STRREV)
   8.324 +    return _strrev(str);
   8.325 +#else
   8.326      size_t len = SDL_strlen(string);
   8.327      char *a = &string[0];
   8.328      char *b = &string[len - 1];
   8.329 @@ -563,48 +538,47 @@
   8.330          *b-- = c;
   8.331      }
   8.332      return string;
   8.333 +#endif /* HAVE__STRREV */
   8.334  }
   8.335 -#endif
   8.336  
   8.337 -#ifdef SDL_strupr
   8.338 -#undef SDL_strupr
   8.339 -char *SDL_strupr(char *string) { return SDL_strupr_inline(string); }
   8.340 -#else
   8.341  char *
   8.342  SDL_strupr(char *string)
   8.343  {
   8.344 +#if defined(HAVE__STRUPR)
   8.345 +    return _strupr(str);
   8.346 +#else
   8.347      char *bufp = string;
   8.348      while (*bufp) {
   8.349          *bufp = SDL_toupper((unsigned char) *bufp);
   8.350          ++bufp;
   8.351      }
   8.352      return string;
   8.353 +#endif /* HAVE__STRUPR */
   8.354  }
   8.355 -#endif
   8.356  
   8.357 -#ifdef SDL_strlwr
   8.358 -#undef SDL_strlwr
   8.359 -char *SDL_strlwr(char *string) { return SDL_strlwr_inline(string); }
   8.360 -#else
   8.361  char *
   8.362  SDL_strlwr(char *string)
   8.363  {
   8.364 +#if defined(HAVE__STRLWR)
   8.365 +    return _strlwr(str);
   8.366 +#else
   8.367      char *bufp = string;
   8.368      while (*bufp) {
   8.369          *bufp = SDL_tolower((unsigned char) *bufp);
   8.370          ++bufp;
   8.371      }
   8.372      return string;
   8.373 +#endif /* HAVE__STRLWR */
   8.374  }
   8.375 -#endif
   8.376  
   8.377 -#ifdef SDL_strchr
   8.378 -#undef SDL_strchr
   8.379 -char *SDL_strchr(const char *string, int c) { return SDL_strchr_inline(string, c); }
   8.380 -#else
   8.381  char *
   8.382  SDL_strchr(const char *string, int c)
   8.383  {
   8.384 +#ifdef HAVE_STRCHR
   8.385 +    return SDL_const_cast(char*,strchr(str, c));
   8.386 +#elif defined(HAVE_INDEX)
   8.387 +    return SDL_const_cast(char*,index(str, c));
   8.388 +#else
   8.389      while (*string) {
   8.390          if (*string == c) {
   8.391              return (char *) string;
   8.392 @@ -612,16 +586,17 @@
   8.393          ++string;
   8.394      }
   8.395      return NULL;
   8.396 +#endif /* HAVE_STRCHR */
   8.397  }
   8.398 -#endif
   8.399  
   8.400 -#ifdef SDL_strrchr
   8.401 -#undef SDL_strrchr
   8.402 -char *SDL_strrchr(const char *string, int c) { return SDL_strrchr_inline(string, c); }
   8.403 -#else
   8.404  char *
   8.405  SDL_strrchr(const char *string, int c)
   8.406  {
   8.407 +#ifdef HAVE_STRRCHR
   8.408 +    return SDL_const_cast(char*,strrchr(str, c));
   8.409 +#elif defined(HAVE_RINDEX)
   8.410 +    return SDL_const_cast(char*,rindex(str, c));
   8.411 +#else
   8.412      const char *bufp = string + SDL_strlen(string) - 1;
   8.413      while (bufp >= string) {
   8.414          if (*bufp == c) {
   8.415 @@ -630,16 +605,15 @@
   8.416          --bufp;
   8.417      }
   8.418      return NULL;
   8.419 +#endif /* HAVE_STRRCHR */
   8.420  }
   8.421 -#endif
   8.422  
   8.423 -#ifdef SDL_strstr
   8.424 -#undef SDL_strstr
   8.425 -char *SDL_strstr(const char *haystack, const char *needle) { return SDL_strstr_inline(haystack, needle); }
   8.426 -#else
   8.427  char *
   8.428  SDL_strstr(const char *haystack, const char *needle)
   8.429  {
   8.430 +#if defined(HAVE_STRSTR)
   8.431 +    return SDL_const_cast(char*,strstr(haystack, needle));
   8.432 +#else
   8.433      size_t length = SDL_strlen(needle);
   8.434      while (*haystack) {
   8.435          if (SDL_strncmp(haystack, needle, length) == 0) {
   8.436 @@ -648,10 +622,10 @@
   8.437          ++haystack;
   8.438      }
   8.439      return NULL;
   8.440 +#endif /* HAVE_STRSTR */
   8.441  }
   8.442 -#endif
   8.443  
   8.444 -#if !defined(SDL_ltoa) || !defined(SDL_lltoa) || \
   8.445 +#if !defined(HAVE__LTOA) || !defined(SDL_lltoa) || \
   8.446      !defined(SDL_ultoa) || !defined(SDL_ulltoa)
   8.447  static const char ntoa_table[] = {
   8.448      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
   8.449 @@ -661,13 +635,90 @@
   8.450  };
   8.451  #endif /* ntoa() conversion table */
   8.452  
   8.453 -#ifdef SDL_ltoa
   8.454 -#undef SDL_ltoa
   8.455 -char *SDL_ltoa(long value, char *string, int radix) { return SDL_ltoa_inline(value, string, radix); }
   8.456 +char *
   8.457 +SDL_itoa(int value, char *str, int radix)
   8.458 +{
   8.459 +#ifdef HAVE_ITOA
   8.460 +    return itoa(value, str, radix);
   8.461  #else
   8.462 +    return SDL_ltoa((long)value, str, radix);
   8.463 +#endif /* HAVE_ITOA */
   8.464 +}
   8.465 +
   8.466 +char *
   8.467 +SDL_uitoa(unsigned int value, char *str, int radix)
   8.468 +{
   8.469 +#ifdef HAVE__UITOA
   8.470 +    return _uitoa(value, str, radix);
   8.471 +#else
   8.472 +    return SDL_ultoa((unsigned long)value, str, radix);
   8.473 +#endif /* HAVE__UITOA */
   8.474 +}
   8.475 +
   8.476  char *
   8.477  SDL_ltoa(long value, char *string, int radix)
   8.478  {
   8.479 +#if defined(HAVE__LTOA)
   8.480 +    return _ltoa(value, str, radix);
   8.481 +#else
   8.482 +    char *bufp = string;
   8.483 +
   8.484 +    if (value < 0) {
   8.485 +        *bufp++ = '-';
   8.486 +        value = -value;
   8.487 +    }
   8.488 +    if (value) {
   8.489 +        while (value > 0) {
   8.490 +            *bufp++ = ntoa_table[value % radix];
   8.491 +            value /= radix;
   8.492 +        }
   8.493 +    } else {
   8.494 +        *bufp++ = '0';
   8.495 +    }
   8.496 +    *bufp = '\0';
   8.497 +
   8.498 +    /* The numbers went into the string backwards. :) */
   8.499 +    if (*string == '-') {
   8.500 +        SDL_strrev(string + 1);
   8.501 +    } else {
   8.502 +        SDL_strrev(string);
   8.503 +    }
   8.504 +
   8.505 +    return string;
   8.506 +#endif /* HAVE__LTOA */
   8.507 +}
   8.508 +
   8.509 +char *
   8.510 +SDL_ultoa(unsigned long value, char *string, int radix)
   8.511 +{
   8.512 +#if defined(HAVE__ULTOA)
   8.513 +    return _ultoa(value, str, radix);
   8.514 +#else
   8.515 +    char *bufp = string;
   8.516 +
   8.517 +    if (value) {
   8.518 +        while (value > 0) {
   8.519 +            *bufp++ = ntoa_table[value % radix];
   8.520 +            value /= radix;
   8.521 +        }
   8.522 +    } else {
   8.523 +        *bufp++ = '0';
   8.524 +    }
   8.525 +    *bufp = '\0';
   8.526 +
   8.527 +    /* The numbers went into the string backwards. :) */
   8.528 +    SDL_strrev(string);
   8.529 +
   8.530 +    return string;
   8.531 +#endif /* HAVE__ULTOA */
   8.532 +}
   8.533 +
   8.534 +char *
   8.535 +SDL_lltoa(Sint64 value, char *string, int radix)
   8.536 +{
   8.537 +#if defined(HAVE__I64TOA)
   8.538 +    return _i64toa(value, str, radix);
   8.539 +#else
   8.540      char *bufp = string;
   8.541  
   8.542      if (value < 0) {
   8.543 @@ -692,128 +743,15 @@
   8.544      }
   8.545  
   8.546      return string;
   8.547 -}
   8.548 -#endif
   8.549 -
   8.550 -#ifdef SDL_ultoa
   8.551 -#undef SDL_ultoa
   8.552 -char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); }
   8.553 -#else
   8.554 -char *
   8.555 -SDL_ultoa(unsigned long value, char *string, int radix)
   8.556 -{
   8.557 -    char *bufp = string;
   8.558 -
   8.559 -    if (value) {
   8.560 -        while (value > 0) {
   8.561 -            *bufp++ = ntoa_table[value % radix];
   8.562 -            value /= radix;
   8.563 -        }
   8.564 -    } else {
   8.565 -        *bufp++ = '0';
   8.566 -    }
   8.567 -    *bufp = '\0';
   8.568 -
   8.569 -    /* The numbers went into the string backwards. :) */
   8.570 -    SDL_strrev(string);
   8.571 -
   8.572 -    return string;
   8.573 +#endif /* HAVE__I64TOA */
   8.574  }
   8.575 -#endif
   8.576 -
   8.577 -#ifdef SDL_strtol
   8.578 -#undef SDL_strtol
   8.579 -long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); }
   8.580 -#else
   8.581 -long
   8.582 -SDL_strtol(const char *string, char **endp, int base)
   8.583 -{
   8.584 -    size_t len;
   8.585 -    long value;
   8.586 -
   8.587 -    if (!base) {
   8.588 -        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.589 -            base = 16;
   8.590 -        } else {
   8.591 -            base = 10;
   8.592 -        }
   8.593 -    }
   8.594 -
   8.595 -    len = SDL_ScanLong(string, base, &value);
   8.596 -    if (endp) {
   8.597 -        *endp = (char *) string + len;
   8.598 -    }
   8.599 -    return value;
   8.600 -}
   8.601 -#endif
   8.602  
   8.603 -#ifdef SDL_strtoul
   8.604 -#undef SDL_strtoul
   8.605 -unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); }
   8.606 -#else
   8.607 -unsigned long
   8.608 -SDL_strtoul(const char *string, char **endp, int base)
   8.609 -{
   8.610 -    size_t len;
   8.611 -    unsigned long value;
   8.612 -
   8.613 -    if (!base) {
   8.614 -        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.615 -            base = 16;
   8.616 -        } else {
   8.617 -            base = 10;
   8.618 -        }
   8.619 -    }
   8.620 -
   8.621 -    len = SDL_ScanUnsignedLong(string, base, &value);
   8.622 -    if (endp) {
   8.623 -        *endp = (char *) string + len;
   8.624 -    }
   8.625 -    return value;
   8.626 -}
   8.627 -#endif
   8.628 -
   8.629 -#ifdef SDL_lltoa
   8.630 -#undef SDL_lltoa
   8.631 -char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); }
   8.632 -#else
   8.633 -char *
   8.634 -SDL_lltoa(Sint64 value, char *string, int radix)
   8.635 -{
   8.636 -    char *bufp = string;
   8.637 -
   8.638 -    if (value < 0) {
   8.639 -        *bufp++ = '-';
   8.640 -        value = -value;
   8.641 -    }
   8.642 -    if (value) {
   8.643 -        while (value > 0) {
   8.644 -            *bufp++ = ntoa_table[value % radix];
   8.645 -            value /= radix;
   8.646 -        }
   8.647 -    } else {
   8.648 -        *bufp++ = '0';
   8.649 -    }
   8.650 -    *bufp = '\0';
   8.651 -
   8.652 -    /* The numbers went into the string backwards. :) */
   8.653 -    if (*string == '-') {
   8.654 -        SDL_strrev(string + 1);
   8.655 -    } else {
   8.656 -        SDL_strrev(string);
   8.657 -    }
   8.658 -
   8.659 -    return string;
   8.660 -}
   8.661 -#endif
   8.662 -
   8.663 -#ifdef SDL_ulltoa
   8.664 -#undef SDL_ulltoa
   8.665 -char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); }
   8.666 -#else
   8.667  char *
   8.668  SDL_ulltoa(Uint64 value, char *string, int radix)
   8.669  {
   8.670 +#if defined(HAVE__UI64TOA)
   8.671 +    return _ui64toa(value, str, radix);
   8.672 +#else
   8.673      char *bufp = string;
   8.674  
   8.675      if (value) {
   8.676 @@ -830,16 +768,83 @@
   8.677      SDL_strrev(string);
   8.678  
   8.679      return string;
   8.680 +#endif /* HAVE__UI64TOA */
   8.681  }
   8.682 -#endif
   8.683 +
   8.684 +int SDL_atoi(const char *str)
   8.685 +{
   8.686 +#ifdef HAVE_ATOI
   8.687 +    return atoi(str);
   8.688 +#else
   8.689 +    return SDL_strtol(str, NULL, 0);
   8.690 +#endif /* HAVE_ATOI */
   8.691 +}
   8.692 +
   8.693 +double SDL_atof(const char *str)
   8.694 +{
   8.695 +#ifdef HAVE_ATOF
   8.696 +    return (double) atof(str);
   8.697 +#else
   8.698 +    return SDL_strtod(str, NULL);
   8.699 +#endif /* HAVE_ATOF */
   8.700 +}
   8.701 +
   8.702 +long
   8.703 +SDL_strtol(const char *string, char **endp, int base)
   8.704 +{
   8.705 +#if defined(HAVE_STRTOL)
   8.706 +    return strtol(str, endp, base);
   8.707 +#else
   8.708 +    size_t len;
   8.709 +    long value;
   8.710  
   8.711 -#ifdef SDL_strtoll
   8.712 -#undef SDL_strtoll
   8.713 -Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); }
   8.714 +    if (!base) {
   8.715 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.716 +            base = 16;
   8.717 +        } else {
   8.718 +            base = 10;
   8.719 +        }
   8.720 +    }
   8.721 +
   8.722 +    len = SDL_ScanLong(string, base, &value);
   8.723 +    if (endp) {
   8.724 +        *endp = (char *) string + len;
   8.725 +    }
   8.726 +    return value;
   8.727 +#endif /* HAVE_STRTOL */
   8.728 +}
   8.729 +
   8.730 +unsigned long
   8.731 +SDL_strtoul(const char *string, char **endp, int base)
   8.732 +{
   8.733 +#if defined(HAVE_STRTOUL)
   8.734 +    return strtoul(str, endp, base);
   8.735  #else
   8.736 +    size_t len;
   8.737 +    unsigned long value;
   8.738 +
   8.739 +    if (!base) {
   8.740 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.741 +            base = 16;
   8.742 +        } else {
   8.743 +            base = 10;
   8.744 +        }
   8.745 +    }
   8.746 +
   8.747 +    len = SDL_ScanUnsignedLong(string, base, &value);
   8.748 +    if (endp) {
   8.749 +        *endp = (char *) string + len;
   8.750 +    }
   8.751 +    return value;
   8.752 +#endif /* HAVE_STRTOUL */
   8.753 +}
   8.754 +
   8.755  Sint64
   8.756  SDL_strtoll(const char *string, char **endp, int base)
   8.757  {
   8.758 +#if defined(HAVE_STRTOLL)
   8.759 +    return strtoll(str, endp, base);
   8.760 +#else
   8.761      size_t len;
   8.762      Sint64 value;
   8.763  
   8.764 @@ -856,16 +861,15 @@
   8.765          *endp = (char *) string + len;
   8.766      }
   8.767      return value;
   8.768 +#endif /* HAVE_STRTOLL */
   8.769  }
   8.770 -#endif
   8.771  
   8.772 -#ifdef SDL_strtoull
   8.773 -#undef SDL_strtoull
   8.774 -Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); }
   8.775 -#else
   8.776  Uint64
   8.777  SDL_strtoull(const char *string, char **endp, int base)
   8.778  {
   8.779 +#if defined(HAVE_STRTOULL)
   8.780 +    return strtoull(str, endp, base);
   8.781 +#else
   8.782      size_t len;
   8.783      Uint64 value;
   8.784  
   8.785 @@ -882,16 +886,15 @@
   8.786          *endp = (char *) string + len;
   8.787      }
   8.788      return value;
   8.789 +#endif /* HAVE_STRTOULL */
   8.790  }
   8.791 -#endif
   8.792  
   8.793 -#ifdef SDL_strtod
   8.794 -#undef SDL_strtod
   8.795 -double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); }
   8.796 -#else
   8.797  double
   8.798  SDL_strtod(const char *string, char **endp)
   8.799  {
   8.800 +#if defined(HAVE_STRTOD)
   8.801 +    return strtod(str, endp);
   8.802 +#else
   8.803      size_t len;
   8.804      double value;
   8.805  
   8.806 @@ -900,16 +903,15 @@
   8.807          *endp = (char *) string + len;
   8.808      }
   8.809      return value;
   8.810 +#endif /* HAVE_STRTOD */
   8.811  }
   8.812 -#endif
   8.813  
   8.814 -#ifdef SDL_strcmp
   8.815 -#undef SDL_strcmp
   8.816 -int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); }
   8.817 -#else
   8.818  int
   8.819  SDL_strcmp(const char *str1, const char *str2)
   8.820  {
   8.821 +#if defined(HAVE_STRCMP)
   8.822 +    return strcmp(str1, str2);
   8.823 +#else
   8.824      while (*str1 && *str2) {
   8.825          if (*str1 != *str2)
   8.826              break;
   8.827 @@ -917,16 +919,15 @@
   8.828          ++str2;
   8.829      }
   8.830      return (int) ((unsigned char) *str1 - (unsigned char) *str2);
   8.831 +#endif /* HAVE_STRCMP */
   8.832  }
   8.833 -#endif
   8.834  
   8.835 -#ifdef SDL_strncmp
   8.836 -#undef SDL_strncmp
   8.837 -int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); }
   8.838 -#else
   8.839  int
   8.840  SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
   8.841  {
   8.842 +#if defined(HAVE_STRNCMP)
   8.843 +    return strncmp(str1, str2, maxlen);
   8.844 +#else
   8.845      while (*str1 && *str2 && maxlen) {
   8.846          if (*str1 != *str2)
   8.847              break;
   8.848 @@ -938,39 +939,41 @@
   8.849          return 0;
   8.850      }
   8.851      return (int) ((unsigned char) *str1 - (unsigned char) *str2);
   8.852 +#endif /* HAVE_STRNCMP */
   8.853  }
   8.854 -#endif
   8.855  
   8.856 -#ifdef SDL_strcasecmp
   8.857 -#undef SDL_strcasecmp
   8.858 -int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp_inline(str1, str2); }
   8.859 -#else
   8.860  int
   8.861  SDL_strcasecmp(const char *str1, const char *str2)
   8.862  {
   8.863 +#ifdef HAVE_STRCASECMP
   8.864 +    return strcasecmp(str1, str2);
   8.865 +#elif defined(HAVE__STRICMP)
   8.866 +    return _stricmp(str1, str2);
   8.867 +#else
   8.868      char a = 0;
   8.869      char b = 0;
   8.870      while (*str1 && *str2) {
   8.871 -        a = SDL_tolower((unsigned char) *str1);
   8.872 -        b = SDL_tolower((unsigned char) *str2);
   8.873 +        a = SDL_toupper((unsigned char) *str1);
   8.874 +        b = SDL_toupper((unsigned char) *str2);
   8.875          if (a != b)
   8.876              break;
   8.877          ++str1;
   8.878          ++str2;
   8.879      }
   8.880 -    a = SDL_tolower(*str1);
   8.881 -    b = SDL_tolower(*str2);
   8.882 +    a = SDL_toupper(*str1);
   8.883 +    b = SDL_toupper(*str2);
   8.884      return (int) ((unsigned char) a - (unsigned char) b);
   8.885 +#endif /* HAVE_STRCASECMP */
   8.886  }
   8.887 -#endif
   8.888  
   8.889 -#ifdef SDL_strncasecmp
   8.890 -#undef SDL_strncasecmp
   8.891 -int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); }
   8.892 -#else
   8.893  int
   8.894  SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
   8.895  {
   8.896 +#ifdef HAVE_STRNCASECMP
   8.897 +    return strncasecmp(str1, str2, len);
   8.898 +#elif defined(HAVE__STRNICMP)
   8.899 +    return _strnicmp(str1, str2, len);
   8.900 +#else
   8.901      char a = 0;
   8.902      char b = 0;
   8.903      while (*str1 && *str2 && maxlen) {
   8.904 @@ -989,11 +992,10 @@
   8.905          b = SDL_tolower((unsigned char) *str2);
   8.906          return (int) ((unsigned char) a - (unsigned char) b);
   8.907      }
   8.908 +#endif /* HAVE_STRNCASECMP */
   8.909  }
   8.910 -#endif
   8.911  
   8.912 -#ifdef SDL_sscanf
   8.913 -#undef SDL_sscanf
   8.914 +#ifdef HAVE_SSCANF
   8.915  int
   8.916  SDL_sscanf(const char *text, const char *fmt, ...)
   8.917  {
   8.918 @@ -1269,12 +1271,8 @@
   8.919  
   8.920      return retval;
   8.921  }
   8.922 -#endif
   8.923 +#endif /* HAVE_SSCANF */
   8.924  
   8.925 -/* just undef; the headers only define this to snprintf because of varargs. */
   8.926 -#ifdef SDL_snprintf
   8.927 -#undef SDL_snprintf
   8.928 -#endif
   8.929  int
   8.930  SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
   8.931  {
   8.932 @@ -1288,9 +1286,11 @@
   8.933      return retval;
   8.934  }
   8.935  
   8.936 -#ifdef SDL_vsnprintf
   8.937 -#undef SDL_vsnprintf
   8.938 -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
   8.939 +#ifdef HAVE_VSNPRINTF
   8.940 +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
   8.941 +{
   8.942 +    return vsnprintf(text, maxlen, fmt, ap);
   8.943 +}
   8.944  #else
   8.945   /* FIXME: implement more of the format specifiers */
   8.946  typedef struct
   8.947 @@ -1633,6 +1633,6 @@
   8.948      }
   8.949      return (int)(text - textstart);
   8.950  }
   8.951 -#endif
   8.952 +#endif /* HAVE_VSNPRINTF */
   8.953  
   8.954  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/SDL_RLEaccel.c	Fri Jul 05 21:37:27 2013 -0700
     9.2 +++ b/src/video/SDL_RLEaccel.c	Fri Jul 05 23:57:19 2013 -0700
     9.3 @@ -98,13 +98,7 @@
     9.4  #endif
     9.5  
     9.6  #define PIXEL_COPY(to, from, len, bpp)          \
     9.7 -do {                            \
     9.8 -    if(bpp == 4) {                  \
     9.9 -    SDL_memcpy4(to, from, (size_t)(len));       \
    9.10 -    } else {                        \
    9.11 -    SDL_memcpy(to, from, (size_t)(len) * (bpp));    \
    9.12 -    }                           \
    9.13 -} while(0)
    9.14 +    SDL_memcpy(to, from, (size_t)(len) * (bpp))
    9.15  
    9.16  /*
    9.17   * Various colorkey blit methods, for opaque and per-surface alpha