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