include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 14 Mar 2013 23:10:51 -0700
changeset 7005 6c69ad0b184e
parent 7003 eeaf77005c30
child 7006 ffcf28627e1c
permissions -rw-r--r--
Clarified inline function documentation, removed obsolete Metrowerks compiler directive.
     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(__NINTENDODS__) && !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 #if !defined(wchar_t) && defined(__NINTENDODS__)
   194 #define wchar_t short           /* TODO: figure out why libnds doesn't have this */
   195 #endif
   196 
   197 #include "begin_code.h"
   198 /* Set up for C function definitions, even when using C++ */
   199 #ifdef __cplusplus
   200 /* *INDENT-OFF* */
   201 extern "C" {
   202 /* *INDENT-ON* */
   203 #endif
   204 
   205 #if defined(HAVE_ALLOCA) && !defined(alloca)
   206 # if defined(HAVE_ALLOCA_H)
   207 #  include <alloca.h>
   208 # elif defined(__GNUC__)
   209 #  define alloca __builtin_alloca
   210 # elif defined(_MSC_VER)
   211 #  include <malloc.h>
   212 #  define alloca _alloca
   213 # elif defined(__WATCOMC__)
   214 #  include <malloc.h>
   215 # elif defined(__BORLANDC__)
   216 #  include <malloc.h>
   217 # elif defined(__DMC__)
   218 #  include <stdlib.h>
   219 # elif defined(__AIX__)
   220 #pragma alloca
   221 # elif defined(__MRC__)
   222 void *alloca(unsigned);
   223 # else
   224 char *alloca();
   225 # endif
   226 #endif
   227 #ifdef HAVE_ALLOCA
   228 #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*(count))
   229 #define SDL_stack_free(data)
   230 #else
   231 #define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*(count))
   232 #define SDL_stack_free(data)            SDL_free(data)
   233 #endif
   234 
   235 
   236 /* SDL stdinc inline functions:
   237 
   238    The theory here is that by default we forcibly inline what we can, and your
   239    app will use the inline version by default. However we expose a non-inline
   240    version too, so the symbol is always available in the library even if your app
   241    bypassed the inline version. The SDL_*_inline versions aren't guaranteed to
   242    exist, so never call them directly; use SDL_* instead, and trust the system
   243    to give you the right thing.
   244 
   245    The benefit here is that you can dlsym() these functions, which you
   246    couldn't if you had macros, you can link against a foreign build of SDL
   247    even if you configured differently, and you can drop the unconfigured SDL
   248    headers into a project without #defining HAVE_MALLOC (etc) and still link.
   249 */
   250 
   251 extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
   252 #ifdef HAVE_MALLOC
   253 SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); }
   254 #define SDL_malloc SDL_malloc_inline
   255 #endif
   256 
   257 extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
   258 #ifdef HAVE_CALLOC
   259 SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); }
   260 #define SDL_calloc SDL_calloc_inline
   261 #endif
   262 
   263 extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
   264 #ifdef HAVE_REALLOC
   265 SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); }
   266 #define SDL_realloc SDL_realloc_inline
   267 #endif
   268 
   269 extern DECLSPEC void SDLCALL SDL_free(void *mem);
   270 #ifdef HAVE_FREE
   271 SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); }
   272 #define SDL_free SDL_free_inline
   273 #endif
   274 
   275 extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   276 #ifdef HAVE_GETENV
   277 SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); }
   278 #define SDL_getenv SDL_getenv_inline
   279 #endif
   280 
   281 extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
   282 #ifdef HAVE_SETENV
   283 SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); }
   284 #define SDL_setenv SDL_setenv_inline
   285 #endif
   286 
   287 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
   288 #ifdef HAVE_QSORT
   289 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); }
   290 #define SDL_qsort SDL_qsort_inline
   291 #endif
   292 
   293 extern DECLSPEC int SDLCALL SDL_abs(int x);
   294 #ifdef HAVE_ABS
   295 SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); }
   296 #else
   297 SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); }
   298 #endif
   299 #define SDL_abs SDL_abs_inline
   300 
   301 /* !!! FIXME: these have side effects. You probably shouldn't use them. */
   302 /* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
   303 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
   304 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
   305 
   306 extern DECLSPEC int SDLCALL SDL_isdigit(int x);
   307 extern DECLSPEC int SDLCALL SDL_isspace(int x);
   308 extern DECLSPEC int SDLCALL SDL_toupper(int x);
   309 extern DECLSPEC int SDLCALL SDL_tolower(int x);
   310 #ifdef HAVE_CTYPE_H
   311 SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); }
   312 SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); }
   313 SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); }
   314 SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); }
   315 #else
   316 SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); }
   317 SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
   318 SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   319 SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   320 #endif
   321 #define SDL_isdigit SDL_isdigit_inline
   322 #define SDL_isspace SDL_isspace_inline
   323 #define SDL_toupper SDL_toupper_inline
   324 #define SDL_tolower SDL_tolower_inline
   325 
   326 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   327 #ifdef HAVE_MEMSET
   328 SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); }
   329 #define SDL_memset SDL_memset_inline
   330 #endif
   331 
   332 #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
   333 #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
   334 
   335 /* !!! FIXME: does this _really_ beat memset() on any modern platform? */
   336 SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len)
   337 {
   338 #if defined(__GNUC__) && defined(i386)
   339     int u0, u1, u2;
   340     __asm__ __volatile__ (
   341         "cld \n\t"
   342         "rep ; stosl \n\t"
   343         : "=&D" (u0), "=&a" (u1), "=&c" (u2)
   344         : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))
   345         : "memory"
   346     );
   347 /* !!! FIXME: amd64? */
   348 #else
   349     unsigned int _count = (len);
   350     unsigned int _n = (_count + 3) / 4;
   351     Uint32 *_p = SDL_static_cast(Uint32 *, dst);
   352     Uint32 _val = (val);
   353     if (len == 0)
   354         return;
   355     switch (_count % 4)
   356     {
   357         case 0: do {    *_p++ = _val;
   358         case 3:         *_p++ = _val;
   359         case 2:         *_p++ = _val;
   360         case 1:         *_p++ = _val;
   361         } while ( --_n );
   362     }
   363 #endif
   364 }
   365 
   366 
   367 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
   368 #if defined(__MACOSX__)
   369 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   370 {
   371     /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   372     return memcpy(dst, src, len);
   373 }
   374 #define SDL_memcpy SDL_memcpy_inline
   375 #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   376 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   377 {
   378     /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   379     /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   380     /* !!! FIXME: amd64? */
   381     int u0, u1, u2;
   382     __asm__ __volatile__ (
   383         "cld \n\t"
   384         "rep ; movsl \n\t"
   385         "testb $2,%b4 \n\t"
   386         "je 1f \n\t"
   387         "movsw \n"
   388         "1:\ttestb $1,%b4 \n\t"
   389         "je 2f \n\t"
   390         "movsb \n"
   391         "2:"
   392         : "=&c" (u0), "=&D" (u1), "=&S" (u2)
   393         : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src)
   394         : "memory"
   395     );
   396     return dst;
   397 }
   398 #define SDL_memcpy SDL_memcpy_inline
   399 #elif defined(HAVE_MEMCPY)
   400 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   401 {
   402     return memcpy(dst, src, len);
   403 }
   404 #define SDL_memcpy SDL_memcpy_inline
   405 #elif defined(HAVE_BCOPY)  /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */
   406 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   407 {
   408     bcopy(src, dst, len);
   409     return dst;
   410 }
   411 #define SDL_memcpy SDL_memcpy_inline
   412 #endif
   413 
   414 
   415 SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
   416 {
   417 #if defined(__MACOSX__)
   418     /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   419     return memcpy(dst, src, dwords * 4);
   420 #elif defined(__GNUC__) && defined(i386)
   421     /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   422     /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   423     /* !!! FIXME: amd64? */
   424     int ecx, edi, esi;
   425     __asm__ __volatile__ (
   426         "cld \n\t"
   427         "rep ; movsl \n\t"
   428         : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
   429         : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)
   430         : "memory"
   431     );
   432     return dst;
   433 #else
   434     return SDL_memcpy(dst, src, dwords * 4);
   435 #endif
   436 }
   437 
   438 extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
   439 #ifdef HAVE_MEMMOVE
   440 SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); }
   441 #define SDL_memmove SDL_memmove_inline
   442 #endif
   443 
   444 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   445 #ifdef HAVE_MEMCMP
   446 SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
   447 #define SDL_memcmp SDL_memcmp_inline
   448 #endif
   449 
   450 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   451 #ifdef HAVE_STRLEN
   452 SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
   453 #define SDL_strlen SDL_strlen_inline
   454 #endif
   455 
   456 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   457 #ifdef HAVE_WCSLEN
   458 SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
   459 #define SDL_wcslen SDL_wcslen_inline
   460 #endif
   461 
   462 extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   463 #ifdef HAVE_WCSLCPY
   464 SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
   465 #define SDL_wcslcpy SDL_wcslcpy_inline
   466 #endif
   467 
   468 extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   469 #ifdef HAVE_WCSLCAT
   470 SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
   471 #define SDL_wcslcat SDL_wcslcat_inline
   472 #endif
   473 
   474 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   475 #ifdef HAVE_STRLCPY
   476 SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
   477 #define SDL_strlcpy SDL_strlcpy_inline
   478 #else
   479 #endif
   480 
   481 extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
   482 
   483 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   484 #ifdef HAVE_STRLCAT
   485 SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
   486 #define SDL_strlcat SDL_strlcat_inline
   487 #endif
   488 
   489 extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
   490 #ifdef HAVE_STRDUP
   491 SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
   492 #define SDL_strdup SDL_strdup_inline
   493 #endif
   494 
   495 extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
   496 #ifdef HAVE__STRREV
   497 SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
   498 #define SDL_strrev SDL_strrev_inline
   499 #endif
   500 
   501 extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
   502 #ifdef HAVE__STRUPR
   503 SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
   504 #define SDL_strupr SDL_strupr_inline
   505 #endif
   506 
   507 extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
   508 #ifdef HAVE__STRLWR
   509 SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
   510 #define SDL_strlwr SDL_strlwr_inline
   511 #endif
   512 
   513 extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
   514 #ifdef HAVE_STRCHR
   515 SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return strchr(str, c); }
   516 #define SDL_strchr SDL_strchr_inline
   517 #elif defined(HAVE_INDEX)  /* !!! FIXME: is there anywhere that has this but not strchr? */
   518 SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); }
   519 #define SDL_strchr SDL_strchr_inline
   520 #endif
   521 
   522 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
   523 #ifdef HAVE_STRRCHR
   524 SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return strrchr(str, c); }
   525 #define SDL_strrchr SDL_strrchr_inline
   526 #elif defined(HAVE_RINDEX)  /* !!! FIXME: is there anywhere that has this but not strrchr? */
   527 SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return rindex(str, c); }
   528 #define SDL_strrchr SDL_strrchr_inline
   529 #endif
   530 
   531 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
   532 #ifdef HAVE_STRSTR
   533 SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return strstr(haystack, needle); }
   534 #define SDL_strstr SDL_strstr_inline
   535 #endif
   536 
   537 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   538 #ifdef HAVE__LTOA
   539 SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
   540 #define SDL_ltoa SDL_ltoa_inline
   541 #endif
   542 
   543 extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
   544 #ifdef HAVE_ITOA
   545 SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
   546 #else
   547 SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
   548 #endif
   549 #define SDL_itoa SDL_itoa_inline
   550 
   551 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
   552 #ifdef HAVE__ULTOA
   553 SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
   554 #define SDL_ultoa SDL_ultoa_inline
   555 #endif
   556 
   557 extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   558 #ifdef HAVE__UITOA
   559 SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
   560 #else
   561 SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
   562 #endif
   563 #define SDL_uitoa SDL_uitoa_inline
   564 
   565 
   566 extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   567 #ifdef HAVE_STRTOL
   568 SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
   569 #define SDL_strtol SDL_strtol_inline
   570 #endif
   571 
   572 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   573 #ifdef HAVE_STRTOUL
   574 SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
   575 #define SDL_strtoul SDL_strtoul_inline
   576 #endif
   577 
   578 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
   579 #ifdef HAVE__I64TOA
   580 SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
   581 #define SDL_lltoa SDL_lltoa_inline
   582 #endif
   583 
   584 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
   585 #ifdef HAVE__UI64TOA
   586 SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
   587 #define SDL_ulltoa SDL_ulltoa_inline
   588 #endif
   589 
   590 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   591 #ifdef HAVE_STRTOLL
   592 SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
   593 #define SDL_strtoll SDL_strtoll_inline
   594 #endif
   595 
   596 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   597 #ifdef HAVE_STRTOULL
   598 SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
   599 #define SDL_strtoull SDL_strtoull_inline
   600 #endif
   601 
   602 extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   603 #ifdef HAVE_STRTOD
   604 SDL_FORCE_INLINE Uint64 SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
   605 #define SDL_strtod SDL_strtod_inline
   606 #endif
   607 
   608 extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
   609 #ifdef HAVE_ATOI
   610 SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
   611 #else
   612 SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
   613 #endif
   614 #define SDL_atoi SDL_atoi_inline
   615 
   616 extern DECLSPEC double SDLCALL SDL_atof(const char *str);
   617 #ifdef HAVE_ATOF
   618 SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
   619 #else
   620 SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
   621 #endif
   622 #define SDL_atof SDL_atof_inline
   623 
   624 
   625 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   626 #ifdef HAVE_STRCMP
   627 SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
   628 #define SDL_strcmp SDL_strcmp_inline
   629 #endif
   630 
   631 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   632 #ifdef HAVE_STRNCMP
   633 SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
   634 #define SDL_strncmp SDL_strncmp_inline
   635 #endif
   636 
   637 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   638 #ifdef HAVE_STRCASECMP
   639 SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
   640 #define SDL_strcasecmp SDL_strcasecmp_inline
   641 #elif defined(HAVE__STRICMP)
   642 SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
   643 #define SDL_strcasecmp SDL_strcasecmp_inline
   644 #endif
   645 
   646 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   647 #ifdef HAVE_STRNCASECMP
   648 SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
   649 #define SDL_strncasecmp SDL_strncasecmp_inline
   650 #elif defined(HAVE__STRNICMP)
   651 SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
   652 #define SDL_strncasecmp SDL_strncasecmp_inline
   653 #endif
   654 
   655 /* Not doing SDL_*_inline functions for these, because of the varargs. */
   656 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   657 #ifdef HAVE_SSCANF
   658 #define SDL_sscanf sscanf
   659 #endif
   660 
   661 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   662 #ifdef HAVE_SNPRINTF
   663 #define SDL_snprintf snprintf
   664 #endif
   665 
   666 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   667 #ifdef HAVE_VSNPRINTF
   668 SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); }
   669 #define SDL_vsnprintf SDL_vsnprintf_inline
   670 #endif
   671 
   672 #ifndef HAVE_M_PI
   673 #ifndef M_PI
   674 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   675 #endif
   676 #endif
   677 
   678 extern DECLSPEC double SDLCALL SDL_atan(double x);
   679 #ifdef HAVE_ATAN
   680 SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
   681 #define SDL_atan SDL_atan_inline
   682 #endif
   683 
   684 extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
   685 #ifdef HAVE_ATAN2
   686 SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
   687 #define SDL_atan2 SDL_atan2_inline
   688 #endif
   689 
   690 extern DECLSPEC double SDLCALL SDL_ceil(double x);
   691 #ifdef HAVE_CEIL
   692 SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
   693 #else
   694 SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
   695 #endif
   696 #define SDL_ceil SDL_ceil_inline
   697 
   698 extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   699 #ifdef HAVE_COPYSIGN
   700 SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
   701 #define SDL_copysign SDL_copysign_inline
   702 #endif
   703 
   704 extern DECLSPEC double SDLCALL SDL_cos(double x);
   705 #ifdef HAVE_COS
   706 SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
   707 #define SDL_cos SDL_cos_inline
   708 #endif
   709 
   710 extern DECLSPEC float SDLCALL SDL_cosf(float x);
   711 #ifdef HAVE_COSF
   712 SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
   713 #else
   714 SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
   715 #endif
   716 #define SDL_cosf SDL_cosf_inline
   717 
   718 extern DECLSPEC double SDLCALL SDL_fabs(double x);
   719 #ifdef HAVE_FABS
   720 SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
   721 #define SDL_fabs SDL_fabs_inline
   722 #endif
   723 
   724 extern DECLSPEC double SDLCALL SDL_floor(double x);
   725 #ifdef HAVE_FLOOR
   726 SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
   727 #define SDL_floor SDL_floor_inline
   728 #endif
   729 
   730 extern DECLSPEC double SDLCALL SDL_log(double x);
   731 #ifdef HAVE_LOG
   732 SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
   733 #define SDL_log SDL_log_inline
   734 #endif
   735 
   736 extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   737 #ifdef HAVE_POW
   738 SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
   739 #define SDL_pow SDL_pow_inline
   740 #endif
   741 
   742 extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   743 #ifdef HAVE_SCALBN
   744 SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
   745 #define SDL_scalbn SDL_scalbn_inline
   746 #endif
   747 
   748 extern DECLSPEC double SDLCALL SDL_sin(double x);
   749 #ifdef HAVE_SIN
   750 SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
   751 #define SDL_sin SDL_sin_inline
   752 #endif
   753 
   754 extern DECLSPEC float SDLCALL SDL_sinf(float x);
   755 #ifdef HAVE_SINF
   756 SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
   757 #else
   758 SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
   759 #endif
   760 #define SDL_sinf SDL_sinf_inline
   761 
   762 extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   763 #ifdef HAVE_SQRT
   764 SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
   765 #define SDL_sqrt SDL_sqrt_inline
   766 #endif
   767 
   768 /* The SDL implementation of iconv() returns these error codes */
   769 #define SDL_ICONV_ERROR		(size_t)-1
   770 #define SDL_ICONV_E2BIG		(size_t)-2
   771 #define SDL_ICONV_EILSEQ	(size_t)-3
   772 #define SDL_ICONV_EINVAL	(size_t)-4
   773 
   774 /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
   775 typedef struct _SDL_iconv_t *SDL_iconv_t;
   776 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   777                                                    const char *fromcode);
   778 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   779 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   780                                          size_t * inbytesleft, char **outbuf,
   781                                          size_t * outbytesleft);
   782 /**
   783  *  This function converts a string between encodings in one pass, returning a
   784  *  string that must be freed with SDL_free() or NULL on error.
   785  */
   786 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   787                                                const char *fromcode,
   788                                                const char *inbuf,
   789                                                size_t inbytesleft);
   790 #define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   791 #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   792 #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   793 
   794 /* Ends C function definitions when using C++ */
   795 #ifdef __cplusplus
   796 /* *INDENT-OFF* */
   797 }
   798 /* *INDENT-ON* */
   799 #endif
   800 #include "close_code.h"
   801 
   802 #endif /* _SDL_stdinc_h */
   803 
   804 /* vi: set ts=4 sw=4 expandtab: */