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