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 +extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   1.218  
   1.219 -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   1.220 -#if defined(HAVE_MEMCMP) && !defined(SDL_STDINC_NO_INLINES)
   1.221 -SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
   1.222 -#define SDL_memcmp SDL_memcmp_inline
   1.223 -#endif
   1.224 +extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   1.225 +extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.226 +extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.227  
   1.228  extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   1.229 -#if defined(HAVE_STRLEN) && !defined(SDL_STDINC_NO_INLINES)
   1.230 -SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
   1.231 -#define SDL_strlen SDL_strlen_inline
   1.232 -#endif
   1.233 -
   1.234 -extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   1.235 -#if defined(HAVE_WCSLEN) && !defined(SDL_STDINC_NO_INLINES)
   1.236 -SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
   1.237 -#define SDL_wcslen SDL_wcslen_inline
   1.238 -#endif
   1.239 -
   1.240 -extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.241 -#if defined(HAVE_WCSLCPY) && !defined(SDL_STDINC_NO_INLINES)
   1.242 -SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
   1.243 -#define SDL_wcslcpy SDL_wcslcpy_inline
   1.244 -#endif
   1.245 -
   1.246 -extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.247 -#if defined(HAVE_WCSLCAT) && !defined(SDL_STDINC_NO_INLINES)
   1.248 -SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
   1.249 -#define SDL_wcslcat SDL_wcslcat_inline
   1.250 -#endif
   1.251 -
   1.252  extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   1.253 -#if defined(HAVE_STRLCPY) && !defined(SDL_STDINC_NO_INLINES)
   1.254 -SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
   1.255 -#define SDL_strlcpy SDL_strlcpy_inline
   1.256 -#else
   1.257 -#endif
   1.258 -
   1.259  extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
   1.260 -
   1.261  extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   1.262 -#if defined(HAVE_STRLCAT) && !defined(SDL_STDINC_NO_INLINES)
   1.263 -SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
   1.264 -#define SDL_strlcat SDL_strlcat_inline
   1.265 -#endif
   1.266 -
   1.267  extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
   1.268 -#if defined(HAVE_STRDUP) && !defined(SDL_STDINC_NO_INLINES)
   1.269 -SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
   1.270 -#define SDL_strdup SDL_strdup_inline
   1.271 -#endif
   1.272 -
   1.273  extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
   1.274 -#if defined(HAVE__STRREV) && !defined(SDL_STDINC_NO_INLINES)
   1.275 -SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
   1.276 -#define SDL_strrev SDL_strrev_inline
   1.277 -#endif
   1.278 -
   1.279  extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
   1.280 -#if defined(HAVE__STRUPR) && !defined(SDL_STDINC_NO_INLINES)
   1.281 -SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
   1.282 -#define SDL_strupr SDL_strupr_inline
   1.283 -#endif
   1.284 -
   1.285  extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
   1.286 -#if defined(HAVE__STRLWR) && !defined(SDL_STDINC_NO_INLINES)
   1.287 -SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
   1.288 -#define SDL_strlwr SDL_strlwr_inline
   1.289 -#endif
   1.290 -
   1.291  extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
   1.292 -#ifndef SDL_STDINC_NO_INLINES
   1.293 -#ifdef HAVE_STRCHR
   1.294 -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,strchr(str, c)); }
   1.295 -#define SDL_strchr SDL_strchr_inline
   1.296 -#elif defined(HAVE_INDEX)  /* !!! FIXME: is there anywhere that has this but not strchr? */
   1.297 -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,index(str, c)); }
   1.298 -#define SDL_strchr SDL_strchr_inline
   1.299 -#endif
   1.300 -#endif /* !SDL_STDINC_NO_INLINES */
   1.301 -
   1.302  extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
   1.303 -#ifndef SDL_STDINC_NO_INLINES
   1.304 -#ifdef HAVE_STRRCHR
   1.305 -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,strrchr(str, c)); }
   1.306 -#define SDL_strrchr SDL_strrchr_inline
   1.307 -#elif defined(HAVE_RINDEX)  /* !!! FIXME: is there anywhere that has this but not strrchr? */
   1.308 -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,rindex(str, c)); }
   1.309 -#define SDL_strrchr SDL_strrchr_inline
   1.310 -#endif
   1.311 -#endif /* !SDL_STDINC_NO_INLINES */
   1.312 -
   1.313  extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
   1.314 -#if defined(HAVE_STRSTR) && !defined(SDL_STDINC_NO_INLINES)
   1.315 -SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return SDL_const_cast(char*,strstr(haystack, needle)); }
   1.316 -#define SDL_strstr SDL_strstr_inline
   1.317 -#endif
   1.318 -
   1.319 -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   1.320 -#if defined(HAVE__LTOA) && !defined(SDL_STDINC_NO_INLINES)
   1.321 -SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
   1.322 -#define SDL_ltoa SDL_ltoa_inline
   1.323 -#endif
   1.324  
   1.325  extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
   1.326 -#ifndef SDL_STDINC_NO_INLINES
   1.327 -#ifdef HAVE_ITOA
   1.328 -SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
   1.329 -#else
   1.330 -SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
   1.331 -#endif
   1.332 -#define SDL_itoa SDL_itoa_inline
   1.333 -#endif /* !SDL_STDINC_NO_INLINES */
   1.334 -
   1.335 +extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   1.336 +extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   1.337  extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
   1.338 -#if defined(HAVE__ULTOA) && !defined(SDL_STDINC_NO_INLINES)
   1.339 -SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
   1.340 -#define SDL_ultoa SDL_ultoa_inline
   1.341 -#endif
   1.342 -
   1.343 -extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   1.344 -#ifndef SDL_STDINC_NO_INLINES
   1.345 -#ifdef HAVE__UITOA
   1.346 -SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
   1.347 -#else
   1.348 -SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
   1.349 -#endif
   1.350 -#define SDL_uitoa SDL_uitoa_inline
   1.351 -#endif /* !SDL_STDINC_NO_INLINES */
   1.352 -
   1.353 -
   1.354 -extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   1.355 -#if defined(HAVE_STRTOL) && !defined(SDL_STDINC_NO_INLINES)
   1.356 -SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
   1.357 -#define SDL_strtol SDL_strtol_inline
   1.358 -#endif
   1.359 -
   1.360 -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   1.361 -#if defined(HAVE_STRTOUL) && !defined(SDL_STDINC_NO_INLINES)
   1.362 -SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
   1.363 -#define SDL_strtoul SDL_strtoul_inline
   1.364 -#endif
   1.365 -
   1.366  extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
   1.367 -#if defined(HAVE__I64TOA) && !defined(SDL_STDINC_NO_INLINES)
   1.368 -SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
   1.369 -#define SDL_lltoa SDL_lltoa_inline
   1.370 -#endif
   1.371 -
   1.372  extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
   1.373 -#if defined(HAVE__UI64TOA) && !defined(SDL_STDINC_NO_INLINES)
   1.374 -SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
   1.375 -#define SDL_ulltoa SDL_ulltoa_inline
   1.376 -#endif
   1.377 -
   1.378 -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   1.379 -#if defined(HAVE_STRTOLL) && !defined(SDL_STDINC_NO_INLINES)
   1.380 -SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
   1.381 -#define SDL_strtoll SDL_strtoll_inline
   1.382 -#endif
   1.383 -
   1.384 -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   1.385 -#if defined(HAVE_STRTOULL) && !defined(SDL_STDINC_NO_INLINES)
   1.386 -SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
   1.387 -#define SDL_strtoull SDL_strtoull_inline
   1.388 -#endif
   1.389 -
   1.390 -extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   1.391 -#if defined(HAVE_STRTOD) && !defined(SDL_STDINC_NO_INLINES)
   1.392 -SDL_FORCE_INLINE double SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
   1.393 -#define SDL_strtod SDL_strtod_inline
   1.394 -#endif
   1.395  
   1.396  extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
   1.397 -#ifndef SDL_STDINC_NO_INLINES
   1.398 -#ifdef HAVE_ATOI
   1.399 -SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
   1.400 -#else
   1.401 -SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
   1.402 -#endif
   1.403 -#define SDL_atoi SDL_atoi_inline
   1.404 -#endif /* !SDL_STDINC_NO_INLINES */
   1.405 -
   1.406  extern DECLSPEC double SDLCALL SDL_atof(const char *str);
   1.407 -#ifndef SDL_STDINC_NO_INLINES
   1.408 -#ifdef HAVE_ATOF
   1.409 -SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
   1.410 -#else
   1.411 -SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
   1.412 -#endif
   1.413 -#define SDL_atof SDL_atof_inline
   1.414 -#endif /* !SDL_STDINC_NO_INLINES */
   1.415 -
   1.416 +extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   1.417 +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   1.418 +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   1.419 +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   1.420 +extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   1.421  
   1.422  extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   1.423 -#if defined(HAVE_STRCMP) && !defined(SDL_STDINC_NO_INLINES)
   1.424 -SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
   1.425 -#define SDL_strcmp SDL_strcmp_inline
   1.426 -#endif
   1.427 +extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   1.428 +extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   1.429 +extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   1.430  
   1.431 -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   1.432 -#if defined(HAVE_STRNCMP) && !defined(SDL_STDINC_NO_INLINES)
   1.433 -SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
   1.434 -#define SDL_strncmp SDL_strncmp_inline
   1.435 -#endif
   1.436 -
   1.437 -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   1.438 -#ifndef SDL_STDINC_NO_INLINES
   1.439 -#ifdef HAVE_STRCASECMP
   1.440 -SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
   1.441 -#define SDL_strcasecmp SDL_strcasecmp_inline
   1.442 -#elif defined(HAVE__STRICMP)
   1.443 -SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
   1.444 -#define SDL_strcasecmp SDL_strcasecmp_inline
   1.445 -#endif
   1.446 -#endif /* !SDL_STDINC_NO_INLINES */
   1.447 -
   1.448 -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   1.449 -#ifndef SDL_STDINC_NO_INLINES
   1.450 -#ifdef HAVE_STRNCASECMP
   1.451 -SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
   1.452 -#define SDL_strncasecmp SDL_strncasecmp_inline
   1.453 -#elif defined(HAVE__STRNICMP)
   1.454 -SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
   1.455 -#define SDL_strncasecmp SDL_strncasecmp_inline
   1.456 -#endif
   1.457 -#endif /* !SDL_STDINC_NO_INLINES */
   1.458 -
   1.459 -/* Not doing SDL_*_inline functions for these, because of the varargs. */
   1.460  extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   1.461 -#ifdef HAVE_SSCANF
   1.462 -#define SDL_sscanf sscanf
   1.463 -#endif
   1.464 -
   1.465  extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   1.466 -#ifdef HAVE_SNPRINTF
   1.467 -#define SDL_snprintf snprintf
   1.468 -#endif
   1.469 -
   1.470  extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   1.471 -#if defined(HAVE_VSNPRINTF) && !defined(SDL_STDINC_NO_INLINES)
   1.472 -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.473 -#define SDL_vsnprintf SDL_vsnprintf_inline
   1.474 -#endif
   1.475  
   1.476  #ifndef HAVE_M_PI
   1.477  #ifndef M_PI
   1.478 @@ -691,100 +341,19 @@
   1.479  #endif
   1.480  
   1.481  extern DECLSPEC double SDLCALL SDL_atan(double x);
   1.482 -#if defined(HAVE_ATAN) && !defined(SDL_STDINC_NO_INLINES)
   1.483 -SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
   1.484 -#define SDL_atan SDL_atan_inline
   1.485 -#endif
   1.486 -
   1.487  extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
   1.488 -#if defined(HAVE_ATAN2) && !defined(SDL_STDINC_NO_INLINES)
   1.489 -SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
   1.490 -#define SDL_atan2 SDL_atan2_inline
   1.491 -#endif
   1.492 -
   1.493  extern DECLSPEC double SDLCALL SDL_ceil(double x);
   1.494 -#ifndef SDL_STDINC_NO_INLINES
   1.495 -#ifdef HAVE_CEIL
   1.496 -SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
   1.497 -#else
   1.498 -SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
   1.499 -#endif
   1.500 -#define SDL_ceil SDL_ceil_inline
   1.501 -#endif /* !SDL_STDINC_NO_INLINES */
   1.502 -
   1.503  extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   1.504 -#if defined(HAVE_COPYSIGN) && !defined(SDL_STDINC_NO_INLINES)
   1.505 -SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
   1.506 -#define SDL_copysign SDL_copysign_inline
   1.507 -#endif
   1.508 -
   1.509  extern DECLSPEC double SDLCALL SDL_cos(double x);
   1.510 -#if defined(HAVE_COS) && !defined(SDL_STDINC_NO_INLINES)
   1.511 -SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
   1.512 -#define SDL_cos SDL_cos_inline
   1.513 -#endif
   1.514 -
   1.515  extern DECLSPEC float SDLCALL SDL_cosf(float x);
   1.516 -#ifndef SDL_STDINC_NO_INLINES
   1.517 -#ifdef HAVE_COSF
   1.518 -SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
   1.519 -#else
   1.520 -SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
   1.521 -#endif
   1.522 -#define SDL_cosf SDL_cosf_inline
   1.523 -#endif /* !SDL_STDINC_NO_INLINES */
   1.524 -
   1.525  extern DECLSPEC double SDLCALL SDL_fabs(double x);
   1.526 -#if defined(HAVE_FABS) && !defined(SDL_STDINC_NO_INLINES)
   1.527 -SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
   1.528 -#define SDL_fabs SDL_fabs_inline
   1.529 -#endif
   1.530 -
   1.531  extern DECLSPEC double SDLCALL SDL_floor(double x);
   1.532 -#if defined(HAVE_FLOOR) && !defined(SDL_STDINC_NO_INLINES)
   1.533 -SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
   1.534 -#define SDL_floor SDL_floor_inline
   1.535 -#endif
   1.536 -
   1.537  extern DECLSPEC double SDLCALL SDL_log(double x);
   1.538 -#if defined(HAVE_LOG) && !defined(SDL_STDINC_NO_INLINES)
   1.539 -SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
   1.540 -#define SDL_log SDL_log_inline
   1.541 -#endif
   1.542 -
   1.543  extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   1.544 -#if defined(HAVE_POW) && !defined(SDL_STDINC_NO_INLINES)
   1.545 -SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
   1.546 -#define SDL_pow SDL_pow_inline
   1.547 -#endif
   1.548 -
   1.549  extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   1.550 -#if defined(HAVE_SCALBN) && !defined(SDL_STDINC_NO_INLINES)
   1.551 -SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
   1.552 -#define SDL_scalbn SDL_scalbn_inline
   1.553 -#endif
   1.554 -
   1.555  extern DECLSPEC double SDLCALL SDL_sin(double x);
   1.556 -#if defined(HAVE_SIN) && !defined(SDL_STDINC_NO_INLINES)
   1.557 -SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
   1.558 -#define SDL_sin SDL_sin_inline
   1.559 -#endif
   1.560 -
   1.561  extern DECLSPEC float SDLCALL SDL_sinf(float x);
   1.562 -#ifndef SDL_STDINC_NO_INLINES
   1.563 -#ifdef HAVE_SINF
   1.564 -SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
   1.565 -#else
   1.566 -SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
   1.567 -#endif
   1.568 -#define SDL_sinf SDL_sinf_inline
   1.569 -#endif /* !SDL_STDINC_NO_INLINES */
   1.570 -
   1.571  extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   1.572 -#if defined(HAVE_SQRT) && !defined(SDL_STDINC_NO_INLINES)
   1.573 -SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
   1.574 -#define SDL_sqrt SDL_sqrt_inline
   1.575 -#endif
   1.576  
   1.577  /* The SDL implementation of iconv() returns these error codes */
   1.578  #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,32 @@
   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 @@ -692,16 +685,15 @@
   8.486      }
   8.487  
   8.488      return string;
   8.489 +#endif /* HAVE__LTOA */
   8.490  }
   8.491 -#endif
   8.492  
   8.493 -#ifdef SDL_ultoa
   8.494 -#undef SDL_ultoa
   8.495 -char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); }
   8.496 -#else
   8.497  char *
   8.498  SDL_ultoa(unsigned long value, char *string, int radix)
   8.499  {
   8.500 +#if defined(HAVE__ULTOA)
   8.501 +    return _ultoa(value, str, radix);
   8.502 +#else
   8.503      char *bufp = string;
   8.504  
   8.505      if (value) {
   8.506 @@ -718,68 +710,15 @@
   8.507      SDL_strrev(string);
   8.508  
   8.509      return string;
   8.510 +#endif /* HAVE__ULTOA */
   8.511  }
   8.512 -#endif
   8.513  
   8.514 -#ifdef SDL_strtol
   8.515 -#undef SDL_strtol
   8.516 -long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); }
   8.517 -#else
   8.518 -long
   8.519 -SDL_strtol(const char *string, char **endp, int base)
   8.520 -{
   8.521 -    size_t len;
   8.522 -    long value;
   8.523 -
   8.524 -    if (!base) {
   8.525 -        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.526 -            base = 16;
   8.527 -        } else {
   8.528 -            base = 10;
   8.529 -        }
   8.530 -    }
   8.531 -
   8.532 -    len = SDL_ScanLong(string, base, &value);
   8.533 -    if (endp) {
   8.534 -        *endp = (char *) string + len;
   8.535 -    }
   8.536 -    return value;
   8.537 -}
   8.538 -#endif
   8.539 -
   8.540 -#ifdef SDL_strtoul
   8.541 -#undef SDL_strtoul
   8.542 -unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); }
   8.543 -#else
   8.544 -unsigned long
   8.545 -SDL_strtoul(const char *string, char **endp, int base)
   8.546 -{
   8.547 -    size_t len;
   8.548 -    unsigned long value;
   8.549 -
   8.550 -    if (!base) {
   8.551 -        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.552 -            base = 16;
   8.553 -        } else {
   8.554 -            base = 10;
   8.555 -        }
   8.556 -    }
   8.557 -
   8.558 -    len = SDL_ScanUnsignedLong(string, base, &value);
   8.559 -    if (endp) {
   8.560 -        *endp = (char *) string + len;
   8.561 -    }
   8.562 -    return value;
   8.563 -}
   8.564 -#endif
   8.565 -
   8.566 -#ifdef SDL_lltoa
   8.567 -#undef SDL_lltoa
   8.568 -char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); }
   8.569 -#else
   8.570  char *
   8.571  SDL_lltoa(Sint64 value, char *string, int radix)
   8.572  {
   8.573 +#if defined(HAVE__I64TOA)
   8.574 +    return _i64toa(value, str, radix);
   8.575 +#else
   8.576      char *bufp = string;
   8.577  
   8.578      if (value < 0) {
   8.579 @@ -804,16 +743,15 @@
   8.580      }
   8.581  
   8.582      return string;
   8.583 +#endif /* HAVE__I64TOA */
   8.584  }
   8.585 -#endif
   8.586  
   8.587 -#ifdef SDL_ulltoa
   8.588 -#undef SDL_ulltoa
   8.589 -char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); }
   8.590 -#else
   8.591  char *
   8.592  SDL_ulltoa(Uint64 value, char *string, int radix)
   8.593  {
   8.594 +#if defined(HAVE__UI64TOA)
   8.595 +    return _ui64toa(value, str, radix);
   8.596 +#else
   8.597      char *bufp = string;
   8.598  
   8.599      if (value) {
   8.600 @@ -830,16 +768,83 @@
   8.601      SDL_strrev(string);
   8.602  
   8.603      return string;
   8.604 +#endif /* HAVE__UI64TOA */
   8.605  }
   8.606 -#endif
   8.607  
   8.608 -#ifdef SDL_strtoll
   8.609 -#undef SDL_strtoll
   8.610 -Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); }
   8.611 +int SDL_atoi(const char *str)
   8.612 +{
   8.613 +#ifdef HAVE_ATOI
   8.614 +    return atoi(str);
   8.615  #else
   8.616 +    return SDL_strtol(str, NULL, 0);
   8.617 +#endif /* HAVE_ATOI */
   8.618 +}
   8.619 +
   8.620 +double SDL_atof(const char *str)
   8.621 +{
   8.622 +#ifdef HAVE_ATOF
   8.623 +    return (double) atof(str);
   8.624 +#else
   8.625 +    return SDL_strtod(str, NULL);
   8.626 +#endif /* HAVE_ATOF */
   8.627 +}
   8.628 +
   8.629 +long
   8.630 +SDL_strtol(const char *string, char **endp, int base)
   8.631 +{
   8.632 +#if defined(HAVE_STRTOL)
   8.633 +    return strtol(str, endp, base);
   8.634 +#else
   8.635 +    size_t len;
   8.636 +    long value;
   8.637 +
   8.638 +    if (!base) {
   8.639 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.640 +            base = 16;
   8.641 +        } else {
   8.642 +            base = 10;
   8.643 +        }
   8.644 +    }
   8.645 +
   8.646 +    len = SDL_ScanLong(string, base, &value);
   8.647 +    if (endp) {
   8.648 +        *endp = (char *) string + len;
   8.649 +    }
   8.650 +    return value;
   8.651 +#endif /* HAVE_STRTOL */
   8.652 +}
   8.653 +
   8.654 +unsigned long
   8.655 +SDL_strtoul(const char *string, char **endp, int base)
   8.656 +{
   8.657 +#if defined(HAVE_STRTOUL)
   8.658 +    return strtoul(str, endp, base);
   8.659 +#else
   8.660 +    size_t len;
   8.661 +    unsigned long value;
   8.662 +
   8.663 +    if (!base) {
   8.664 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   8.665 +            base = 16;
   8.666 +        } else {
   8.667 +            base = 10;
   8.668 +        }
   8.669 +    }
   8.670 +
   8.671 +    len = SDL_ScanUnsignedLong(string, base, &value);
   8.672 +    if (endp) {
   8.673 +        *endp = (char *) string + len;
   8.674 +    }
   8.675 +    return value;
   8.676 +#endif /* HAVE_STRTOUL */
   8.677 +}
   8.678 +
   8.679  Sint64
   8.680  SDL_strtoll(const char *string, char **endp, int base)
   8.681  {
   8.682 +#if defined(HAVE_STRTOLL)
   8.683 +    return strtoll(str, endp, base);
   8.684 +#else
   8.685      size_t len;
   8.686      Sint64 value;
   8.687  
   8.688 @@ -856,16 +861,15 @@
   8.689          *endp = (char *) string + len;
   8.690      }
   8.691      return value;
   8.692 +#endif /* HAVE_STRTOLL */
   8.693  }
   8.694 -#endif
   8.695  
   8.696 -#ifdef SDL_strtoull
   8.697 -#undef SDL_strtoull
   8.698 -Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); }
   8.699 -#else
   8.700  Uint64
   8.701  SDL_strtoull(const char *string, char **endp, int base)
   8.702  {
   8.703 +#if defined(HAVE_STRTOULL)
   8.704 +    return strtoull(str, endp, base);
   8.705 +#else
   8.706      size_t len;
   8.707      Uint64 value;
   8.708  
   8.709 @@ -882,16 +886,15 @@
   8.710          *endp = (char *) string + len;
   8.711      }
   8.712      return value;
   8.713 +#endif /* HAVE_STRTOULL */
   8.714  }
   8.715 -#endif
   8.716  
   8.717 -#ifdef SDL_strtod
   8.718 -#undef SDL_strtod
   8.719 -double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); }
   8.720 -#else
   8.721  double
   8.722  SDL_strtod(const char *string, char **endp)
   8.723  {
   8.724 +#if defined(HAVE_STRTOD)
   8.725 +    return strtod(str, endp);
   8.726 +#else
   8.727      size_t len;
   8.728      double value;
   8.729  
   8.730 @@ -900,16 +903,15 @@
   8.731          *endp = (char *) string + len;
   8.732      }
   8.733      return value;
   8.734 +#endif /* HAVE_STRTOD */
   8.735  }
   8.736 -#endif
   8.737  
   8.738 -#ifdef SDL_strcmp
   8.739 -#undef SDL_strcmp
   8.740 -int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); }
   8.741 -#else
   8.742  int
   8.743  SDL_strcmp(const char *str1, const char *str2)
   8.744  {
   8.745 +#if defined(HAVE_STRCMP)
   8.746 +    return strcmp(str1, str2);
   8.747 +#else
   8.748      while (*str1 && *str2) {
   8.749          if (*str1 != *str2)
   8.750              break;
   8.751 @@ -917,16 +919,15 @@
   8.752          ++str2;
   8.753      }
   8.754      return (int) ((unsigned char) *str1 - (unsigned char) *str2);
   8.755 +#endif /* HAVE_STRCMP */
   8.756  }
   8.757 -#endif
   8.758  
   8.759 -#ifdef SDL_strncmp
   8.760 -#undef SDL_strncmp
   8.761 -int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); }
   8.762 -#else
   8.763  int
   8.764  SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
   8.765  {
   8.766 +#if defined(HAVE_STRNCMP)
   8.767 +    return strncmp(str1, str2, maxlen);
   8.768 +#else
   8.769      while (*str1 && *str2 && maxlen) {
   8.770          if (*str1 != *str2)
   8.771              break;
   8.772 @@ -938,39 +939,41 @@
   8.773          return 0;
   8.774      }
   8.775      return (int) ((unsigned char) *str1 - (unsigned char) *str2);
   8.776 +#endif /* HAVE_STRNCMP */
   8.777  }
   8.778 -#endif
   8.779  
   8.780 -#ifdef SDL_strcasecmp
   8.781 -#undef SDL_strcasecmp
   8.782 -int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp_inline(str1, str2); }
   8.783 -#else
   8.784  int
   8.785  SDL_strcasecmp(const char *str1, const char *str2)
   8.786  {
   8.787 +#ifdef HAVE_STRCASECMP
   8.788 +    return strcasecmp(str1, str2);
   8.789 +#elif defined(HAVE__STRICMP)
   8.790 +    return _stricmp(str1, str2);
   8.791 +#else
   8.792      char a = 0;
   8.793      char b = 0;
   8.794      while (*str1 && *str2) {
   8.795 -        a = SDL_tolower((unsigned char) *str1);
   8.796 -        b = SDL_tolower((unsigned char) *str2);
   8.797 +        a = SDL_toupper((unsigned char) *str1);
   8.798 +        b = SDL_toupper((unsigned char) *str2);
   8.799          if (a != b)
   8.800              break;
   8.801          ++str1;
   8.802          ++str2;
   8.803      }
   8.804 -    a = SDL_tolower(*str1);
   8.805 -    b = SDL_tolower(*str2);
   8.806 +    a = SDL_toupper(*str1);
   8.807 +    b = SDL_toupper(*str2);
   8.808      return (int) ((unsigned char) a - (unsigned char) b);
   8.809 +#endif /* HAVE_STRCASECMP */
   8.810  }
   8.811 -#endif
   8.812  
   8.813 -#ifdef SDL_strncasecmp
   8.814 -#undef SDL_strncasecmp
   8.815 -int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); }
   8.816 -#else
   8.817  int
   8.818  SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
   8.819  {
   8.820 +#ifdef HAVE_STRNCASECMP
   8.821 +    return strncasecmp(str1, str2, len);
   8.822 +#elif defined(HAVE__STRNICMP)
   8.823 +    return _strnicmp(str1, str2, len);
   8.824 +#else
   8.825      char a = 0;
   8.826      char b = 0;
   8.827      while (*str1 && *str2 && maxlen) {
   8.828 @@ -989,11 +992,10 @@
   8.829          b = SDL_tolower((unsigned char) *str2);
   8.830          return (int) ((unsigned char) a - (unsigned char) b);
   8.831      }
   8.832 +#endif /* HAVE_STRNCASECMP */
   8.833  }
   8.834 -#endif
   8.835  
   8.836 -#ifdef SDL_sscanf
   8.837 -#undef SDL_sscanf
   8.838 +#ifdef HAVE_SSCANF
   8.839  int
   8.840  SDL_sscanf(const char *text, const char *fmt, ...)
   8.841  {
   8.842 @@ -1269,12 +1271,8 @@
   8.843  
   8.844      return retval;
   8.845  }
   8.846 -#endif
   8.847 +#endif /* HAVE_SSCANF */
   8.848  
   8.849 -/* just undef; the headers only define this to snprintf because of varargs. */
   8.850 -#ifdef SDL_snprintf
   8.851 -#undef SDL_snprintf
   8.852 -#endif
   8.853  int
   8.854  SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
   8.855  {
   8.856 @@ -1288,9 +1286,11 @@
   8.857      return retval;
   8.858  }
   8.859  
   8.860 -#ifdef SDL_vsnprintf
   8.861 -#undef SDL_vsnprintf
   8.862 -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
   8.863 +#ifdef HAVE_VSNPRINTF
   8.864 +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
   8.865 +{
   8.866 +    return vsnprintf(text, maxlen, fmt, ap);
   8.867 +}
   8.868  #else
   8.869   /* FIXME: implement more of the format specifiers */
   8.870  typedef struct
   8.871 @@ -1633,6 +1633,6 @@
   8.872      }
   8.873      return (int)(text - textstart);
   8.874  }
   8.875 -#endif
   8.876 +#endif /* HAVE_VSNPRINTF */
   8.877  
   8.878  /* 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