SDL_stdinc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #ifndef _SDL_stdinc_h
  2. #define _SDL_stdinc_h
  3. #include "SDL_config.h"
  4. #ifdef HAVE_SYS_TYPES_H
  5. #include <sys/types.h>
  6. #endif
  7. #ifdef HAVE_STDIO_H
  8. #include <stdio.h>
  9. #endif
  10. #if defined(STDC_HEADERS)
  11. # include <stdlib.h>
  12. # include <stddef.h>
  13. # include <stdarg.h>
  14. #else
  15. # if defined(HAVE_STDLIB_H)
  16. # include <stdlib.h>
  17. # elif defined(HAVE_MALLOC_H)
  18. # include <malloc.h>
  19. # endif
  20. # if defined(HAVE_STDDEF_H)
  21. # include <stddef.h>
  22. # endif
  23. # if defined(HAVE_STDARG_H)
  24. # include <stdarg.h>
  25. # endif
  26. #endif
  27. #ifdef HAVE_STRING_H
  28. # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
  29. # include <memory.h>
  30. # endif
  31. # include <string.h>
  32. #endif
  33. #ifdef HAVE_STRINGS_H
  34. # include <strings.h>
  35. #endif
  36. #if defined(HAVE_INTTYPES_H)
  37. # include <inttypes.h>
  38. #elif defined(HAVE_STDINT_H)
  39. # include <stdint.h>
  40. #endif
  41. #ifdef HAVE_CTYPE_H
  42. # include <ctype.h>
  43. #endif
  44. #ifdef HAVE_MATH_H
  45. # include <math.h>
  46. #endif
  47. #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
  48. # include <iconv.h>
  49. #endif
  50. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  51. #define SDL_TABLESIZE(table) SDL_arraysize(table)
  52. #ifdef __cplusplus
  53. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  54. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  55. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  56. #else
  57. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  58. #define SDL_static_cast(type, expression) ((type)(expression))
  59. #define SDL_const_cast(type, expression) ((type)(expression))
  60. #endif
  61. #define SDL_FOURCC(A, B, C, D) \
  62. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  63. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  64. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  65. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  66. typedef enum
  67. {
  68. SDL_FALSE = 0,
  69. SDL_TRUE = 1
  70. } SDL_bool;
  71. typedef int8_t Sint8;
  72. typedef uint8_t Uint8;
  73. typedef int16_t Sint16;
  74. typedef uint16_t Uint16;
  75. typedef int32_t Sint32;
  76. typedef uint32_t Uint32;
  77. typedef int64_t Sint64;
  78. typedef uint64_t Uint64;
  79. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  80. typedef int SDL_dummy_ ## name[(x) * 2 - 1]
  81. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  82. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  83. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  84. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  85. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  86. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  87. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  88. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  89. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  90. #endif
  91. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  92. #if !defined(__ANDROID__)
  93. typedef enum
  94. {
  95. DUMMY_ENUM_VALUE
  96. } SDL_DUMMY_ENUM;
  97. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  98. #endif
  99. #endif
  100. #include "begin_code.h"
  101. #ifdef __cplusplus
  102. extern "C" {
  103. #endif
  104. #if defined(HAVE_ALLOCA) && !defined(alloca)
  105. # if defined(HAVE_ALLOCA_H)
  106. # include <alloca.h>
  107. # elif defined(__GNUC__)
  108. # define alloca __builtin_alloca
  109. # elif defined(_MSC_VER)
  110. # include <malloc.h>
  111. # define alloca _alloca
  112. # elif defined(__WATCOMC__)
  113. # include <malloc.h>
  114. # elif defined(__BORLANDC__)
  115. # include <malloc.h>
  116. # elif defined(__DMC__)
  117. # include <stdlib.h>
  118. # elif defined(__AIX__)
  119. #pragma alloca
  120. # elif defined(__MRC__)
  121. void *alloca(unsigned);
  122. # else
  123. char *alloca();
  124. # endif
  125. #endif
  126. #ifdef HAVE_ALLOCA
  127. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  128. #define SDL_stack_free(data)
  129. #else
  130. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  131. #define SDL_stack_free(data) SDL_free(data)
  132. #endif
  133. typedef void * SDLCALL tSDL_malloc(size_t size);
  134. typedef void * SDLCALL tSDL_calloc(size_t nmemb, size_t size);
  135. typedef void * SDLCALL tSDL_realloc(void *mem, size_t size);
  136. typedef void SDLCALL tSDL_free(void *mem);
  137. typedef char * SDLCALL tSDL_getenv(const char *name);
  138. typedef int SDLCALL tSDL_setenv(const char *name, const char *value, int overwrite);
  139. typedef void SDLCALL tSDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
  140. typedef int SDLCALL tSDL_abs(int x);
  141. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  142. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  143. typedef int SDLCALL tSDL_isdigit(int x);
  144. typedef int SDLCALL tSDL_isspace(int x);
  145. typedef int SDLCALL tSDL_toupper(int x);
  146. typedef int SDLCALL tSDL_tolower(int x);
  147. typedef void * SDLCALL tSDL_memset(void *dst, int c, size_t len);
  148. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  149. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  150. SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t dwords)
  151. {
  152. #if defined(__GNUC__) && defined(i386)
  153. int u0, u1, u2;
  154. __asm__ __volatile__ (
  155. "cld \n\t"
  156. "rep ; stosl \n\t"
  157. : "=&D" (u0), "=&a" (u1), "=&c" (u2)
  158. : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
  159. : "memory"
  160. );
  161. #else
  162. size_t _n = (dwords + 3) / 4;
  163. Uint32 *_p = SDL_static_cast(Uint32 *, dst);
  164. Uint32 _val = (val);
  165. if (dwords == 0)
  166. return;
  167. switch (dwords % 4)
  168. {
  169. case 0: do { *_p++ = _val;
  170. case 3: *_p++ = _val;
  171. case 2: *_p++ = _val;
  172. case 1: *_p++ = _val;
  173. } while ( --_n );
  174. }
  175. #endif
  176. }
  177. typedef void * SDLCALL tSDL_memcpy(void *dst, const void *src, size_t len);
  178. extern tSDL_memcpy *SDL_memcpy;
  179. SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
  180. {
  181. return SDL_memcpy(dst, src, dwords * 4);
  182. }
  183. typedef void * SDLCALL tSDL_memmove(void *dst, const void *src, size_t len);
  184. typedef int SDLCALL tSDL_memcmp(const void *s1, const void *s2, size_t len);
  185. typedef size_t SDLCALL tSDL_wcslen(const wchar_t *wstr);
  186. typedef size_t SDLCALL tSDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
  187. typedef size_t SDLCALL tSDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
  188. typedef size_t SDLCALL tSDL_strlen(const char *str);
  189. typedef size_t SDLCALL tSDL_strlcpy(char *dst, const char *src, size_t maxlen);
  190. typedef size_t SDLCALL tSDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
  191. typedef size_t SDLCALL tSDL_strlcat(char *dst, const char *src, size_t maxlen);
  192. typedef char * SDLCALL tSDL_strdup(const char *str);
  193. typedef char * SDLCALL tSDL_strrev(char *str);
  194. typedef char * SDLCALL tSDL_strupr(char *str);
  195. typedef char * SDLCALL tSDL_strlwr(char *str);
  196. typedef char * SDLCALL tSDL_strchr(const char *str, int c);
  197. typedef char * SDLCALL tSDL_strrchr(const char *str, int c);
  198. typedef char * SDLCALL tSDL_strstr(const char *haystack, const char *needle);
  199. typedef char * SDLCALL tSDL_itoa(int value, char *str, int radix);
  200. typedef char * SDLCALL tSDL_uitoa(unsigned int value, char *str, int radix);
  201. typedef char * SDLCALL tSDL_ltoa(long value, char *str, int radix);
  202. typedef char * SDLCALL tSDL_ultoa(unsigned long value, char *str, int radix);
  203. typedef char * SDLCALL tSDL_lltoa(Sint64 value, char *str, int radix);
  204. typedef char * SDLCALL tSDL_ulltoa(Uint64 value, char *str, int radix);
  205. typedef int SDLCALL tSDL_atoi(const char *str);
  206. typedef double SDLCALL tSDL_atof(const char *str);
  207. typedef long SDLCALL tSDL_strtol(const char *str, char **endp, int base);
  208. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  209. typedef Sint64 SDLCALL tSDL_strtoll(const char *str, char **endp, int base);
  210. typedef Uint64 SDLCALL tSDL_strtoull(const char *str, char **endp, int base);
  211. typedef double SDLCALL tSDL_strtod(const char *str, char **endp);
  212. typedef int SDLCALL tSDL_strcmp(const char *str1, const char *str2);
  213. typedef int SDLCALL tSDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  214. typedef int SDLCALL tSDL_strcasecmp(const char *str1, const char *str2);
  215. typedef int SDLCALL tSDL_strncasecmp(const char *str1, const char *str2, size_t len);
  216. typedef int SDLCALL tSDL_sscanf(const char *text, const char *fmt, ...);
  217. typedef int SDLCALL tSDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
  218. typedef int SDLCALL tSDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
  219. #ifndef HAVE_M_PI
  220. #ifndef M_PI
  221. #define M_PI 3.14159265358979323846264338327950288
  222. #endif
  223. #endif
  224. typedef double SDLCALL tSDL_atan(double x);
  225. typedef double SDLCALL tSDL_atan2(double x, double y);
  226. typedef double SDLCALL tSDL_ceil(double x);
  227. typedef double SDLCALL tSDL_copysign(double x, double y);
  228. typedef double SDLCALL tSDL_cos(double x);
  229. typedef float SDLCALL tSDL_cosf(float x);
  230. typedef double SDLCALL tSDL_fabs(double x);
  231. typedef double SDLCALL tSDL_floor(double x);
  232. typedef double SDLCALL tSDL_log(double x);
  233. typedef double SDLCALL tSDL_pow(double x, double y);
  234. typedef double SDLCALL tSDL_scalbn(double x, int n);
  235. typedef double SDLCALL tSDL_sin(double x);
  236. typedef float SDLCALL tSDL_sinf(float x);
  237. typedef double SDLCALL tSDL_sqrt(double x);
  238. #define SDL_ICONV_ERROR (size_t)-1
  239. #define SDL_ICONV_E2BIG (size_t)-2
  240. #define SDL_ICONV_EILSEQ (size_t)-3
  241. #define SDL_ICONV_EINVAL (size_t)-4
  242. typedef struct _SDL_iconv_t *SDL_iconv_t;
  243. typedef SDL_iconv_t SDLCALL tSDL_iconv_open(const char *tocode,
  244. const char *fromcode);
  245. typedef int SDLCALL tSDL_iconv_close(SDL_iconv_t cd);
  246. typedef size_t SDLCALL tSDL_iconv(SDL_iconv_t cd, const char **inbuf,
  247. size_t * inbytesleft, char **outbuf,
  248. size_t * outbytesleft);
  249. typedef char * SDLCALL tSDL_iconv_string(const char *tocode,
  250. const char *fromcode,
  251. const char *inbuf,
  252. size_t inbytesleft);
  253. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  254. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  255. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  256. #ifndef HAVE_ALLOCA
  257. extern tSDL_malloc *SDL_malloc;
  258. #endif
  259. extern tSDL_calloc *SDL_calloc;
  260. extern tSDL_realloc *SDL_realloc;
  261. extern tSDL_free *SDL_free;
  262. extern tSDL_getenv *SDL_getenv;
  263. extern tSDL_setenv *SDL_setenv;
  264. extern tSDL_qsort *SDL_qsort;
  265. extern tSDL_abs *SDL_abs;
  266. extern tSDL_isdigit *SDL_isdigit;
  267. extern tSDL_isspace *SDL_isspace;
  268. extern tSDL_toupper *SDL_toupper;
  269. extern tSDL_tolower *SDL_tolower;
  270. extern tSDL_memset *SDL_memset;
  271. extern tSDL_memmove *SDL_memmove;
  272. extern tSDL_memcmp *SDL_memcmp;
  273. extern tSDL_wcslen *SDL_wcslen;
  274. extern tSDL_wcslcpy *SDL_wcslcpy;
  275. extern tSDL_wcslcat *SDL_wcslcat;
  276. extern tSDL_strlen *SDL_strlen;
  277. extern tSDL_strlcpy *SDL_strlcpy;
  278. extern tSDL_utf8strlcpy *SDL_utf8strlcpy;
  279. extern tSDL_strlcat *SDL_strlcat;
  280. extern tSDL_strdup *SDL_strdup;
  281. extern tSDL_strrev *SDL_strrev;
  282. extern tSDL_strupr *SDL_strupr;
  283. extern tSDL_strlwr *SDL_strlwr;
  284. extern tSDL_strchr *SDL_strchr;
  285. extern tSDL_strrchr *SDL_strrchr;
  286. extern tSDL_strstr *SDL_strstr;
  287. extern tSDL_itoa *SDL_itoa;
  288. extern tSDL_uitoa *SDL_uitoa;
  289. extern tSDL_ltoa *SDL_ltoa;
  290. extern tSDL_ultoa *SDL_ultoa;
  291. extern tSDL_lltoa *SDL_lltoa;
  292. extern tSDL_ulltoa *SDL_ulltoa;
  293. extern tSDL_atoi *SDL_atoi;
  294. extern tSDL_atof *SDL_atof;
  295. extern tSDL_strtol *SDL_strtol;
  296. extern tSDL_strtoll *SDL_strtoll;
  297. extern tSDL_strtoull *SDL_strtoull;
  298. extern tSDL_strtod *SDL_strtod;
  299. extern tSDL_strcmp *SDL_strcmp;
  300. extern tSDL_strncmp *SDL_strncmp;
  301. extern tSDL_strcasecmp *SDL_strcasecmp;
  302. extern tSDL_strncasecmp *SDL_strncasecmp;
  303. extern tSDL_sscanf *SDL_sscanf;
  304. extern tSDL_snprintf *SDL_snprintf;
  305. extern tSDL_vsnprintf *SDL_vsnprintf;
  306. extern tSDL_atan *SDL_atan;
  307. extern tSDL_atan2 *SDL_atan2;
  308. extern tSDL_ceil *SDL_ceil;
  309. extern tSDL_copysign *SDL_copysign;
  310. extern tSDL_cos *SDL_cos;
  311. extern tSDL_cosf *SDL_cosf;
  312. extern tSDL_fabs *SDL_fabs;
  313. extern tSDL_floor *SDL_floor;
  314. extern tSDL_log *SDL_log;
  315. extern tSDL_pow *SDL_pow;
  316. extern tSDL_scalbn *SDL_scalbn;
  317. extern tSDL_sin *SDL_sin;
  318. extern tSDL_sinf *SDL_sinf;
  319. extern tSDL_sqrt *SDL_sqrt;
  320. extern tSDL_iconv_open *SDL_iconv_open;
  321. extern tSDL_iconv_close *SDL_iconv_close;
  322. extern tSDL_iconv *SDL_iconv;
  323. extern tSDL_iconv_string *SDL_iconv_string;
  324. #ifdef __cplusplus
  325. }
  326. #endif
  327. #include "close_code.h"
  328. #endif