include/SDL_stdinc.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 29 Mar 2013 21:29:57 -0400
changeset 7036 8c891504e325
parent 7015 e3cba60c0f0a
child 7057 c1563f514b5b
permissions -rw-r--r--
Corrected function signature on SDL_strtod_inline() (thanks, Axel!).

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