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