Mercurial > sdl-ios-xcode
annotate include/SDL_stdinc.h @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | e18467d67cfd |
children | e440d5c488c1 |
rev | line source |
---|---|
1357 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 Sam Lantinga | |
4 | |
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. | |
9 | |
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. | |
14 | |
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 | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 /* This is a general header that includes C language support */ | |
24 | |
25 #ifndef _SDL_stdinc_h | |
26 #define _SDL_stdinc_h | |
27 | |
28 #include "SDL_config.h" | |
29 | |
30 /* AIX requires this to be the first thing in the file. */ | |
31 #ifndef __GNUC__ | |
32 # if HAVE_ALLOCA_H | |
33 # include <alloca.h> | |
34 # else | |
35 # ifdef _AIX | |
36 #pragma alloca | |
37 # else | |
38 # ifndef alloca /* predefined by HP cc +Olibcalls */ | |
39 char *alloca (); | |
40 # endif | |
41 # endif | |
42 # endif | |
43 #endif | |
44 | |
45 #if HAVE_SYS_TYPES_H | |
46 #include <sys/types.h> | |
47 #endif | |
48 #if HAVE_STDIO_H | |
49 #include <stdio.h> | |
50 #endif | |
51 #if STDC_HEADERS | |
52 # include <stdlib.h> | |
53 # include <stddef.h> | |
54 # include <stdarg.h> | |
55 #else | |
56 # if HAVE_STDLIB_H | |
57 # include <stdlib.h> | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1357
diff
changeset
|
58 # elif HAVE_MALLOC_H |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1357
diff
changeset
|
59 # include <malloc.h> |
1357 | 60 # endif |
61 # if HAVE_STDARG_H | |
62 # include <stdarg.h> | |
63 # endif | |
64 #endif | |
65 #if HAVE_STRING_H | |
66 # if !STDC_HEADERS && HAVE_MEMORY_H | |
67 # include <memory.h> | |
68 # endif | |
69 # include <string.h> | |
70 #endif | |
71 #if HAVE_STRINGS_H | |
72 # include <strings.h> | |
73 #endif | |
74 #if HAVE_INTTYPES_H | |
75 # include <inttypes.h> | |
76 #else | |
77 # if HAVE_STDINT_H | |
78 # include <stdint.h> | |
79 # endif | |
80 #endif | |
81 #if HAVE_CTYPE_H | |
82 # include <ctype.h> | |
83 #endif | |
84 | |
85 /* The number of elements in an array */ | |
86 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) | |
87 #define SDL_TABLESIZE(table) SDL_arraysize(table) | |
88 | |
89 /* Basic data types */ | |
90 typedef enum SDL_bool { | |
91 SDL_FALSE = 0, | |
92 SDL_TRUE = 1 | |
93 } SDL_bool; | |
94 | |
95 typedef int8_t Sint8; | |
96 typedef uint8_t Uint8; | |
97 typedef int16_t Sint16; | |
98 typedef uint16_t Uint16; | |
99 typedef int32_t Sint32; | |
100 typedef uint32_t Uint32; | |
101 | |
102 #ifdef SDL_HAS_64BIT_TYPE | |
103 typedef int64_t Sint64; | |
104 typedef uint64_t Uint64; | |
105 #else | |
106 /* This is really just a hack to prevent the compiler from complaining */ | |
107 typedef struct { | |
108 Uint32 hi; | |
109 Uint32 lo; | |
110 } Uint64, Sint64; | |
111 #endif | |
112 | |
113 /* Make sure the types really have the right sizes */ | |
114 #define SDL_COMPILE_TIME_ASSERT(name, x) \ | |
115 typedef int SDL_dummy_ ## name[(x) * 2 - 1] | |
116 | |
117 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1); | |
118 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1); | |
119 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); | |
120 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); | |
121 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); | |
122 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); | |
123 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); | |
124 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); | |
125 | |
126 /* Check to make sure enums are the size of ints, for structure packing. | |
127 For both Watcom C/C++ and Borland C/C++ the compiler option that makes | |
128 enums having the size of an int must be enabled. | |
129 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). | |
130 */ | |
131 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */ | |
132 #ifdef __MWERKS__ | |
133 #pragma enumsalwaysint on | |
134 #endif | |
135 | |
136 typedef enum { | |
137 DUMMY_ENUM_VALUE | |
138 } SDL_DUMMY_ENUM; | |
139 | |
140 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); | |
141 | |
142 | |
143 #include "begin_code.h" | |
144 /* Set up for C function definitions, even when using C++ */ | |
145 #ifdef __cplusplus | |
146 extern "C" { | |
147 #endif | |
148 | |
149 #if HAVE_MALLOC | |
150 #define SDL_malloc malloc | |
151 #else | |
152 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size); | |
153 #endif | |
154 | |
155 #if HAVE_CALLOC | |
156 #define SDL_calloc calloc | |
157 #else | |
158 extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size); | |
159 #endif | |
160 | |
161 #if HAVE_REALLOC | |
162 #define SDL_realloc realloc | |
163 #else | |
164 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size); | |
165 #endif | |
166 | |
167 #if HAVE_FREE | |
168 #define SDL_free free | |
169 #else | |
170 extern DECLSPEC void SDLCALL SDL_free(void *mem); | |
171 #endif | |
172 | |
173 #if HAVE_ALLOCA | |
174 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count) | |
175 #define SDL_stack_free(data) | |
176 #else | |
177 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*count) | |
178 #define SDL_stack_free(data) SDL_free(data) | |
179 #endif | |
180 | |
181 #if HAVE_GETENV | |
182 #define SDL_getenv getenv | |
183 #else | |
184 extern DECLSPEC char * SDLCALL SDL_getenv(const char *name); | |
185 #endif | |
186 | |
187 #if HAVE_PUTENV | |
188 #define SDL_putenv putenv | |
189 #else | |
190 extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); | |
191 #endif | |
192 | |
193 #if HAVE_QSORT | |
194 #define SDL_qsort qsort | |
195 #else | |
196 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, | |
197 int (*compare)(const void *, const void *)); | |
198 #endif | |
199 | |
200 #if HAVE_ABS | |
201 #define SDL_abs abs | |
202 #else | |
203 #define SDL_abs(X) ((X) < 0 ? -(X) : (X)) | |
204 #endif | |
205 | |
206 #if HAVE_CTYPE_H | |
207 #define SDL_isdigit(X) isdigit(X) | |
208 #define SDL_isspace(X) isspace(X) | |
209 #define SDL_toupper(X) toupper(X) | |
210 #define SDL_tolower(X) tolower(X) | |
211 #else | |
212 #define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9')) | |
213 #define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n')) | |
214 #define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X)) | |
215 #define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X)) | |
216 #endif | |
217 | |
218 #if HAVE_MEMSET | |
219 #define SDL_memset memset | |
220 #else | |
221 extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len); | |
222 #endif | |
223 | |
224 #if defined(__GNUC__) && defined(i386) | |
225 #define SDL_memset4(dst, val, len) \ | |
226 do { \ | |
227 int u0, u1, u2; \ | |
228 __asm__ __volatile__ ( \ | |
229 "cld\n\t" \ | |
230 "rep ; stosl\n\t" \ | |
231 : "=&D" (u0), "=&a" (u1), "=&c" (u2) \ | |
232 : "0" (dst), "1" (val), "2" ((Uint32)(len)) \ | |
233 : "memory" ); \ | |
234 } while(0) | |
235 #endif | |
236 #ifndef SDL_memset4 | |
237 #define SDL_memset4(dst, val, len) \ | |
238 do { \ | |
239 unsigned _count = (len); \ | |
240 unsigned _n = (_count + 3) / 4; \ | |
241 Uint32 *_p = (Uint32 *)(dst); \ | |
242 Uint32 _val = (val); \ | |
243 switch (_count % 4) { \ | |
244 case 0: do { *_p++ = _val; \ | |
245 case 3: *_p++ = _val; \ | |
246 case 2: *_p++ = _val; \ | |
247 case 1: *_p++ = _val; \ | |
248 } while ( --_n ); \ | |
249 } \ | |
250 } while(0) | |
251 #endif | |
252 | |
253 #if defined(__GNUC__) && defined(i386) | |
254 #define SDL_memcpy(dst, src, len) \ | |
255 do { \ | |
256 int u0, u1, u2; \ | |
257 __asm__ __volatile__ ( \ | |
258 "cld\n\t" \ | |
259 "rep ; movsl\n\t" \ | |
260 "testb $2,%b4\n\t" \ | |
261 "je 1f\n\t" \ | |
262 "movsw\n" \ | |
263 "1:\ttestb $1,%b4\n\t" \ | |
264 "je 2f\n\t" \ | |
265 "movsb\n" \ | |
266 "2:" \ | |
267 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ | |
268 : "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \ | |
269 : "memory" ); \ | |
270 } while(0) | |
271 #endif | |
272 #ifndef SDL_memcpy | |
273 #if HAVE_MEMCPY | |
274 #define SDL_memcpy memcpy | |
275 #elif HAVE_BCOPY | |
276 #define SDL_memcpy(d, s, n) bcopy((s), (d), (n)) | |
277 #else | |
278 extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); | |
279 #endif | |
280 #endif | |
281 | |
282 #if defined(__GNUC__) && defined(i386) | |
283 #define SDL_memcpy4(dst, src, len) \ | |
284 do { \ | |
285 int ecx, edi, esi; \ | |
286 __asm__ __volatile__ ( \ | |
287 "cld\n\t" \ | |
288 "rep ; movsl" \ | |
289 : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \ | |
290 : "0" ((unsigned)(len)), "1" (dst), "2" (src) \ | |
291 : "memory" ); \ | |
292 } while(0) | |
293 #endif | |
294 #ifndef SDL_memcpy4 | |
295 #define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2) | |
296 #endif | |
297 | |
298 #if defined(__GNUC__) && defined(i386) | |
299 #define SDL_revcpy(dst, src, len) \ | |
300 do { \ | |
301 int u0, u1, u2; \ | |
302 char *dstp = (char *)(dst); \ | |
303 char *srcp = (char *)(src); \ | |
304 int n = (len); \ | |
305 if ( n >= 4 ) { \ | |
306 __asm__ __volatile__ ( \ | |
307 "std\n\t" \ | |
308 "rep ; movsl\n\t" \ | |
309 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ | |
310 : "0" (n >> 2), \ | |
311 "1" (dstp+(n-4)), "2" (srcp+(n-4)) \ | |
312 : "memory" ); \ | |
313 } \ | |
314 switch (n & 3) { \ | |
315 case 3: dstp[2] = srcp[2]; \ | |
316 case 2: dstp[1] = srcp[1]; \ | |
317 case 1: dstp[0] = srcp[0]; \ | |
318 break; \ | |
319 default: \ | |
320 break; \ | |
321 } \ | |
322 } while(0) | |
323 #endif | |
324 #ifndef SDL_revcpy | |
325 extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len); | |
326 #endif | |
327 | |
328 #if HAVE_MEMMOVE | |
329 #define SDL_memmove memmove | |
330 #elif HAVE_BCOPY | |
331 #define SDL_memmove(d, s, n) bcopy((s), (d), (n)) | |
332 #else | |
333 #define SDL_memmove(dst, src, len) \ | |
334 do { \ | |
335 if ( dst < src ) { \ | |
336 SDL_memcpy(dst, src, len); \ | |
337 } else { \ | |
338 SDL_revcpy(dst, src, len); \ | |
339 } \ | |
340 } while(0) | |
341 #endif | |
342 | |
343 #if HAVE_MEMCMP | |
344 #define SDL_memcmp memcmp | |
345 #else | |
346 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); | |
347 #endif | |
348 | |
349 #if HAVE_STRLEN | |
350 #define SDL_strlen strlen | |
351 #else | |
352 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); | |
353 #endif | |
354 | |
355 #if HAVE_STRCPY | |
356 #define SDL_strcpy strcpy | |
357 #else | |
358 extern DECLSPEC char * SDLCALL SDL_strcpy(char *dst, const char *src); | |
359 #endif | |
360 | |
361 #if HAVE_STRNCPY | |
362 #define SDL_strncpy strncpy | |
363 #else | |
364 extern DECLSPEC char * SDLCALL SDL_strncpy(char *dst, const char *src, size_t maxlen); | |
365 #endif | |
366 | |
367 #if HAVE_STRCAT | |
368 #define SDL_strcat strcat | |
369 #else | |
370 #define SDL_strcat(dst, src) (SDL_strcpy(dst+SDL_strlen(dst), src), dst) | |
371 #endif | |
372 | |
373 #if HAVE_STRNCAT | |
374 #define SDL_strncat strncat | |
375 #else | |
376 #define SDL_strncat(dst, src, n) (SDL_strncpy(dst+SDL_strlen(dst), src, n), dst) | |
377 #endif | |
378 | |
379 #if HAVE_STRDUP | |
380 #define SDL_strdup strdup | |
381 #else | |
382 extern DECLSPEC char * SDLCALL SDL_strdup(const char *string); | |
383 #endif | |
384 | |
385 #if HAVE__STRREV | |
386 #define SDL_strrev _strrev | |
387 #else | |
388 extern DECLSPEC char * SDLCALL SDL_strrev(char *string); | |
389 #endif | |
390 | |
391 #if HAVE__STRUPR | |
392 #define SDL_strupr _strupr | |
393 #else | |
394 extern DECLSPEC char * SDLCALL SDL_strupr(char *string); | |
395 #endif | |
396 | |
397 #if HAVE__STRLWR | |
398 #define SDL_strlwr _strlwr | |
399 #else | |
400 extern DECLSPEC char * SDLCALL SDL_strlwr(char *string); | |
401 #endif | |
402 | |
403 #if HAVE_STRCHR | |
404 #define SDL_strchr strchr | |
405 #elif HAVE_INDEX | |
406 #define SDL_strchr index | |
407 #else | |
408 extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c); | |
409 #endif | |
410 | |
411 #if HAVE_STRRCHR | |
412 #define SDL_strrchr strrchr | |
413 #elif HAVE_RINDEX | |
414 #define SDL_strrchr rindex | |
415 #else | |
416 extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c); | |
417 #endif | |
418 | |
419 #if HAVE_STRSTR | |
420 #define SDL_strstr strstr | |
421 #else | |
422 extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle); | |
423 #endif | |
424 | |
425 #if HAVE_ITOA | |
426 #define SDL_itoa itoa | |
427 #else | |
428 #define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix) | |
429 #endif | |
430 | |
431 #if HAVE__LTOA | |
432 #define SDL_ltoa _ltoa | |
433 #else | |
434 extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix); | |
435 #endif | |
436 | |
437 #if HAVE__UITOA | |
438 #define SDL_uitoa _uitoa | |
439 #else | |
440 #define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix) | |
441 #endif | |
442 | |
443 #if HAVE__ULTOA | |
444 #define SDL_ultoa _ultoa | |
445 #else | |
446 extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix); | |
447 #endif | |
448 | |
449 #if HAVE_STRTOL | |
450 #define SDL_strtol strtol | |
451 #else | |
452 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base); | |
453 #endif | |
454 | |
455 #if SDL_HAS_64BIT_TYPE | |
456 | |
457 #if HAVE__I64TOA | |
458 #define SDL_lltoa _i64toa | |
459 #else | |
460 extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix); | |
461 #endif | |
462 | |
463 #if HAVE__UI64TOA | |
464 #define SDL_ulltoa _ui64toa | |
465 #else | |
466 extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix); | |
467 #endif | |
468 | |
469 #if HAVE_STRTOLL | |
470 #define SDL_strtoll strtoll | |
471 #else | |
472 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base); | |
473 #endif | |
474 | |
475 #endif /* SDL_HAS_64BIT_TYPE */ | |
476 | |
477 #if HAVE_STRTOD | |
478 #define SDL_strtod strtod | |
479 #else | |
480 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); | |
481 #endif | |
482 | |
483 #if HAVE_ATOI | |
484 #define SDL_atoi atoi | |
485 #else | |
486 #define SDL_atoi(X) SDL_strtol(X, NULL, 0) | |
487 #endif | |
488 | |
489 #if HAVE_ATOF | |
490 #define SDL_atof atof | |
491 #else | |
492 #define SDL_atof(X) SDL_strtod(X, NULL) | |
493 #endif | |
494 | |
495 #if HAVE_STRCMP | |
496 #define SDL_strcmp strcmp | |
497 #else | |
498 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); | |
499 #endif | |
500 | |
501 #if HAVE_STRNCMP | |
502 #define SDL_strncmp strncmp | |
503 #else | |
504 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); | |
505 #endif | |
506 | |
507 #if HAVE_STRCASECMP | |
508 #define SDL_strcasecmp strcasecmp | |
509 #elif HAVE_STRICMP | |
510 #define SDL_strcasecmp stricmp | |
511 #else | |
512 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); | |
513 #endif | |
514 | |
515 #if HAVE_SSCANF | |
516 #define SDL_sscanf sscanf | |
517 #else | |
518 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); | |
519 #endif | |
520 | |
521 #if HAVE_SNPRINTF | |
522 #define SDL_snprintf snprintf | |
523 #else | |
524 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); | |
525 #endif | |
526 | |
527 #if HAVE_VSNPRINTF | |
528 #define SDL_vsnprintf vsnprintf | |
529 #else | |
530 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); | |
531 #endif | |
532 | |
533 /* Ends C function definitions when using C++ */ | |
534 #ifdef __cplusplus | |
535 } | |
536 #endif | |
537 #include "close_code.h" | |
538 | |
539 #endif /* _SDL_stdinc_h */ |