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