include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 07 Aug 2009 10:20:10 +0000
changeset 3234 f8c02d0560d5
parent 3067 bcd41b269091
child 3294 470d0a416aa7
permissions -rw-r--r--
Fixed bug #746

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