include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 19 Oct 2009 13:31:58 +0000
changeset 3407 d3baf5ac4e37
parent 3365 9cd5b35c0184
child 3567 fb9ea4b549c3
permissions -rw-r--r--
Partial fix for bug #859

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