diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 0bd372607..ca52376ff 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -194,6 +194,10 @@ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ /** \endcond */ +#if !defined(wchar_t) && defined(__NINTENDODS__) +#define wchar_t short /* TODO: figure out why libnds doesn't have this */ +#endif + #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus @@ -202,30 +206,6 @@ extern "C" { /* *INDENT-ON* */ #endif -#ifdef HAVE_MALLOC -#define SDL_malloc malloc -#else -extern DECLSPEC void *SDLCALL SDL_malloc(size_t size); -#endif - -#ifdef HAVE_CALLOC -#define SDL_calloc calloc -#else -extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size); -#endif - -#ifdef HAVE_REALLOC -#define SDL_realloc realloc -#else -extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size); -#endif - -#ifdef HAVE_FREE -#define SDL_free free -#else -extern DECLSPEC void SDLCALL SDL_free(void *mem); -#endif - #if defined(HAVE_ALLOCA) && !defined(alloca) # if defined(HAVE_ALLOCA_H) # include @@ -256,380 +236,443 @@ char *alloca(); #define SDL_stack_free(data) SDL_free(data) #endif -#ifdef HAVE_GETENV -#define SDL_getenv getenv -#else + +/* SDL stdinc inline functions: + + The theory here is that, by default, we forcibly inline what we can--with + real inline functions that avoid macro side-effects--and your app will use + the inline version by default. However, we expose a non-inline version + too, which internally just wraps the inline version in a real function, + so the symbol is always available in the library even if your app + bypassed it with the inline version. The SDL_*_inline versions aren't + guaranteed to exist, so never call them directly; use SDL_* instead, + and trust the system to give you the right thing. + + The benefit here is that you can dlsym() these functions, which you + couldn't if you had macros, you can link against a foreign build of SDL + even if you configured differently, and you can drop the unconfigured SDL + headers into a project without #defining HAVE_MALLOC (etc) and still link. +*/ + +extern DECLSPEC void *SDLCALL SDL_malloc(size_t size); +#ifdef HAVE_MALLOC +SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); } +#define SDL_malloc SDL_malloc_inline +#endif + +extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size); +#ifdef HAVE_CALLOC +SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); } +#define SDL_calloc SDL_calloc_inline +#endif + +extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size); +#ifdef HAVE_REALLOC +SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); } +#define SDL_realloc SDL_realloc_inline +#endif + +extern DECLSPEC void SDLCALL SDL_free(void *mem); +#ifdef HAVE_FREE +SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); } +#define SDL_free SDL_free_inline +#endif + extern DECLSPEC char *SDLCALL SDL_getenv(const char *name); +#ifdef HAVE_GETENV +SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); } +#define SDL_getenv SDL_getenv_inline #endif -/* SDL_putenv() has moved to SDL_compat. */ +extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite); #ifdef HAVE_SETENV -#define SDL_setenv setenv -#else -extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, - int overwrite); +SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); } +#define SDL_setenv SDL_setenv_inline #endif +extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)); #ifdef HAVE_QSORT -#define SDL_qsort qsort -#else -extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, - int (*compare) (const void *, - const void *)); +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); } +#define SDL_qsort SDL_qsort_inline #endif +extern DECLSPEC int SDLCALL SDL_abs(int x); #ifdef HAVE_ABS -#define SDL_abs abs +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); } #else -#define SDL_abs(X) ((X) < 0 ? -(X) : (X)) +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); } #endif +#define SDL_abs SDL_abs_inline -#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) -#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) +/* !!! FIXME: these have side effects. You probably shouldn't use them. */ +/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */ +#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) +#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) +extern DECLSPEC int SDLCALL SDL_isdigit(int x); +extern DECLSPEC int SDLCALL SDL_isspace(int x); +extern DECLSPEC int SDLCALL SDL_toupper(int x); +extern DECLSPEC int SDLCALL SDL_tolower(int x); #ifdef HAVE_CTYPE_H -#define SDL_isdigit(X) isdigit(X) -#define SDL_isspace(X) isspace(X) -#define SDL_toupper(X) toupper(X) -#define SDL_tolower(X) tolower(X) +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); } +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); } +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); } +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); } #else -#define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9')) -#define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n')) -#define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X)) -#define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X)) +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); } +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); } +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); } +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); } #endif +#define SDL_isdigit SDL_isdigit_inline +#define SDL_isspace SDL_isspace_inline +#define SDL_toupper SDL_toupper_inline +#define SDL_tolower SDL_tolower_inline -#ifdef HAVE_MEMSET -#define SDL_memset memset -#else extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len); +#ifdef HAVE_MEMSET +SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); } +#define SDL_memset SDL_memset_inline #endif -#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) -#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) +#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) +#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) + +/* !!! FIXME: does this _really_ beat memset() on any modern platform? */ +SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len) +{ #if defined(__GNUC__) && defined(i386) -#define SDL_memset4(dst, val, len) \ -do { \ - int u0, u1, u2; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; stosl\n\t" \ - : "=&D" (u0), "=&a" (u1), "=&c" (u2) \ - : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memset4 -#define SDL_memset4(dst, val, len) \ -do { \ - unsigned _count = (len); \ - unsigned _n = (_count + 3) / 4; \ - Uint32 *_p = SDL_static_cast(Uint32 *, dst); \ - Uint32 _val = (val); \ - if (len == 0) break; \ - switch (_count % 4) { \ - case 0: do { *_p++ = _val; \ - case 3: *_p++ = _val; \ - case 2: *_p++ = _val; \ - case 1: *_p++ = _val; \ - } while ( --_n ); \ - } \ -} while(0) + int u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; stosl \n\t" + : "=&D" (u0), "=&a" (u1), "=&c" (u2) + : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) + : "memory" + ); +/* !!! FIXME: amd64? */ +#else + unsigned int _count = (len); + unsigned int _n = (_count + 3) / 4; + Uint32 *_p = SDL_static_cast(Uint32 *, dst); + Uint32 _val = (val); + if (len == 0) + return; + switch (_count % 4) + { + case 0: do { *_p++ = _val; + case 3: *_p++ = _val; + case 2: *_p++ = _val; + case 1: *_p++ = _val; + } while ( --_n ); + } #endif +} -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ + +extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); #if defined(__MACOSX__) -#define SDL_memcpy memcpy +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + /* We can count on memcpy existing on Mac OS X and being well-tuned. */ + return memcpy(dst, src, len); +} +#define SDL_memcpy SDL_memcpy_inline #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__) -#define SDL_memcpy(dst, src, len) \ -do { \ - int u0, u1, u2; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; movsl\n\t" \ - "testb $2,%b4\n\t" \ - "je 1f\n\t" \ - "movsw\n" \ - "1:\ttestb $1,%b4\n\t" \ - "je 2f\n\t" \ - "movsb\n" \ - "2:" \ - : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ - : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memcpy -#ifdef HAVE_MEMCPY -#define SDL_memcpy memcpy -#elif defined(HAVE_BCOPY) -#define SDL_memcpy(d, s, n) bcopy((s), (d), (n)) -#else -extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, - size_t len); -#endif +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ + /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ + /* !!! FIXME: amd64? */ + int u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; movsl \n\t" + "testb $2,%b4 \n\t" + "je 1f \n\t" + "movsw \n" + "1:\ttestb $1,%b4 \n\t" + "je 2f \n\t" + "movsb \n" + "2:" + : "=&c" (u0), "=&D" (u1), "=&S" (u2) + : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src) + : "memory" + ); + return dst; +} +#define SDL_memcpy SDL_memcpy_inline +#elif defined(HAVE_MEMCPY) +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + return memcpy(dst, src, len); +} +#define SDL_memcpy SDL_memcpy_inline +#elif defined(HAVE_BCOPY) /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */ +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + bcopy(src, dst, len); + return dst; +} +#define SDL_memcpy SDL_memcpy_inline #endif -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ + +SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords) +{ #if defined(__MACOSX__) -#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2) + /* We can count on memcpy existing on Mac OS X and being well-tuned. */ + return memcpy(dst, src, dwords * 4); #elif defined(__GNUC__) && defined(i386) -#define SDL_memcpy4(dst, src, len) \ -do { \ - int ecx, edi, esi; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; movsl" \ - : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \ - : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memcpy4 -#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2) + /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ + /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ + /* !!! FIXME: amd64? */ + int ecx, edi, esi; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; movsl \n\t" + : "=&c" (ecx), "=&D" (edi), "=&S" (esi) + : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) + : "memory" + ); + return dst; +#else + return SDL_memcpy(dst, src, dwords * 4); #endif +} +extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len); #ifdef HAVE_MEMMOVE -#define SDL_memmove memmove -#else -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, - size_t len); +SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); } +#define SDL_memmove SDL_memmove_inline #endif +extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); #ifdef HAVE_MEMCMP -#define SDL_memcmp memcmp -#else -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, - size_t len); +SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); } +#define SDL_memcmp SDL_memcmp_inline #endif +extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str); #ifdef HAVE_STRLEN -#define SDL_strlen strlen -#else -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); +SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); } +#define SDL_strlen SDL_strlen_inline #endif +extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr); #ifdef HAVE_WCSLEN -#define SDL_wcslen wcslen -#else -#if !defined(wchar_t) && defined(__NINTENDODS__) -#define wchar_t short /* TODO: figure out why libnds doesn't have this */ -#endif -extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string); +SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); } +#define SDL_wcslen SDL_wcslen_inline #endif -#ifdef HAVE_WCSLCPY -#define SDL_wcslcpy wcslcpy -#else extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen); +#ifdef HAVE_WCSLCPY +SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); } +#define SDL_wcslcpy SDL_wcslcpy_inline #endif -#ifdef HAVE_WCSLCAT -#define SDL_wcslcat wcslcat -#else extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen); +#ifdef HAVE_WCSLCAT +SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); } +#define SDL_wcslcat SDL_wcslcat_inline #endif - +extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); #ifdef HAVE_STRLCPY -#define SDL_strlcpy strlcpy +SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); } +#define SDL_strlcpy SDL_strlcpy_inline #else -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, - size_t maxlen); #endif -extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, - size_t dst_bytes); +extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes); +extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); #ifdef HAVE_STRLCAT -#define SDL_strlcat strlcat -#else -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, - size_t maxlen); +SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); } +#define SDL_strlcat SDL_strlcat_inline #endif +extern DECLSPEC char *SDLCALL SDL_strdup(const char *str); #ifdef HAVE_STRDUP -#define SDL_strdup strdup -#else -extern DECLSPEC char *SDLCALL SDL_strdup(const char *string); +SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); } +#define SDL_strdup SDL_strdup_inline #endif +extern DECLSPEC char *SDLCALL SDL_strrev(char *str); #ifdef HAVE__STRREV -#define SDL_strrev _strrev -#else -extern DECLSPEC char *SDLCALL SDL_strrev(char *string); +SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); } +#define SDL_strrev SDL_strrev_inline #endif +extern DECLSPEC char *SDLCALL SDL_strupr(char *str); #ifdef HAVE__STRUPR -#define SDL_strupr _strupr -#else -extern DECLSPEC char *SDLCALL SDL_strupr(char *string); +SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); } +#define SDL_strupr SDL_strupr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strlwr(char *str); #ifdef HAVE__STRLWR -#define SDL_strlwr _strlwr -#else -extern DECLSPEC char *SDLCALL SDL_strlwr(char *string); +SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); } +#define SDL_strlwr SDL_strlwr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); #ifdef HAVE_STRCHR -#define SDL_strchr strchr -#elif defined(HAVE_INDEX) -#define SDL_strchr index -#else -extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c); +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return strchr(str, c); } +#define SDL_strchr SDL_strchr_inline +#elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */ +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); } +#define SDL_strchr SDL_strchr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); #ifdef HAVE_STRRCHR -#define SDL_strrchr strrchr -#elif defined(HAVE_RINDEX) -#define SDL_strrchr rindex -#else -extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c); +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return strrchr(str, c); } +#define SDL_strrchr SDL_strrchr_inline +#elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */ +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return rindex(str, c); } +#define SDL_strrchr SDL_strrchr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); #ifdef HAVE_STRSTR -#define SDL_strstr strstr -#else -extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, - const char *needle); -#endif - -#ifdef HAVE_ITOA -#define SDL_itoa itoa -#else -#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix) +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return strstr(haystack, needle); } +#define SDL_strstr SDL_strstr_inline #endif +extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix); #ifdef HAVE__LTOA -#define SDL_ltoa _ltoa -#else -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix); +SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); } +#define SDL_ltoa SDL_ltoa_inline #endif -#ifdef HAVE__UITOA -#define SDL_uitoa _uitoa +extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix); +#ifdef HAVE_ITOA +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); } #else -#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix) +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); } #endif +#define SDL_itoa SDL_itoa_inline +extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix); #ifdef HAVE__ULTOA -#define SDL_ultoa _ultoa -#else -extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); } +#define SDL_ultoa SDL_ultoa_inline #endif +extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix); +#ifdef HAVE__UITOA +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); } +#else +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); } +#endif +#define SDL_uitoa SDL_uitoa_inline + + +extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base); #ifdef HAVE_STRTOL -#define SDL_strtol strtol -#else -extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, - int base); +SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); } +#define SDL_strtol SDL_strtol_inline #endif +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base); #ifdef HAVE_STRTOUL -#define SDL_strtoul strtoul -#else -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, - char **endp, int base); +SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); } +#define SDL_strtoul SDL_strtoul_inline #endif +extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix); #ifdef HAVE__I64TOA -#define SDL_lltoa _i64toa -#else -extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); } +#define SDL_lltoa SDL_lltoa_inline #endif +extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix); #ifdef HAVE__UI64TOA -#define SDL_ulltoa _ui64toa -#else -extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); } +#define SDL_ulltoa SDL_ulltoa_inline #endif +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base); #ifdef HAVE_STRTOLL -#define SDL_strtoll strtoll -#else -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, - int base); +SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); } +#define SDL_strtoll SDL_strtoll_inline #endif +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base); #ifdef HAVE_STRTOULL -#define SDL_strtoull strtoull -#else -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, - int base); +SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); } +#define SDL_strtoull SDL_strtoull_inline #endif +extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp); #ifdef HAVE_STRTOD -#define SDL_strtod strtod -#else -extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); +SDL_FORCE_INLINE Uint64 SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); } +#define SDL_strtod SDL_strtod_inline #endif +extern DECLSPEC int SDLCALL SDL_atoi(const char *str); #ifdef HAVE_ATOI -#define SDL_atoi atoi +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); } #else -#define SDL_atoi(X) SDL_strtol(X, NULL, 0) +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); } #endif +#define SDL_atoi SDL_atoi_inline +extern DECLSPEC double SDLCALL SDL_atof(const char *str); #ifdef HAVE_ATOF -#define SDL_atof atof +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); } #else -#define SDL_atof(X) SDL_strtod(X, NULL) +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); } #endif +#define SDL_atof SDL_atof_inline + -#ifdef HAVE_STRCMP -#define SDL_strcmp strcmp -#else extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); +#ifdef HAVE_STRCMP +SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); } +#define SDL_strcmp SDL_strcmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); #ifdef HAVE_STRNCMP -#define SDL_strncmp strncmp -#else -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, - size_t maxlen); +SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); } +#define SDL_strncmp SDL_strncmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); #ifdef HAVE_STRCASECMP -#define SDL_strcasecmp strcasecmp +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); } +#define SDL_strcasecmp SDL_strcasecmp_inline #elif defined(HAVE__STRICMP) -#define SDL_strcasecmp _stricmp -#else -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, - const char *str2); +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); } +#define SDL_strcasecmp SDL_strcasecmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len); #ifdef HAVE_STRNCASECMP -#define SDL_strncasecmp strncasecmp +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); } +#define SDL_strncasecmp SDL_strncasecmp_inline #elif defined(HAVE__STRNICMP) -#define SDL_strncasecmp _strnicmp -#else -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, - const char *str2, size_t maxlen); +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); } +#define SDL_strncasecmp SDL_strncasecmp_inline #endif +/* Not doing SDL_*_inline functions for these, because of the varargs. */ +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); #ifdef HAVE_SSCANF -#define SDL_sscanf sscanf -#else -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, - ...); +#define SDL_sscanf sscanf #endif +extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); #ifdef HAVE_SNPRINTF -#define SDL_snprintf snprintf -#else -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, - const char *fmt, ...); +#define SDL_snprintf snprintf #endif +extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); #ifdef HAVE_VSNPRINTF -#define SDL_vsnprintf vsnprintf -#else -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, - const char *fmt, va_list ap); +SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); } +#define SDL_vsnprintf SDL_vsnprintf_inline #endif #ifndef HAVE_M_PI @@ -638,88 +681,94 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, #endif #endif -#ifdef HAVE_ATAN -#define SDL_atan atan -#else extern DECLSPEC double SDLCALL SDL_atan(double x); +#ifdef HAVE_ATAN +SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); } +#define SDL_atan SDL_atan_inline #endif +extern DECLSPEC double SDLCALL SDL_atan2(double x, double y); #ifdef HAVE_ATAN2 -#define SDL_atan2 atan2 -#else -extern DECLSPEC double SDLCALL SDL_atan2(double y, double x); +SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); } +#define SDL_atan2 SDL_atan2_inline #endif +extern DECLSPEC double SDLCALL SDL_ceil(double x); #ifdef HAVE_CEIL -#define SDL_ceil ceil +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); } #else -#define SDL_ceil(x) ((double)(int)((x)+0.5)) +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); } #endif +#define SDL_ceil SDL_ceil_inline -#ifdef HAVE_COPYSIGN -#define SDL_copysign copysign -#else extern DECLSPEC double SDLCALL SDL_copysign(double x, double y); +#ifdef HAVE_COPYSIGN +SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); } +#define SDL_copysign SDL_copysign_inline #endif -#ifdef HAVE_COS -#define SDL_cos cos -#else extern DECLSPEC double SDLCALL SDL_cos(double x); +#ifdef HAVE_COS +SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); } +#define SDL_cos SDL_cos_inline #endif +extern DECLSPEC float SDLCALL SDL_cosf(float x); #ifdef HAVE_COSF -#define SDL_cosf cosf +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); } #else -#define SDL_cosf(x) (float)SDL_cos((double)x) +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); } #endif +#define SDL_cosf SDL_cosf_inline -#ifdef HAVE_FABS -#define SDL_fabs fabs -#else extern DECLSPEC double SDLCALL SDL_fabs(double x); +#ifdef HAVE_FABS +SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); } +#define SDL_fabs SDL_fabs_inline #endif -#ifdef HAVE_FLOOR -#define SDL_floor floor -#else extern DECLSPEC double SDLCALL SDL_floor(double x); +#ifdef HAVE_FLOOR +SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); } +#define SDL_floor SDL_floor_inline #endif -#ifdef HAVE_LOG -#define SDL_log log -#else extern DECLSPEC double SDLCALL SDL_log(double x); +#ifdef HAVE_LOG +SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); } +#define SDL_log SDL_log_inline #endif -#ifdef HAVE_POW -#define SDL_pow pow -#else extern DECLSPEC double SDLCALL SDL_pow(double x, double y); +#ifdef HAVE_POW +SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); } +#define SDL_pow SDL_pow_inline #endif -#ifdef HAVE_SCALBN -#define SDL_scalbn scalbn -#else extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n); +#ifdef HAVE_SCALBN +SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); } +#define SDL_scalbn SDL_scalbn_inline #endif -#ifdef HAVE_SIN -#define SDL_sin sin -#else extern DECLSPEC double SDLCALL SDL_sin(double x); +#ifdef HAVE_SIN +SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); } +#define SDL_sin SDL_sin_inline #endif +extern DECLSPEC float SDLCALL SDL_sinf(float x); #ifdef HAVE_SINF -#define SDL_sinf sinf +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); } #else -#define SDL_sinf(x) (float)SDL_sin((double)x) +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); } #endif +#define SDL_sinf SDL_sinf_inline -#ifdef HAVE_SQRT -#define SDL_sqrt sqrt -#else extern DECLSPEC double SDLCALL SDL_sqrt(double x); +#ifdef HAVE_SQRT +SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); } +#define SDL_sqrt SDL_sqrt_inline #endif /* The SDL implementation of iconv() returns these error codes */ @@ -728,16 +777,11 @@ extern DECLSPEC double SDLCALL SDL_sqrt(double x); #define SDL_ICONV_EILSEQ (size_t)-3 #define SDL_ICONV_EINVAL (size_t)-4 -#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H) -#define SDL_iconv_t iconv_t -#define SDL_iconv_open iconv_open -#define SDL_iconv_close iconv_close -#else +/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */ typedef struct _SDL_iconv_t *SDL_iconv_t; extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode); extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd); -#endif extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft); diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 161003004..9079387cd 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -22,18 +22,19 @@ #include "SDL_stdinc.h" -#ifndef HAVE_GETENV - -#if defined(__WIN32__) - +#if !defined(SDL_setenv) && defined(__WIN32__) #include "../core/windows/SDL_windows.h" - /* Note this isn't thread-safe! */ - static char *SDL_envmem = NULL; /* Ugh, memory leak */ static size_t SDL_envmemlen = 0; +#endif + /* Put a variable into the environment */ +#ifdef SDL_setenv +#undef SDL_setenv +int SDL_setenv(const char *name, const char *value, int overwrite) { return SDL_setenv_inline(name, value, overwrite); } +#elif defined(__WIN32__) int SDL_setenv(const char *name, const char *value, int overwrite) { @@ -49,35 +50,34 @@ SDL_setenv(const char *name, const char *value, int overwrite) } return 0; } - -/* Retrieve a variable named "name" from the environment */ -char * -SDL_getenv(const char *name) +/* We have a real environment table, but no real setenv? Fake it w/ putenv. */ +#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) +int +SDL_setenv(const char *name, const char *value, int overwrite) { - size_t bufferlen; + size_t len; + char *new_variable; - bufferlen = - GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); - if (bufferlen == 0) { - return NULL; - } - if (bufferlen > SDL_envmemlen) { - char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); - if (newmem == NULL) { - return NULL; + if (getenv(name) != NULL) { + if (overwrite) { + unsetenv(name); + } else { + return 0; /* leave the existing one there. */ } - SDL_envmem = newmem; - SDL_envmemlen = bufferlen; - GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); } - return SDL_envmem; + + /* This leaks. Sorry. Get a better OS so we don't have to do this. */ + len = SDL_strlen(name) + SDL_strlen(value) + 2; + new_variable = (char *) SDL_malloc(len); + if (!new_variable) { + return (-1); + } + + SDL_snprintf(new_variable, len, "%s=%s", name, value); + return putenv(new_variable); } - #else /* roll our own */ - static char **SDL_env = (char **) 0; - -/* Put a variable into the environment */ int SDL_setenv(const char *name, const char *value, int overwrite) { @@ -140,8 +140,35 @@ SDL_setenv(const char *name, const char *value, int overwrite) } return (added ? 0 : -1); } +#endif /* Retrieve a variable named "name" from the environment */ +#ifdef SDL_getenv +#undef SDL_getenv +char *SDL_getenv(const char *name) { return SDL_getenv_inline(name); } +#elif defined(__WIN32__) +char * +SDL_getenv(const char *name) +{ + size_t bufferlen; + + bufferlen = + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); + if (bufferlen == 0) { + return NULL; + } + if (bufferlen > SDL_envmemlen) { + char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); + if (newmem == NULL) { + return NULL; + } + SDL_envmem = newmem; + SDL_envmemlen = bufferlen; + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); + } + return SDL_envmem; +} +#else char * SDL_getenv(const char *name) { @@ -160,38 +187,6 @@ SDL_getenv(const char *name) } return value; } - -#endif /* __WIN32__ */ - -#endif /* !HAVE_GETENV */ - - -/* We have a real environment table, but no real setenv? Fake it w/ putenv. */ -#if (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) -int -SDL_setenv(const char *name, const char *value, int overwrite) -{ - size_t len; - char *new_variable; - - if (getenv(name) != NULL) { - if (overwrite) { - unsetenv(name); - } else { - return 0; /* leave the existing one there. */ - } - } - - /* This leaks. Sorry. Get a better OS so we don't have to do this. */ - len = SDL_strlen(name) + SDL_strlen(value) + 2; - new_variable = (char *) SDL_malloc(len); - if (!new_variable) { - return (-1); - } - - SDL_snprintf(new_variable, len, "%s=%s", name, value); - return putenv(new_variable); -} #endif diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index 8d2f2c034..4e5e51d87 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -38,6 +38,20 @@ #include +SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t)); + +SDL_iconv_t +SDL_iconv_open(const char *tocode, const char *fromcode) +{ + return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode)); +} + +int +SDL_iconv_close(SDL_iconv_t cd) +{ + return iconv_close((iconv_t) ((size_t) cd)); +} + size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, @@ -45,9 +59,9 @@ SDL_iconv(SDL_iconv_t cd, { size_t retCode; #ifdef ICONV_INBUF_NONCONST - retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft); + retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft); #else - retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); + retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft); #endif if (retCode == (size_t) - 1) { switch (errno) { diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c index 6533f0b97..65d1e1d16 100644 --- a/src/stdlib/SDL_malloc.c +++ b/src/stdlib/SDL_malloc.c @@ -24,7 +24,18 @@ #include "SDL_stdinc.h" -#ifndef HAVE_MALLOC +#ifdef SDL_malloc +/* expose the symbol, but use what we figured out elsewhere. */ +#undef SDL_malloc +#undef SDL_calloc +#undef SDL_realloc +#undef SDL_free +void *SDL_malloc(size_t size) { return SDL_malloc_inline(size); } +void *SDL_calloc(size_t nmemb, size_t size) { return SDL_calloc_inline(nmemb, size); } +void *SDL_realloc(void *ptr, size_t size) { return SDL_realloc_inline(ptr, size); } +void SDL_free(void *ptr) { SDL_free_inline(ptr); } + +#else /* the rest of this is a LOT of tapdancing to implement malloc. :) */ #define LACKS_SYS_TYPES_H #define LACKS_STDIO_H diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 6d56c6758..8c73419c9 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -51,6 +51,15 @@ #include "SDL_stdinc.h" #include "SDL_assert.h" +#ifdef SDL_qsort +#undef SDL_qsort +void +SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) +{ + SDL_qsort_inline(base, nmemb, size, compare); +} +#else + #ifdef assert #undef assert #endif @@ -76,9 +85,6 @@ #endif #define qsort SDL_qsort - -#ifndef HAVE_QSORT - static const char _ID[] = ""; /* How many bytes are there per word? (Must be a power of 2, @@ -466,5 +472,6 @@ qsort(void *base, size_t nmemb, size_t size, qsort_words(base, nmemb, compare); } -#endif /* !HAVE_QSORT */ +#endif /* !SDL_qsort */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 496b99e1f..1c19ab72f 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -24,6 +24,25 @@ #include "SDL_stdinc.h" +/* these are always #defined, make them real symbol in the library, too... */ +#undef SDL_ceil +#undef SDL_abs +#undef SDL_sinf +#undef SDL_cosf +#undef SDL_isdigit +#undef SDL_isspace +#undef SDL_toupper +#undef SDL_tolower +double SDL_ceil(double x) { return SDL_ceil_inline(x); } +float SDL_cosf(float x) { return SDL_cosf_inline(x); } +float SDL_sinf(float x) { return SDL_sinf_inline(x); } +int SDL_abs(int x) { return SDL_abs_inline(x); } +int SDL_isdigit(int x) { return SDL_isdigit_inline(x); } +int SDL_isspace(int x) { return SDL_isspace_inline(x); } +int SDL_toupper(int x) { return SDL_toupper_inline(x); } +int SDL_tolower(int x) { return SDL_tolower_inline(x); } + + #ifndef HAVE_LIBC /* These are some C runtime intrinsics that need to be defined */ diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 89c14d958..a1bfe6105 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -24,6 +24,17 @@ #include "SDL_stdinc.h" +/* these are always #defined, make them real symbol in the library, too... */ +#undef SDL_itoa +#undef SDL_uitoa +#undef SDL_atoi +#undef SDL_atof +char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); } +char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); } +int SDL_atoi(const char *str) { return SDL_atoi(str); } +double SDL_atof(const char *str) { return SDL_atof(str); } + + #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) @@ -43,7 +54,7 @@ static int UTF8_TrailingBytes(unsigned char c) return 0; } -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) +#if !defined(SDL_sscanf) || !defined(SDL_strtol) static size_t SDL_ScanLong(const char *text, int radix, long *valuep) { @@ -84,7 +95,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) +#if !defined(SDL_sscanf) || !defined(SDL_strtoul) || !defined(SDL_strtod) static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) { @@ -116,7 +127,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) } #endif -#ifndef HAVE_SSCANF +#ifndef SDL_sscanf static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) { @@ -148,7 +159,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) +#if !defined(SDL_sscanf) || !defined(SDL_strtoll) static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) { @@ -189,7 +200,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) +#if !defined(SDL_sscanf) || !defined(SDL_strtoull) static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) { @@ -221,7 +232,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) +#if !defined(SDL_sscanf) || !defined(SDL_strtod) static size_t SDL_ScanFloat(const char *text, double *valuep) { @@ -257,7 +268,11 @@ SDL_ScanFloat(const char *text, double *valuep) } #endif -#ifndef SDL_memset + +#ifdef SDL_memset +#undef SDL_memset +void *SDL_memset(void *dst, int c, size_t len) { return SDL_memset_inline(dst, c, len); } +#else void * SDL_memset(void *dst, int c, size_t len) { @@ -287,7 +302,11 @@ SDL_memset(void *dst, int c, size_t len) } #endif -#ifndef SDL_memcpy + +#ifdef SDL_memcpy +#undef SDL_memcpy +void *SDL_memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy_inline(dst, src, len); } +#else void * SDL_memcpy(void *dst, const void *src, size_t len) { @@ -317,7 +336,11 @@ SDL_memcpy(void *dst, const void *src, size_t len) } #endif -#ifndef SDL_memmove + +#ifdef SDL_memmove +#undef SDL_memmove +void *SDL_memmove(void *dst, const void *src, size_t len) { return SDL_memmove_inline(dst, src, len); } +#else void * SDL_memmove(void *dst, const void *src, size_t len) { @@ -339,7 +362,10 @@ SDL_memmove(void *dst, const void *src, size_t len) } #endif -#ifndef SDL_memcmp +#ifdef SDL_memcmp +#undef SDL_memcmp +int SDL_memcmp(const void *s1, const void *s2, size_t len) { return SDL_memcmp_inline(s1, s2, len); } +#else int SDL_memcmp(const void *s1, const void *s2, size_t len) { @@ -356,7 +382,10 @@ SDL_memcmp(const void *s1, const void *s2, size_t len) } #endif -#ifndef HAVE_STRLEN +#ifdef SDL_strlen +#undef SDL_strlen +size_t SDL_strlen(const char *string) { return SDL_strlen_inline(string); } +#else size_t SDL_strlen(const char *string) { @@ -368,7 +397,10 @@ SDL_strlen(const char *string) } #endif -#ifndef HAVE_WCSLEN +#ifdef SDL_wcslen +#undef SDL_wcslen +size_t SDL_wcslen(const wchar_t * string) { return SDL_wcslen_inline(string); } +#else size_t SDL_wcslen(const wchar_t * string) { @@ -380,7 +412,10 @@ SDL_wcslen(const wchar_t * string) } #endif -#ifndef HAVE_WCSLCPY +#ifdef SDL_wcslcpy +#undef SDL_wcslcpy +size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcpy_inline(dst, src, maxlen); } +#else size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { @@ -394,7 +429,10 @@ SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) } #endif -#ifndef HAVE_WCSLCAT +#ifdef SDL_wcslcat +#undef SDL_wcslcat +size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcat_inline(dst, src, maxlen); } +#else size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { @@ -407,7 +445,10 @@ SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) } #endif -#ifndef HAVE_STRLCPY +#ifdef SDL_strlcpy +#undef SDL_strlcpy +size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { return SDL_strlcpy_inline(dst, src, maxlen); } +#else size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { @@ -453,7 +494,10 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes) return bytes; } -#ifndef HAVE_STRLCAT +#ifdef SDL_strlcat +#undef SDL_strlcat +size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { return SDL_strlcat_inline(dst, src, maxlen); } +#else size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { @@ -466,7 +510,10 @@ SDL_strlcat(char *dst, const char *src, size_t maxlen) } #endif -#ifndef HAVE_STRDUP +#ifdef SDL_strdup +#undef SDL_strdup +char *SDL_strdup(const char *string) { return SDL_strdup_inline(string); } +#else char * SDL_strdup(const char *string) { @@ -479,7 +526,10 @@ SDL_strdup(const char *string) } #endif -#ifndef HAVE__STRREV +#ifdef SDL_strrev +#undef SDL_strrev +char *SDL_strrev(char *string) { return SDL_strrev_inline(string); } +#else char * SDL_strrev(char *string) { @@ -496,7 +546,10 @@ SDL_strrev(char *string) } #endif -#ifndef HAVE__STRUPR +#ifdef SDL_strupr +#undef SDL_strupr +char *SDL_strupr(char *string) { return SDL_strupr_inline(string); } +#else char * SDL_strupr(char *string) { @@ -509,7 +562,10 @@ SDL_strupr(char *string) } #endif -#ifndef HAVE__STRLWR +#ifdef SDL_strlwr +#undef SDL_strlwr +char *SDL_strlwr(char *string) { return SDL_strlwr_inline(string); } +#else char * SDL_strlwr(char *string) { @@ -522,7 +578,10 @@ SDL_strlwr(char *string) } #endif -#ifndef HAVE_STRCHR +#ifdef SDL_strchr +#undef SDL_strchr +char *SDL_strchr(const char *string, int c) { return SDL_strchr_inline(string, c); } +#else char * SDL_strchr(const char *string, int c) { @@ -536,7 +595,10 @@ SDL_strchr(const char *string, int c) } #endif -#ifndef HAVE_STRRCHR +#ifdef SDL_strrchr +#undef SDL_strrchr +char *SDL_strrchr(const char *string, int c) { return SDL_strrchr_inline(string, c); } +#else char * SDL_strrchr(const char *string, int c) { @@ -551,7 +613,10 @@ SDL_strrchr(const char *string, int c) } #endif -#ifndef HAVE_STRSTR +#ifdef SDL_strstr +#undef SDL_strstr +char *SDL_strstr(const char *haystack, const char *needle) { return SDL_strstr_inline(haystack, needle); } +#else char * SDL_strstr(const char *haystack, const char *needle) { @@ -566,8 +631,8 @@ SDL_strstr(const char *haystack, const char *needle) } #endif -#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \ - !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA) +#if !defined(SDL_ltoa) || !defined(SDL_lltoa) || \ + !defined(SDL_ultoa) || !defined(SDL_ulltoa) static const char ntoa_table[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -576,7 +641,10 @@ static const char ntoa_table[] = { }; #endif /* ntoa() conversion table */ -#ifndef HAVE__LTOA +#ifdef SDL_ltoa +#undef SDL_ltoa +char *SDL_ltoa(long value, char *string, int radix) { return SDL_ltoa_inline(value, string, radix); } +#else char * SDL_ltoa(long value, char *string, int radix) { @@ -607,7 +675,10 @@ SDL_ltoa(long value, char *string, int radix) } #endif -#ifndef HAVE__ULTOA +#ifdef SDL_ultoa +#undef SDL_ultoa +char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); } +#else char * SDL_ultoa(unsigned long value, char *string, int radix) { @@ -630,7 +701,10 @@ SDL_ultoa(unsigned long value, char *string, int radix) } #endif -#ifndef HAVE_STRTOL +#ifdef SDL_strtol +#undef SDL_strtol +long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); } +#else long SDL_strtol(const char *string, char **endp, int base) { @@ -653,7 +727,10 @@ SDL_strtol(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOUL +#ifdef SDL_strtoul +#undef SDL_strtoul +unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); } +#else unsigned long SDL_strtoul(const char *string, char **endp, int base) { @@ -676,7 +753,10 @@ SDL_strtoul(const char *string, char **endp, int base) } #endif -#ifndef HAVE__I64TOA +#ifdef SDL_lltoa +#undef SDL_lltoa +char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); } +#else char * SDL_lltoa(Sint64 value, char *string, int radix) { @@ -707,7 +787,10 @@ SDL_lltoa(Sint64 value, char *string, int radix) } #endif -#ifndef HAVE__UI64TOA +#ifdef SDL_ulltoa +#undef SDL_ulltoa +char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); } +#else char * SDL_ulltoa(Uint64 value, char *string, int radix) { @@ -730,7 +813,10 @@ SDL_ulltoa(Uint64 value, char *string, int radix) } #endif -#ifndef HAVE_STRTOLL +#ifdef SDL_strtoll +#undef SDL_strtoll +Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); } +#else Sint64 SDL_strtoll(const char *string, char **endp, int base) { @@ -753,7 +839,10 @@ SDL_strtoll(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOULL +#ifdef SDL_strtoull +#undef SDL_strtoull +Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); } +#else Uint64 SDL_strtoull(const char *string, char **endp, int base) { @@ -776,7 +865,10 @@ SDL_strtoull(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOD +#ifdef SDL_strtod +#undef SDL_strtod +double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); } +#else double SDL_strtod(const char *string, char **endp) { @@ -791,7 +883,10 @@ SDL_strtod(const char *string, char **endp) } #endif -#ifndef HAVE_STRCMP +#ifdef SDL_strcmp +#undef SDL_strcmp +int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); } +#else int SDL_strcmp(const char *str1, const char *str2) { @@ -805,7 +900,10 @@ SDL_strcmp(const char *str1, const char *str2) } #endif -#ifndef HAVE_STRNCMP +#ifdef SDL_strncmp +#undef SDL_strncmp +int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); } +#else int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { @@ -823,7 +921,10 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen) } #endif -#if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP) +#ifdef SDL_strcasecmp +#undef SDL_strcasecmp +int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp(str1, str2); } +#else int SDL_strcasecmp(const char *str1, const char *str2) { @@ -843,7 +944,10 @@ SDL_strcasecmp(const char *str1, const char *str2) } #endif -#if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP) +#ifdef SDL_strncasecmp +#undef SDL_strncasecmp +int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); } +#else int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { @@ -868,7 +972,19 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) } #endif -#ifndef HAVE_SSCANF +#ifdef SDL_sscanf +#undef SDL_sscanf +int +SDL_sscanf(const char *text, const char *fmt, ...) +{ + int rc; + va_list ap; + va_start(ap, fmt); + rc = vsscanf(text, fmt, ap); + va_end(ap); + return rc; +} +#else int SDL_sscanf(const char *text, const char *fmt, ...) { @@ -1136,7 +1252,10 @@ SDL_sscanf(const char *text, const char *fmt, ...) } #endif -#ifndef HAVE_SNPRINTF +/* just undef; the headers only define this to snprintf because of varargs. */ +#ifdef SDL_snprintf +#undef SDL_snprintf +#endif int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) { @@ -1149,9 +1268,11 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) return retval; } -#endif -#ifndef HAVE_VSNPRINTF +#ifdef SDL_vsnprintf +#undef SDL_vsnprintf +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); } +#else static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen) { @@ -1414,4 +1535,5 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) return (int)(text - textstart); } #endif + /* vi: set ts=4 sw=4 expandtab: */