include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Jun 2013 22:30:02 -0700
changeset 7308 728e5f22a82f
parent 7307 5d6b7b9432d3
child 7351 668a3dc28361
permissions -rw-r--r--
Allow users to define SDL_STDINC_NO_INLINES if they don't want the inline functions defined.
This is useful, for example, if the standard config defines HAVE_SETENV but you're building with C99 that doesn't include that feature.
     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 #define SDL_const_cast(type, expression) const_cast<type>(expression)
    97 #else
    98 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
    99 #define SDL_static_cast(type, expression) ((type)(expression))
   100 #define SDL_const_cast(type, expression) ((type)(expression))
   101 #endif
   102 /*@}*//*Cast operators*/
   103 
   104 /* Define a four character code as a Uint32 */
   105 #define SDL_FOURCC(A, B, C, D) \
   106     ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
   107      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
   108      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
   109      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
   110 
   111 /**
   112  *  \name Basic data types
   113  */
   114 /*@{*/
   115 
   116 typedef enum
   117 {
   118     SDL_FALSE = 0,
   119     SDL_TRUE = 1
   120 } SDL_bool;
   121 
   122 /**
   123  * \brief A signed 8-bit integer type.
   124  */
   125 typedef int8_t Sint8;
   126 /**
   127  * \brief An unsigned 8-bit integer type.
   128  */
   129 typedef uint8_t Uint8;
   130 /**
   131  * \brief A signed 16-bit integer type.
   132  */
   133 typedef int16_t Sint16;
   134 /**
   135  * \brief An unsigned 16-bit integer type.
   136  */
   137 typedef uint16_t Uint16;
   138 /**
   139  * \brief A signed 32-bit integer type.
   140  */
   141 typedef int32_t Sint32;
   142 /**
   143  * \brief An unsigned 32-bit integer type.
   144  */
   145 typedef uint32_t Uint32;
   146 
   147 /**
   148  * \brief A signed 64-bit integer type.
   149  */
   150 typedef int64_t Sint64;
   151 /**
   152  * \brief An unsigned 64-bit integer type.
   153  */
   154 typedef uint64_t Uint64;
   155 
   156 /*@}*//*Basic data types*/
   157 
   158 
   159 #define SDL_COMPILE_TIME_ASSERT(name, x)               \
   160        typedef int SDL_dummy_ ## name[(x) * 2 - 1]
   161 /** \cond */
   162 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   163 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
   164 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
   165 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
   166 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
   167 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
   168 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
   169 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
   170 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
   171 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   172 /** \endcond */
   173 
   174 /* Check to make sure enums are the size of ints, for structure packing.
   175    For both Watcom C/C++ and Borland C/C++ the compiler option that makes
   176    enums having the size of an int must be enabled.
   177    This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
   178 */
   179 
   180 /** \cond */
   181 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   182 #if !defined(__ANDROID__)
   183    /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
   184 typedef enum
   185 {
   186     DUMMY_ENUM_VALUE
   187 } SDL_DUMMY_ENUM;
   188 
   189 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
   190 #endif
   191 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   192 /** \endcond */
   193 
   194 #include "begin_code.h"
   195 /* Set up for C function definitions, even when using C++ */
   196 #ifdef __cplusplus
   197 extern "C" {
   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    If you want to disable the inline functions and just use SDL's functions,
   246    you can define SDL_STDINC_NO_INLINES before including this file.
   247 */
   248 
   249 extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
   250 #if defined(HAVE_MALLOC) && !defined(SDL_STDINC_NO_INLINES)
   251 SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); }
   252 #define SDL_malloc SDL_malloc_inline
   253 #endif
   254 
   255 extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
   256 #if defined(HAVE_CALLOC) && !defined(SDL_STDINC_NO_INLINES)
   257 SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); }
   258 #define SDL_calloc SDL_calloc_inline
   259 #endif
   260 
   261 extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
   262 #if defined(HAVE_REALLOC) && !defined(SDL_STDINC_NO_INLINES)
   263 SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); }
   264 #define SDL_realloc SDL_realloc_inline
   265 #endif
   266 
   267 extern DECLSPEC void SDLCALL SDL_free(void *mem);
   268 #if defined(HAVE_FREE) && !defined(SDL_STDINC_NO_INLINES)
   269 SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); }
   270 #define SDL_free SDL_free_inline
   271 #endif
   272 
   273 extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   274 #if defined(HAVE_GETENV) && !defined(SDL_STDINC_NO_INLINES)
   275 SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); }
   276 #define SDL_getenv SDL_getenv_inline
   277 #endif
   278 
   279 extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
   280 #if defined(HAVE_SETENV) && !defined(SDL_STDINC_NO_INLINES)
   281 SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); }
   282 #define SDL_setenv SDL_setenv_inline
   283 #endif
   284 
   285 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
   286 #if defined(HAVE_QSORT) && !defined(SDL_STDINC_NO_INLINES)
   287 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); }
   288 #define SDL_qsort SDL_qsort_inline
   289 #endif
   290 
   291 extern DECLSPEC int SDLCALL SDL_abs(int x);
   292 #ifndef SDL_STDINC_NO_INLINES
   293 #ifdef HAVE_ABS
   294 SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); }
   295 #else
   296 SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); }
   297 #endif
   298 #define SDL_abs SDL_abs_inline
   299 #endif /* !SDL_STDINC_NO_INLINES */
   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 #ifndef SDL_STDINC_NO_INLINES
   311 #ifdef HAVE_CTYPE_H
   312 SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); }
   313 SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); }
   314 SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); }
   315 SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); }
   316 #else
   317 SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); }
   318 SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
   319 SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   320 SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   321 #endif
   322 #define SDL_isdigit SDL_isdigit_inline
   323 #define SDL_isspace SDL_isspace_inline
   324 #define SDL_toupper SDL_toupper_inline
   325 #define SDL_tolower SDL_tolower_inline
   326 #endif /* !SDL_STDINC_NO_INLINES */
   327 
   328 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   329 #if defined(HAVE_MEMSET) && !defined(SDL_STDINC_NO_INLINES)
   330 SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); }
   331 #define SDL_memset SDL_memset_inline
   332 #endif
   333 
   334 #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
   335 #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
   336 
   337 /* !!! FIXME: does this _really_ beat memset() on any modern platform? */
   338 SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len)
   339 {
   340 #if defined(__GNUC__) && defined(i386)
   341     int u0, u1, u2;
   342     __asm__ __volatile__ (
   343         "cld \n\t"
   344         "rep ; stosl \n\t"
   345         : "=&D" (u0), "=&a" (u1), "=&c" (u2)
   346         : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))
   347         : "memory"
   348     );
   349 /* !!! FIXME: amd64? */
   350 #else
   351     size_t _n = (len + 3) / 4;
   352     Uint32 *_p = SDL_static_cast(Uint32 *, dst);
   353     Uint32 _val = (val);
   354     if (len == 0)
   355         return;
   356     switch (len % 4)
   357     {
   358         case 0: do {    *_p++ = _val;
   359         case 3:         *_p++ = _val;
   360         case 2:         *_p++ = _val;
   361         case 1:         *_p++ = _val;
   362         } while ( --_n );
   363     }
   364 #endif
   365 }
   366 
   367 
   368 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
   369 #if !defined(SDL_STDINC_NO_INLINES)
   370 #if defined(__MACOSX__) && defined(HAVE_MEMCPY)
   371 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   372 {
   373     /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   374     return memcpy(dst, src, len);
   375 }
   376 #define SDL_memcpy SDL_memcpy_inline
   377 #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   378 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   379 {
   380     /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
   381     /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
   382     /* !!! FIXME: amd64? */
   383     int u0, u1, u2;
   384     __asm__ __volatile__ (
   385         "cld \n\t"
   386         "rep ; movsl \n\t"
   387         "testb $2,%b4 \n\t"
   388         "je 1f \n\t"
   389         "movsw \n"
   390         "1:\ttestb $1,%b4 \n\t"
   391         "je 2f \n\t"
   392         "movsb \n"
   393         "2:"
   394         : "=&c" (u0), "=&D" (u1), "=&S" (u2)
   395         : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src)
   396         : "memory"
   397     );
   398     return dst;
   399 }
   400 #define SDL_memcpy SDL_memcpy_inline
   401 #elif defined(HAVE_MEMCPY)
   402 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   403 {
   404     return memcpy(dst, src, len);
   405 }
   406 #define SDL_memcpy SDL_memcpy_inline
   407 #elif defined(HAVE_BCOPY)  /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */
   408 SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
   409 {
   410     bcopy(src, dst, len);
   411     return dst;
   412 }
   413 #define SDL_memcpy SDL_memcpy_inline
   414 #endif
   415 #endif /* !SDL_STDINC_NO_INLINES */
   416 
   417 
   418 SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
   419 {
   420 #if 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     int ecx, edi, esi;
   424     __asm__ __volatile__ (
   425         "cld \n\t"
   426         "rep ; movsl \n\t"
   427         : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
   428         : "0" (SDL_static_cast(unsigned, dwords)), "1" (dst), "2" (src)
   429         : "memory"
   430     );
   431     return dst;
   432 #else
   433     return SDL_memcpy(dst, src, dwords * 4);
   434 #endif
   435 }
   436 
   437 extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
   438 #if defined(HAVE_MEMMOVE) && !defined(SDL_STDINC_NO_INLINES)
   439 SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); }
   440 #define SDL_memmove SDL_memmove_inline
   441 #endif
   442 
   443 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   444 #if defined(HAVE_MEMCMP) && !defined(SDL_STDINC_NO_INLINES)
   445 SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
   446 #define SDL_memcmp SDL_memcmp_inline
   447 #endif
   448 
   449 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
   450 #if defined(HAVE_STRLEN) && !defined(SDL_STDINC_NO_INLINES)
   451 SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
   452 #define SDL_strlen SDL_strlen_inline
   453 #endif
   454 
   455 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
   456 #if defined(HAVE_WCSLEN) && !defined(SDL_STDINC_NO_INLINES)
   457 SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
   458 #define SDL_wcslen SDL_wcslen_inline
   459 #endif
   460 
   461 extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   462 #if defined(HAVE_WCSLCPY) && !defined(SDL_STDINC_NO_INLINES)
   463 SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
   464 #define SDL_wcslcpy SDL_wcslcpy_inline
   465 #endif
   466 
   467 extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   468 #if defined(HAVE_WCSLCAT) && !defined(SDL_STDINC_NO_INLINES)
   469 SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
   470 #define SDL_wcslcat SDL_wcslcat_inline
   471 #endif
   472 
   473 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   474 #if defined(HAVE_STRLCPY) && !defined(SDL_STDINC_NO_INLINES)
   475 SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
   476 #define SDL_strlcpy SDL_strlcpy_inline
   477 #else
   478 #endif
   479 
   480 extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
   481 
   482 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   483 #if defined(HAVE_STRLCAT) && !defined(SDL_STDINC_NO_INLINES)
   484 SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
   485 #define SDL_strlcat SDL_strlcat_inline
   486 #endif
   487 
   488 extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
   489 #if defined(HAVE_STRDUP) && !defined(SDL_STDINC_NO_INLINES)
   490 SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
   491 #define SDL_strdup SDL_strdup_inline
   492 #endif
   493 
   494 extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
   495 #if defined(HAVE__STRREV) && !defined(SDL_STDINC_NO_INLINES)
   496 SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
   497 #define SDL_strrev SDL_strrev_inline
   498 #endif
   499 
   500 extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
   501 #if defined(HAVE__STRUPR) && !defined(SDL_STDINC_NO_INLINES)
   502 SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
   503 #define SDL_strupr SDL_strupr_inline
   504 #endif
   505 
   506 extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
   507 #if defined(HAVE__STRLWR) && !defined(SDL_STDINC_NO_INLINES)
   508 SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
   509 #define SDL_strlwr SDL_strlwr_inline
   510 #endif
   511 
   512 extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
   513 #ifndef SDL_STDINC_NO_INLINES
   514 #ifdef HAVE_STRCHR
   515 SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,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 SDL_const_cast(char*,index(str, c)); }
   519 #define SDL_strchr SDL_strchr_inline
   520 #endif
   521 #endif /* !SDL_STDINC_NO_INLINES */
   522 
   523 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
   524 #ifndef SDL_STDINC_NO_INLINES
   525 #ifdef HAVE_STRRCHR
   526 SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,strrchr(str, c)); }
   527 #define SDL_strrchr SDL_strrchr_inline
   528 #elif defined(HAVE_RINDEX)  /* !!! FIXME: is there anywhere that has this but not strrchr? */
   529 SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,rindex(str, c)); }
   530 #define SDL_strrchr SDL_strrchr_inline
   531 #endif
   532 #endif /* !SDL_STDINC_NO_INLINES */
   533 
   534 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
   535 #if defined(HAVE_STRSTR) && !defined(SDL_STDINC_NO_INLINES)
   536 SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return SDL_const_cast(char*,strstr(haystack, needle)); }
   537 #define SDL_strstr SDL_strstr_inline
   538 #endif
   539 
   540 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
   541 #if defined(HAVE__LTOA) && !defined(SDL_STDINC_NO_INLINES)
   542 SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
   543 #define SDL_ltoa SDL_ltoa_inline
   544 #endif
   545 
   546 extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
   547 #ifndef SDL_STDINC_NO_INLINES
   548 #ifdef HAVE_ITOA
   549 SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
   550 #else
   551 SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
   552 #endif
   553 #define SDL_itoa SDL_itoa_inline
   554 #endif /* !SDL_STDINC_NO_INLINES */
   555 
   556 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
   557 #if defined(HAVE__ULTOA) && !defined(SDL_STDINC_NO_INLINES)
   558 SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
   559 #define SDL_ultoa SDL_ultoa_inline
   560 #endif
   561 
   562 extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
   563 #ifndef SDL_STDINC_NO_INLINES
   564 #ifdef HAVE__UITOA
   565 SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
   566 #else
   567 SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
   568 #endif
   569 #define SDL_uitoa SDL_uitoa_inline
   570 #endif /* !SDL_STDINC_NO_INLINES */
   571 
   572 
   573 extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
   574 #if defined(HAVE_STRTOL) && !defined(SDL_STDINC_NO_INLINES)
   575 SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
   576 #define SDL_strtol SDL_strtol_inline
   577 #endif
   578 
   579 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
   580 #if defined(HAVE_STRTOUL) && !defined(SDL_STDINC_NO_INLINES)
   581 SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
   582 #define SDL_strtoul SDL_strtoul_inline
   583 #endif
   584 
   585 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
   586 #if defined(HAVE__I64TOA) && !defined(SDL_STDINC_NO_INLINES)
   587 SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
   588 #define SDL_lltoa SDL_lltoa_inline
   589 #endif
   590 
   591 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
   592 #if defined(HAVE__UI64TOA) && !defined(SDL_STDINC_NO_INLINES)
   593 SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
   594 #define SDL_ulltoa SDL_ulltoa_inline
   595 #endif
   596 
   597 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
   598 #if defined(HAVE_STRTOLL) && !defined(SDL_STDINC_NO_INLINES)
   599 SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
   600 #define SDL_strtoll SDL_strtoll_inline
   601 #endif
   602 
   603 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
   604 #if defined(HAVE_STRTOULL) && !defined(SDL_STDINC_NO_INLINES)
   605 SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
   606 #define SDL_strtoull SDL_strtoull_inline
   607 #endif
   608 
   609 extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
   610 #if defined(HAVE_STRTOD) && !defined(SDL_STDINC_NO_INLINES)
   611 SDL_FORCE_INLINE double SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
   612 #define SDL_strtod SDL_strtod_inline
   613 #endif
   614 
   615 extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
   616 #ifndef SDL_STDINC_NO_INLINES
   617 #ifdef HAVE_ATOI
   618 SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
   619 #else
   620 SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
   621 #endif
   622 #define SDL_atoi SDL_atoi_inline
   623 #endif /* !SDL_STDINC_NO_INLINES */
   624 
   625 extern DECLSPEC double SDLCALL SDL_atof(const char *str);
   626 #ifndef SDL_STDINC_NO_INLINES
   627 #ifdef HAVE_ATOF
   628 SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
   629 #else
   630 SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
   631 #endif
   632 #define SDL_atof SDL_atof_inline
   633 #endif /* !SDL_STDINC_NO_INLINES */
   634 
   635 
   636 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   637 #if defined(HAVE_STRCMP) && !defined(SDL_STDINC_NO_INLINES)
   638 SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
   639 #define SDL_strcmp SDL_strcmp_inline
   640 #endif
   641 
   642 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   643 #if defined(HAVE_STRNCMP) && !defined(SDL_STDINC_NO_INLINES)
   644 SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
   645 #define SDL_strncmp SDL_strncmp_inline
   646 #endif
   647 
   648 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   649 #ifndef SDL_STDINC_NO_INLINES
   650 #ifdef HAVE_STRCASECMP
   651 SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
   652 #define SDL_strcasecmp SDL_strcasecmp_inline
   653 #elif defined(HAVE__STRICMP)
   654 SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
   655 #define SDL_strcasecmp SDL_strcasecmp_inline
   656 #endif
   657 #endif /* !SDL_STDINC_NO_INLINES */
   658 
   659 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
   660 #ifndef SDL_STDINC_NO_INLINES
   661 #ifdef HAVE_STRNCASECMP
   662 SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
   663 #define SDL_strncasecmp SDL_strncasecmp_inline
   664 #elif defined(HAVE__STRNICMP)
   665 SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
   666 #define SDL_strncasecmp SDL_strncasecmp_inline
   667 #endif
   668 #endif /* !SDL_STDINC_NO_INLINES */
   669 
   670 /* Not doing SDL_*_inline functions for these, because of the varargs. */
   671 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   672 #ifdef HAVE_SSCANF
   673 #define SDL_sscanf sscanf
   674 #endif
   675 
   676 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   677 #ifdef HAVE_SNPRINTF
   678 #define SDL_snprintf snprintf
   679 #endif
   680 
   681 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   682 #if defined(HAVE_VSNPRINTF) && !defined(SDL_STDINC_NO_INLINES)
   683 SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); }
   684 #define SDL_vsnprintf SDL_vsnprintf_inline
   685 #endif
   686 
   687 #ifndef HAVE_M_PI
   688 #ifndef M_PI
   689 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   690 #endif
   691 #endif
   692 
   693 extern DECLSPEC double SDLCALL SDL_atan(double x);
   694 #if defined(HAVE_ATAN) && !defined(SDL_STDINC_NO_INLINES)
   695 SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
   696 #define SDL_atan SDL_atan_inline
   697 #endif
   698 
   699 extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
   700 #if defined(HAVE_ATAN2) && !defined(SDL_STDINC_NO_INLINES)
   701 SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
   702 #define SDL_atan2 SDL_atan2_inline
   703 #endif
   704 
   705 extern DECLSPEC double SDLCALL SDL_ceil(double x);
   706 #ifndef SDL_STDINC_NO_INLINES
   707 #ifdef HAVE_CEIL
   708 SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
   709 #else
   710 SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
   711 #endif
   712 #define SDL_ceil SDL_ceil_inline
   713 #endif /* !SDL_STDINC_NO_INLINES */
   714 
   715 extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   716 #if defined(HAVE_COPYSIGN) && !defined(SDL_STDINC_NO_INLINES)
   717 SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
   718 #define SDL_copysign SDL_copysign_inline
   719 #endif
   720 
   721 extern DECLSPEC double SDLCALL SDL_cos(double x);
   722 #if defined(HAVE_COS) && !defined(SDL_STDINC_NO_INLINES)
   723 SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
   724 #define SDL_cos SDL_cos_inline
   725 #endif
   726 
   727 extern DECLSPEC float SDLCALL SDL_cosf(float x);
   728 #ifndef SDL_STDINC_NO_INLINES
   729 #ifdef HAVE_COSF
   730 SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
   731 #else
   732 SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
   733 #endif
   734 #define SDL_cosf SDL_cosf_inline
   735 #endif /* !SDL_STDINC_NO_INLINES */
   736 
   737 extern DECLSPEC double SDLCALL SDL_fabs(double x);
   738 #if defined(HAVE_FABS) && !defined(SDL_STDINC_NO_INLINES)
   739 SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
   740 #define SDL_fabs SDL_fabs_inline
   741 #endif
   742 
   743 extern DECLSPEC double SDLCALL SDL_floor(double x);
   744 #if defined(HAVE_FLOOR) && !defined(SDL_STDINC_NO_INLINES)
   745 SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
   746 #define SDL_floor SDL_floor_inline
   747 #endif
   748 
   749 extern DECLSPEC double SDLCALL SDL_log(double x);
   750 #if defined(HAVE_LOG) && !defined(SDL_STDINC_NO_INLINES)
   751 SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
   752 #define SDL_log SDL_log_inline
   753 #endif
   754 
   755 extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   756 #if defined(HAVE_POW) && !defined(SDL_STDINC_NO_INLINES)
   757 SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
   758 #define SDL_pow SDL_pow_inline
   759 #endif
   760 
   761 extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   762 #if defined(HAVE_SCALBN) && !defined(SDL_STDINC_NO_INLINES)
   763 SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
   764 #define SDL_scalbn SDL_scalbn_inline
   765 #endif
   766 
   767 extern DECLSPEC double SDLCALL SDL_sin(double x);
   768 #if defined(HAVE_SIN) && !defined(SDL_STDINC_NO_INLINES)
   769 SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
   770 #define SDL_sin SDL_sin_inline
   771 #endif
   772 
   773 extern DECLSPEC float SDLCALL SDL_sinf(float x);
   774 #ifndef SDL_STDINC_NO_INLINES
   775 #ifdef HAVE_SINF
   776 SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
   777 #else
   778 SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
   779 #endif
   780 #define SDL_sinf SDL_sinf_inline
   781 #endif /* !SDL_STDINC_NO_INLINES */
   782 
   783 extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   784 #if defined(HAVE_SQRT) && !defined(SDL_STDINC_NO_INLINES)
   785 SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
   786 #define SDL_sqrt SDL_sqrt_inline
   787 #endif
   788 
   789 /* The SDL implementation of iconv() returns these error codes */
   790 #define SDL_ICONV_ERROR     (size_t)-1
   791 #define SDL_ICONV_E2BIG     (size_t)-2
   792 #define SDL_ICONV_EILSEQ    (size_t)-3
   793 #define SDL_ICONV_EINVAL    (size_t)-4
   794 
   795 /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
   796 typedef struct _SDL_iconv_t *SDL_iconv_t;
   797 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   798                                                    const char *fromcode);
   799 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   800 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   801                                          size_t * inbytesleft, char **outbuf,
   802                                          size_t * outbytesleft);
   803 /**
   804  *  This function converts a string between encodings in one pass, returning a
   805  *  string that must be freed with SDL_free() or NULL on error.
   806  */
   807 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   808                                                const char *fromcode,
   809                                                const char *inbuf,
   810                                                size_t inbytesleft);
   811 #define SDL_iconv_utf8_locale(S)    SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   812 #define SDL_iconv_utf8_ucs2(S)      (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   813 #define SDL_iconv_utf8_ucs4(S)      (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   814 
   815 /* Ends C function definitions when using C++ */
   816 #ifdef __cplusplus
   817 }
   818 #endif
   819 #include "close_code.h"
   820 
   821 #endif /* _SDL_stdinc_h */
   822 
   823 /* vi: set ts=4 sw=4 expandtab: */