include/SDL_stdinc.h
author Ryan C. Gordon <icculus@icculus.org>
Wed, 21 Nov 2012 23:00:06 -0500
changeset 6680 9d3df1f5c542
parent 6627 23b7cef164ae
child 6885 700f1b25f77f
child 8337 4a67a3cca43d
permissions -rw-r--r--
Removed some tab chars.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 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 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */
   179 #ifdef __MWERKS__
   180 #pragma enumsalwaysint on
   181 #endif
   182 
   183 /** \cond */
   184 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   185 #if !defined(__NINTENDODS__) && !defined(__ANDROID__) 
   186    /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
   187 typedef enum
   188 {
   189     DUMMY_ENUM_VALUE
   190 } SDL_DUMMY_ENUM;
   191 
   192 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
   193 #endif
   194 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   195 /** \endcond */
   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 #ifdef HAVE_MALLOC
   206 #define SDL_malloc	malloc
   207 #else
   208 extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
   209 #endif
   210 
   211 #ifdef HAVE_CALLOC
   212 #define SDL_calloc	calloc
   213 #else
   214 extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
   215 #endif
   216 
   217 #ifdef HAVE_REALLOC
   218 #define SDL_realloc	realloc
   219 #else
   220 extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
   221 #endif
   222 
   223 #ifdef HAVE_FREE
   224 #define SDL_free	free
   225 #else
   226 extern DECLSPEC void SDLCALL SDL_free(void *mem);
   227 #endif
   228 
   229 #if defined(HAVE_ALLOCA) && !defined(alloca)
   230 # if defined(HAVE_ALLOCA_H)
   231 #  include <alloca.h>
   232 # elif defined(__GNUC__)
   233 #  define alloca __builtin_alloca
   234 # elif defined(_MSC_VER)
   235 #  include <malloc.h>
   236 #  define alloca _alloca
   237 # elif defined(__WATCOMC__)
   238 #  include <malloc.h>
   239 # elif defined(__BORLANDC__)
   240 #  include <malloc.h>
   241 # elif defined(__DMC__)
   242 #  include <stdlib.h>
   243 # elif defined(__AIX__)
   244 #pragma alloca
   245 # elif defined(__MRC__)
   246 void *alloca(unsigned);
   247 # else
   248 char *alloca();
   249 # endif
   250 #endif
   251 #ifdef HAVE_ALLOCA
   252 #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*(count))
   253 #define SDL_stack_free(data)
   254 #else
   255 #define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*(count))
   256 #define SDL_stack_free(data)            SDL_free(data)
   257 #endif
   258 
   259 #ifdef HAVE_GETENV
   260 #define SDL_getenv	getenv
   261 #else
   262 extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   263 #endif
   264 
   265 /* SDL_putenv() has moved to SDL_compat. */
   266 #ifdef HAVE_SETENV
   267 #define SDL_setenv	setenv
   268 #else
   269 extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value,
   270                                        int overwrite);
   271 #endif
   272 
   273 #ifdef HAVE_QSORT
   274 #define SDL_qsort	qsort
   275 #else
   276 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
   277                                        int (*compare) (const void *,
   278                                                        const void *));
   279 #endif
   280 
   281 #ifdef HAVE_ABS
   282 #define SDL_abs		abs
   283 #else
   284 #define SDL_abs(X)	((X) < 0 ? -(X) : (X))
   285 #endif
   286 
   287 #define SDL_min(x, y)	(((x) < (y)) ? (x) : (y))
   288 #define SDL_max(x, y)	(((x) > (y)) ? (x) : (y))
   289 
   290 #ifdef HAVE_CTYPE_H
   291 #define SDL_isdigit(X)  isdigit(X)
   292 #define SDL_isspace(X)  isspace(X)
   293 #define SDL_toupper(X)  toupper(X)
   294 #define SDL_tolower(X)  tolower(X)
   295 #else
   296 #define SDL_isdigit(X)  (((X) >= '0') && ((X) <= '9'))
   297 #define SDL_isspace(X)  (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
   298 #define SDL_toupper(X)  (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
   299 #define SDL_tolower(X)  (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
   300 #endif
   301 
   302 #ifdef HAVE_MEMSET
   303 #define SDL_memset      memset
   304 #else
   305 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   306 #endif
   307 #define SDL_zero(x)	SDL_memset(&(x), 0, sizeof((x)))
   308 #define SDL_zerop(x)	SDL_memset((x), 0, sizeof(*(x)))
   309 
   310 #if defined(__GNUC__) && defined(i386)
   311 #define SDL_memset4(dst, val, len)				\
   312 do {								\
   313 	int u0, u1, u2;						\
   314 	__asm__ __volatile__ (					\
   315 		"cld\n\t"					\
   316 		"rep ; stosl\n\t"				\
   317 		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
   318 		: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))	\
   319 		: "memory" );					\
   320 } while(0)
   321 #endif
   322 #ifndef SDL_memset4
   323 #define SDL_memset4(dst, val, len)		\
   324 do {						\
   325 	unsigned _count = (len);		\
   326 	unsigned _n = (_count + 3) / 4;		\
   327 	Uint32 *_p = SDL_static_cast(Uint32 *, dst);		\
   328 	Uint32 _val = (val);			\
   329 	if (len == 0) break;			\
   330         switch (_count % 4) {			\
   331         case 0: do {    *_p++ = _val;		\
   332         case 3:         *_p++ = _val;		\
   333         case 2:         *_p++ = _val;		\
   334         case 1:         *_p++ = _val;		\
   335 		} while ( --_n );		\
   336 	}					\
   337 } while(0)
   338 #endif
   339 
   340 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   341 #if defined(__MACOSX__)
   342 #define SDL_memcpy      memcpy
   343 #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   344 #define SDL_memcpy(dst, src, len)					  \
   345 do {									  \
   346 	int u0, u1, u2;						  	  \
   347 	__asm__ __volatile__ (						  \
   348 		"cld\n\t"						  \
   349 		"rep ; movsl\n\t"					  \
   350 		"testb $2,%b4\n\t"					  \
   351 		"je 1f\n\t"						  \
   352 		"movsw\n"						  \
   353 		"1:\ttestb $1,%b4\n\t"					  \
   354 		"je 2f\n\t"						  \
   355 		"movsb\n"						  \
   356 		"2:"							  \
   357 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   358 		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
   359 		: "memory" );						  \
   360 } while(0)
   361 #endif
   362 #ifndef SDL_memcpy
   363 #ifdef HAVE_MEMCPY
   364 #define SDL_memcpy      memcpy
   365 #elif defined(HAVE_BCOPY)
   366 #define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
   367 #else
   368 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
   369                                          size_t len);
   370 #endif
   371 #endif
   372 
   373 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   374 #if defined(__MACOSX__)
   375 #define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   376 #elif defined(__GNUC__) && defined(i386)
   377 #define SDL_memcpy4(dst, src, len)				\
   378 do {								\
   379 	int ecx, edi, esi;					\
   380 	__asm__ __volatile__ (					\
   381 		"cld\n\t"					\
   382 		"rep ; movsl"					\
   383 		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   384 		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
   385 		: "memory" );					\
   386 } while(0)
   387 #endif
   388 #ifndef SDL_memcpy4
   389 #define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   390 #endif
   391 
   392 #ifdef HAVE_MEMMOVE
   393 #define SDL_memmove     memmove
   394 #else
   395 extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src,
   396                                           size_t len);
   397 #endif
   398 
   399 #ifdef HAVE_MEMCMP
   400 #define SDL_memcmp      memcmp
   401 #else
   402 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
   403                                        size_t len);
   404 #endif
   405 
   406 #ifdef HAVE_STRLEN
   407 #define SDL_strlen      strlen
   408 #else
   409 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
   410 #endif
   411 
   412 #ifdef HAVE_WCSLEN
   413 #define SDL_wcslen      wcslen
   414 #else
   415 #if !defined(wchar_t) && defined(__NINTENDODS__)
   416 #define wchar_t short           /* TODO: figure out why libnds doesn't have this */
   417 #endif
   418 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
   419 #endif
   420 
   421 #ifdef HAVE_WCSLCPY
   422 #define SDL_wcslcpy      wcslcpy
   423 #else
   424 extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   425 #endif
   426 
   427 #ifdef HAVE_WCSLCAT
   428 #define SDL_wcslcat      wcslcat
   429 #else
   430 extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   431 #endif
   432 
   433 
   434 #ifdef HAVE_STRLCPY
   435 #define SDL_strlcpy     strlcpy
   436 #else
   437 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
   438                                            size_t maxlen);
   439 #endif
   440 
   441 extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src,
   442                                             size_t dst_bytes);
   443 
   444 #ifdef HAVE_STRLCAT
   445 #define SDL_strlcat    strlcat
   446 #else
   447 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
   448                                            size_t maxlen);
   449 #endif
   450 
   451 #ifdef HAVE_STRDUP
   452 #define SDL_strdup     strdup
   453 #else
   454 extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
   455 #endif
   456 
   457 #ifdef HAVE__STRREV
   458 #define SDL_strrev      _strrev
   459 #else
   460 extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
   461 #endif
   462 
   463 #ifdef HAVE__STRUPR
   464 #define SDL_strupr      _strupr
   465 #else
   466 extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
   467 #endif
   468 
   469 #ifdef HAVE__STRLWR
   470 #define SDL_strlwr      _strlwr
   471 #else
   472 extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
   473 #endif
   474 
   475 #ifdef HAVE_STRCHR
   476 #define SDL_strchr      strchr
   477 #elif defined(HAVE_INDEX)
   478 #define SDL_strchr      index
   479 #else
   480 extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
   481 #endif
   482 
   483 #ifdef HAVE_STRRCHR
   484 #define SDL_strrchr     strrchr
   485 #elif defined(HAVE_RINDEX)
   486 #define SDL_strrchr     rindex
   487 #else
   488 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
   489 #endif
   490 
   491 #ifdef HAVE_STRSTR
   492 #define SDL_strstr      strstr
   493 #else
   494 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
   495                                          const char *needle);
   496 #endif
   497 
   498 #ifdef HAVE_ITOA
   499 #define SDL_itoa        itoa
   500 #else
   501 #define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
   502 #endif
   503 
   504 #ifdef HAVE__LTOA
   505 #define SDL_ltoa        _ltoa
   506 #else
   507 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
   508 #endif
   509 
   510 #ifdef HAVE__UITOA
   511 #define SDL_uitoa       _uitoa
   512 #else
   513 #define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
   514 #endif
   515 
   516 #ifdef HAVE__ULTOA
   517 #define SDL_ultoa       _ultoa
   518 #else
   519 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
   520                                         int radix);
   521 #endif
   522 
   523 #ifdef HAVE_STRTOL
   524 #define SDL_strtol      strtol
   525 #else
   526 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
   527                                         int base);
   528 #endif
   529 
   530 #ifdef HAVE_STRTOUL
   531 #define SDL_strtoul      strtoul
   532 #else
   533 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
   534                                                   char **endp, int base);
   535 #endif
   536 
   537 #ifdef HAVE__I64TOA
   538 #define SDL_lltoa       _i64toa
   539 #else
   540 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
   541                                         int radix);
   542 #endif
   543 
   544 #ifdef HAVE__UI64TOA
   545 #define SDL_ulltoa      _ui64toa
   546 #else
   547 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
   548                                          int radix);
   549 #endif
   550 
   551 #ifdef HAVE_STRTOLL
   552 #define SDL_strtoll     strtoll
   553 #else
   554 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
   555                                            int base);
   556 #endif
   557 
   558 #ifdef HAVE_STRTOULL
   559 #define SDL_strtoull     strtoull
   560 #else
   561 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
   562                                             int base);
   563 #endif
   564 
   565 #ifdef HAVE_STRTOD
   566 #define SDL_strtod      strtod
   567 #else
   568 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
   569 #endif
   570 
   571 #ifdef HAVE_ATOI
   572 #define SDL_atoi        atoi
   573 #else
   574 #define SDL_atoi(X)     SDL_strtol(X, NULL, 0)
   575 #endif
   576 
   577 #ifdef HAVE_ATOF
   578 #define SDL_atof        atof
   579 #else
   580 #define SDL_atof(X)     SDL_strtod(X, NULL)
   581 #endif
   582 
   583 #ifdef HAVE_STRCMP
   584 #define SDL_strcmp      strcmp
   585 #else
   586 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   587 #endif
   588 
   589 #ifdef HAVE_STRNCMP
   590 #define SDL_strncmp     strncmp
   591 #else
   592 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
   593                                         size_t maxlen);
   594 #endif
   595 
   596 #ifdef HAVE_STRCASECMP
   597 #define SDL_strcasecmp  strcasecmp
   598 #elif defined(HAVE__STRICMP)
   599 #define SDL_strcasecmp  _stricmp
   600 #else
   601 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
   602                                            const char *str2);
   603 #endif
   604 
   605 #ifdef HAVE_STRNCASECMP
   606 #define SDL_strncasecmp strncasecmp
   607 #elif defined(HAVE__STRNICMP)
   608 #define SDL_strncasecmp _strnicmp
   609 #else
   610 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
   611                                             const char *str2, size_t maxlen);
   612 #endif
   613 
   614 #ifdef HAVE_SSCANF
   615 #define SDL_sscanf      sscanf
   616 #else
   617 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
   618                                        ...);
   619 #endif
   620 
   621 #ifdef HAVE_SNPRINTF
   622 #define SDL_snprintf    snprintf
   623 #else
   624 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
   625                                          const char *fmt, ...);
   626 #endif
   627 
   628 #ifdef HAVE_VSNPRINTF
   629 #define SDL_vsnprintf   vsnprintf
   630 #else
   631 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
   632                                           const char *fmt, va_list ap);
   633 #endif
   634 
   635 #ifndef HAVE_M_PI
   636 #ifndef M_PI
   637 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   638 #endif
   639 #endif
   640 
   641 #ifdef HAVE_ATAN
   642 #define SDL_atan        atan
   643 #else
   644 extern DECLSPEC double SDLCALL SDL_atan(double x);
   645 #endif
   646 
   647 #ifdef HAVE_ATAN2
   648 #define SDL_atan2       atan2
   649 #else
   650 extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
   651 #endif
   652 
   653 #ifdef HAVE_CEIL
   654 #define SDL_ceil        ceil
   655 #else
   656 #define SDL_ceil(x)     ((double)(int)((x)+0.5))
   657 #endif
   658 
   659 #ifdef HAVE_COPYSIGN
   660 #define SDL_copysign    copysign
   661 #else
   662 extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   663 #endif
   664 
   665 #ifdef HAVE_COS
   666 #define SDL_cos         cos
   667 #else
   668 extern DECLSPEC double SDLCALL SDL_cos(double x);
   669 #endif
   670 
   671 #ifdef HAVE_COSF
   672 #define SDL_cosf        cosf
   673 #else
   674 #define SDL_cosf(x) (float)SDL_cos((double)x)
   675 #endif
   676 
   677 #ifdef HAVE_FABS
   678 #define SDL_fabs        fabs
   679 #else
   680 extern DECLSPEC double SDLCALL SDL_fabs(double x);
   681 #endif
   682 
   683 #ifdef HAVE_FLOOR
   684 #define SDL_floor       floor
   685 #else
   686 extern DECLSPEC double SDLCALL SDL_floor(double x);
   687 #endif
   688 
   689 #ifdef HAVE_LOG
   690 #define SDL_log         log
   691 #else
   692 extern DECLSPEC double SDLCALL SDL_log(double x);
   693 #endif
   694 
   695 #ifdef HAVE_POW
   696 #define SDL_pow         pow
   697 #else
   698 extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   699 #endif
   700 
   701 #ifdef HAVE_SCALBN
   702 #define SDL_scalbn      scalbn
   703 #else
   704 extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   705 #endif
   706 
   707 #ifdef HAVE_SIN
   708 #define SDL_sin         sin
   709 #else
   710 extern DECLSPEC double SDLCALL SDL_sin(double x);
   711 #endif
   712 
   713 #ifdef HAVE_SINF
   714 #define SDL_sinf        sinf
   715 #else
   716 #define SDL_sinf(x) (float)SDL_sin((double)x)
   717 #endif
   718 
   719 #ifdef HAVE_SQRT
   720 #define SDL_sqrt        sqrt
   721 #else
   722 extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   723 #endif
   724 
   725 /* The SDL implementation of iconv() returns these error codes */
   726 #define SDL_ICONV_ERROR		(size_t)-1
   727 #define SDL_ICONV_E2BIG		(size_t)-2
   728 #define SDL_ICONV_EILSEQ	(size_t)-3
   729 #define SDL_ICONV_EINVAL	(size_t)-4
   730 
   731 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
   732 #define SDL_iconv_t     iconv_t
   733 #define SDL_iconv_open  iconv_open
   734 #define SDL_iconv_close iconv_close
   735 #else
   736 typedef struct _SDL_iconv_t *SDL_iconv_t;
   737 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   738                                                    const char *fromcode);
   739 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   740 #endif
   741 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   742                                          size_t * inbytesleft, char **outbuf,
   743                                          size_t * outbytesleft);
   744 /**
   745  *  This function converts a string between encodings in one pass, returning a
   746  *  string that must be freed with SDL_free() or NULL on error.
   747  */
   748 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   749                                                const char *fromcode,
   750                                                const char *inbuf,
   751                                                size_t inbytesleft);
   752 #define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   753 #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   754 #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   755 
   756 /* Ends C function definitions when using C++ */
   757 #ifdef __cplusplus
   758 /* *INDENT-OFF* */
   759 }
   760 /* *INDENT-ON* */
   761 #endif
   762 #include "close_code.h"
   763 
   764 #endif /* _SDL_stdinc_h */
   765 
   766 /* vi: set ts=4 sw=4 expandtab: */