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