31 #include "SDL_config.h"
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
39 #if defined(STDC_HEADERS)
44 # if defined(HAVE_STDLIB_H)
46 # elif defined(HAVE_MALLOC_H)
49 # if defined(HAVE_STDDEF_H)
52 # if defined(HAVE_STDARG_H)
57 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
65 #if defined(HAVE_INTTYPES_H)
66 # include <inttypes.h>
67 #elif defined(HAVE_STDINT_H)
74 # if defined(__WINRT__)
79 # define _USE_MATH_DEFINES
86 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
93 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
94 #define SDL_TABLESIZE(table) SDL_arraysize(table)
104 #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
105 #define SDL_static_cast(type, expression) static_cast<type>(expression)
106 #define SDL_const_cast(type, expression) const_cast<type>(expression)
108 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
109 #define SDL_static_cast(type, expression) ((type)(expression))
110 #define SDL_const_cast(type, expression) ((type)(expression))
115 #define SDL_FOURCC(A, B, C, D) \
116 ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
117 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
118 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
119 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
135 #define SDL_MAX_SINT8 ((Sint8)0x7F)
136 #define SDL_MIN_SINT8 ((Sint8)(~0x7F))
137 typedef int8_t Sint8;
141 #define SDL_MAX_UINT8 ((Uint8)0xFF)
142 #define SDL_MIN_UINT8 ((Uint8)0x00)
143 typedef uint8_t Uint8;
147 #define SDL_MAX_SINT16 ((Sint16)0x7FFF)
148 #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF))
149 typedef int16_t Sint16;
153 #define SDL_MAX_UINT16 ((Uint16)0xFFFF)
154 #define SDL_MIN_UINT16 ((Uint16)0x0000)
155 typedef uint16_t Uint16;
159 #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF)
160 #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF))
161 typedef int32_t Sint32;
165 #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu)
166 #define SDL_MIN_UINT32 ((Uint32)0x00000000)
172 #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll)
173 #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll))
174 typedef int64_t Sint64;
178 #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull)
179 #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull))
180 typedef uint64_t Uint64;
185 #define SDL_COMPILE_TIME_ASSERT(name, x) \
186 typedef int SDL_dummy_ ## name[(x) * 2 - 1]
188 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
189 SDL_COMPILE_TIME_ASSERT(uint8,
sizeof(Uint8) == 1);
190 SDL_COMPILE_TIME_ASSERT(sint8,
sizeof(Sint8) == 1);
191 SDL_COMPILE_TIME_ASSERT(uint16,
sizeof(Uint16) == 2);
192 SDL_COMPILE_TIME_ASSERT(sint16,
sizeof(Sint16) == 2);
193 SDL_COMPILE_TIME_ASSERT(uint32,
sizeof(Uint32) == 4);
194 SDL_COMPILE_TIME_ASSERT(sint32,
sizeof(Sint32) == 4);
195 SDL_COMPILE_TIME_ASSERT(uint64,
sizeof(Uint64) == 8);
196 SDL_COMPILE_TIME_ASSERT(sint64,
sizeof(Sint64) == 8);
207 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
208 #if !defined(__ANDROID__)
215 SDL_COMPILE_TIME_ASSERT(
enum,
sizeof(SDL_DUMMY_ENUM) ==
sizeof(
int));
226 #if defined(HAVE_ALLOCA) && !defined(alloca)
227 # if defined(HAVE_ALLOCA_H)
229 # elif defined(__GNUC__)
230 # define alloca __builtin_alloca
231 # elif defined(_MSC_VER)
233 # define alloca _alloca
234 # elif defined(__WATCOMC__)
236 # elif defined(__BORLANDC__)
238 # elif defined(__DMC__)
240 # elif defined(__AIX__)
242 # elif defined(__MRC__)
243 void *alloca(
unsigned);
249 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
250 #define SDL_stack_free(data)
252 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
253 #define SDL_stack_free(data) SDL_free(data)
256 extern DECLSPEC
void *SDLCALL SDL_malloc(
size_t size);
257 extern DECLSPEC
void *SDLCALL SDL_calloc(
size_t nmemb,
size_t size);
258 extern DECLSPEC
void *SDLCALL SDL_realloc(
void *mem,
size_t size);
259 extern DECLSPEC
void SDLCALL SDL_free(
void *mem);
261 extern DECLSPEC
char *SDLCALL SDL_getenv(
const char *name);
262 extern DECLSPEC
int SDLCALL SDL_setenv(
const char *name,
const char *value,
int overwrite);
264 extern DECLSPEC
void SDLCALL SDL_qsort(
void *base,
size_t nmemb,
size_t size,
int (*compare) (
const void *,
const void *));
266 extern DECLSPEC
int SDLCALL SDL_abs(
int x);
270 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
271 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
273 extern DECLSPEC
int SDLCALL SDL_isdigit(
int x);
274 extern DECLSPEC
int SDLCALL SDL_isspace(
int x);
275 extern DECLSPEC
int SDLCALL SDL_toupper(
int x);
276 extern DECLSPEC
int SDLCALL SDL_tolower(
int x);
278 extern DECLSPEC
void *SDLCALL SDL_memset(
void *dst,
int c,
size_t len);
280 #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
281 #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
284 SDL_FORCE_INLINE
void SDL_memset4(
void *dst, Uint32 val,
size_t dwords)
286 #if defined(__GNUC__) && defined(i386)
288 __asm__ __volatile__ (
291 :
"=&D" (u0),
"=&a" (u1),
"=&c" (u2)
292 :
"0" (dst),
"1" (val),
"2" (SDL_static_cast(Uint32, dwords))
296 size_t _n = (dwords + 3) / 4;
297 Uint32 *_p = SDL_static_cast(Uint32 *, dst);
303 case 0:
do { *_p++ = _val;
304 case 3: *_p++ = _val;
305 case 2: *_p++ = _val;
306 case 1: *_p++ = _val;
313 extern DECLSPEC
void *SDLCALL SDL_memcpy(
void *dst,
const void *src,
size_t len);
315 SDL_FORCE_INLINE
void *SDL_memcpy4(
void *dst,
const void *src,
size_t dwords)
317 return SDL_memcpy(dst, src, dwords * 4);
320 extern DECLSPEC
void *SDLCALL SDL_memmove(
void *dst,
const void *src,
size_t len);
321 extern DECLSPEC
int SDLCALL SDL_memcmp(
const void *s1,
const void *s2,
size_t len);
323 extern DECLSPEC
size_t SDLCALL SDL_wcslen(
const wchar_t *wstr);
324 extern DECLSPEC
size_t SDLCALL SDL_wcslcpy(
wchar_t *dst,
const wchar_t *src,
size_t maxlen);
325 extern DECLSPEC
size_t SDLCALL SDL_wcslcat(
wchar_t *dst,
const wchar_t *src,
size_t maxlen);
327 extern DECLSPEC
size_t SDLCALL SDL_strlen(
const char *str);
328 extern DECLSPEC
size_t SDLCALL SDL_strlcpy(
char *dst,
const char *src,
size_t maxlen);
329 extern DECLSPEC
size_t SDLCALL SDL_utf8strlcpy(
char *dst,
const char *src,
size_t dst_bytes);
330 extern DECLSPEC
size_t SDLCALL SDL_strlcat(
char *dst,
const char *src,
size_t maxlen);
331 extern DECLSPEC
char *SDLCALL SDL_strdup(
const char *str);
332 extern DECLSPEC
char *SDLCALL SDL_strrev(
char *str);
333 extern DECLSPEC
char *SDLCALL SDL_strupr(
char *str);
334 extern DECLSPEC
char *SDLCALL SDL_strlwr(
char *str);
335 extern DECLSPEC
char *SDLCALL SDL_strchr(
const char *str,
int c);
336 extern DECLSPEC
char *SDLCALL SDL_strrchr(
const char *str,
int c);
337 extern DECLSPEC
char *SDLCALL SDL_strstr(
const char *haystack,
const char *needle);
339 extern DECLSPEC
char *SDLCALL SDL_itoa(
int value,
char *str,
int radix);
340 extern DECLSPEC
char *SDLCALL SDL_uitoa(
unsigned int value,
char *str,
int radix);
341 extern DECLSPEC
char *SDLCALL SDL_ltoa(
long value,
char *str,
int radix);
342 extern DECLSPEC
char *SDLCALL SDL_ultoa(
unsigned long value,
char *str,
int radix);
343 extern DECLSPEC
char *SDLCALL SDL_lltoa(Sint64 value,
char *str,
int radix);
344 extern DECLSPEC
char *SDLCALL SDL_ulltoa(Uint64 value,
char *str,
int radix);
346 extern DECLSPEC
int SDLCALL SDL_atoi(
const char *str);
347 extern DECLSPEC
double SDLCALL SDL_atof(
const char *str);
348 extern DECLSPEC
long SDLCALL SDL_strtol(
const char *str,
char **endp,
int base);
349 extern DECLSPEC
unsigned long SDLCALL SDL_strtoul(
const char *str,
char **endp,
int base);
350 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(
const char *str,
char **endp,
int base);
351 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(
const char *str,
char **endp,
int base);
352 extern DECLSPEC
double SDLCALL SDL_strtod(
const char *str,
char **endp);
354 extern DECLSPEC
int SDLCALL SDL_strcmp(
const char *str1,
const char *str2);
355 extern DECLSPEC
int SDLCALL SDL_strncmp(
const char *str1,
const char *str2,
size_t maxlen);
356 extern DECLSPEC
int SDLCALL SDL_strcasecmp(
const char *str1,
const char *str2);
357 extern DECLSPEC
int SDLCALL SDL_strncasecmp(
const char *str1,
const char *str2,
size_t len);
359 extern DECLSPEC
int SDLCALL SDL_sscanf(
const char *text,
const char *fmt, ...);
360 extern DECLSPEC
int SDLCALL SDL_vsscanf(
const char *text,
const char *fmt, va_list ap);
361 extern DECLSPEC
int SDLCALL SDL_snprintf(
char *text,
size_t maxlen,
const char *fmt, ...);
362 extern DECLSPEC
int SDLCALL SDL_vsnprintf(
char *text,
size_t maxlen,
const char *fmt, va_list ap);
366 #define M_PI 3.14159265358979323846264338327950288
370 extern DECLSPEC
double SDLCALL SDL_acos(
double x);
371 extern DECLSPEC
double SDLCALL SDL_asin(
double x);
372 extern DECLSPEC
double SDLCALL SDL_atan(
double x);
373 extern DECLSPEC
double SDLCALL SDL_atan2(
double x,
double y);
374 extern DECLSPEC
double SDLCALL SDL_ceil(
double x);
375 extern DECLSPEC
double SDLCALL SDL_copysign(
double x,
double y);
376 extern DECLSPEC
double SDLCALL SDL_cos(
double x);
377 extern DECLSPEC
float SDLCALL SDL_cosf(
float x);
378 extern DECLSPEC
double SDLCALL SDL_fabs(
double x);
379 extern DECLSPEC
double SDLCALL SDL_floor(
double x);
380 extern DECLSPEC
double SDLCALL SDL_log(
double x);
381 extern DECLSPEC
double SDLCALL SDL_pow(
double x,
double y);
382 extern DECLSPEC
double SDLCALL SDL_scalbn(
double x,
int n);
383 extern DECLSPEC
double SDLCALL SDL_sin(
double x);
384 extern DECLSPEC
float SDLCALL SDL_sinf(
float x);
385 extern DECLSPEC
double SDLCALL SDL_sqrt(
double x);
388 #define SDL_ICONV_ERROR (size_t)-1
389 #define SDL_ICONV_E2BIG (size_t)-2
390 #define SDL_ICONV_EILSEQ (size_t)-3
391 #define SDL_ICONV_EINVAL (size_t)-4
394 typedef struct _SDL_iconv_t *SDL_iconv_t;
395 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(
const char *tocode,
396 const char *fromcode);
397 extern DECLSPEC
int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
398 extern DECLSPEC
size_t SDLCALL SDL_iconv(SDL_iconv_t cd,
const char **inbuf,
399 size_t * inbytesleft,
char **outbuf,
400 size_t * outbytesleft);
406 const char *fromcode,
409 #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
410 #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
411 #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
typedef Uint32(SDLCALL *SDL_TimerCallback)(Uint32 interval
DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)