include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 12 Mar 2011 13:21:57 -0800
changeset 5481 22dfc3958dc3
parent 5325 b9c224e16859
child 5512 56ab281d7d3e
permissions -rw-r--r--
Fixed so code will compile with SDL_config_minimal.h
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  *  \file SDL_stdinc.h
    25  *  
    26  *  This is a general header that includes C language support.
    27  */
    28 
    29 #ifndef _SDL_stdinc_h
    30 #define _SDL_stdinc_h
    31 
    32 #include "SDL_config.h"
    33 
    34 
    35 #ifdef HAVE_SYS_TYPES_H
    36 #include <sys/types.h>
    37 #endif
    38 #ifdef HAVE_STDIO_H
    39 #include <stdio.h>
    40 #endif
    41 #if defined(STDC_HEADERS)
    42 # include <stdlib.h>
    43 # include <stddef.h>
    44 # include <stdarg.h>
    45 #else
    46 # if defined(HAVE_STDLIB_H)
    47 #  include <stdlib.h>
    48 # elif defined(HAVE_MALLOC_H)
    49 #  include <malloc.h>
    50 # endif
    51 # if defined(HAVE_STDDEF_H)
    52 #  include <stddef.h>
    53 # endif
    54 # if defined(HAVE_STDARG_H)
    55 #  include <stdarg.h>
    56 # endif
    57 #endif
    58 #ifdef HAVE_STRING_H
    59 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
    60 #  include <memory.h>
    61 # endif
    62 # include <string.h>
    63 #endif
    64 #ifdef HAVE_STRINGS_H
    65 # include <strings.h>
    66 #endif
    67 #if defined(HAVE_INTTYPES_H)
    68 # include <inttypes.h>
    69 #elif defined(HAVE_STDINT_H)
    70 # include <stdint.h>
    71 #endif
    72 #ifdef HAVE_CTYPE_H
    73 # include <ctype.h>
    74 #endif
    75 #ifdef HAVE_MATH_H
    76 # include <math.h>
    77 #endif
    78 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
    79 # include <iconv.h>
    80 #endif
    81 
    82 /**
    83  *  The number of elements in an array.
    84  */
    85 #define SDL_arraysize(array)	(sizeof(array)/sizeof(array[0]))
    86 #define SDL_TABLESIZE(table)	SDL_arraysize(table)
    87 
    88 /**
    89  *  \name Cast operators
    90  *  
    91  *  Use proper C++ casts when compiled as C++ to be compatible with the option
    92  *  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
    93  */
    94 /*@{*/
    95 #ifdef __cplusplus
    96 #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
    97 #define SDL_static_cast(type, expression) static_cast<type>(expression)
    98 #else
    99 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
   100 #define SDL_static_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 #ifdef SDL_HAS_64BIT_TYPE
   148 /**
   149  * \brief A signed 64-bit integer type.
   150  * \warning On platforms without any sort of 64-bit datatype, this is equivalent to Sint32!
   151  */
   152 typedef int64_t Sint64;
   153 /**
   154  * \brief An unsigned 64-bit integer type.
   155  * \warning On platforms without any sort of 64-bit datatype, this is equivalent to Uint32!
   156  */
   157 typedef uint64_t Uint64;
   158 #else
   159 /* This is really just a hack to prevent the compiler from complaining */
   160 typedef Sint32 Sint64;
   161 typedef Uint32 Uint64;
   162 #endif
   163 
   164 /*@}*//*Basic data types*/
   165 
   166 
   167 #define SDL_COMPILE_TIME_ASSERT(name, x)               \
   168        typedef int SDL_dummy_ ## name[(x) * 2 - 1]
   169 /** \cond */
   170 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   171 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
   172 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
   173 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
   174 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
   175 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
   176 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
   177 #ifdef SDL_HAS_64BIT_TYPE
   178 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
   179 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
   180 #endif
   181 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   182 /** \endcond */
   183 
   184 /* Check to make sure enums are the size of ints, for structure packing.
   185    For both Watcom C/C++ and Borland C/C++ the compiler option that makes
   186    enums having the size of an int must be enabled.
   187    This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
   188 */
   189 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */
   190 #ifdef __MWERKS__
   191 #pragma enumsalwaysint on
   192 #endif
   193 
   194 /** \cond */
   195 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   196 #if !defined(__NINTENDODS__) && !defined(__ANDROID__) 
   197    /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
   198 typedef enum
   199 {
   200     DUMMY_ENUM_VALUE
   201 } SDL_DUMMY_ENUM;
   202 
   203 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
   204 #endif
   205 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   206 /** \endcond */
   207 
   208 #include "begin_code.h"
   209 /* Set up for C function definitions, even when using C++ */
   210 #ifdef __cplusplus
   211 /* *INDENT-OFF* */
   212 extern "C" {
   213 /* *INDENT-ON* */
   214 #endif
   215 
   216 #ifdef HAVE_MALLOC
   217 #define SDL_malloc	malloc
   218 #else
   219 extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
   220 #endif
   221 
   222 #ifdef HAVE_CALLOC
   223 #define SDL_calloc	calloc
   224 #else
   225 extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
   226 #endif
   227 
   228 #ifdef HAVE_REALLOC
   229 #define SDL_realloc	realloc
   230 #else
   231 extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
   232 #endif
   233 
   234 #ifdef HAVE_FREE
   235 #define SDL_free	free
   236 #else
   237 extern DECLSPEC void SDLCALL SDL_free(void *mem);
   238 #endif
   239 
   240 #if defined(HAVE_ALLOCA) && !defined(alloca)
   241 # if defined(HAVE_ALLOCA_H)
   242 #  include <alloca.h>
   243 # elif defined(__GNUC__)
   244 #  define alloca __builtin_alloca
   245 # elif defined(_MSC_VER)
   246 #  include <malloc.h>
   247 #  define alloca _alloca
   248 # elif defined(__WATCOMC__)
   249 #  include <malloc.h>
   250 # elif defined(__BORLANDC__)
   251 #  include <malloc.h>
   252 # elif defined(__DMC__)
   253 #  include <stdlib.h>
   254 # elif defined(__AIX__)
   255 #pragma alloca
   256 # elif defined(__MRC__)
   257 void *alloca(unsigned);
   258 # else
   259 char *alloca();
   260 # endif
   261 #endif
   262 #ifdef HAVE_ALLOCA
   263 #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*(count))
   264 #define SDL_stack_free(data)
   265 #else
   266 #define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*(count))
   267 #define SDL_stack_free(data)            SDL_free(data)
   268 #endif
   269 
   270 #ifdef HAVE_GETENV
   271 #define SDL_getenv	getenv
   272 #else
   273 extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   274 #endif
   275 
   276 /* SDL_putenv() has moved to SDL_compat. */
   277 #ifdef HAVE_SETENV
   278 #define SDL_setenv	setenv
   279 #else
   280 extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value,
   281                                        int overwrite);
   282 #endif
   283 
   284 #ifdef HAVE_QSORT
   285 #define SDL_qsort	qsort
   286 #else
   287 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
   288                                        int (*compare) (const void *,
   289                                                        const void *));
   290 #endif
   291 
   292 #ifdef HAVE_ABS
   293 #define SDL_abs		abs
   294 #else
   295 #define SDL_abs(X)	((X) < 0 ? -(X) : (X))
   296 #endif
   297 
   298 #define SDL_min(x, y)	(((x) < (y)) ? (x) : (y))
   299 #define SDL_max(x, y)	(((x) > (y)) ? (x) : (y))
   300 
   301 #ifdef HAVE_CTYPE_H
   302 #define SDL_isdigit(X)  isdigit(X)
   303 #define SDL_isspace(X)  isspace(X)
   304 #define SDL_toupper(X)  toupper(X)
   305 #define SDL_tolower(X)  tolower(X)
   306 #else
   307 #define SDL_isdigit(X)  (((X) >= '0') && ((X) <= '9'))
   308 #define SDL_isspace(X)  (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
   309 #define SDL_toupper(X)  (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
   310 #define SDL_tolower(X)  (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
   311 #endif
   312 
   313 #ifdef HAVE_MEMSET
   314 #define SDL_memset      memset
   315 #else
   316 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   317 #endif
   318 #define SDL_zero(x)	SDL_memset(&(x), 0, sizeof((x)))
   319 #define SDL_zerop(x)	SDL_memset((x), 0, sizeof(*(x)))
   320 
   321 #if defined(__GNUC__) && defined(i386)
   322 #define SDL_memset4(dst, val, len)				\
   323 do {								\
   324 	int u0, u1, u2;						\
   325 	__asm__ __volatile__ (					\
   326 		"cld\n\t"					\
   327 		"rep ; stosl\n\t"				\
   328 		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
   329 		: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))	\
   330 		: "memory" );					\
   331 } while(0)
   332 #endif
   333 #ifndef SDL_memset4
   334 #define SDL_memset4(dst, val, len)		\
   335 do {						\
   336 	unsigned _count = (len);		\
   337 	unsigned _n = (_count + 3) / 4;		\
   338 	Uint32 *_p = SDL_static_cast(Uint32 *, dst);		\
   339 	Uint32 _val = (val);			\
   340 	if (len == 0) break;			\
   341         switch (_count % 4) {			\
   342         case 0: do {    *_p++ = _val;		\
   343         case 3:         *_p++ = _val;		\
   344         case 2:         *_p++ = _val;		\
   345         case 1:         *_p++ = _val;		\
   346 		} while ( --_n );		\
   347 	}					\
   348 } while(0)
   349 #endif
   350 
   351 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   352 #if defined(__MACOSX__)
   353 #define SDL_memcpy      memcpy
   354 #elif defined(__GNUC__) && defined(i386)
   355 #define SDL_memcpy(dst, src, len)					  \
   356 do {									  \
   357 	int u0, u1, u2;						  	  \
   358 	__asm__ __volatile__ (						  \
   359 		"cld\n\t"						  \
   360 		"rep ; movsl\n\t"					  \
   361 		"testb $2,%b4\n\t"					  \
   362 		"je 1f\n\t"						  \
   363 		"movsw\n"						  \
   364 		"1:\ttestb $1,%b4\n\t"					  \
   365 		"je 2f\n\t"						  \
   366 		"movsb\n"						  \
   367 		"2:"							  \
   368 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   369 		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
   370 		: "memory" );						  \
   371 } while(0)
   372 #endif
   373 #ifndef SDL_memcpy
   374 #ifdef HAVE_MEMCPY
   375 #define SDL_memcpy      memcpy
   376 #elif defined(HAVE_BCOPY)
   377 #define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
   378 #else
   379 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
   380                                          size_t len);
   381 #endif
   382 #endif
   383 
   384 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   385 #if defined(__MACOSX__)
   386 #define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   387 #elif defined(__GNUC__) && defined(i386)
   388 #define SDL_memcpy4(dst, src, len)				\
   389 do {								\
   390 	int ecx, edi, esi;					\
   391 	__asm__ __volatile__ (					\
   392 		"cld\n\t"					\
   393 		"rep ; movsl"					\
   394 		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   395 		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
   396 		: "memory" );					\
   397 } while(0)
   398 #endif
   399 #ifndef SDL_memcpy4
   400 #define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   401 #endif
   402 
   403 #ifdef HAVE_MEMMOVE
   404 #define SDL_memmove     memmove
   405 #else
   406 extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src,
   407                                           size_t len);
   408 #endif
   409 
   410 #ifdef HAVE_MEMCMP
   411 #define SDL_memcmp      memcmp
   412 #else
   413 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
   414                                        size_t len);
   415 #endif
   416 
   417 #ifdef HAVE_STRLEN
   418 #define SDL_strlen      strlen
   419 #else
   420 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
   421 #endif
   422 
   423 #ifdef HAVE_WCSLEN
   424 #define SDL_wcslen      wcslen
   425 #else
   426 #if !defined(wchar_t) && defined(__NINTENDODS__)
   427 #define wchar_t short           /* TODO: figure out why libnds doesn't have this */
   428 #endif
   429 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
   430 #endif
   431 
   432 #ifdef HAVE_WCSLCPY
   433 #define SDL_wcslcpy      wcslcpy
   434 #else
   435 extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   436 #endif
   437 
   438 #ifdef HAVE_WCSLCAT
   439 #define SDL_wcslcat      wcslcat
   440 #else
   441 extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   442 #endif
   443 
   444 
   445 #ifdef HAVE_STRLCPY
   446 #define SDL_strlcpy     strlcpy
   447 #else
   448 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
   449                                            size_t maxlen);
   450 #endif
   451 
   452 extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src,
   453                                             size_t dst_bytes);
   454 
   455 #ifdef HAVE_STRLCAT
   456 #define SDL_strlcat    strlcat
   457 #else
   458 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
   459                                            size_t maxlen);
   460 #endif
   461 
   462 #ifdef HAVE_STRDUP
   463 #define SDL_strdup     strdup
   464 #else
   465 extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
   466 #endif
   467 
   468 #ifdef HAVE__STRREV
   469 #define SDL_strrev      _strrev
   470 #else
   471 extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
   472 #endif
   473 
   474 #ifdef HAVE__STRUPR
   475 #define SDL_strupr      _strupr
   476 #else
   477 extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
   478 #endif
   479 
   480 #ifdef HAVE__STRLWR
   481 #define SDL_strlwr      _strlwr
   482 #else
   483 extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
   484 #endif
   485 
   486 #ifdef HAVE_STRCHR
   487 #define SDL_strchr      strchr
   488 #elif defined(HAVE_INDEX)
   489 #define SDL_strchr      index
   490 #else
   491 extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
   492 #endif
   493 
   494 #ifdef HAVE_STRRCHR
   495 #define SDL_strrchr     strrchr
   496 #elif defined(HAVE_RINDEX)
   497 #define SDL_strrchr     rindex
   498 #else
   499 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
   500 #endif
   501 
   502 #ifdef HAVE_STRSTR
   503 #define SDL_strstr      strstr
   504 #else
   505 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
   506                                          const char *needle);
   507 #endif
   508 
   509 #ifdef HAVE_ITOA
   510 #define SDL_itoa        itoa
   511 #else
   512 #define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
   513 #endif
   514 
   515 #ifdef HAVE__LTOA
   516 #define SDL_ltoa        _ltoa
   517 #else
   518 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
   519 #endif
   520 
   521 #ifdef HAVE__UITOA
   522 #define SDL_uitoa       _uitoa
   523 #else
   524 #define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
   525 #endif
   526 
   527 #ifdef HAVE__ULTOA
   528 #define SDL_ultoa       _ultoa
   529 #else
   530 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
   531                                         int radix);
   532 #endif
   533 
   534 #ifdef HAVE_STRTOL
   535 #define SDL_strtol      strtol
   536 #else
   537 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
   538                                         int base);
   539 #endif
   540 
   541 #ifdef HAVE_STRTOUL
   542 #define SDL_strtoul      strtoul
   543 #else
   544 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
   545                                                   char **endp, int base);
   546 #endif
   547 
   548 #ifdef SDL_HAS_64BIT_TYPE
   549 
   550 #ifdef HAVE__I64TOA
   551 #define SDL_lltoa       _i64toa
   552 #else
   553 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
   554                                         int radix);
   555 #endif
   556 
   557 #ifdef HAVE__UI64TOA
   558 #define SDL_ulltoa      _ui64toa
   559 #else
   560 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
   561                                          int radix);
   562 #endif
   563 
   564 #ifdef HAVE_STRTOLL
   565 #define SDL_strtoll     strtoll
   566 #else
   567 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
   568                                            int base);
   569 #endif
   570 
   571 #ifdef HAVE_STRTOULL
   572 #define SDL_strtoull     strtoull
   573 #else
   574 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
   575                                             int base);
   576 #endif
   577 
   578 #endif /* SDL_HAS_64BIT_TYPE */
   579 
   580 #ifdef HAVE_STRTOD
   581 #define SDL_strtod      strtod
   582 #else
   583 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
   584 #endif
   585 
   586 #ifdef HAVE_ATOI
   587 #define SDL_atoi        atoi
   588 #else
   589 #define SDL_atoi(X)     SDL_strtol(X, NULL, 0)
   590 #endif
   591 
   592 #ifdef HAVE_ATOF
   593 #define SDL_atof        atof
   594 #else
   595 #define SDL_atof(X)     SDL_strtod(X, NULL)
   596 #endif
   597 
   598 #ifdef HAVE_STRCMP
   599 #define SDL_strcmp      strcmp
   600 #else
   601 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   602 #endif
   603 
   604 #ifdef HAVE_STRNCMP
   605 #define SDL_strncmp     strncmp
   606 #else
   607 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
   608                                         size_t maxlen);
   609 #endif
   610 
   611 #ifdef HAVE_STRCASECMP
   612 #define SDL_strcasecmp  strcasecmp
   613 #elif defined(HAVE__STRICMP)
   614 #define SDL_strcasecmp  _stricmp
   615 #else
   616 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
   617                                            const char *str2);
   618 #endif
   619 
   620 #ifdef HAVE_STRNCASECMP
   621 #define SDL_strncasecmp strncasecmp
   622 #elif defined(HAVE__STRNICMP)
   623 #define SDL_strncasecmp _strnicmp
   624 #else
   625 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
   626                                             const char *str2, size_t maxlen);
   627 #endif
   628 
   629 #ifdef HAVE_SSCANF
   630 #define SDL_sscanf      sscanf
   631 #else
   632 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
   633                                        ...);
   634 #endif
   635 
   636 #ifdef HAVE_SNPRINTF
   637 #define SDL_snprintf    snprintf
   638 #else
   639 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
   640                                          const char *fmt, ...);
   641 #endif
   642 
   643 #ifdef HAVE_VSNPRINTF
   644 #define SDL_vsnprintf   vsnprintf
   645 #else
   646 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
   647                                           const char *fmt, va_list ap);
   648 #endif
   649 
   650 #ifndef HAVE_M_PI
   651 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   652 #endif
   653 
   654 #ifdef HAVE_ATAN
   655 #define SDL_atan        atan
   656 #else
   657 extern DECLSPEC double SDLCALL SDL_atan(double x);
   658 #endif
   659 
   660 #ifdef HAVE_ATAN2
   661 #define SDL_atan2       atan2
   662 #else
   663 extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
   664 #endif
   665 
   666 #ifdef HAVE_CEIL
   667 #define SDL_ceil        ceil
   668 #else
   669 #define SDL_ceil(x)     ((double)(int)((x)+0.5))
   670 #endif
   671 
   672 #ifdef HAVE_COPYSIGN
   673 #define SDL_copysign    copysign
   674 #else
   675 extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   676 #endif
   677 
   678 #ifdef HAVE_COS
   679 #define SDL_cos         cos
   680 #else
   681 extern DECLSPEC double SDLCALL SDL_cos(double x);
   682 #endif
   683 
   684 #ifdef HAVE_COSF
   685 #define SDL_cosf        cosf
   686 #else
   687 #define SDL_cosf(x) (float)SDL_cos((double)x)
   688 #endif
   689 
   690 #ifdef HAVE_FABS
   691 #define SDL_fabs        fabs
   692 #else
   693 extern DECLSPEC double SDLCALL SDL_fabs(double x);
   694 #endif
   695 
   696 #ifdef HAVE_FLOOR
   697 #define SDL_floor       floor
   698 #else
   699 extern DECLSPEC double SDLCALL SDL_floor(double x);
   700 #endif
   701 
   702 #ifdef HAVE_LOG
   703 #define SDL_log         log
   704 #else
   705 extern DECLSPEC double SDLCALL SDL_log(double x);
   706 #endif
   707 
   708 #ifdef HAVE_POW
   709 #define SDL_pow         pow
   710 #else
   711 extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   712 #endif
   713 
   714 #ifdef HAVE_SCALBN
   715 #define SDL_scalbn      scalbn
   716 #else
   717 extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   718 #endif
   719 
   720 #ifdef HAVE_SIN
   721 #define SDL_sin         sin
   722 #else
   723 extern DECLSPEC double SDLCALL SDL_sin(double x);
   724 #endif
   725 
   726 #ifdef HAVE_SINF
   727 #define SDL_sinf        sinf
   728 #else
   729 #define SDL_sinf(x) (float)SDL_sin((double)x)
   730 #endif
   731 
   732 #ifdef HAVE_SQRT
   733 #define SDL_sqrt        sqrt
   734 #else
   735 extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   736 #endif
   737 
   738 /* The SDL implementation of iconv() returns these error codes */
   739 #define SDL_ICONV_ERROR		(size_t)-1
   740 #define SDL_ICONV_E2BIG		(size_t)-2
   741 #define SDL_ICONV_EILSEQ	(size_t)-3
   742 #define SDL_ICONV_EINVAL	(size_t)-4
   743 
   744 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
   745 #define SDL_iconv_t     iconv_t
   746 #define SDL_iconv_open  iconv_open
   747 #define SDL_iconv_close iconv_close
   748 #else
   749 typedef struct _SDL_iconv_t *SDL_iconv_t;
   750 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   751                                                    const char *fromcode);
   752 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   753 #endif
   754 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   755                                          size_t * inbytesleft, char **outbuf,
   756                                          size_t * outbytesleft);
   757 /**
   758  *  This function converts a string between encodings in one pass, returning a
   759  *  string that must be freed with SDL_free() or NULL on error.
   760  */
   761 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   762                                                const char *fromcode,
   763                                                const char *inbuf,
   764                                                size_t inbytesleft);
   765 #define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   766 #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
   767 #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
   768 
   769 /* Ends C function definitions when using C++ */
   770 #ifdef __cplusplus
   771 /* *INDENT-OFF* */
   772 }
   773 /* *INDENT-ON* */
   774 #endif
   775 #include "close_code.h"
   776 
   777 #endif /* _SDL_stdinc_h */
   778 
   779 /* vi: set ts=4 sw=4 expandtab: */