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