include/SDL_stdinc.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 04 Apr 2013 11:35:22 -0400
changeset 7057 c1563f514b5b
parent 7036 8c891504e325
child 7059 cd194e03c1da
permissions -rw-r--r--
Corrected some stdinc inline functions (thanks, Martin!).

qsort() returns void, so remove the "return" keyword, plus some C++
const_casting magic.

Fixes Bugzilla #1785.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file SDL_stdinc.h
    24  *  
    25  *  This is a general header that includes C language support.
    26  */
    27 
    28 #ifndef _SDL_stdinc_h
    29 #define _SDL_stdinc_h
    30 
    31 #include "SDL_config.h"
    32 
    33 #ifdef HAVE_SYS_TYPES_H
    34 #include <sys/types.h>
    35 #endif
    36 #ifdef HAVE_STDIO_H
    37 #include <stdio.h>
    38 #endif
    39 #if defined(STDC_HEADERS)
    40 # include <stdlib.h>
    41 # include <stddef.h>
    42 # include <stdarg.h>
    43 #else
    44 # if defined(HAVE_STDLIB_H)
    45 #  include <stdlib.h>
    46 # elif defined(HAVE_MALLOC_H)
    47 #  include <malloc.h>
    48 # endif
    49 # if defined(HAVE_STDDEF_H)
    50 #  include <stddef.h>
    51 # endif
    52 # if defined(HAVE_STDARG_H)
    53 #  include <stdarg.h>
    54 # endif
    55 #endif
    56 #ifdef HAVE_STRING_H
    57 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
    58 #  include <memory.h>
    59 # endif
    60 # include <string.h>
    61 #endif
    62 #ifdef HAVE_STRINGS_H
    63 # include <strings.h>
    64 #endif
    65 #if defined(HAVE_INTTYPES_H)
    66 # include <inttypes.h>
    67 #elif defined(HAVE_STDINT_H)
    68 # include <stdint.h>
    69 #endif
    70 #ifdef HAVE_CTYPE_H
    71 # include <ctype.h>
    72 #endif
    73 #ifdef HAVE_MATH_H
    74 # include <math.h>
    75 #endif
    76 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
    77 # include <iconv.h>
    78 #endif
    79 
    80 /**
    81  *  The number of elements in an array.
    82  */
    83 #define SDL_arraysize(array)	(sizeof(array)/sizeof(array[0]))
    84 #define SDL_TABLESIZE(table)	SDL_arraysize(table)
    85 
    86 /**
    87  *  \name Cast operators
    88  *  
    89  *  Use proper C++ casts when compiled as C++ to be compatible with the option
    90  *  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
    91  */
    92 /*@{*/
    93 #ifdef __cplusplus
    94 #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
    95 #define SDL_static_cast(type, expression) static_cast<type>(expression)
    96 #else
    97 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
    98 #define SDL_static_cast(type, expression) ((type)(expression))
    99 #endif
   100 /*@}*//*Cast operators*/
   101 
   102 /* Define a four character code as a Uint32 */
   103 #define SDL_FOURCC(A, B, C, D) \
   104     ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
   105      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
   106      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
   107      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
   108 
   109 /**
   110  *  \name Basic data types
   111  */
   112 /*@{*/
   113 
   114 typedef enum
   115 {
   116     SDL_FALSE = 0,
   117     SDL_TRUE = 1
   118 } SDL_bool;
   119 
   120 /**
   121  * \brief A signed 8-bit integer type.
   122  */
   123 typedef int8_t Sint8;
   124 /**
   125  * \brief An unsigned 8-bit integer type.
   126  */
   127 typedef uint8_t Uint8;
   128 /**
   129  * \brief A signed 16-bit integer type.
   130  */
   131 typedef int16_t Sint16;
   132 /**
   133  * \brief An unsigned 16-bit integer type.
   134  */
   135 typedef uint16_t Uint16;
   136 /**
   137  * \brief A signed 32-bit integer type.
   138  */
   139 typedef int32_t Sint32;
   140 /**
   141  * \brief An unsigned 32-bit integer type.
   142  */
   143 typedef uint32_t Uint32;
   144 
   145 /**
   146  * \brief A signed 64-bit integer type.
   147  */
   148 typedef int64_t Sint64;
   149 /**
   150  * \brief An unsigned 64-bit integer type.
   151  */
   152 typedef uint64_t Uint64;
   153 
   154 /*@}*//*Basic data types*/
   155 
   156 
   157 #define SDL_COMPILE_TIME_ASSERT(name, x)               \
   158        typedef int SDL_dummy_ ## name[(x) * 2 - 1]
   159 /** \cond */
   160 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   161 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
   162 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
   163 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
   164 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
   165 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
   166 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
   167 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
   168 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
   169 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   170 /** \endcond */
   171 
   172 /* Check to make sure enums are the size of ints, for structure packing.
   173    For both Watcom C/C++ and Borland C/C++ the compiler option that makes
   174    enums having the size of an int must be enabled.
   175    This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
   176 */
   177 
   178 /** \cond */
   179 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   180 #if !defined(__ANDROID__) 
   181    /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
   182 typedef enum
   183 {
   184     DUMMY_ENUM_VALUE
   185 } SDL_DUMMY_ENUM;
   186 
   187 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
   188 #endif
   189 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   190 /** \endcond */
   191 
   192 #include "begin_code.h"
   193 /* Set up for C function definitions, even when using C++ */
   194 #ifdef __cplusplus
   195 /* *INDENT-OFF* */
   196 extern "C" {
   197 /* *INDENT-ON* */
   198 #endif
   199 
   200 #if defined(HAVE_ALLOCA) && !defined(alloca)
   201 # if defined(HAVE_ALLOCA_H)
   202 #  include <alloca.h>
   203 # elif defined(__GNUC__)
   204 #  define alloca __builtin_alloca
   205 # elif defined(_MSC_VER)
   206 #  include <malloc.h>
   207 #  define alloca _alloca
   208 # elif defined(__WATCOMC__)
   209 #  include <malloc.h>
   210 # elif defined(__BORLANDC__)
   211 #  include <malloc.h>
   212 # elif defined(__DMC__)
   213 #  include <stdlib.h>
   214 # elif defined(__AIX__)
   215 #pragma alloca
   216 # elif defined(__MRC__)
   217 void *alloca(unsigned);
   218 # else
   219 char *alloca();
   220 # endif
   221 #endif
   222 #ifdef HAVE_ALLOCA
   223 #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*(count))
   224 #define SDL_stack_free(data)
   225 #else
   226 #define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*(count))
   227 #define SDL_stack_free(data)            SDL_free(data)
   228 #endif
   229 
   230 
   231 /* SDL stdinc inline functions:
   232 
   233    The theory here is that by default we forcibly inline what we can, and your
   234    app will use the inline version by default. However we expose a non-inline
   235    version too, so the symbol is always available in the library even if your app
   236    bypassed the inline version. The SDL_*_inline versions aren't guaranteed to
   237    exist, so never call them directly; use SDL_* instead, and trust the system
   238    to give you the right thing.
   239 
   240    The benefit here is that you can dlsym() these functions, which you
   241    couldn't if you had macros, you can link against a foreign build of SDL
   242    even if you configured differently, and you can drop the unconfigured SDL
   243    headers into a project without #defining HAVE_MALLOC (etc) and still link.
   244 */
   245 
   246 extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
   247 #ifdef HAVE_MALLOC
   248 SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); }
   249 #define SDL_malloc SDL_malloc_inline
   250 #endif
   251 
   252 extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
   253 #ifdef HAVE_CALLOC
   254 SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); }
   255 #define SDL_calloc SDL_calloc_inline
   256 #endif
   257 
   258 extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
   259 #ifdef HAVE_REALLOC
   260 SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); }
   261 #define SDL_realloc SDL_realloc_inline
   262 #endif
   263 
   264 extern DECLSPEC void SDLCALL SDL_free(void *mem);
   265 #ifdef HAVE_FREE
   266 SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); }
   267 #define SDL_free SDL_free_inline
   268 #endif
   269 
   270 extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   271 #ifdef HAVE_GETENV
   272 SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); }
   273 #define SDL_getenv SDL_getenv_inline
   274 #endif
   275 
   276 extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
   277 #ifdef HAVE_SETENV
   278 SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); }
   279 #define SDL_setenv SDL_setenv_inline
   280 #endif
   281 
   282 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
   283 #ifdef HAVE_QSORT
   284 SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { qsort(base, nmemb, size, compare); }
   285 #define SDL_qsort SDL_qsort_inline
   286 #endif
   287 
   288 extern DECLSPEC int SDLCALL SDL_abs(int x);
   289 #ifdef HAVE_ABS
   290 SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); }
   291 #else
   292 SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); }
   293 #endif
   294 #define SDL_abs SDL_abs_inline
   295 
   296 /* !!! FIXME: these have side effects. You probably shouldn't use them. */
   297 /* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
   298 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
   299 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
   300 
   301 extern DECLSPEC int SDLCALL SDL_isdigit(int x);
   302 extern DECLSPEC int SDLCALL SDL_isspace(int x);
   303 extern DECLSPEC int SDLCALL SDL_toupper(int x);
   304 extern DECLSPEC int SDLCALL SDL_tolower(int x);
   305 #ifdef HAVE_CTYPE_H
   306 SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); }
   307 SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); }
   308 SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); }
   309 SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); }
   310 #else
   311 SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); }
   312 SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
   313 SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   314 SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   315 #endif
   316 #define SDL_isdigit SDL_isdigit_inline
   317 #define SDL_isspace SDL_isspace_inline
   318 #define SDL_toupper SDL_toupper_inline
   319 #define SDL_tolower SDL_tolower_inline
   320 
   321 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   322 #ifdef HAVE_MEMSET
   323 SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); }
   324 #define SDL_memset SDL_memset_inline
   325 #endif
   326 
   327 #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
   328 #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
   329 
   330 /* !!! FIXME: does this _really_ beat memset() on any modern platform? */
   331 SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len)
   332 {
   333 #if defined(__GNUC__) && defined(i386)
   334     int u0, u1, u2;
   335     __asm__ __volatile__ (
   336         "cld \n\t"
   337         "rep ; stosl \n\t"
   338         : "=&D" (u0), "=&a" (u1), "=&c" (u2)
   339         : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))
   340         : "memory"
   341     );
   342 /* !!! FIXME: amd64? */
   343 #else
   344     size_t _n = (len + 3) / 4;
   345     Uint32 *_p = SDL_static_cast(Uint32 *, dst);
   346     Uint32 _val = (val);
   347     if (len == 0)
   348         return;
   349     switch (len % 4)
   350     {
   351         case 0: do {    *_p++ = _val;
   352         case 3:         *_p++ = _val;
   353         case 2:         *_p++ = _val;
   354         case 1:         *_p++ = _val;
   355         } while ( --_n );
   356     }
   357 #endif
   358 }
   359 
   360 
   361 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
   362 #if defined(__MACOSX__)
   363 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   364 {
   365     /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   366     return memcpy(dst, src, len);
   367 }
   368 #define SDL_memcpy SDL_memcpy_inline
   369 #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   370 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   371 {
   372     /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   373     /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   374     /* !!! FIXME: amd64? */
   375     int u0, u1, u2;
   376     __asm__ __volatile__ (
   377         "cld \n\t"
   378         "rep ; movsl \n\t"
   379         "testb $2,%b4 \n\t"
   380         "je 1f \n\t"
   381         "movsw \n"
   382         "1:\ttestb $1,%b4 \n\t"
   383         "je 2f \n\t"
   384         "movsb \n"
   385         "2:"
   386         : "=&c" (u0), "=&D" (u1), "=&S" (u2)
   387         : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src)
   388         : "memory"
   389     );
   390     return dst;
   391 }
   392 #define SDL_memcpy SDL_memcpy_inline
   393 #elif defined(HAVE_MEMCPY)
   394 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   395 {
   396     return memcpy(dst, src, len);
   397 }
   398 #define SDL_memcpy SDL_memcpy_inline
   399 #elif defined(HAVE_BCOPY)  /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */
   400 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   401 {
   402     bcopy(src, dst, len);
   403     return dst;
   404 }
   405 #define SDL_memcpy SDL_memcpy_inline
   406 #endif
   407 
   408 
   409 SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
   410 {
   411 #if defined(__GNUC__) && defined(i386)
   412     /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   413     /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   414     int ecx, edi, esi;
   415     __asm__ __volatile__ (
   416         "cld \n\t"
   417         "rep ; movsl \n\t"
   418         : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
   419         : "0" (SDL_static_cast(unsigned, dwords)), "1" (dst), "2" (src)
   420         : "memory"
   421     );
   422     return dst;
   423 #else
   424     return SDL_memcpy(dst, src, dwords * 4);
   425 #endif
   426 }
   427 
   428 extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
   429 #ifdef HAVE_MEMMOVE
   430 SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); }
   431 #define SDL_memmove SDL_memmove_inline
   432 #endif
   433 
   434 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   435 #ifdef HAVE_MEMCMP
   436 SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
   437 #define SDL_memcmp SDL_memcmp_inline
   438 #endif
   439 
   440 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   441 #ifdef HAVE_STRLEN
   442 SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
   443 #define SDL_strlen SDL_strlen_inline
   444 #endif
   445 
   446 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   447 #ifdef HAVE_WCSLEN
   448 SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
   449 #define SDL_wcslen SDL_wcslen_inline
   450 #endif
   451 
   452 extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   453 #ifdef HAVE_WCSLCPY
   454 SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
   455 #define SDL_wcslcpy SDL_wcslcpy_inline
   456 #endif
   457 
   458 extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   459 #ifdef HAVE_WCSLCAT
   460 SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
   461 #define SDL_wcslcat SDL_wcslcat_inline
   462 #endif
   463 
   464 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   465 #ifdef HAVE_STRLCPY
   466 SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
   467 #define SDL_strlcpy SDL_strlcpy_inline
   468 #else
   469 #endif
   470 
   471 extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
   472 
   473 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   474 #ifdef HAVE_STRLCAT
   475 SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
   476 #define SDL_strlcat SDL_strlcat_inline
   477 #endif
   478 
   479 extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
   480 #ifdef HAVE_STRDUP
   481 SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
   482 #define SDL_strdup SDL_strdup_inline
   483 #endif
   484 
   485 extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
   486 #ifdef HAVE__STRREV
   487 SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
   488 #define SDL_strrev SDL_strrev_inline
   489 #endif
   490 
   491 extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
   492 #ifdef HAVE__STRUPR
   493 SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
   494 #define SDL_strupr SDL_strupr_inline
   495 #endif
   496 
   497 extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
   498 #ifdef HAVE__STRLWR
   499 SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
   500 #define SDL_strlwr SDL_strlwr_inline
   501 #endif
   502 
   503 extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
   504 #ifdef HAVE_STRCHR
   505 SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return (char*)strchr(str, c); }
   506 #define SDL_strchr SDL_strchr_inline
   507 #elif defined(HAVE_INDEX)  /* !!! FIXME: is there anywhere that has this but not strchr? */
   508 SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); }
   509 #define SDL_strchr SDL_strchr_inline
   510 #endif
   511 
   512 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
   513 #ifdef HAVE_STRRCHR
   514 SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) {
   515 #ifdef __cplusplus
   516 return const_cast<char*>(strrchr(str, c));
   517 #else
   518 return (char*)strrchr(str, c);
   519 #endif
   520 }
   521 #define SDL_strrchr SDL_strrchr_inline
   522 #elif defined(HAVE_RINDEX)  /* !!! FIXME: is there anywhere that has this but not strrchr? */
   523 SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) {
   524 #ifdef __cplusplus
   525 return const_cast<char*>(rindex(str, c));
   526 #else
   527 return (char*)rindex(str, c);
   528 #endif
   529 }
   530 #define SDL_strrchr SDL_strrchr_inline
   531 #endif
   532 
   533 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
   534 #ifdef HAVE_STRSTR
   535 SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return (char*)strstr(haystack, needle); }
   536 #define SDL_strstr SDL_strstr_inline
   537 #endif
   538 
   539 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   540 #ifdef HAVE__LTOA
   541 SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
   542 #define SDL_ltoa SDL_ltoa_inline
   543 #endif
   544 
   545 extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
   546 #ifdef HAVE_ITOA
   547 SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
   548 #else
   549 SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
   550 #endif
   551 #define SDL_itoa SDL_itoa_inline
   552 
   553 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
   554 #ifdef HAVE__ULTOA
   555 SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
   556 #define SDL_ultoa SDL_ultoa_inline
   557 #endif
   558 
   559 extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   560 #ifdef HAVE__UITOA
   561 SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
   562 #else
   563 SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
   564 #endif
   565 #define SDL_uitoa SDL_uitoa_inline
   566 
   567 
   568 extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   569 #ifdef HAVE_STRTOL
   570 SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
   571 #define SDL_strtol SDL_strtol_inline
   572 #endif
   573 
   574 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   575 #ifdef HAVE_STRTOUL
   576 SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
   577 #define SDL_strtoul SDL_strtoul_inline
   578 #endif
   579 
   580 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
   581 #ifdef HAVE__I64TOA
   582 SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
   583 #define SDL_lltoa SDL_lltoa_inline
   584 #endif
   585 
   586 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
   587 #ifdef HAVE__UI64TOA
   588 SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
   589 #define SDL_ulltoa SDL_ulltoa_inline
   590 #endif
   591 
   592 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   593 #ifdef HAVE_STRTOLL
   594 SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
   595 #define SDL_strtoll SDL_strtoll_inline
   596 #endif
   597 
   598 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   599 #ifdef HAVE_STRTOULL
   600 SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
   601 #define SDL_strtoull SDL_strtoull_inline
   602 #endif
   603 
   604 extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   605 #ifdef HAVE_STRTOD
   606 SDL_FORCE_INLINE double SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
   607 #define SDL_strtod SDL_strtod_inline
   608 #endif
   609 
   610 extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
   611 #ifdef HAVE_ATOI
   612 SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
   613 #else
   614 SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
   615 #endif
   616 #define SDL_atoi SDL_atoi_inline
   617 
   618 extern DECLSPEC double SDLCALL SDL_atof(const char *str);
   619 #ifdef HAVE_ATOF
   620 SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
   621 #else
   622 SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
   623 #endif
   624 #define SDL_atof SDL_atof_inline
   625 
   626 
   627 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   628 #ifdef HAVE_STRCMP
   629 SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
   630 #define SDL_strcmp SDL_strcmp_inline
   631 #endif
   632 
   633 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   634 #ifdef HAVE_STRNCMP
   635 SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
   636 #define SDL_strncmp SDL_strncmp_inline
   637 #endif
   638 
   639 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   640 #ifdef HAVE_STRCASECMP
   641 SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
   642 #define SDL_strcasecmp SDL_strcasecmp_inline
   643 #elif defined(HAVE__STRICMP)
   644 SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
   645 #define SDL_strcasecmp SDL_strcasecmp_inline
   646 #endif
   647 
   648 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   649 #ifdef HAVE_STRNCASECMP
   650 SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
   651 #define SDL_strncasecmp SDL_strncasecmp_inline
   652 #elif defined(HAVE__STRNICMP)
   653 SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
   654 #define SDL_strncasecmp SDL_strncasecmp_inline
   655 #endif
   656 
   657 /* Not doing SDL_*_inline functions for these, because of the varargs. */
   658 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   659 #ifdef HAVE_SSCANF
   660 #define SDL_sscanf sscanf
   661 #endif
   662 
   663 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   664 #ifdef HAVE_SNPRINTF
   665 #define SDL_snprintf snprintf
   666 #endif
   667 
   668 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   669 #ifdef HAVE_VSNPRINTF
   670 SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); }
   671 #define SDL_vsnprintf SDL_vsnprintf_inline
   672 #endif
   673 
   674 #ifndef HAVE_M_PI
   675 #ifndef M_PI
   676 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   677 #endif
   678 #endif
   679 
   680 extern DECLSPEC double SDLCALL SDL_atan(double x);
   681 #ifdef HAVE_ATAN
   682 SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
   683 #define SDL_atan SDL_atan_inline
   684 #endif
   685 
   686 extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
   687 #ifdef HAVE_ATAN2
   688 SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
   689 #define SDL_atan2 SDL_atan2_inline
   690 #endif
   691 
   692 extern DECLSPEC double SDLCALL SDL_ceil(double x);
   693 #ifdef HAVE_CEIL
   694 SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
   695 #else
   696 SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
   697 #endif
   698 #define SDL_ceil SDL_ceil_inline
   699 
   700 extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   701 #ifdef HAVE_COPYSIGN
   702 SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
   703 #define SDL_copysign SDL_copysign_inline
   704 #endif
   705 
   706 extern DECLSPEC double SDLCALL SDL_cos(double x);
   707 #ifdef HAVE_COS
   708 SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
   709 #define SDL_cos SDL_cos_inline
   710 #endif
   711 
   712 extern DECLSPEC float SDLCALL SDL_cosf(float x);
   713 #ifdef HAVE_COSF
   714 SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
   715 #else
   716 SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
   717 #endif
   718 #define SDL_cosf SDL_cosf_inline
   719 
   720 extern DECLSPEC double SDLCALL SDL_fabs(double x);
   721 #ifdef HAVE_FABS
   722 SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
   723 #define SDL_fabs SDL_fabs_inline
   724 #endif
   725 
   726 extern DECLSPEC double SDLCALL SDL_floor(double x);
   727 #ifdef HAVE_FLOOR
   728 SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
   729 #define SDL_floor SDL_floor_inline
   730 #endif
   731 
   732 extern DECLSPEC double SDLCALL SDL_log(double x);
   733 #ifdef HAVE_LOG
   734 SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
   735 #define SDL_log SDL_log_inline
   736 #endif
   737 
   738 extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   739 #ifdef HAVE_POW
   740 SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
   741 #define SDL_pow SDL_pow_inline
   742 #endif
   743 
   744 extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   745 #ifdef HAVE_SCALBN
   746 SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
   747 #define SDL_scalbn SDL_scalbn_inline
   748 #endif
   749 
   750 extern DECLSPEC double SDLCALL SDL_sin(double x);
   751 #ifdef HAVE_SIN
   752 SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
   753 #define SDL_sin SDL_sin_inline
   754 #endif
   755 
   756 extern DECLSPEC float SDLCALL SDL_sinf(float x);
   757 #ifdef HAVE_SINF
   758 SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
   759 #else
   760 SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
   761 #endif
   762 #define SDL_sinf SDL_sinf_inline
   763 
   764 extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   765 #ifdef HAVE_SQRT
   766 SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
   767 #define SDL_sqrt SDL_sqrt_inline
   768 #endif
   769 
   770 /* The SDL implementation of iconv() returns these error codes */
   771 #define SDL_ICONV_ERROR		(size_t)-1
   772 #define SDL_ICONV_E2BIG		(size_t)-2
   773 #define SDL_ICONV_EILSEQ	(size_t)-3
   774 #define SDL_ICONV_EINVAL	(size_t)-4
   775 
   776 /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
   777 typedef struct _SDL_iconv_t *SDL_iconv_t;
   778 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   779                                                    const char *fromcode);
   780 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   781 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   782                                          size_t * inbytesleft, char **outbuf,
   783                                          size_t * outbytesleft);
   784 /**
   785  *  This function converts a string between encodings in one pass, returning a
   786  *  string that must be freed with SDL_free() or NULL on error.
   787  */
   788 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   789                                                const char *fromcode,
   790                                                const char *inbuf,
   791                                                size_t inbytesleft);
   792 #define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   793 #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   794 #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   795 
   796 /* Ends C function definitions when using C++ */
   797 #ifdef __cplusplus
   798 /* *INDENT-OFF* */
   799 }
   800 /* *INDENT-ON* */
   801 #endif
   802 #include "close_code.h"
   803 
   804 #endif /* _SDL_stdinc_h */
   805 
   806 /* vi: set ts=4 sw=4 expandtab: */