Improvements to stdlib.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 15 Mar 2013 01:01:20 -0400
changeset 7003eeaf77005c30
parent 7002 978ff4e06388
child 7004 18d4df6942c2
Improvements to stdlib.

All SDL_* functions are always available as real symbols, so you can always
link against them as a stable ABI. By default, however, all the things that
might have dithered down to macros in your application are now force-inlined,
to give you the same effect as before and theoretically better performance,
but still solve the classic macro problems.

Elsewhere, we provide real functions for these things that simply wrap the
inline functions, in case one needs to have a real function available.

Also: this exposed bugs: SDL_abs() does something different if you had the
macro vs the libc function, SDL_memcpy() returns a void* in the function
but not the macro, etc.
include/SDL_stdinc.h
src/stdlib/SDL_getenv.c
src/stdlib/SDL_iconv.c
src/stdlib/SDL_malloc.c
src/stdlib/SDL_qsort.c
src/stdlib/SDL_stdlib.c
src/stdlib/SDL_string.c
     1.1 --- a/include/SDL_stdinc.h	Fri Mar 15 01:02:30 2013 -0400
     1.2 +++ b/include/SDL_stdinc.h	Fri Mar 15 01:01:20 2013 -0400
     1.3 @@ -194,6 +194,10 @@
     1.4  #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
     1.5  /** \endcond */
     1.6  
     1.7 +#if !defined(wchar_t) && defined(__NINTENDODS__)
     1.8 +#define wchar_t short           /* TODO: figure out why libnds doesn't have this */
     1.9 +#endif
    1.10 +
    1.11  #include "begin_code.h"
    1.12  /* Set up for C function definitions, even when using C++ */
    1.13  #ifdef __cplusplus
    1.14 @@ -202,30 +206,6 @@
    1.15  /* *INDENT-ON* */
    1.16  #endif
    1.17  
    1.18 -#ifdef HAVE_MALLOC
    1.19 -#define SDL_malloc	malloc
    1.20 -#else
    1.21 -extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
    1.22 -#endif
    1.23 -
    1.24 -#ifdef HAVE_CALLOC
    1.25 -#define SDL_calloc	calloc
    1.26 -#else
    1.27 -extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
    1.28 -#endif
    1.29 -
    1.30 -#ifdef HAVE_REALLOC
    1.31 -#define SDL_realloc	realloc
    1.32 -#else
    1.33 -extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
    1.34 -#endif
    1.35 -
    1.36 -#ifdef HAVE_FREE
    1.37 -#define SDL_free	free
    1.38 -#else
    1.39 -extern DECLSPEC void SDLCALL SDL_free(void *mem);
    1.40 -#endif
    1.41 -
    1.42  #if defined(HAVE_ALLOCA) && !defined(alloca)
    1.43  # if defined(HAVE_ALLOCA_H)
    1.44  #  include <alloca.h>
    1.45 @@ -256,380 +236,443 @@
    1.46  #define SDL_stack_free(data)            SDL_free(data)
    1.47  #endif
    1.48  
    1.49 -#ifdef HAVE_GETENV
    1.50 -#define SDL_getenv	getenv
    1.51 -#else
    1.52 -extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
    1.53 +
    1.54 +/* SDL stdinc inline functions:
    1.55 +
    1.56 +   The theory here is that, by default, we forcibly inline what we can--with
    1.57 +   real inline functions that avoid macro side-effects--and your app will use
    1.58 +   the inline version by default. However, we expose a non-inline version
    1.59 +   too, which internally just wraps the inline version in a real function,
    1.60 +   so the symbol is always available in the library even if your app
    1.61 +   bypassed it with the inline version. The SDL_*_inline versions aren't
    1.62 +   guaranteed to exist, so never call them directly; use SDL_* instead,
    1.63 +   and trust the system to give you the right thing.
    1.64 +
    1.65 +   The benefit here is that you can dlsym() these functions, which you
    1.66 +   couldn't if you had macros, you can link against a foreign build of SDL
    1.67 +   even if you configured differently, and you can drop the unconfigured SDL
    1.68 +   headers into a project without #defining HAVE_MALLOC (etc) and still link.
    1.69 +*/
    1.70 +
    1.71 +extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
    1.72 +#ifdef HAVE_MALLOC
    1.73 +SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); }
    1.74 +#define SDL_malloc SDL_malloc_inline
    1.75  #endif
    1.76  
    1.77 -/* SDL_putenv() has moved to SDL_compat. */
    1.78 -#ifdef HAVE_SETENV
    1.79 -#define SDL_setenv	setenv
    1.80 -#else
    1.81 -extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value,
    1.82 -                                       int overwrite);
    1.83 +extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
    1.84 +#ifdef HAVE_CALLOC
    1.85 +SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); }
    1.86 +#define SDL_calloc SDL_calloc_inline
    1.87  #endif
    1.88  
    1.89 -#ifdef HAVE_QSORT
    1.90 -#define SDL_qsort	qsort
    1.91 -#else
    1.92 -extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
    1.93 -                                       int (*compare) (const void *,
    1.94 -                                                       const void *));
    1.95 +extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
    1.96 +#ifdef HAVE_REALLOC
    1.97 +SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); }
    1.98 +#define SDL_realloc SDL_realloc_inline
    1.99  #endif
   1.100  
   1.101 -#ifdef HAVE_ABS
   1.102 -#define SDL_abs		abs
   1.103 -#else
   1.104 -#define SDL_abs(X)	((X) < 0 ? -(X) : (X))
   1.105 +extern DECLSPEC void SDLCALL SDL_free(void *mem);
   1.106 +#ifdef HAVE_FREE
   1.107 +SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); }
   1.108 +#define SDL_free SDL_free_inline
   1.109  #endif
   1.110  
   1.111 -#define SDL_min(x, y)	(((x) < (y)) ? (x) : (y))
   1.112 -#define SDL_max(x, y)	(((x) > (y)) ? (x) : (y))
   1.113 -
   1.114 -#ifdef HAVE_CTYPE_H
   1.115 -#define SDL_isdigit(X)  isdigit(X)
   1.116 -#define SDL_isspace(X)  isspace(X)
   1.117 -#define SDL_toupper(X)  toupper(X)
   1.118 -#define SDL_tolower(X)  tolower(X)
   1.119 -#else
   1.120 -#define SDL_isdigit(X)  (((X) >= '0') && ((X) <= '9'))
   1.121 -#define SDL_isspace(X)  (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
   1.122 -#define SDL_toupper(X)  (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
   1.123 -#define SDL_tolower(X)  (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
   1.124 +extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   1.125 +#ifdef HAVE_GETENV
   1.126 +SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); }
   1.127 +#define SDL_getenv SDL_getenv_inline
   1.128  #endif
   1.129  
   1.130 -#ifdef HAVE_MEMSET
   1.131 -#define SDL_memset      memset
   1.132 -#else
   1.133 -extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   1.134 -#endif
   1.135 -#define SDL_zero(x)	SDL_memset(&(x), 0, sizeof((x)))
   1.136 -#define SDL_zerop(x)	SDL_memset((x), 0, sizeof(*(x)))
   1.137 -
   1.138 -#if defined(__GNUC__) && defined(i386)
   1.139 -#define SDL_memset4(dst, val, len)				\
   1.140 -do {								\
   1.141 -	int u0, u1, u2;						\
   1.142 -	__asm__ __volatile__ (					\
   1.143 -		"cld\n\t"					\
   1.144 -		"rep ; stosl\n\t"				\
   1.145 -		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
   1.146 -		: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))	\
   1.147 -		: "memory" );					\
   1.148 -} while(0)
   1.149 -#endif
   1.150 -#ifndef SDL_memset4
   1.151 -#define SDL_memset4(dst, val, len)		\
   1.152 -do {						\
   1.153 -	unsigned _count = (len);		\
   1.154 -	unsigned _n = (_count + 3) / 4;		\
   1.155 -	Uint32 *_p = SDL_static_cast(Uint32 *, dst);		\
   1.156 -	Uint32 _val = (val);			\
   1.157 -	if (len == 0) break;			\
   1.158 -        switch (_count % 4) {			\
   1.159 -        case 0: do {    *_p++ = _val;		\
   1.160 -        case 3:         *_p++ = _val;		\
   1.161 -        case 2:         *_p++ = _val;		\
   1.162 -        case 1:         *_p++ = _val;		\
   1.163 -		} while ( --_n );		\
   1.164 -	}					\
   1.165 -} while(0)
   1.166 +extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
   1.167 +#ifdef HAVE_SETENV
   1.168 +SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); }
   1.169 +#define SDL_setenv SDL_setenv_inline
   1.170  #endif
   1.171  
   1.172 -/* We can count on memcpy existing on Mac OS X and being well-tuned. */
   1.173 -#if defined(__MACOSX__)
   1.174 -#define SDL_memcpy      memcpy
   1.175 -#elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   1.176 -#define SDL_memcpy(dst, src, len)					  \
   1.177 -do {									  \
   1.178 -	int u0, u1, u2;						  	  \
   1.179 -	__asm__ __volatile__ (						  \
   1.180 -		"cld\n\t"						  \
   1.181 -		"rep ; movsl\n\t"					  \
   1.182 -		"testb $2,%b4\n\t"					  \
   1.183 -		"je 1f\n\t"						  \
   1.184 -		"movsw\n"						  \
   1.185 -		"1:\ttestb $1,%b4\n\t"					  \
   1.186 -		"je 2f\n\t"						  \
   1.187 -		"movsb\n"						  \
   1.188 -		"2:"							  \
   1.189 -		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   1.190 -		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
   1.191 -		: "memory" );						  \
   1.192 -} while(0)
   1.193 -#endif
   1.194 -#ifndef SDL_memcpy
   1.195 -#ifdef HAVE_MEMCPY
   1.196 -#define SDL_memcpy      memcpy
   1.197 -#elif defined(HAVE_BCOPY)
   1.198 -#define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
   1.199 -#else
   1.200 -extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
   1.201 -                                         size_t len);
   1.202 -#endif
   1.203 +extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
   1.204 +#ifdef HAVE_QSORT
   1.205 +SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { return qsort(base, nmemb, size, compare); }
   1.206 +#define SDL_qsort SDL_qsort_inline
   1.207  #endif
   1.208  
   1.209 -/* We can count on memcpy existing on Mac OS X and being well-tuned. */
   1.210 -#if defined(__MACOSX__)
   1.211 -#define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   1.212 -#elif defined(__GNUC__) && defined(i386)
   1.213 -#define SDL_memcpy4(dst, src, len)				\
   1.214 -do {								\
   1.215 -	int ecx, edi, esi;					\
   1.216 -	__asm__ __volatile__ (					\
   1.217 -		"cld\n\t"					\
   1.218 -		"rep ; movsl"					\
   1.219 -		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   1.220 -		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
   1.221 -		: "memory" );					\
   1.222 -} while(0)
   1.223 +extern DECLSPEC int SDLCALL SDL_abs(int x);
   1.224 +#ifdef HAVE_ABS
   1.225 +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); }
   1.226 +#else
   1.227 +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); }
   1.228  #endif
   1.229 -#ifndef SDL_memcpy4
   1.230 -#define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   1.231 +#define SDL_abs SDL_abs_inline
   1.232 +
   1.233 +/* !!! FIXME: these have side effects. You probably shouldn't use them. */
   1.234 +/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
   1.235 +#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
   1.236 +#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
   1.237 +
   1.238 +extern DECLSPEC int SDLCALL SDL_isdigit(int x);
   1.239 +extern DECLSPEC int SDLCALL SDL_isspace(int x);
   1.240 +extern DECLSPEC int SDLCALL SDL_toupper(int x);
   1.241 +extern DECLSPEC int SDLCALL SDL_tolower(int x);
   1.242 +#ifdef HAVE_CTYPE_H
   1.243 +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); }
   1.244 +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); }
   1.245 +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); }
   1.246 +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); }
   1.247 +#else
   1.248 +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); }
   1.249 +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
   1.250 +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   1.251 +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   1.252 +#endif
   1.253 +#define SDL_isdigit SDL_isdigit_inline
   1.254 +#define SDL_isspace SDL_isspace_inline
   1.255 +#define SDL_toupper SDL_toupper_inline
   1.256 +#define SDL_tolower SDL_tolower_inline
   1.257 +
   1.258 +extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   1.259 +#ifdef HAVE_MEMSET
   1.260 +SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); }
   1.261 +#define SDL_memset SDL_memset_inline
   1.262  #endif
   1.263  
   1.264 -#ifdef HAVE_MEMMOVE
   1.265 -#define SDL_memmove     memmove
   1.266 +#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
   1.267 +#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
   1.268 +
   1.269 +/* !!! FIXME: does this _really_ beat memset() on any modern platform? */
   1.270 +SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len)
   1.271 +{
   1.272 +#if defined(__GNUC__) && defined(i386)
   1.273 +    int u0, u1, u2;
   1.274 +    __asm__ __volatile__ (
   1.275 +        "cld \n\t"
   1.276 +        "rep ; stosl \n\t"
   1.277 +        : "=&D" (u0), "=&a" (u1), "=&c" (u2)
   1.278 +        : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))
   1.279 +        : "memory"
   1.280 +    );
   1.281 +/* !!! FIXME: amd64? */
   1.282  #else
   1.283 -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src,
   1.284 -                                          size_t len);
   1.285 +    unsigned int _count = (len);
   1.286 +    unsigned int _n = (_count + 3) / 4;
   1.287 +    Uint32 *_p = SDL_static_cast(Uint32 *, dst);
   1.288 +    Uint32 _val = (val);
   1.289 +    if (len == 0)
   1.290 +        return;
   1.291 +    switch (_count % 4)
   1.292 +    {
   1.293 +        case 0: do {    *_p++ = _val;
   1.294 +        case 3:         *_p++ = _val;
   1.295 +        case 2:         *_p++ = _val;
   1.296 +        case 1:         *_p++ = _val;
   1.297 +        } while ( --_n );
   1.298 +    }
   1.299 +#endif
   1.300 +}
   1.301 +
   1.302 +
   1.303 +extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
   1.304 +#if defined(__MACOSX__)
   1.305 +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.306 +{
   1.307 +    /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   1.308 +    return memcpy(dst, src, len);
   1.309 +}
   1.310 +#define SDL_memcpy SDL_memcpy_inline
   1.311 +#elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   1.312 +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.313 +{
   1.314 +    /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   1.315 +    /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   1.316 +    /* !!! FIXME: amd64? */
   1.317 +    int u0, u1, u2;
   1.318 +    __asm__ __volatile__ (
   1.319 +        "cld \n\t"
   1.320 +        "rep ; movsl \n\t"
   1.321 +        "testb $2,%b4 \n\t"
   1.322 +        "je 1f \n\t"
   1.323 +        "movsw \n"
   1.324 +        "1:\ttestb $1,%b4 \n\t"
   1.325 +        "je 2f \n\t"
   1.326 +        "movsb \n"
   1.327 +        "2:"
   1.328 +        : "=&c" (u0), "=&D" (u1), "=&S" (u2)
   1.329 +        : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src)
   1.330 +        : "memory"
   1.331 +    );
   1.332 +    return dst;
   1.333 +}
   1.334 +#define SDL_memcpy SDL_memcpy_inline
   1.335 +#elif defined(HAVE_MEMCPY)
   1.336 +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.337 +{
   1.338 +    return memcpy(dst, src, len);
   1.339 +}
   1.340 +#define SDL_memcpy SDL_memcpy_inline
   1.341 +#elif defined(HAVE_BCOPY)  /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */
   1.342 +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   1.343 +{
   1.344 +    bcopy(src, dst, len);
   1.345 +    return dst;
   1.346 +}
   1.347 +#define SDL_memcpy SDL_memcpy_inline
   1.348  #endif
   1.349  
   1.350 -#ifdef HAVE_MEMCMP
   1.351 -#define SDL_memcmp      memcmp
   1.352 +
   1.353 +SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
   1.354 +{
   1.355 +#if defined(__MACOSX__)
   1.356 +    /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   1.357 +    return memcpy(dst, src, dwords * 4);
   1.358 +#elif defined(__GNUC__) && defined(i386)
   1.359 +    /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   1.360 +    /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   1.361 +    /* !!! FIXME: amd64? */
   1.362 +    int ecx, edi, esi;
   1.363 +    __asm__ __volatile__ (
   1.364 +        "cld \n\t"
   1.365 +        "rep ; movsl \n\t"
   1.366 +        : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
   1.367 +        : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)
   1.368 +        : "memory"
   1.369 +    );
   1.370 +    return dst;
   1.371  #else
   1.372 -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
   1.373 -                                       size_t len);
   1.374 +    return SDL_memcpy(dst, src, dwords * 4);
   1.375 +#endif
   1.376 +}
   1.377 +
   1.378 +extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
   1.379 +#ifdef HAVE_MEMMOVE
   1.380 +SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); }
   1.381 +#define SDL_memmove SDL_memmove_inline
   1.382  #endif
   1.383  
   1.384 -#ifdef HAVE_STRLEN
   1.385 -#define SDL_strlen      strlen
   1.386 -#else
   1.387 -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
   1.388 +extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   1.389 +#ifdef HAVE_MEMCMP
   1.390 +SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
   1.391 +#define SDL_memcmp SDL_memcmp_inline
   1.392  #endif
   1.393  
   1.394 -#ifdef HAVE_WCSLEN
   1.395 -#define SDL_wcslen      wcslen
   1.396 -#else
   1.397 -#if !defined(wchar_t) && defined(__NINTENDODS__)
   1.398 -#define wchar_t short           /* TODO: figure out why libnds doesn't have this */
   1.399 -#endif
   1.400 -extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
   1.401 +extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   1.402 +#ifdef HAVE_STRLEN
   1.403 +SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
   1.404 +#define SDL_strlen SDL_strlen_inline
   1.405  #endif
   1.406  
   1.407 -#ifdef HAVE_WCSLCPY
   1.408 -#define SDL_wcslcpy      wcslcpy
   1.409 -#else
   1.410 -extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.411 +extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   1.412 +#ifdef HAVE_WCSLEN
   1.413 +SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
   1.414 +#define SDL_wcslen SDL_wcslen_inline
   1.415  #endif
   1.416  
   1.417 -#ifdef HAVE_WCSLCAT
   1.418 -#define SDL_wcslcat      wcslcat
   1.419 -#else
   1.420 -extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.421 +extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.422 +#ifdef HAVE_WCSLCPY
   1.423 +SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
   1.424 +#define SDL_wcslcpy SDL_wcslcpy_inline
   1.425  #endif
   1.426  
   1.427 -
   1.428 -#ifdef HAVE_STRLCPY
   1.429 -#define SDL_strlcpy     strlcpy
   1.430 -#else
   1.431 -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
   1.432 -                                           size_t maxlen);
   1.433 +extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   1.434 +#ifdef HAVE_WCSLCAT
   1.435 +SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
   1.436 +#define SDL_wcslcat SDL_wcslcat_inline
   1.437  #endif
   1.438  
   1.439 -extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src,
   1.440 -                                            size_t dst_bytes);
   1.441 -
   1.442 -#ifdef HAVE_STRLCAT
   1.443 -#define SDL_strlcat    strlcat
   1.444 +extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   1.445 +#ifdef HAVE_STRLCPY
   1.446 +SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
   1.447 +#define SDL_strlcpy SDL_strlcpy_inline
   1.448  #else
   1.449 -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
   1.450 -                                           size_t maxlen);
   1.451  #endif
   1.452  
   1.453 -#ifdef HAVE_STRDUP
   1.454 -#define SDL_strdup     strdup
   1.455 -#else
   1.456 -extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
   1.457 +extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
   1.458 +
   1.459 +extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   1.460 +#ifdef HAVE_STRLCAT
   1.461 +SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
   1.462 +#define SDL_strlcat SDL_strlcat_inline
   1.463  #endif
   1.464  
   1.465 -#ifdef HAVE__STRREV
   1.466 -#define SDL_strrev      _strrev
   1.467 -#else
   1.468 -extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
   1.469 +extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
   1.470 +#ifdef HAVE_STRDUP
   1.471 +SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
   1.472 +#define SDL_strdup SDL_strdup_inline
   1.473  #endif
   1.474  
   1.475 -#ifdef HAVE__STRUPR
   1.476 -#define SDL_strupr      _strupr
   1.477 -#else
   1.478 -extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
   1.479 +extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
   1.480 +#ifdef HAVE__STRREV
   1.481 +SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
   1.482 +#define SDL_strrev SDL_strrev_inline
   1.483  #endif
   1.484  
   1.485 -#ifdef HAVE__STRLWR
   1.486 -#define SDL_strlwr      _strlwr
   1.487 -#else
   1.488 -extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
   1.489 +extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
   1.490 +#ifdef HAVE__STRUPR
   1.491 +SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
   1.492 +#define SDL_strupr SDL_strupr_inline
   1.493  #endif
   1.494  
   1.495 -#ifdef HAVE_STRCHR
   1.496 -#define SDL_strchr      strchr
   1.497 -#elif defined(HAVE_INDEX)
   1.498 -#define SDL_strchr      index
   1.499 -#else
   1.500 -extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
   1.501 +extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
   1.502 +#ifdef HAVE__STRLWR
   1.503 +SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
   1.504 +#define SDL_strlwr SDL_strlwr_inline
   1.505  #endif
   1.506  
   1.507 -#ifdef HAVE_STRRCHR
   1.508 -#define SDL_strrchr     strrchr
   1.509 -#elif defined(HAVE_RINDEX)
   1.510 -#define SDL_strrchr     rindex
   1.511 -#else
   1.512 -extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
   1.513 +extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
   1.514 +#ifdef HAVE_STRCHR
   1.515 +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return strchr(str, c); }
   1.516 +#define SDL_strchr SDL_strchr_inline
   1.517 +#elif defined(HAVE_INDEX)  /* !!! FIXME: is there anywhere that has this but not strchr? */
   1.518 +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); }
   1.519 +#define SDL_strchr SDL_strchr_inline
   1.520  #endif
   1.521  
   1.522 -#ifdef HAVE_STRSTR
   1.523 -#define SDL_strstr      strstr
   1.524 -#else
   1.525 -extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
   1.526 -                                         const char *needle);
   1.527 +extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
   1.528 +#ifdef HAVE_STRRCHR
   1.529 +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return strrchr(str, c); }
   1.530 +#define SDL_strrchr SDL_strrchr_inline
   1.531 +#elif defined(HAVE_RINDEX)  /* !!! FIXME: is there anywhere that has this but not strrchr? */
   1.532 +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return rindex(str, c); }
   1.533 +#define SDL_strrchr SDL_strrchr_inline
   1.534  #endif
   1.535  
   1.536 -#ifdef HAVE_ITOA
   1.537 -#define SDL_itoa        itoa
   1.538 -#else
   1.539 -#define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
   1.540 +extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
   1.541 +#ifdef HAVE_STRSTR
   1.542 +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return strstr(haystack, needle); }
   1.543 +#define SDL_strstr SDL_strstr_inline
   1.544  #endif
   1.545  
   1.546 +extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   1.547  #ifdef HAVE__LTOA
   1.548 -#define SDL_ltoa        _ltoa
   1.549 -#else
   1.550 -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
   1.551 +SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
   1.552 +#define SDL_ltoa SDL_ltoa_inline
   1.553  #endif
   1.554  
   1.555 -#ifdef HAVE__UITOA
   1.556 -#define SDL_uitoa       _uitoa
   1.557 +extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
   1.558 +#ifdef HAVE_ITOA
   1.559 +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
   1.560  #else
   1.561 -#define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
   1.562 +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
   1.563 +#endif
   1.564 +#define SDL_itoa SDL_itoa_inline
   1.565 +
   1.566 +extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
   1.567 +#ifdef HAVE__ULTOA
   1.568 +SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
   1.569 +#define SDL_ultoa SDL_ultoa_inline
   1.570  #endif
   1.571  
   1.572 -#ifdef HAVE__ULTOA
   1.573 -#define SDL_ultoa       _ultoa
   1.574 +extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   1.575 +#ifdef HAVE__UITOA
   1.576 +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
   1.577  #else
   1.578 -extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
   1.579 -                                        int radix);
   1.580 +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
   1.581 +#endif
   1.582 +#define SDL_uitoa SDL_uitoa_inline
   1.583 +
   1.584 +
   1.585 +extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   1.586 +#ifdef HAVE_STRTOL
   1.587 +SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
   1.588 +#define SDL_strtol SDL_strtol_inline
   1.589  #endif
   1.590  
   1.591 -#ifdef HAVE_STRTOL
   1.592 -#define SDL_strtol      strtol
   1.593 -#else
   1.594 -extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
   1.595 -                                        int base);
   1.596 +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   1.597 +#ifdef HAVE_STRTOUL
   1.598 +SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
   1.599 +#define SDL_strtoul SDL_strtoul_inline
   1.600  #endif
   1.601  
   1.602 -#ifdef HAVE_STRTOUL
   1.603 -#define SDL_strtoul      strtoul
   1.604 -#else
   1.605 -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
   1.606 -                                                  char **endp, int base);
   1.607 +extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
   1.608 +#ifdef HAVE__I64TOA
   1.609 +SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
   1.610 +#define SDL_lltoa SDL_lltoa_inline
   1.611  #endif
   1.612  
   1.613 -#ifdef HAVE__I64TOA
   1.614 -#define SDL_lltoa       _i64toa
   1.615 -#else
   1.616 -extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
   1.617 -                                        int radix);
   1.618 +extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
   1.619 +#ifdef HAVE__UI64TOA
   1.620 +SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
   1.621 +#define SDL_ulltoa SDL_ulltoa_inline
   1.622  #endif
   1.623  
   1.624 -#ifdef HAVE__UI64TOA
   1.625 -#define SDL_ulltoa      _ui64toa
   1.626 -#else
   1.627 -extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
   1.628 -                                         int radix);
   1.629 +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   1.630 +#ifdef HAVE_STRTOLL
   1.631 +SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
   1.632 +#define SDL_strtoll SDL_strtoll_inline
   1.633  #endif
   1.634  
   1.635 -#ifdef HAVE_STRTOLL
   1.636 -#define SDL_strtoll     strtoll
   1.637 -#else
   1.638 -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
   1.639 -                                           int base);
   1.640 +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   1.641 +#ifdef HAVE_STRTOULL
   1.642 +SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
   1.643 +#define SDL_strtoull SDL_strtoull_inline
   1.644  #endif
   1.645  
   1.646 -#ifdef HAVE_STRTOULL
   1.647 -#define SDL_strtoull     strtoull
   1.648 -#else
   1.649 -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
   1.650 -                                            int base);
   1.651 +extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   1.652 +#ifdef HAVE_STRTOD
   1.653 +SDL_FORCE_INLINE Uint64 SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
   1.654 +#define SDL_strtod SDL_strtod_inline
   1.655  #endif
   1.656  
   1.657 -#ifdef HAVE_STRTOD
   1.658 -#define SDL_strtod      strtod
   1.659 +extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
   1.660 +#ifdef HAVE_ATOI
   1.661 +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
   1.662  #else
   1.663 -extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
   1.664 +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
   1.665 +#endif
   1.666 +#define SDL_atoi SDL_atoi_inline
   1.667 +
   1.668 +extern DECLSPEC double SDLCALL SDL_atof(const char *str);
   1.669 +#ifdef HAVE_ATOF
   1.670 +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
   1.671 +#else
   1.672 +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
   1.673 +#endif
   1.674 +#define SDL_atof SDL_atof_inline
   1.675 +
   1.676 +
   1.677 +extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   1.678 +#ifdef HAVE_STRCMP
   1.679 +SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
   1.680 +#define SDL_strcmp SDL_strcmp_inline
   1.681  #endif
   1.682  
   1.683 -#ifdef HAVE_ATOI
   1.684 -#define SDL_atoi        atoi
   1.685 -#else
   1.686 -#define SDL_atoi(X)     SDL_strtol(X, NULL, 0)
   1.687 +extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   1.688 +#ifdef HAVE_STRNCMP
   1.689 +SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
   1.690 +#define SDL_strncmp SDL_strncmp_inline
   1.691  #endif
   1.692  
   1.693 -#ifdef HAVE_ATOF
   1.694 -#define SDL_atof        atof
   1.695 -#else
   1.696 -#define SDL_atof(X)     SDL_strtod(X, NULL)
   1.697 +extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   1.698 +#ifdef HAVE_STRCASECMP
   1.699 +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
   1.700 +#define SDL_strcasecmp SDL_strcasecmp_inline
   1.701 +#elif defined(HAVE__STRICMP)
   1.702 +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
   1.703 +#define SDL_strcasecmp SDL_strcasecmp_inline
   1.704  #endif
   1.705  
   1.706 -#ifdef HAVE_STRCMP
   1.707 -#define SDL_strcmp      strcmp
   1.708 -#else
   1.709 -extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   1.710 +extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   1.711 +#ifdef HAVE_STRNCASECMP
   1.712 +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
   1.713 +#define SDL_strncasecmp SDL_strncasecmp_inline
   1.714 +#elif defined(HAVE__STRNICMP)
   1.715 +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
   1.716 +#define SDL_strncasecmp SDL_strncasecmp_inline
   1.717  #endif
   1.718  
   1.719 -#ifdef HAVE_STRNCMP
   1.720 -#define SDL_strncmp     strncmp
   1.721 -#else
   1.722 -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
   1.723 -                                        size_t maxlen);
   1.724 +/* Not doing SDL_*_inline functions for these, because of the varargs. */
   1.725 +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   1.726 +#ifdef HAVE_SSCANF
   1.727 +#define SDL_sscanf sscanf
   1.728  #endif
   1.729  
   1.730 -#ifdef HAVE_STRCASECMP
   1.731 -#define SDL_strcasecmp  strcasecmp
   1.732 -#elif defined(HAVE__STRICMP)
   1.733 -#define SDL_strcasecmp  _stricmp
   1.734 -#else
   1.735 -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
   1.736 -                                           const char *str2);
   1.737 +extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   1.738 +#ifdef HAVE_SNPRINTF
   1.739 +#define SDL_snprintf snprintf
   1.740  #endif
   1.741  
   1.742 -#ifdef HAVE_STRNCASECMP
   1.743 -#define SDL_strncasecmp strncasecmp
   1.744 -#elif defined(HAVE__STRNICMP)
   1.745 -#define SDL_strncasecmp _strnicmp
   1.746 -#else
   1.747 -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
   1.748 -                                            const char *str2, size_t maxlen);
   1.749 -#endif
   1.750 -
   1.751 -#ifdef HAVE_SSCANF
   1.752 -#define SDL_sscanf      sscanf
   1.753 -#else
   1.754 -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
   1.755 -                                       ...);
   1.756 -#endif
   1.757 -
   1.758 -#ifdef HAVE_SNPRINTF
   1.759 -#define SDL_snprintf    snprintf
   1.760 -#else
   1.761 -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
   1.762 -                                         const char *fmt, ...);
   1.763 -#endif
   1.764 -
   1.765 +extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   1.766  #ifdef HAVE_VSNPRINTF
   1.767 -#define SDL_vsnprintf   vsnprintf
   1.768 -#else
   1.769 -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
   1.770 -                                          const char *fmt, va_list ap);
   1.771 +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.772 +#define SDL_vsnprintf SDL_vsnprintf_inline
   1.773  #endif
   1.774  
   1.775  #ifndef HAVE_M_PI
   1.776 @@ -638,88 +681,94 @@
   1.777  #endif
   1.778  #endif
   1.779  
   1.780 +extern DECLSPEC double SDLCALL SDL_atan(double x);
   1.781  #ifdef HAVE_ATAN
   1.782 -#define SDL_atan        atan
   1.783 -#else
   1.784 -extern DECLSPEC double SDLCALL SDL_atan(double x);
   1.785 +SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
   1.786 +#define SDL_atan SDL_atan_inline
   1.787  #endif
   1.788  
   1.789 +extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
   1.790  #ifdef HAVE_ATAN2
   1.791 -#define SDL_atan2       atan2
   1.792 -#else
   1.793 -extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
   1.794 +SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
   1.795 +#define SDL_atan2 SDL_atan2_inline
   1.796  #endif
   1.797  
   1.798 +extern DECLSPEC double SDLCALL SDL_ceil(double x);
   1.799  #ifdef HAVE_CEIL
   1.800 -#define SDL_ceil        ceil
   1.801 +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
   1.802  #else
   1.803 -#define SDL_ceil(x)     ((double)(int)((x)+0.5))
   1.804 +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
   1.805 +#endif
   1.806 +#define SDL_ceil SDL_ceil_inline
   1.807 +
   1.808 +extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   1.809 +#ifdef HAVE_COPYSIGN
   1.810 +SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
   1.811 +#define SDL_copysign SDL_copysign_inline
   1.812  #endif
   1.813  
   1.814 -#ifdef HAVE_COPYSIGN
   1.815 -#define SDL_copysign    copysign
   1.816 -#else
   1.817 -extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   1.818 +extern DECLSPEC double SDLCALL SDL_cos(double x);
   1.819 +#ifdef HAVE_COS
   1.820 +SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
   1.821 +#define SDL_cos SDL_cos_inline
   1.822  #endif
   1.823  
   1.824 -#ifdef HAVE_COS
   1.825 -#define SDL_cos         cos
   1.826 +extern DECLSPEC float SDLCALL SDL_cosf(float x);
   1.827 +#ifdef HAVE_COSF
   1.828 +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
   1.829  #else
   1.830 -extern DECLSPEC double SDLCALL SDL_cos(double x);
   1.831 +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
   1.832 +#endif
   1.833 +#define SDL_cosf SDL_cosf_inline
   1.834 +
   1.835 +extern DECLSPEC double SDLCALL SDL_fabs(double x);
   1.836 +#ifdef HAVE_FABS
   1.837 +SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
   1.838 +#define SDL_fabs SDL_fabs_inline
   1.839  #endif
   1.840  
   1.841 -#ifdef HAVE_COSF
   1.842 -#define SDL_cosf        cosf
   1.843 -#else
   1.844 -#define SDL_cosf(x) (float)SDL_cos((double)x)
   1.845 +extern DECLSPEC double SDLCALL SDL_floor(double x);
   1.846 +#ifdef HAVE_FLOOR
   1.847 +SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
   1.848 +#define SDL_floor SDL_floor_inline
   1.849  #endif
   1.850  
   1.851 -#ifdef HAVE_FABS
   1.852 -#define SDL_fabs        fabs
   1.853 -#else
   1.854 -extern DECLSPEC double SDLCALL SDL_fabs(double x);
   1.855 +extern DECLSPEC double SDLCALL SDL_log(double x);
   1.856 +#ifdef HAVE_LOG
   1.857 +SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
   1.858 +#define SDL_log SDL_log_inline
   1.859  #endif
   1.860  
   1.861 -#ifdef HAVE_FLOOR
   1.862 -#define SDL_floor       floor
   1.863 -#else
   1.864 -extern DECLSPEC double SDLCALL SDL_floor(double x);
   1.865 +extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   1.866 +#ifdef HAVE_POW
   1.867 +SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
   1.868 +#define SDL_pow SDL_pow_inline
   1.869  #endif
   1.870  
   1.871 -#ifdef HAVE_LOG
   1.872 -#define SDL_log         log
   1.873 -#else
   1.874 -extern DECLSPEC double SDLCALL SDL_log(double x);
   1.875 +extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   1.876 +#ifdef HAVE_SCALBN
   1.877 +SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
   1.878 +#define SDL_scalbn SDL_scalbn_inline
   1.879  #endif
   1.880  
   1.881 -#ifdef HAVE_POW
   1.882 -#define SDL_pow         pow
   1.883 -#else
   1.884 -extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   1.885 +extern DECLSPEC double SDLCALL SDL_sin(double x);
   1.886 +#ifdef HAVE_SIN
   1.887 +SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
   1.888 +#define SDL_sin SDL_sin_inline
   1.889  #endif
   1.890  
   1.891 -#ifdef HAVE_SCALBN
   1.892 -#define SDL_scalbn      scalbn
   1.893 +extern DECLSPEC float SDLCALL SDL_sinf(float x);
   1.894 +#ifdef HAVE_SINF
   1.895 +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
   1.896  #else
   1.897 -extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   1.898 +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
   1.899  #endif
   1.900 +#define SDL_sinf SDL_sinf_inline
   1.901  
   1.902 -#ifdef HAVE_SIN
   1.903 -#define SDL_sin         sin
   1.904 -#else
   1.905 -extern DECLSPEC double SDLCALL SDL_sin(double x);
   1.906 -#endif
   1.907 -
   1.908 -#ifdef HAVE_SINF
   1.909 -#define SDL_sinf        sinf
   1.910 -#else
   1.911 -#define SDL_sinf(x) (float)SDL_sin((double)x)
   1.912 -#endif
   1.913 -
   1.914 +extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   1.915  #ifdef HAVE_SQRT
   1.916 -#define SDL_sqrt        sqrt
   1.917 -#else
   1.918 -extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   1.919 +SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
   1.920 +#define SDL_sqrt SDL_sqrt_inline
   1.921  #endif
   1.922  
   1.923  /* The SDL implementation of iconv() returns these error codes */
   1.924 @@ -728,16 +777,11 @@
   1.925  #define SDL_ICONV_EILSEQ	(size_t)-3
   1.926  #define SDL_ICONV_EINVAL	(size_t)-4
   1.927  
   1.928 -#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
   1.929 -#define SDL_iconv_t     iconv_t
   1.930 -#define SDL_iconv_open  iconv_open
   1.931 -#define SDL_iconv_close iconv_close
   1.932 -#else
   1.933 +/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
   1.934  typedef struct _SDL_iconv_t *SDL_iconv_t;
   1.935  extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   1.936                                                     const char *fromcode);
   1.937  extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   1.938 -#endif
   1.939  extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   1.940                                           size_t * inbytesleft, char **outbuf,
   1.941                                           size_t * outbytesleft);
     2.1 --- a/src/stdlib/SDL_getenv.c	Fri Mar 15 01:02:30 2013 -0400
     2.2 +++ b/src/stdlib/SDL_getenv.c	Fri Mar 15 01:01:20 2013 -0400
     2.3 @@ -22,18 +22,19 @@
     2.4  
     2.5  #include "SDL_stdinc.h"
     2.6  
     2.7 -#ifndef HAVE_GETENV
     2.8 -
     2.9 -#if defined(__WIN32__)
    2.10 -
    2.11 +#if !defined(SDL_setenv) && defined(__WIN32__)
    2.12  #include "../core/windows/SDL_windows.h"
    2.13 -
    2.14  /* Note this isn't thread-safe! */
    2.15 -
    2.16  static char *SDL_envmem = NULL; /* Ugh, memory leak */
    2.17  static size_t SDL_envmemlen = 0;
    2.18 +#endif
    2.19 +
    2.20  
    2.21  /* Put a variable into the environment */
    2.22 +#ifdef SDL_setenv
    2.23 +#undef SDL_setenv
    2.24 +int SDL_setenv(const char *name, const char *value, int overwrite) { return SDL_setenv_inline(name, value, overwrite); }
    2.25 +#elif defined(__WIN32__)
    2.26  int
    2.27  SDL_setenv(const char *name, const char *value, int overwrite)
    2.28  {
    2.29 @@ -49,35 +50,34 @@
    2.30      }
    2.31      return 0;
    2.32  }
    2.33 +/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
    2.34 +#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
    2.35 +int
    2.36 +SDL_setenv(const char *name, const char *value, int overwrite)
    2.37 +{
    2.38 +    size_t len;
    2.39 +    char *new_variable;
    2.40  
    2.41 -/* Retrieve a variable named "name" from the environment */
    2.42 -char *
    2.43 -SDL_getenv(const char *name)
    2.44 -{
    2.45 -    size_t bufferlen;
    2.46 +    if (getenv(name) != NULL) {
    2.47 +        if (overwrite) {
    2.48 +            unsetenv(name);
    2.49 +        } else {
    2.50 +            return 0;  /* leave the existing one there. */
    2.51 +        }
    2.52 +    }
    2.53  
    2.54 -    bufferlen =
    2.55 -        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
    2.56 -    if (bufferlen == 0) {
    2.57 -        return NULL;
    2.58 +    /* This leaks. Sorry. Get a better OS so we don't have to do this. */
    2.59 +    len = SDL_strlen(name) + SDL_strlen(value) + 2;
    2.60 +    new_variable = (char *) SDL_malloc(len);
    2.61 +    if (!new_variable) {
    2.62 +        return (-1);
    2.63      }
    2.64 -    if (bufferlen > SDL_envmemlen) {
    2.65 -        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
    2.66 -        if (newmem == NULL) {
    2.67 -            return NULL;
    2.68 -        }
    2.69 -        SDL_envmem = newmem;
    2.70 -        SDL_envmemlen = bufferlen;
    2.71 -        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
    2.72 -    }
    2.73 -    return SDL_envmem;
    2.74 +
    2.75 +    SDL_snprintf(new_variable, len, "%s=%s", name, value);
    2.76 +    return putenv(new_variable);
    2.77  }
    2.78 -
    2.79  #else /* roll our own */
    2.80 -
    2.81  static char **SDL_env = (char **) 0;
    2.82 -
    2.83 -/* Put a variable into the environment */
    2.84  int
    2.85  SDL_setenv(const char *name, const char *value, int overwrite)
    2.86  {
    2.87 @@ -140,8 +140,35 @@
    2.88      }
    2.89      return (added ? 0 : -1);
    2.90  }
    2.91 +#endif
    2.92  
    2.93  /* Retrieve a variable named "name" from the environment */
    2.94 +#ifdef SDL_getenv
    2.95 +#undef SDL_getenv
    2.96 +char *SDL_getenv(const char *name) { return SDL_getenv_inline(name); }
    2.97 +#elif defined(__WIN32__)
    2.98 +char *
    2.99 +SDL_getenv(const char *name)
   2.100 +{
   2.101 +    size_t bufferlen;
   2.102 +
   2.103 +    bufferlen =
   2.104 +        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
   2.105 +    if (bufferlen == 0) {
   2.106 +        return NULL;
   2.107 +    }
   2.108 +    if (bufferlen > SDL_envmemlen) {
   2.109 +        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
   2.110 +        if (newmem == NULL) {
   2.111 +            return NULL;
   2.112 +        }
   2.113 +        SDL_envmem = newmem;
   2.114 +        SDL_envmemlen = bufferlen;
   2.115 +        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
   2.116 +    }
   2.117 +    return SDL_envmem;
   2.118 +}
   2.119 +#else
   2.120  char *
   2.121  SDL_getenv(const char *name)
   2.122  {
   2.123 @@ -160,38 +187,6 @@
   2.124      }
   2.125      return value;
   2.126  }
   2.127 -
   2.128 -#endif /* __WIN32__ */
   2.129 -
   2.130 -#endif /* !HAVE_GETENV */
   2.131 -
   2.132 -
   2.133 -/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
   2.134 -#if (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
   2.135 -int
   2.136 -SDL_setenv(const char *name, const char *value, int overwrite)
   2.137 -{
   2.138 -    size_t len;
   2.139 -    char *new_variable;
   2.140 -
   2.141 -    if (getenv(name) != NULL) {
   2.142 -        if (overwrite) {
   2.143 -            unsetenv(name);
   2.144 -        } else {
   2.145 -            return 0;  /* leave the existing one there. */
   2.146 -        }
   2.147 -    }
   2.148 -
   2.149 -    /* This leaks. Sorry. Get a better OS so we don't have to do this. */
   2.150 -    len = SDL_strlen(name) + SDL_strlen(value) + 2;
   2.151 -    new_variable = (char *) SDL_malloc(len);
   2.152 -    if (!new_variable) {
   2.153 -        return (-1);
   2.154 -    }
   2.155 -
   2.156 -    SDL_snprintf(new_variable, len, "%s=%s", name, value);
   2.157 -    return putenv(new_variable);
   2.158 -}
   2.159  #endif
   2.160  
   2.161  
     3.1 --- a/src/stdlib/SDL_iconv.c	Fri Mar 15 01:02:30 2013 -0400
     3.2 +++ b/src/stdlib/SDL_iconv.c	Fri Mar 15 01:01:20 2013 -0400
     3.3 @@ -38,6 +38,20 @@
     3.4  
     3.5  #include <errno.h>
     3.6  
     3.7 +SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t));
     3.8 +
     3.9 +SDL_iconv_t
    3.10 +SDL_iconv_open(const char *tocode, const char *fromcode)
    3.11 +{
    3.12 +    return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode));
    3.13 +}
    3.14 +
    3.15 +int
    3.16 +SDL_iconv_close(SDL_iconv_t cd)
    3.17 +{
    3.18 +    return iconv_close((iconv_t) ((size_t) cd));
    3.19 +}
    3.20 +
    3.21  size_t
    3.22  SDL_iconv(SDL_iconv_t cd,
    3.23            const char **inbuf, size_t * inbytesleft,
    3.24 @@ -45,9 +59,9 @@
    3.25  {
    3.26      size_t retCode;
    3.27  #ifdef ICONV_INBUF_NONCONST
    3.28 -    retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft);
    3.29 +    retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft);
    3.30  #else
    3.31 -    retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
    3.32 +    retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
    3.33  #endif
    3.34      if (retCode == (size_t) - 1) {
    3.35          switch (errno) {
     4.1 --- a/src/stdlib/SDL_malloc.c	Fri Mar 15 01:02:30 2013 -0400
     4.2 +++ b/src/stdlib/SDL_malloc.c	Fri Mar 15 01:01:20 2013 -0400
     4.3 @@ -24,7 +24,18 @@
     4.4  
     4.5  #include "SDL_stdinc.h"
     4.6  
     4.7 -#ifndef HAVE_MALLOC
     4.8 +#ifdef SDL_malloc
     4.9 +/* expose the symbol, but use what we figured out elsewhere. */
    4.10 +#undef SDL_malloc
    4.11 +#undef SDL_calloc
    4.12 +#undef SDL_realloc
    4.13 +#undef SDL_free
    4.14 +void *SDL_malloc(size_t size) { return SDL_malloc_inline(size); }
    4.15 +void *SDL_calloc(size_t nmemb, size_t size) { return SDL_calloc_inline(nmemb, size); }
    4.16 +void *SDL_realloc(void *ptr, size_t size) { return SDL_realloc_inline(ptr, size); }
    4.17 +void SDL_free(void *ptr) { SDL_free_inline(ptr); }
    4.18 +
    4.19 +#else  /* the rest of this is a LOT of tapdancing to implement malloc. :) */
    4.20  
    4.21  #define LACKS_SYS_TYPES_H
    4.22  #define LACKS_STDIO_H
     5.1 --- a/src/stdlib/SDL_qsort.c	Fri Mar 15 01:02:30 2013 -0400
     5.2 +++ b/src/stdlib/SDL_qsort.c	Fri Mar 15 01:01:20 2013 -0400
     5.3 @@ -51,6 +51,15 @@
     5.4  #include "SDL_stdinc.h"
     5.5  #include "SDL_assert.h"
     5.6  
     5.7 +#ifdef SDL_qsort
     5.8 +#undef SDL_qsort
     5.9 +void
    5.10 +SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *))
    5.11 +{
    5.12 +    SDL_qsort_inline(base, nmemb, size, compare);
    5.13 +}
    5.14 +#else
    5.15 +
    5.16  #ifdef assert
    5.17  #undef assert
    5.18  #endif
    5.19 @@ -76,9 +85,6 @@
    5.20  #endif
    5.21  #define qsort	SDL_qsort
    5.22  
    5.23 -
    5.24 -#ifndef HAVE_QSORT
    5.25 -
    5.26  static const char _ID[] = "<qsort.c gjm 1.12 1998-03-19>";
    5.27  
    5.28  /* How many bytes are there per word? (Must be a power of 2,
    5.29 @@ -466,5 +472,6 @@
    5.30          qsort_words(base, nmemb, compare);
    5.31  }
    5.32  
    5.33 -#endif /* !HAVE_QSORT */
    5.34 +#endif /* !SDL_qsort */
    5.35 +
    5.36  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/stdlib/SDL_stdlib.c	Fri Mar 15 01:02:30 2013 -0400
     6.2 +++ b/src/stdlib/SDL_stdlib.c	Fri Mar 15 01:01:20 2013 -0400
     6.3 @@ -24,6 +24,25 @@
     6.4  
     6.5  #include "SDL_stdinc.h"
     6.6  
     6.7 +/* these are always #defined, make them real symbol in the library, too... */
     6.8 +#undef SDL_ceil
     6.9 +#undef SDL_abs
    6.10 +#undef SDL_sinf
    6.11 +#undef SDL_cosf
    6.12 +#undef SDL_isdigit
    6.13 +#undef SDL_isspace
    6.14 +#undef SDL_toupper
    6.15 +#undef SDL_tolower
    6.16 +double SDL_ceil(double x) { return SDL_ceil_inline(x); }
    6.17 +float SDL_cosf(float x) { return SDL_cosf_inline(x); }
    6.18 +float SDL_sinf(float x) { return SDL_sinf_inline(x); }
    6.19 +int SDL_abs(int x) { return SDL_abs_inline(x); }
    6.20 +int SDL_isdigit(int x) { return SDL_isdigit_inline(x); }
    6.21 +int SDL_isspace(int x) { return SDL_isspace_inline(x); }
    6.22 +int SDL_toupper(int x) { return SDL_toupper_inline(x); }
    6.23 +int SDL_tolower(int x) { return SDL_tolower_inline(x); }
    6.24 +
    6.25 +
    6.26  #ifndef HAVE_LIBC
    6.27  /* These are some C runtime intrinsics that need to be defined */
    6.28  
     7.1 --- a/src/stdlib/SDL_string.c	Fri Mar 15 01:02:30 2013 -0400
     7.2 +++ b/src/stdlib/SDL_string.c	Fri Mar 15 01:01:20 2013 -0400
     7.3 @@ -24,6 +24,17 @@
     7.4  
     7.5  #include "SDL_stdinc.h"
     7.6  
     7.7 +/* these are always #defined, make them real symbol in the library, too... */
     7.8 +#undef SDL_itoa
     7.9 +#undef SDL_uitoa
    7.10 +#undef SDL_atoi
    7.11 +#undef SDL_atof
    7.12 +char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); }
    7.13 +char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); }
    7.14 +int SDL_atoi(const char *str) { return SDL_atoi(str); }
    7.15 +double SDL_atof(const char *str) { return SDL_atof(str); }
    7.16 +
    7.17 +
    7.18  
    7.19  #define SDL_isupperhex(X)   (((X) >= 'A') && ((X) <= 'F'))
    7.20  #define SDL_islowerhex(X)   (((X) >= 'a') && ((X) <= 'f'))
    7.21 @@ -43,7 +54,7 @@
    7.22          return 0;
    7.23  }
    7.24  
    7.25 -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL)
    7.26 +#if !defined(SDL_sscanf) || !defined(SDL_strtol)
    7.27  static size_t
    7.28  SDL_ScanLong(const char *text, int radix, long *valuep)
    7.29  {
    7.30 @@ -84,7 +95,7 @@
    7.31  }
    7.32  #endif
    7.33  
    7.34 -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
    7.35 +#if !defined(SDL_sscanf) || !defined(SDL_strtoul) || !defined(SDL_strtod)
    7.36  static size_t
    7.37  SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
    7.38  {
    7.39 @@ -116,7 +127,7 @@
    7.40  }
    7.41  #endif
    7.42  
    7.43 -#ifndef HAVE_SSCANF
    7.44 +#ifndef SDL_sscanf
    7.45  static size_t
    7.46  SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
    7.47  {
    7.48 @@ -148,7 +159,7 @@
    7.49  }
    7.50  #endif
    7.51  
    7.52 -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
    7.53 +#if !defined(SDL_sscanf) || !defined(SDL_strtoll)
    7.54  static size_t
    7.55  SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
    7.56  {
    7.57 @@ -189,7 +200,7 @@
    7.58  }
    7.59  #endif
    7.60  
    7.61 -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
    7.62 +#if !defined(SDL_sscanf) || !defined(SDL_strtoull)
    7.63  static size_t
    7.64  SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
    7.65  {
    7.66 @@ -221,7 +232,7 @@
    7.67  }
    7.68  #endif
    7.69  
    7.70 -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
    7.71 +#if !defined(SDL_sscanf) || !defined(SDL_strtod)
    7.72  static size_t
    7.73  SDL_ScanFloat(const char *text, double *valuep)
    7.74  {
    7.75 @@ -257,7 +268,11 @@
    7.76  }
    7.77  #endif
    7.78  
    7.79 -#ifndef SDL_memset
    7.80 +
    7.81 +#ifdef SDL_memset
    7.82 +#undef SDL_memset
    7.83 +void *SDL_memset(void *dst, int c, size_t len) { return SDL_memset_inline(dst, c, len); }
    7.84 +#else
    7.85  void *
    7.86  SDL_memset(void *dst, int c, size_t len)
    7.87  {
    7.88 @@ -287,7 +302,11 @@
    7.89  }
    7.90  #endif
    7.91  
    7.92 -#ifndef SDL_memcpy
    7.93 +
    7.94 +#ifdef SDL_memcpy
    7.95 +#undef SDL_memcpy
    7.96 +void *SDL_memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy_inline(dst, src, len); }
    7.97 +#else
    7.98  void *
    7.99  SDL_memcpy(void *dst, const void *src, size_t len)
   7.100  {
   7.101 @@ -317,7 +336,11 @@
   7.102  }
   7.103  #endif
   7.104  
   7.105 -#ifndef SDL_memmove
   7.106 +
   7.107 +#ifdef SDL_memmove
   7.108 +#undef SDL_memmove
   7.109 +void *SDL_memmove(void *dst, const void *src, size_t len) { return SDL_memmove_inline(dst, src, len); }
   7.110 +#else
   7.111  void *
   7.112  SDL_memmove(void *dst, const void *src, size_t len)
   7.113  {
   7.114 @@ -339,7 +362,10 @@
   7.115  }
   7.116  #endif
   7.117  
   7.118 -#ifndef SDL_memcmp
   7.119 +#ifdef SDL_memcmp
   7.120 +#undef SDL_memcmp
   7.121 +int SDL_memcmp(const void *s1, const void *s2, size_t len) { return SDL_memcmp_inline(s1, s2, len); }
   7.122 +#else
   7.123  int
   7.124  SDL_memcmp(const void *s1, const void *s2, size_t len)
   7.125  {
   7.126 @@ -356,7 +382,10 @@
   7.127  }
   7.128  #endif
   7.129  
   7.130 -#ifndef HAVE_STRLEN
   7.131 +#ifdef SDL_strlen
   7.132 +#undef SDL_strlen
   7.133 +size_t SDL_strlen(const char *string) { return SDL_strlen_inline(string); }
   7.134 +#else
   7.135  size_t
   7.136  SDL_strlen(const char *string)
   7.137  {
   7.138 @@ -368,7 +397,10 @@
   7.139  }
   7.140  #endif
   7.141  
   7.142 -#ifndef HAVE_WCSLEN
   7.143 +#ifdef SDL_wcslen
   7.144 +#undef SDL_wcslen
   7.145 +size_t SDL_wcslen(const wchar_t * string) { return SDL_wcslen_inline(string); }
   7.146 +#else
   7.147  size_t
   7.148  SDL_wcslen(const wchar_t * string)
   7.149  {
   7.150 @@ -380,7 +412,10 @@
   7.151  }
   7.152  #endif
   7.153  
   7.154 -#ifndef HAVE_WCSLCPY
   7.155 +#ifdef SDL_wcslcpy
   7.156 +#undef SDL_wcslcpy
   7.157 +size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcpy_inline(dst, src, maxlen); }
   7.158 +#else
   7.159  size_t
   7.160  SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
   7.161  {
   7.162 @@ -394,7 +429,10 @@
   7.163  }
   7.164  #endif
   7.165  
   7.166 -#ifndef HAVE_WCSLCAT
   7.167 +#ifdef SDL_wcslcat
   7.168 +#undef SDL_wcslcat
   7.169 +size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcat_inline(dst, src, maxlen); }
   7.170 +#else
   7.171  size_t
   7.172  SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
   7.173  {
   7.174 @@ -407,7 +445,10 @@
   7.175  }
   7.176  #endif
   7.177  
   7.178 -#ifndef HAVE_STRLCPY
   7.179 +#ifdef SDL_strlcpy
   7.180 +#undef SDL_strlcpy
   7.181 +size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { return SDL_strlcpy_inline(dst, src, maxlen); }
   7.182 +#else
   7.183  size_t
   7.184  SDL_strlcpy(char *dst, const char *src, size_t maxlen)
   7.185  {
   7.186 @@ -453,7 +494,10 @@
   7.187      return bytes;
   7.188  }
   7.189  
   7.190 -#ifndef HAVE_STRLCAT
   7.191 +#ifdef SDL_strlcat
   7.192 +#undef SDL_strlcat
   7.193 +size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { return SDL_strlcat_inline(dst, src, maxlen); }
   7.194 +#else
   7.195  size_t
   7.196  SDL_strlcat(char *dst, const char *src, size_t maxlen)
   7.197  {
   7.198 @@ -466,7 +510,10 @@
   7.199  }
   7.200  #endif
   7.201  
   7.202 -#ifndef HAVE_STRDUP
   7.203 +#ifdef SDL_strdup
   7.204 +#undef SDL_strdup
   7.205 +char *SDL_strdup(const char *string) { return SDL_strdup_inline(string); }
   7.206 +#else
   7.207  char *
   7.208  SDL_strdup(const char *string)
   7.209  {
   7.210 @@ -479,7 +526,10 @@
   7.211  }
   7.212  #endif
   7.213  
   7.214 -#ifndef HAVE__STRREV
   7.215 +#ifdef SDL_strrev
   7.216 +#undef SDL_strrev
   7.217 +char *SDL_strrev(char *string) { return SDL_strrev_inline(string); }
   7.218 +#else
   7.219  char *
   7.220  SDL_strrev(char *string)
   7.221  {
   7.222 @@ -496,7 +546,10 @@
   7.223  }
   7.224  #endif
   7.225  
   7.226 -#ifndef HAVE__STRUPR
   7.227 +#ifdef SDL_strupr
   7.228 +#undef SDL_strupr
   7.229 +char *SDL_strupr(char *string) { return SDL_strupr_inline(string); }
   7.230 +#else
   7.231  char *
   7.232  SDL_strupr(char *string)
   7.233  {
   7.234 @@ -509,7 +562,10 @@
   7.235  }
   7.236  #endif
   7.237  
   7.238 -#ifndef HAVE__STRLWR
   7.239 +#ifdef SDL_strlwr
   7.240 +#undef SDL_strlwr
   7.241 +char *SDL_strlwr(char *string) { return SDL_strlwr_inline(string); }
   7.242 +#else
   7.243  char *
   7.244  SDL_strlwr(char *string)
   7.245  {
   7.246 @@ -522,7 +578,10 @@
   7.247  }
   7.248  #endif
   7.249  
   7.250 -#ifndef HAVE_STRCHR
   7.251 +#ifdef SDL_strchr
   7.252 +#undef SDL_strchr
   7.253 +char *SDL_strchr(const char *string, int c) { return SDL_strchr_inline(string, c); }
   7.254 +#else
   7.255  char *
   7.256  SDL_strchr(const char *string, int c)
   7.257  {
   7.258 @@ -536,7 +595,10 @@
   7.259  }
   7.260  #endif
   7.261  
   7.262 -#ifndef HAVE_STRRCHR
   7.263 +#ifdef SDL_strrchr
   7.264 +#undef SDL_strrchr
   7.265 +char *SDL_strrchr(const char *string, int c) { return SDL_strrchr_inline(string, c); }
   7.266 +#else
   7.267  char *
   7.268  SDL_strrchr(const char *string, int c)
   7.269  {
   7.270 @@ -551,7 +613,10 @@
   7.271  }
   7.272  #endif
   7.273  
   7.274 -#ifndef HAVE_STRSTR
   7.275 +#ifdef SDL_strstr
   7.276 +#undef SDL_strstr
   7.277 +char *SDL_strstr(const char *haystack, const char *needle) { return SDL_strstr_inline(haystack, needle); }
   7.278 +#else
   7.279  char *
   7.280  SDL_strstr(const char *haystack, const char *needle)
   7.281  {
   7.282 @@ -566,8 +631,8 @@
   7.283  }
   7.284  #endif
   7.285  
   7.286 -#if !defined(HAVE__LTOA)  || !defined(HAVE__I64TOA) || \
   7.287 -    !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
   7.288 +#if !defined(SDL_ltoa) || !defined(SDL_lltoa) || \
   7.289 +    !defined(SDL_ultoa) || !defined(SDL_ulltoa)
   7.290  static const char ntoa_table[] = {
   7.291      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
   7.292      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
   7.293 @@ -576,7 +641,10 @@
   7.294  };
   7.295  #endif /* ntoa() conversion table */
   7.296  
   7.297 -#ifndef HAVE__LTOA
   7.298 +#ifdef SDL_ltoa
   7.299 +#undef SDL_ltoa
   7.300 +char *SDL_ltoa(long value, char *string, int radix) { return SDL_ltoa_inline(value, string, radix); }
   7.301 +#else
   7.302  char *
   7.303  SDL_ltoa(long value, char *string, int radix)
   7.304  {
   7.305 @@ -607,7 +675,10 @@
   7.306  }
   7.307  #endif
   7.308  
   7.309 -#ifndef HAVE__ULTOA
   7.310 +#ifdef SDL_ultoa
   7.311 +#undef SDL_ultoa
   7.312 +char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); }
   7.313 +#else
   7.314  char *
   7.315  SDL_ultoa(unsigned long value, char *string, int radix)
   7.316  {
   7.317 @@ -630,7 +701,10 @@
   7.318  }
   7.319  #endif
   7.320  
   7.321 -#ifndef HAVE_STRTOL
   7.322 +#ifdef SDL_strtol
   7.323 +#undef SDL_strtol
   7.324 +long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); }
   7.325 +#else
   7.326  long
   7.327  SDL_strtol(const char *string, char **endp, int base)
   7.328  {
   7.329 @@ -653,7 +727,10 @@
   7.330  }
   7.331  #endif
   7.332  
   7.333 -#ifndef HAVE_STRTOUL
   7.334 +#ifdef SDL_strtoul
   7.335 +#undef SDL_strtoul
   7.336 +unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); }
   7.337 +#else
   7.338  unsigned long
   7.339  SDL_strtoul(const char *string, char **endp, int base)
   7.340  {
   7.341 @@ -676,7 +753,10 @@
   7.342  }
   7.343  #endif
   7.344  
   7.345 -#ifndef HAVE__I64TOA
   7.346 +#ifdef SDL_lltoa
   7.347 +#undef SDL_lltoa
   7.348 +char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); }
   7.349 +#else
   7.350  char *
   7.351  SDL_lltoa(Sint64 value, char *string, int radix)
   7.352  {
   7.353 @@ -707,7 +787,10 @@
   7.354  }
   7.355  #endif
   7.356  
   7.357 -#ifndef HAVE__UI64TOA
   7.358 +#ifdef SDL_ulltoa
   7.359 +#undef SDL_ulltoa
   7.360 +char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); }
   7.361 +#else
   7.362  char *
   7.363  SDL_ulltoa(Uint64 value, char *string, int radix)
   7.364  {
   7.365 @@ -730,7 +813,10 @@
   7.366  }
   7.367  #endif
   7.368  
   7.369 -#ifndef HAVE_STRTOLL
   7.370 +#ifdef SDL_strtoll
   7.371 +#undef SDL_strtoll
   7.372 +Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); }
   7.373 +#else
   7.374  Sint64
   7.375  SDL_strtoll(const char *string, char **endp, int base)
   7.376  {
   7.377 @@ -753,7 +839,10 @@
   7.378  }
   7.379  #endif
   7.380  
   7.381 -#ifndef HAVE_STRTOULL
   7.382 +#ifdef SDL_strtoull
   7.383 +#undef SDL_strtoull
   7.384 +Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); }
   7.385 +#else
   7.386  Uint64
   7.387  SDL_strtoull(const char *string, char **endp, int base)
   7.388  {
   7.389 @@ -776,7 +865,10 @@
   7.390  }
   7.391  #endif
   7.392  
   7.393 -#ifndef HAVE_STRTOD
   7.394 +#ifdef SDL_strtod
   7.395 +#undef SDL_strtod
   7.396 +double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); }
   7.397 +#else
   7.398  double
   7.399  SDL_strtod(const char *string, char **endp)
   7.400  {
   7.401 @@ -791,7 +883,10 @@
   7.402  }
   7.403  #endif
   7.404  
   7.405 -#ifndef HAVE_STRCMP
   7.406 +#ifdef SDL_strcmp
   7.407 +#undef SDL_strcmp
   7.408 +int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); }
   7.409 +#else
   7.410  int
   7.411  SDL_strcmp(const char *str1, const char *str2)
   7.412  {
   7.413 @@ -805,7 +900,10 @@
   7.414  }
   7.415  #endif
   7.416  
   7.417 -#ifndef HAVE_STRNCMP
   7.418 +#ifdef SDL_strncmp
   7.419 +#undef SDL_strncmp
   7.420 +int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); }
   7.421 +#else
   7.422  int
   7.423  SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
   7.424  {
   7.425 @@ -823,7 +921,10 @@
   7.426  }
   7.427  #endif
   7.428  
   7.429 -#if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP)
   7.430 +#ifdef SDL_strcasecmp
   7.431 +#undef SDL_strcasecmp
   7.432 +int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp(str1, str2); }
   7.433 +#else
   7.434  int
   7.435  SDL_strcasecmp(const char *str1, const char *str2)
   7.436  {
   7.437 @@ -843,7 +944,10 @@
   7.438  }
   7.439  #endif
   7.440  
   7.441 -#if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP)
   7.442 +#ifdef SDL_strncasecmp
   7.443 +#undef SDL_strncasecmp
   7.444 +int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); }
   7.445 +#else
   7.446  int
   7.447  SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
   7.448  {
   7.449 @@ -868,7 +972,19 @@
   7.450  }
   7.451  #endif
   7.452  
   7.453 -#ifndef HAVE_SSCANF
   7.454 +#ifdef SDL_sscanf
   7.455 +#undef SDL_sscanf
   7.456 +int
   7.457 +SDL_sscanf(const char *text, const char *fmt, ...)
   7.458 +{
   7.459 +    int rc;
   7.460 +    va_list ap;
   7.461 +    va_start(ap, fmt);
   7.462 +    rc = vsscanf(text, fmt, ap);
   7.463 +    va_end(ap);
   7.464 +    return rc;
   7.465 +}
   7.466 +#else
   7.467  int
   7.468  SDL_sscanf(const char *text, const char *fmt, ...)
   7.469  {
   7.470 @@ -1136,7 +1252,10 @@
   7.471  }
   7.472  #endif
   7.473  
   7.474 -#ifndef HAVE_SNPRINTF
   7.475 +/* just undef; the headers only define this to snprintf because of varargs. */
   7.476 +#ifdef SDL_snprintf
   7.477 +#undef SDL_snprintf
   7.478 +#endif
   7.479  int
   7.480  SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
   7.481  {
   7.482 @@ -1149,9 +1268,11 @@
   7.483  
   7.484      return retval;
   7.485  }
   7.486 -#endif
   7.487  
   7.488 -#ifndef HAVE_VSNPRINTF
   7.489 +#ifdef SDL_vsnprintf
   7.490 +#undef SDL_vsnprintf
   7.491 +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
   7.492 +#else
   7.493  static size_t
   7.494  SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
   7.495  {
   7.496 @@ -1414,4 +1535,5 @@
   7.497      return (int)(text - textstart);
   7.498  }
   7.499  #endif
   7.500 +
   7.501  /* vi: set ts=4 sw=4 expandtab: */