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