Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 /* This is a general header that includes C language support */
28 #include "SDL_config.h"
32 #include <sys/types.h>
52 # if !STDC_HEADERS && HAVE_MEMORY_H
61 # include <inttypes.h>
71 /* The number of elements in an array */
72 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
73 #define SDL_TABLESIZE(table) SDL_arraysize(table)
75 /* Basic data types */
76 typedef enum SDL_bool {
82 typedef uint8_t Uint8;
83 typedef int16_t Sint16;
84 typedef uint16_t Uint16;
85 typedef int32_t Sint32;
86 typedef uint32_t Uint32;
88 #ifdef SDL_HAS_64BIT_TYPE
89 typedef int64_t Sint64;
90 typedef uint64_t Uint64;
92 /* This is really just a hack to prevent the compiler from complaining */
99 /* Make sure the types really have the right sizes */
100 #define SDL_COMPILE_TIME_ASSERT(name, x) \
101 typedef int SDL_dummy_ ## name[(x) * 2 - 1]
103 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
104 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
105 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
106 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
107 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
108 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
109 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
110 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
112 /* Check to make sure enums are the size of ints, for structure packing.
113 For both Watcom C/C++ and Borland C/C++ the compiler option that makes
114 enums having the size of an int must be enabled.
115 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
117 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */
119 #pragma enumsalwaysint on
126 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
129 #include "begin_code.h"
130 /* Set up for C function definitions, even when using C++ */
136 #define SDL_malloc malloc
138 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
142 #define SDL_calloc calloc
144 extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
148 #define SDL_realloc realloc
150 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
154 #define SDL_free free
156 extern DECLSPEC void SDLCALL SDL_free(void *mem);
159 #if HAVE_ALLOCA && !defined(alloca)
162 # elif defined(__GNUC__)
163 # define alloca __builtin_alloca
164 # elif defined(_MSC_VER)
166 # define alloca _alloca
167 # elif defined(__AIX__)
174 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count)
175 #define SDL_stack_free(data)
177 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*count)
178 #define SDL_stack_free(data) SDL_free(data)
182 #define SDL_getenv getenv
184 extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
188 #define SDL_putenv putenv
190 extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
194 #define SDL_qsort qsort
196 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
197 int (*compare)(const void *, const void *));
203 #define SDL_abs(X) ((X) < 0 ? -(X) : (X))
206 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
207 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
210 #define SDL_isdigit(X) isdigit(X)
211 #define SDL_isspace(X) isspace(X)
212 #define SDL_toupper(X) toupper(X)
213 #define SDL_tolower(X) tolower(X)
215 #define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9'))
216 #define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
217 #define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
218 #define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
222 #define SDL_memset memset
224 extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
227 #if defined(__GNUC__) && defined(i386)
228 #define SDL_memset4(dst, val, len) \
231 __asm__ __volatile__ ( \
234 : "=&D" (u0), "=&a" (u1), "=&c" (u2) \
235 : "0" (dst), "1" (val), "2" ((Uint32)(len)) \
240 #define SDL_memset4(dst, val, len) \
242 unsigned _count = (len); \
243 unsigned _n = (_count + 3) / 4; \
244 Uint32 *_p = (Uint32 *)(dst); \
245 Uint32 _val = (val); \
246 switch (_count % 4) { \
247 case 0: do { *_p++ = _val; \
248 case 3: *_p++ = _val; \
249 case 2: *_p++ = _val; \
250 case 1: *_p++ = _val; \
256 #if defined(__GNUC__) && defined(i386)
257 #define SDL_memcpy(dst, src, len) \
260 __asm__ __volatile__ ( \
266 "1:\ttestb $1,%b4\n\t" \
270 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
271 : "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
277 #define SDL_memcpy memcpy
279 #define SDL_memcpy(d, s, n) bcopy((s), (d), (n))
281 extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
285 #if defined(__GNUC__) && defined(i386)
286 #define SDL_memcpy4(dst, src, len) \
289 __asm__ __volatile__ ( \
292 : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
293 : "0" ((unsigned)(len)), "1" (dst), "2" (src) \
298 #define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2)
301 #if defined(__GNUC__) && defined(i386)
302 #define SDL_revcpy(dst, src, len) \
305 char *dstp = (char *)(dst); \
306 char *srcp = (char *)(src); \
309 __asm__ __volatile__ ( \
312 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
314 "1" (dstp+(n-4)), "2" (srcp+(n-4)) \
318 case 3: dstp[2] = srcp[2]; \
319 case 2: dstp[1] = srcp[1]; \
320 case 1: dstp[0] = srcp[0]; \
328 extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
332 #define SDL_memmove memmove
334 #define SDL_memmove(d, s, n) bcopy((s), (d), (n))
336 #define SDL_memmove(dst, src, len) \
339 SDL_memcpy(dst, src, len); \
341 SDL_revcpy(dst, src, len); \
347 #define SDL_memcmp memcmp
349 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
353 #define SDL_strlen strlen
355 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
359 #define SDL_strlcpy strlcpy
361 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
365 #define SDL_strlcat strlcat
367 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
371 #define SDL_strdup strdup
373 extern DECLSPEC char * SDLCALL SDL_strdup(const char *string);
377 #define SDL_strrev _strrev
379 extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
383 #define SDL_strupr _strupr
385 extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
389 #define SDL_strlwr _strlwr
391 extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
395 #define SDL_strchr strchr
397 #define SDL_strchr index
399 extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
403 #define SDL_strrchr strrchr
405 #define SDL_strrchr rindex
407 extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
411 #define SDL_strstr strstr
413 extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
417 #define SDL_itoa itoa
419 #define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix)
423 #define SDL_ltoa _ltoa
425 extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
429 #define SDL_uitoa _uitoa
431 #define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
435 #define SDL_ultoa _ultoa
437 extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
441 #define SDL_strtol strtol
443 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
446 #if SDL_HAS_64BIT_TYPE
449 #define SDL_lltoa _i64toa
451 extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
455 #define SDL_ulltoa _ui64toa
457 extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
461 #define SDL_strtoll strtoll
463 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
466 #endif /* SDL_HAS_64BIT_TYPE */
469 #define SDL_strtod strtod
471 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
475 #define SDL_atoi atoi
477 #define SDL_atoi(X) SDL_strtol(X, NULL, 0)
481 #define SDL_atof atof
483 #define SDL_atof(X) SDL_strtod(X, NULL)
487 #define SDL_strcmp strcmp
489 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
493 #define SDL_strncmp strncmp
495 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
499 #define SDL_strcasecmp strcasecmp
501 #define SDL_strcasecmp stricmp
503 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
507 #define SDL_sscanf sscanf
509 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
513 #define SDL_snprintf snprintf
515 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
519 #define SDL_vsnprintf vsnprintf
521 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
524 /* Ends C function definitions when using C++ */
528 #include "close_code.h"
530 #endif /* _SDL_stdinc_h */