include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 17 Feb 2009 04:57:39 +0000
changeset 3067 bcd41b269091
parent 3032 77c3e67f0740
child 3234 f8c02d0560d5
permissions -rw-r--r--
Fixed bug #537

Description From esigra 2008-01-07 16:20:21 (-) [reply]

I try to get a clean compile for a project using SDL. But I get warnings
from SDL headers when I use -Wold-style-cast. This is especially bad
because I plan to build the software with -Werror=old-style-cast when we
have switched over to GCC 4.2, which has that option.

But this problem can be fixed in the SDL headers. I checked out the SVN
version and made some patches. See the attached patch.
     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         switch (_count % 4) {			\
   323         case 0: do {    *_p++ = _val;		\
   324         case 3:         *_p++ = _val;		\
   325         case 2:         *_p++ = _val;		\
   326         case 1:         *_p++ = _val;		\
   327 		} while ( --_n );		\
   328 	}					\
   329 } while(0)
   330 #endif
   331 
   332 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   333 #if defined(__MACH__) && defined(__APPLE__)
   334 #define SDL_memcpy(dst, src, len) memcpy(dst, src, len)
   335 #elif defined(__GNUC__) && defined(i386)
   336 #define SDL_memcpy(dst, src, len)					  \
   337 do {									  \
   338 	int u0, u1, u2;						  	  \
   339 	__asm__ __volatile__ (						  \
   340 		"cld\n\t"						  \
   341 		"rep ; movsl\n\t"					  \
   342 		"testb $2,%b4\n\t"					  \
   343 		"je 1f\n\t"						  \
   344 		"movsw\n"						  \
   345 		"1:\ttestb $1,%b4\n\t"					  \
   346 		"je 2f\n\t"						  \
   347 		"movsb\n"						  \
   348 		"2:"							  \
   349 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   350 		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
   351 		: "memory" );						  \
   352 } while(0)
   353 #endif
   354 #ifndef SDL_memcpy
   355 #ifdef HAVE_MEMCPY
   356 #define SDL_memcpy      memcpy
   357 #elif defined(HAVE_BCOPY)
   358 #define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
   359 #else
   360 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
   361                                          size_t len);
   362 #endif
   363 #endif
   364 
   365 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   366 #if defined(__MACH__) && defined(__APPLE__)
   367 #define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len)*4)
   368 #elif defined(__GNUC__) && defined(i386)
   369 #define SDL_memcpy4(dst, src, len)				\
   370 do {								\
   371 	int ecx, edi, esi;					\
   372 	__asm__ __volatile__ (					\
   373 		"cld\n\t"					\
   374 		"rep ; movsl"					\
   375 		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   376 		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
   377 		: "memory" );					\
   378 } while(0)
   379 #endif
   380 #ifndef SDL_memcpy4
   381 #define SDL_memcpy4(dst, src, len)	SDL_memcpy(dst, src, (len) << 2)
   382 #endif
   383 
   384 #if defined(__GNUC__) && defined(i386)
   385 #define SDL_revcpy(dst, src, len)			\
   386 do {							\
   387 	int u0, u1, u2;					\
   388 	char *dstp = SDL_static_cast(char *, dst);			\
   389 	char *srcp = SDL_static_cast(char *, src);			\
   390 	int n = (len);					\
   391 	if ( n >= 4 ) {					\
   392 	__asm__ __volatile__ (				\
   393 		"std\n\t"				\
   394 		"rep ; movsl\n\t"			\
   395 		"cld\n\t"				\
   396 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)	\
   397 		: "0" (n >> 2),				\
   398 		  "1" (dstp+(n-4)), "2" (srcp+(n-4))	\
   399 		: "memory" );				\
   400 	}						\
   401 	switch (n & 3) {				\
   402 		case 3: dstp[2] = srcp[2];		\
   403 		case 2: dstp[1] = srcp[1];		\
   404 		case 1: dstp[0] = srcp[0];		\
   405 			break;				\
   406 		default:				\
   407 			break;				\
   408 	}						\
   409 } while(0)
   410 #endif
   411 #ifndef SDL_revcpy
   412 extern DECLSPEC void *SDLCALL SDL_revcpy(void *dst, const void *src,
   413                                          size_t len);
   414 #endif
   415 
   416 #ifdef HAVE_MEMMOVE
   417 #define SDL_memmove     memmove
   418 #elif defined(HAVE_BCOPY)
   419 #define SDL_memmove(d, s, n)	bcopy((s), (d), (n))
   420 #else
   421 #define SDL_memmove(dst, src, len)			\
   422 do {							\
   423 	if ( dst < src ) {				\
   424 		SDL_memcpy(dst, src, len);		\
   425 	} else {					\
   426 		SDL_revcpy(dst, src, len);		\
   427 	}						\
   428 } while(0)
   429 #endif
   430 
   431 #ifdef HAVE_MEMCMP
   432 #define SDL_memcmp      memcmp
   433 #else
   434 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
   435                                        size_t len);
   436 #endif
   437 
   438 #ifdef HAVE_STRLEN
   439 #define SDL_strlen      strlen
   440 #else
   441 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
   442 #endif
   443 
   444 #ifdef HAVE_WCSLEN
   445 #define SDL_wcslen      wcslen
   446 #else
   447 #if !defined(wchar_t) && defined(__NINTENDODS__)
   448 #define wchar_t short           /* TODO: figure out why libnds doesn't have this */
   449 #endif
   450 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
   451 #endif
   452 
   453 #ifdef HAVE_STRLCPY
   454 #define SDL_strlcpy     strlcpy
   455 #else
   456 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
   457                                            size_t maxlen);
   458 #endif
   459 
   460 #ifdef HAVE_STRLCAT
   461 #define SDL_strlcat    strlcat
   462 #else
   463 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
   464                                            size_t maxlen);
   465 #endif
   466 
   467 #ifdef HAVE_STRDUP
   468 #define SDL_strdup     strdup
   469 #else
   470 extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
   471 #endif
   472 
   473 #ifdef HAVE__STRREV
   474 #define SDL_strrev      _strrev
   475 #else
   476 extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
   477 #endif
   478 
   479 #ifdef HAVE__STRUPR
   480 #define SDL_strupr      _strupr
   481 #else
   482 extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
   483 #endif
   484 
   485 #ifdef HAVE__STRLWR
   486 #define SDL_strlwr      _strlwr
   487 #else
   488 extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
   489 #endif
   490 
   491 #ifdef HAVE_STRCHR
   492 #define SDL_strchr      strchr
   493 #elif defined(HAVE_INDEX)
   494 #define SDL_strchr      index
   495 #else
   496 extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
   497 #endif
   498 
   499 #ifdef HAVE_STRRCHR
   500 #define SDL_strrchr     strrchr
   501 #elif defined(HAVE_RINDEX)
   502 #define SDL_strrchr     rindex
   503 #else
   504 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
   505 #endif
   506 
   507 #ifdef HAVE_STRSTR
   508 #define SDL_strstr      strstr
   509 #else
   510 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
   511                                          const char *needle);
   512 #endif
   513 
   514 #ifdef HAVE_ITOA
   515 #define SDL_itoa        itoa
   516 #else
   517 #define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
   518 #endif
   519 
   520 #ifdef HAVE__LTOA
   521 #define SDL_ltoa        _ltoa
   522 #else
   523 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
   524 #endif
   525 
   526 #ifdef HAVE__UITOA
   527 #define SDL_uitoa       _uitoa
   528 #else
   529 #define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
   530 #endif
   531 
   532 #ifdef HAVE__ULTOA
   533 #define SDL_ultoa       _ultoa
   534 #else
   535 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
   536                                         int radix);
   537 #endif
   538 
   539 #ifdef HAVE_STRTOL
   540 #define SDL_strtol      strtol
   541 #else
   542 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
   543                                         int base);
   544 #endif
   545 
   546 #ifdef HAVE_STRTOUL
   547 #define SDL_strtoul      strtoul
   548 #else
   549 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
   550                                                   char **endp, int base);
   551 #endif
   552 
   553 #ifdef SDL_HAS_64BIT_TYPE
   554 
   555 #ifdef HAVE__I64TOA
   556 #define SDL_lltoa       _i64toa
   557 #else
   558 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
   559                                         int radix);
   560 #endif
   561 
   562 #ifdef HAVE__UI64TOA
   563 #define SDL_ulltoa      _ui64toa
   564 #else
   565 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
   566                                          int radix);
   567 #endif
   568 
   569 #ifdef HAVE_STRTOLL
   570 #define SDL_strtoll     strtoll
   571 #else
   572 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
   573                                            int base);
   574 #endif
   575 
   576 #ifdef HAVE_STRTOULL
   577 #define SDL_strtoull     strtoull
   578 #else
   579 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
   580                                             int base);
   581 #endif
   582 
   583 #endif /* SDL_HAS_64BIT_TYPE */
   584 
   585 #ifdef HAVE_STRTOD
   586 #define SDL_strtod      strtod
   587 #else
   588 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
   589 #endif
   590 
   591 #ifdef HAVE_ATOI
   592 #define SDL_atoi        atoi
   593 #else
   594 #define SDL_atoi(X)     SDL_strtol(X, NULL, 0)
   595 #endif
   596 
   597 #ifdef HAVE_ATOF
   598 #define SDL_atof        atof
   599 #else
   600 #define SDL_atof(X)     SDL_strtod(X, NULL)
   601 #endif
   602 
   603 #ifdef HAVE_STRCMP
   604 #define SDL_strcmp      strcmp
   605 #else
   606 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   607 #endif
   608 
   609 #ifdef HAVE_STRNCMP
   610 #define SDL_strncmp     strncmp
   611 #else
   612 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
   613                                         size_t maxlen);
   614 #endif
   615 
   616 #ifdef HAVE_STRCASECMP
   617 #define SDL_strcasecmp  strcasecmp
   618 #elif defined(HAVE__STRICMP)
   619 #define SDL_strcasecmp  _stricmp
   620 #else
   621 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
   622                                            const char *str2);
   623 #endif
   624 
   625 #ifdef HAVE_STRNCASECMP
   626 #define SDL_strncasecmp strncasecmp
   627 #elif defined(HAVE__STRNICMP)
   628 #define SDL_strncasecmp _strnicmp
   629 #else
   630 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
   631                                             const char *str2, size_t maxlen);
   632 #endif
   633 
   634 #ifdef HAVE_SSCANF
   635 #define SDL_sscanf      sscanf
   636 #else
   637 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
   638                                        ...);
   639 #endif
   640 
   641 #ifdef HAVE_SNPRINTF
   642 #define SDL_snprintf    snprintf
   643 #else
   644 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
   645                                          const char *fmt, ...);
   646 #endif
   647 
   648 #ifdef HAVE_VSNPRINTF
   649 #define SDL_vsnprintf   vsnprintf
   650 #else
   651 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
   652                                           const char *fmt, va_list ap);
   653 #endif
   654 
   655 #ifndef HAVE_M_PI
   656 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   657 #endif
   658 
   659 #ifdef HAVE_CEIL
   660 #define SDL_ceil        ceil
   661 #else
   662 #define SDL_ceil(x)     ((double)(int)((x)+0.5))
   663 #endif
   664 
   665 #ifdef HAVE_COPYSIGN
   666 #define SDL_copysign    copysign
   667 #else
   668 extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
   669 #endif
   670 
   671 #ifdef HAVE_COS
   672 #define SDL_cos         cos
   673 #else
   674 extern DECLSPEC double SDLCALL SDL_cos(double x);
   675 #endif
   676 
   677 #ifdef HAVE_COSF
   678 #define SDL_cosf        cosf
   679 #else
   680 #define SDL_cosf(x) (float)SDL_cos((double)x)
   681 #endif
   682 
   683 #ifdef HAVE_FABS
   684 #define SDL_fabs        fabs
   685 #else
   686 extern DECLSPEC double SDLCALL SDL_fabs(double x);
   687 #endif
   688 
   689 #ifdef HAVE_FLOOR
   690 #define SDL_floor       floor
   691 #else
   692 extern DECLSPEC double SDLCALL SDL_floor(double x);
   693 #endif
   694 
   695 #ifdef HAVE_LOG
   696 #define SDL_log         log
   697 #else
   698 extern DECLSPEC double SDLCALL SDL_log(double x);
   699 #endif
   700 
   701 #ifdef HAVE_POW
   702 #define SDL_pow         pow
   703 #else
   704 extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
   705 #endif
   706 
   707 #ifdef HAVE_SCALBN
   708 #define SDL_scalbn      scalbn
   709 #else
   710 extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
   711 #endif
   712 
   713 #ifdef HAVE_SIN
   714 #define SDL_sin         sin
   715 #else
   716 extern DECLSPEC double SDLCALL SDL_sin(double x);
   717 #endif
   718 
   719 #ifdef HAVE_SINF
   720 #define SDL_sinf        sinf
   721 #else
   722 #define SDL_sinf(x) (float)SDL_sin((double)x)
   723 #endif
   724 
   725 #ifdef HAVE_SQRT
   726 #define SDL_sqrt        sqrt
   727 #else
   728 extern DECLSPEC double SDLCALL SDL_sqrt(double x);
   729 #endif
   730 
   731 /* The SDL implementation of iconv() returns these error codes */
   732 #define SDL_ICONV_ERROR		(size_t)-1
   733 #define SDL_ICONV_E2BIG		(size_t)-2
   734 #define SDL_ICONV_EILSEQ	(size_t)-3
   735 #define SDL_ICONV_EINVAL	(size_t)-4
   736 
   737 #ifdef HAVE_ICONV
   738 #define SDL_iconv_t     iconv_t
   739 #define SDL_iconv_open  iconv_open
   740 #define SDL_iconv_close iconv_close
   741 #else
   742 typedef struct _SDL_iconv_t *SDL_iconv_t;
   743 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
   744                                                    const char *fromcode);
   745 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
   746 #endif
   747 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
   748                                          size_t * inbytesleft, char **outbuf,
   749                                          size_t * outbytesleft);
   750 /* This function converts a string between encodings in one pass, returning a
   751    string that must be freed with SDL_free() or NULL on error.
   752 */
   753 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   754                                                const char *fromcode,
   755                                                const char *inbuf,
   756                                                size_t inbytesleft);
   757 #define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   758 #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
   759 #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
   760 
   761 /* Ends C function definitions when using C++ */
   762 #ifdef __cplusplus
   763 /* *INDENT-OFF* */
   764 }
   765 /* *INDENT-ON* */
   766 #endif
   767 #include "close_code.h"
   768 
   769 #endif /* _SDL_stdinc_h */
   770 
   771 /* vi: set ts=4 sw=4 expandtab: */