include/SDL_stdinc.h
author David Ludwig <dludwig@pobox.com>
Mon, 01 Apr 2013 21:33:06 -0400
changeset 8453 499aa167ea79
parent 8439 14d94a8a9fb6
child 8460 f483e8bdae3c
permissions -rw-r--r--
WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file SDL_stdinc.h
    24  *  
    25  *  This is a general header that includes C language support.
    26  */
    27 
    28 #ifndef _SDL_stdinc_h
    29 #define _SDL_stdinc_h
    30 
    31 #include "SDL_config.h"
    32 
    33 
    34 #ifdef HAVE_SYS_TYPES_H
    35 #include <sys/types.h>
    36 #endif
    37 #ifdef HAVE_STDIO_H
    38 #include <stdio.h>
    39 #endif
    40 #if defined(STDC_HEADERS)
    41 # include <stdlib.h>
    42 # include <stddef.h>
    43 # include <stdarg.h>
    44 #else
    45 # if defined(HAVE_STDLIB_H)
    46 #  include <stdlib.h>
    47 # elif defined(HAVE_MALLOC_H)
    48 #  include <malloc.h>
    49 # endif
    50 # if defined(HAVE_STDDEF_H)
    51 #  include <stddef.h>
    52 # endif
    53 # if defined(HAVE_STDARG_H)
    54 #  include <stdarg.h>
    55 # endif
    56 #endif
    57 #ifdef HAVE_STRING_H
    58 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
    59 #  include <memory.h>
    60 # endif
    61 # include <string.h>
    62 #endif
    63 #ifdef HAVE_STRINGS_H
    64 # include <strings.h>
    65 #endif
    66 #if defined(HAVE_INTTYPES_H)
    67 # include <inttypes.h>
    68 #elif defined(HAVE_STDINT_H)
    69 # include <stdint.h>
    70 #endif
    71 #ifdef HAVE_CTYPE_H
    72 # include <ctype.h>
    73 #endif
    74 #ifdef HAVE_MATH_H
    75 # if defined(__WINRT__)
    76 /* Defining _USE_MATH_DEFINES is required to get M_PI to be defined on
    77    Windows RT.  See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
    78    for more information.
    79 */
    80 #  define _USE_MATH_DEFINES
    81 # endif
    82 # include <math.h>
    83 #endif
    84 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
    85 # include <iconv.h>
    86 #endif
    87 
    88 /**
    89  *  The number of elements in an array.
    90  */
    91 #define SDL_arraysize(array)	(sizeof(array)/sizeof(array[0]))
    92 #define SDL_TABLESIZE(table)	SDL_arraysize(table)
    93 
    94 /**
    95  *  \name Cast operators
    96  *  
    97  *  Use proper C++ casts when compiled as C++ to be compatible with the option
    98  *  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
    99  */
   100 /*@{*/
   101 #ifdef __cplusplus
   102 #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
   103 #define SDL_static_cast(type, expression) static_cast<type>(expression)
   104 #else
   105 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
   106 #define SDL_static_cast(type, expression) ((type)(expression))
   107 #endif
   108 /*@}*//*Cast operators*/
   109 
   110 /* Define a four character code as a Uint32 */
   111 #define SDL_FOURCC(A, B, C, D) \
   112     ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
   113      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
   114      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
   115      (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
   116 
   117 /**
   118  *  \name Basic data types
   119  */
   120 /*@{*/
   121 
   122 typedef enum
   123 {
   124     SDL_FALSE = 0,
   125     SDL_TRUE = 1
   126 } SDL_bool;
   127 
   128 /**
   129  * \brief A signed 8-bit integer type.
   130  */
   131 typedef int8_t Sint8;
   132 /**
   133  * \brief An unsigned 8-bit integer type.
   134  */
   135 typedef uint8_t Uint8;
   136 /**
   137  * \brief A signed 16-bit integer type.
   138  */
   139 typedef int16_t Sint16;
   140 /**
   141  * \brief An unsigned 16-bit integer type.
   142  */
   143 typedef uint16_t Uint16;
   144 /**
   145  * \brief A signed 32-bit integer type.
   146  */
   147 typedef int32_t Sint32;
   148 /**
   149  * \brief An unsigned 32-bit integer type.
   150  */
   151 typedef uint32_t Uint32;
   152 
   153 /**
   154  * \brief A signed 64-bit integer type.
   155  */
   156 typedef int64_t Sint64;
   157 /**
   158  * \brief An unsigned 64-bit integer type.
   159  */
   160 typedef uint64_t Uint64;
   161 
   162 /*@}*//*Basic data types*/
   163 
   164 
   165 #define SDL_COMPILE_TIME_ASSERT(name, x)               \
   166        typedef int SDL_dummy_ ## name[(x) * 2 - 1]
   167 /** \cond */
   168 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   169 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
   170 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
   171 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
   172 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
   173 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
   174 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
   175 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
   176 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
   177 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   178 /** \endcond */
   179 
   180 /* Check to make sure enums are the size of ints, for structure packing.
   181    For both Watcom C/C++ and Borland C/C++ the compiler option that makes
   182    enums having the size of an int must be enabled.
   183    This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
   184 */
   185 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */
   186 #ifdef __MWERKS__
   187 #pragma enumsalwaysint on
   188 #endif
   189 
   190 /** \cond */
   191 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
   192 #if !defined(__NINTENDODS__) && !defined(__ANDROID__) 
   193    /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
   194 typedef enum
   195 {
   196     DUMMY_ENUM_VALUE
   197 } SDL_DUMMY_ENUM;
   198 
   199 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
   200 #endif
   201 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
   202 /** \endcond */
   203 
   204 #include "begin_code.h"
   205 /* Set up for C function definitions, even when using C++ */
   206 #ifdef __cplusplus
   207 /* *INDENT-OFF* */
   208 extern "C" {
   209 /* *INDENT-ON* */
   210 #endif
   211 
   212 #ifdef HAVE_MALLOC
   213 #define SDL_malloc	malloc
   214 #else
   215 extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
   216 #endif
   217 
   218 #ifdef HAVE_CALLOC
   219 #define SDL_calloc	calloc
   220 #else
   221 extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
   222 #endif
   223 
   224 #ifdef HAVE_REALLOC
   225 #define SDL_realloc	realloc
   226 #else
   227 extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
   228 #endif
   229 
   230 #ifdef HAVE_FREE
   231 #define SDL_free	free
   232 #else
   233 extern DECLSPEC void SDLCALL SDL_free(void *mem);
   234 #endif
   235 
   236 #if defined(HAVE_ALLOCA) && !defined(alloca)
   237 # if defined(HAVE_ALLOCA_H)
   238 #  include <alloca.h>
   239 # elif defined(__GNUC__)
   240 #  define alloca __builtin_alloca
   241 # elif defined(_MSC_VER)
   242 #  include <malloc.h>
   243 #  define alloca _alloca
   244 # elif defined(__WATCOMC__)
   245 #  include <malloc.h>
   246 # elif defined(__BORLANDC__)
   247 #  include <malloc.h>
   248 # elif defined(__DMC__)
   249 #  include <stdlib.h>
   250 # elif defined(__AIX__)
   251 #pragma alloca
   252 # elif defined(__MRC__)
   253 void *alloca(unsigned);
   254 # else
   255 char *alloca();
   256 # endif
   257 #endif
   258 #ifdef HAVE_ALLOCA
   259 #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*(count))
   260 #define SDL_stack_free(data)
   261 #else
   262 #define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*(count))
   263 #define SDL_stack_free(data)            SDL_free(data)
   264 #endif
   265 
   266 #ifdef HAVE_GETENV
   267 #define SDL_getenv	getenv
   268 #else
   269 extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
   270 #endif
   271 
   272 /* SDL_putenv() has moved to SDL_compat. */
   273 #ifdef HAVE_SETENV
   274 #define SDL_setenv	setenv
   275 #else
   276 extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value,
   277                                        int overwrite);
   278 #endif
   279 
   280 #ifdef HAVE_QSORT
   281 #define SDL_qsort	qsort
   282 #else
   283 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
   284                                        int (*compare) (const void *,
   285                                                        const void *));
   286 #endif
   287 
   288 #ifdef HAVE_ABS
   289 #define SDL_abs		abs
   290 #else
   291 #define SDL_abs(X)	((X) < 0 ? -(X) : (X))
   292 #endif
   293 
   294 #define SDL_min(x, y)	(((x) < (y)) ? (x) : (y))
   295 #define SDL_max(x, y)	(((x) > (y)) ? (x) : (y))
   296 
   297 #ifdef HAVE_CTYPE_H
   298 #define SDL_isdigit(X)  isdigit(X)
   299 #define SDL_isspace(X)  isspace(X)
   300 #define SDL_toupper(X)  toupper(X)
   301 #define SDL_tolower(X)  tolower(X)
   302 #else
   303 #define SDL_isdigit(X)  (((X) >= '0') && ((X) <= '9'))
   304 #define SDL_isspace(X)  (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
   305 #define SDL_toupper(X)  (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
   306 #define SDL_tolower(X)  (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
   307 #endif
   308 
   309 #ifdef HAVE_MEMSET
   310 #define SDL_memset      memset
   311 #else
   312 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
   313 #endif
   314 #define SDL_zero(x)	SDL_memset(&(x), 0, sizeof((x)))
   315 #define SDL_zerop(x)	SDL_memset((x), 0, sizeof(*(x)))
   316 
   317 #if defined(__GNUC__) && defined(i386)
   318 #define SDL_memset4(dst, val, len)				\
   319 do {								\
   320 	int u0, u1, u2;						\
   321 	__asm__ __volatile__ (					\
   322 		"cld\n\t"					\
   323 		"rep ; stosl\n\t"				\
   324 		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
   325 		: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))	\
   326 		: "memory" );					\
   327 } while(0)
   328 #endif
   329 #ifndef SDL_memset4
   330 #define SDL_memset4(dst, val, len)		\
   331 do {						\
   332 	unsigned _count = (len);		\
   333 	unsigned _n = (_count + 3) / 4;		\
   334 	Uint32 *_p = SDL_static_cast(Uint32 *, dst);		\
   335 	Uint32 _val = (val);			\
   336 	if (len == 0) break;			\
   337         switch (_count % 4) {			\
   338         case 0: do {    *_p++ = _val;		\
   339         case 3:         *_p++ = _val;		\
   340         case 2:         *_p++ = _val;		\
   341         case 1:         *_p++ = _val;		\
   342 		} while ( --_n );		\
   343 	}					\
   344 } while(0)
   345 #endif
   346 
   347 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   348 #if defined(__MACOSX__)
   349 #define SDL_memcpy      memcpy
   350 #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
   351 #define SDL_memcpy(dst, src, len)					  \
   352 do {									  \
   353 	int u0, u1, u2;						  	  \
   354 	__asm__ __volatile__ (						  \
   355 		"cld\n\t"						  \
   356 		"rep ; movsl\n\t"					  \
   357 		"testb $2,%b4\n\t"					  \
   358 		"je 1f\n\t"						  \
   359 		"movsw\n"						  \
   360 		"1:\ttestb $1,%b4\n\t"					  \
   361 		"je 2f\n\t"						  \
   362 		"movsb\n"						  \
   363 		"2:"							  \
   364 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   365 		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
   366 		: "memory" );						  \
   367 } while(0)
   368 #endif
   369 #ifndef SDL_memcpy
   370 #ifdef HAVE_MEMCPY
   371 #define SDL_memcpy      memcpy
   372 #elif defined(HAVE_BCOPY)
   373 #define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
   374 #else
   375 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
   376                                          size_t len);
   377 #endif
   378 #endif
   379 
   380 /* We can count on memcpy existing on Mac OS X and being well-tuned. */
   381 #if defined(__MACOSX__)
   382 #define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   383 #elif defined(__GNUC__) && defined(i386)
   384 #define SDL_memcpy4(dst, src, len)				\
   385 do {								\
   386 	int ecx, edi, esi;					\
   387 	__asm__ __volatile__ (					\
   388 		"cld\n\t"					\
   389 		"rep ; movsl"					\
   390 		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   391 		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
   392 		: "memory" );					\
   393 } while(0)
   394 #endif
   395 #ifndef SDL_memcpy4
   396 #define SDL_memcpy4(dst, src, len)	SDL_memcpy((dst), (src), (len) << 2)
   397 #endif
   398 
   399 #ifdef HAVE_MEMMOVE
   400 #define SDL_memmove     memmove
   401 #else
   402 extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src,
   403                                           size_t len);
   404 #endif
   405 
   406 #ifdef HAVE_MEMCMP
   407 #define SDL_memcmp      memcmp
   408 #else
   409 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
   410                                        size_t len);
   411 #endif
   412 
   413 #ifdef HAVE_STRLEN
   414 #define SDL_strlen      strlen
   415 #else
   416 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
   417 #endif
   418 
   419 #ifdef HAVE_WCSLEN
   420 #define SDL_wcslen      wcslen
   421 #else
   422 #if !defined(wchar_t) && defined(__NINTENDODS__)
   423 #define wchar_t short           /* TODO: figure out why libnds doesn't have this */
   424 #endif
   425 extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
   426 #endif
   427 
   428 #ifdef HAVE_WCSLCPY
   429 #define SDL_wcslcpy      wcslcpy
   430 #else
   431 extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
   432 #endif
   433 
   434 #ifdef HAVE_WCSLCAT
   435 #define SDL_wcslcat      wcslcat
   436 #else
   437 extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
   438 #endif
   439 
   440 
   441 #ifdef HAVE_STRLCPY
   442 #define SDL_strlcpy     strlcpy
   443 #else
   444 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
   445                                            size_t maxlen);
   446 #endif
   447 
   448 extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src,
   449                                             size_t dst_bytes);
   450 
   451 #ifdef HAVE_STRLCAT
   452 #define SDL_strlcat    strlcat
   453 #else
   454 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
   455                                            size_t maxlen);
   456 #endif
   457 
   458 #ifdef HAVE_STRDUP
   459 #define SDL_strdup     strdup
   460 #else
   461 extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
   462 #endif
   463 
   464 #ifdef HAVE__STRREV
   465 #define SDL_strrev      _strrev
   466 #else
   467 extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
   468 #endif
   469 
   470 #ifdef HAVE__STRUPR
   471 #define SDL_strupr      _strupr
   472 #else
   473 extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
   474 #endif
   475 
   476 #ifdef HAVE__STRLWR
   477 #define SDL_strlwr      _strlwr
   478 #else
   479 extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
   480 #endif
   481 
   482 #ifdef HAVE_STRCHR
   483 #define SDL_strchr      strchr
   484 #elif defined(HAVE_INDEX)
   485 #define SDL_strchr      index
   486 #else
   487 extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
   488 #endif
   489 
   490 #ifdef HAVE_STRRCHR
   491 #define SDL_strrchr     strrchr
   492 #elif defined(HAVE_RINDEX)
   493 #define SDL_strrchr     rindex
   494 #else
   495 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
   496 #endif
   497 
   498 #ifdef HAVE_STRSTR
   499 #define SDL_strstr      strstr
   500 #else
   501 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
   502                                          const char *needle);
   503 #endif
   504 
   505 #ifdef HAVE_ITOA
   506 #define SDL_itoa        itoa
   507 #else
   508 #define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
   509 #endif
   510 
   511 #ifdef HAVE__LTOA
   512 #define SDL_ltoa        _ltoa
   513 #else
   514 extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
   515 #endif
   516 
   517 #ifdef HAVE__UITOA
   518 #define SDL_uitoa       _uitoa
   519 #else
   520 #define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
   521 #endif
   522 
   523 #ifdef HAVE__ULTOA
   524 #define SDL_ultoa       _ultoa
   525 #else
   526 extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
   527                                         int radix);
   528 #endif
   529 
   530 #ifdef HAVE_STRTOL
   531 #define SDL_strtol      strtol
   532 #else
   533 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
   534                                         int base);
   535 #endif
   536 
   537 #ifdef HAVE_STRTOUL
   538 #define SDL_strtoul      strtoul
   539 #else
   540 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
   541                                                   char **endp, int base);
   542 #endif
   543 
   544 #ifdef HAVE__I64TOA
   545 #define SDL_lltoa       _i64toa
   546 #else
   547 extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
   548                                         int radix);
   549 #endif
   550 
   551 #ifdef HAVE__UI64TOA
   552 #define SDL_ulltoa      _ui64toa
   553 #else
   554 extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
   555                                          int radix);
   556 #endif
   557 
   558 #ifdef HAVE_STRTOLL
   559 #define SDL_strtoll     strtoll
   560 #else
   561 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
   562                                            int base);
   563 #endif
   564 
   565 #ifdef HAVE_STRTOULL
   566 #define SDL_strtoull     strtoull
   567 #else
   568 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
   569                                             int base);
   570 #endif
   571 
   572 #ifdef HAVE_STRTOD
   573 #define SDL_strtod      strtod
   574 #else
   575 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
   576 #endif
   577 
   578 #ifdef HAVE_ATOI
   579 #define SDL_atoi        atoi
   580 #else
   581 #define SDL_atoi(X)     SDL_strtol(X, NULL, 0)
   582 #endif
   583 
   584 #ifdef HAVE_ATOF
   585 #define SDL_atof        atof
   586 #else
   587 #define SDL_atof(X)     SDL_strtod(X, NULL)
   588 #endif
   589 
   590 #ifdef HAVE_STRCMP
   591 #define SDL_strcmp      strcmp
   592 #else
   593 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   594 #endif
   595 
   596 #ifdef HAVE_STRNCMP
   597 #define SDL_strncmp     strncmp
   598 #else
   599 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
   600                                         size_t maxlen);
   601 #endif
   602 
   603 #ifdef HAVE_STRCASECMP
   604 #define SDL_strcasecmp  strcasecmp
   605 #elif defined(HAVE__STRICMP)
   606 #define SDL_strcasecmp  _stricmp
   607 #else
   608 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
   609                                            const char *str2);
   610 #endif
   611 
   612 #ifdef HAVE_STRNCASECMP
   613 #define SDL_strncasecmp strncasecmp
   614 #elif defined(HAVE__STRNICMP)
   615 #define SDL_strncasecmp _strnicmp
   616 #else
   617 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
   618                                             const char *str2, size_t maxlen);
   619 #endif
   620 
   621 #ifdef HAVE_SSCANF
   622 #define SDL_sscanf      sscanf
   623 #else
   624 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
   625                                        ...);
   626 #endif
   627 
   628 #ifdef HAVE_SNPRINTF
   629 #define SDL_snprintf    snprintf
   630 #else
   631 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
   632                                          const char *fmt, ...);
   633 #endif
   634 
   635 #ifdef HAVE_VSNPRINTF
   636 #define SDL_vsnprintf   vsnprintf
   637 #else
   638 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
   639                                           const char *fmt, va_list ap);
   640 #endif
   641 
   642 #ifndef HAVE_M_PI
   643 #ifndef M_PI
   644 #define M_PI    3.14159265358979323846264338327950288   /* pi */
   645 #endif
   646 #endif
   647 
   648 #ifdef HAVE_ATAN
   649 #define SDL_atan        atan
   650 #else
   651 extern DECLSPEC double SDLCALL SDL_atan(double x);
   652 #endif
   653 
   654 #ifdef HAVE_ATAN2
   655 #define SDL_atan2       atan2
   656 #else
   657 extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
   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 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
   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 /**
   752  *  This function converts a string between encodings in one pass, returning a
   753  *  string that must be freed with SDL_free() or NULL on error.
   754  */
   755 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
   756                                                const char *fromcode,
   757                                                const char *inbuf,
   758                                                size_t inbytesleft);
   759 #define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
   760 #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   761 #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
   762 
   763 /* Ends C function definitions when using C++ */
   764 #ifdef __cplusplus
   765 /* *INDENT-OFF* */
   766 }
   767 /* *INDENT-ON* */
   768 #endif
   769 #include "close_code.h"
   770 
   771 #endif /* _SDL_stdinc_h */
   772 
   773 /* vi: set ts=4 sw=4 expandtab: */