My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SDL_stdinc.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
28 #ifndef _SDL_stdinc_h
29 #define _SDL_stdinc_h
30 
31 #include "SDL_config.h"
32 
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36 #ifdef HAVE_STDIO_H
37 #include <stdio.h>
38 #endif
39 #if defined(STDC_HEADERS)
40 # include <stdlib.h>
41 # include <stddef.h>
42 # include <stdarg.h>
43 #else
44 # if defined(HAVE_STDLIB_H)
45 # include <stdlib.h>
46 # elif defined(HAVE_MALLOC_H)
47 # include <malloc.h>
48 # endif
49 # if defined(HAVE_STDDEF_H)
50 # include <stddef.h>
51 # endif
52 # if defined(HAVE_STDARG_H)
53 # include <stdarg.h>
54 # endif
55 #endif
56 #ifdef HAVE_STRING_H
57 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
58 # include <memory.h>
59 # endif
60 # include <string.h>
61 #endif
62 #ifdef HAVE_STRINGS_H
63 # include <strings.h>
64 #endif
65 #if defined(HAVE_INTTYPES_H)
66 # include <inttypes.h>
67 #elif defined(HAVE_STDINT_H)
68 # include <stdint.h>
69 #endif
70 #ifdef HAVE_CTYPE_H
71 # include <ctype.h>
72 #endif
73 #ifdef HAVE_MATH_H
74 # if defined(__WINRT__)
75 /* Defining _USE_MATH_DEFINES is required to get M_PI to be defined on
76  WinRT. See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
77  for more information.
78 */
79 # define _USE_MATH_DEFINES
80 # endif
81 # include <math.h>
82 #endif
83 #ifdef HAVE_FLOAT_H
84 # include <float.h>
85 #endif
86 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
87 # include <iconv.h>
88 #endif
89 
93 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
94 #define SDL_TABLESIZE(table) SDL_arraysize(table)
95 
102 /* @{ */
103 #ifdef __cplusplus
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)
107 #else
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))
111 #endif
112 /* @} *//* Cast operators */
113 
114 /* Define a four character code as a Uint32 */
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))
120 
124 /* @{ */
125 
126 typedef enum
127 {
128  SDL_FALSE = 0,
129  SDL_TRUE = 1
130 } SDL_bool;
131 
135 #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
136 #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
137 typedef int8_t Sint8;
141 #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
142 #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
143 typedef uint8_t Uint8;
147 #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
148 #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
149 typedef int16_t Sint16;
153 #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
154 #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
155 typedef uint16_t Uint16;
159 #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
160 #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
161 typedef int32_t Sint32;
165 #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
166 #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
167 typedef uint32_t Uint32;
168 
172 #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
173 #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
174 typedef int64_t Sint64;
178 #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
179 #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
180 typedef uint64_t Uint64;
181 
182 /* @} *//* Basic data types */
183 
184 
185 #define SDL_COMPILE_TIME_ASSERT(name, x) \
186  typedef int SDL_dummy_ ## name[(x) * 2 - 1]
187 
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);
197 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
198 
200 /* Check to make sure enums are the size of ints, for structure packing.
201  For both Watcom C/C++ and Borland C/C++ the compiler option that makes
202  enums having the size of an int must be enabled.
203  This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
204 */
205 
207 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
208 #if !defined(__ANDROID__)
209  /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
210 typedef enum
211 {
212  DUMMY_ENUM_VALUE
213 } SDL_DUMMY_ENUM;
214 
215 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
216 #endif
217 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
218 
220 #include "begin_code.h"
221 /* Set up for C function definitions, even when using C++ */
222 #ifdef __cplusplus
223 extern "C" {
224 #endif
225 
226 #if defined(HAVE_ALLOCA) && !defined(alloca)
227 # if defined(HAVE_ALLOCA_H)
228 # include <alloca.h>
229 # elif defined(__GNUC__)
230 # define alloca __builtin_alloca
231 # elif defined(_MSC_VER)
232 # include <malloc.h>
233 # define alloca _alloca
234 # elif defined(__WATCOMC__)
235 # include <malloc.h>
236 # elif defined(__BORLANDC__)
237 # include <malloc.h>
238 # elif defined(__DMC__)
239 # include <stdlib.h>
240 # elif defined(__AIX__)
241 #pragma alloca
242 # elif defined(__MRC__)
243 void *alloca(unsigned);
244 # else
245 char *alloca();
246 # endif
247 #endif
248 #ifdef HAVE_ALLOCA
249 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
250 #define SDL_stack_free(data)
251 #else
252 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
253 #define SDL_stack_free(data) SDL_free(data)
254 #endif
255 
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);
260 
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);
263 
264 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
265 
266 extern DECLSPEC int SDLCALL SDL_abs(int x);
267 
268 /* !!! FIXME: these have side effects. You probably shouldn't use them. */
269 /* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
270 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
271 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
272 
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);
277 
278 extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
279 
280 #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
281 #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
282 
283 /* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
284 SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
285 {
286 #if defined(__GNUC__) && defined(i386)
287  int u0, u1, u2;
288  __asm__ __volatile__ (
289  "cld \n\t"
290  "rep ; stosl \n\t"
291  : "=&D" (u0), "=&a" (u1), "=&c" (u2)
292  : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
293  : "memory"
294  );
295 #else
296  size_t _n = (dwords + 3) / 4;
297  Uint32 *_p = SDL_static_cast(Uint32 *, dst);
298  Uint32 _val = (val);
299  if (dwords == 0)
300  return;
301  switch (dwords % 4)
302  {
303  case 0: do { *_p++ = _val;
304  case 3: *_p++ = _val;
305  case 2: *_p++ = _val;
306  case 1: *_p++ = _val;
307  } while ( --_n );
308  }
309 #endif
310 }
311 
312 
313 extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
314 
315 SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
316 {
317  return SDL_memcpy(dst, src, dwords * 4);
318 }
319 
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);
322 
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);
326 
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);
338 
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);
345 
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);
353 
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);
358 
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);
363 
364 #ifndef HAVE_M_PI
365 #ifndef M_PI
366 #define M_PI 3.14159265358979323846264338327950288 /* pi */
367 #endif
368 #endif
369 
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);
386 
387 /* The SDL implementation of iconv() returns these error codes */
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
392 
393 /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
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);
405 extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
406  const char *fromcode,
407  const char *inbuf,
408  size_t inbytesleft);
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)
412 
413 /* Ends C function definitions when using C++ */
414 #ifdef __cplusplus
415 }
416 #endif
417 #include "close_code.h"
418 
419 #endif /* _SDL_stdinc_h */
420 
421 /* vi: set ts=4 sw=4 expandtab: */
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)