SDL_stdinc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_stdinc.h
  20. *
  21. * This is a general header that includes C language support.
  22. */
  23. #ifndef SDL_stdinc_h_
  24. #define SDL_stdinc_h_
  25. #include "SDL_config.h"
  26. #ifdef __APPLE__
  27. #ifndef _DARWIN_C_SOURCE
  28. #define _DARWIN_C_SOURCE 1 /* for memset_pattern4() */
  29. #endif
  30. #endif
  31. #ifdef HAVE_SYS_TYPES_H
  32. #include <sys/types.h>
  33. #endif
  34. #ifdef HAVE_STDIO_H
  35. #include <stdio.h>
  36. #endif
  37. #if defined(STDC_HEADERS)
  38. # include <stdlib.h>
  39. # include <stddef.h>
  40. # include <stdarg.h>
  41. #else
  42. # if defined(HAVE_STDLIB_H)
  43. # include <stdlib.h>
  44. # elif defined(HAVE_MALLOC_H)
  45. # include <malloc.h>
  46. # endif
  47. # if defined(HAVE_STDDEF_H)
  48. # include <stddef.h>
  49. # endif
  50. # if defined(HAVE_STDARG_H)
  51. # include <stdarg.h>
  52. # endif
  53. #endif
  54. #ifdef HAVE_STRING_H
  55. # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
  56. # include <memory.h>
  57. # endif
  58. # include <string.h>
  59. #endif
  60. #ifdef HAVE_STRINGS_H
  61. # include <strings.h>
  62. #endif
  63. #ifdef HAVE_WCHAR_H
  64. # include <wchar.h>
  65. #endif
  66. #if defined(HAVE_INTTYPES_H)
  67. # include <inttypes.h>
  68. #elif defined(HAVE_STDINT_H)
  69. # include <stdint.h>
  70. #endif
  71. #ifdef HAVE_CTYPE_H
  72. # include <ctype.h>
  73. #endif
  74. #ifdef HAVE_MATH_H
  75. # if defined(__WINRT__)
  76. /* Defining _USE_MATH_DEFINES is required to get M_PI to be defined on
  77. WinRT. See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
  78. for more information.
  79. */
  80. # define _USE_MATH_DEFINES
  81. # endif
  82. # include <math.h>
  83. #endif
  84. #ifdef HAVE_FLOAT_H
  85. # include <float.h>
  86. #endif
  87. #if defined(HAVE_ALLOCA) && !defined(alloca)
  88. # if defined(HAVE_ALLOCA_H)
  89. # include <alloca.h>
  90. # elif defined(__GNUC__)
  91. # define alloca __builtin_alloca
  92. # elif defined(_MSC_VER)
  93. # include <malloc.h>
  94. # define alloca _alloca
  95. # elif defined(__WATCOMC__)
  96. # include <malloc.h>
  97. # elif defined(__BORLANDC__)
  98. # include <malloc.h>
  99. # elif defined(__DMC__)
  100. # include <stdlib.h>
  101. # elif defined(__AIX__)
  102. #pragma alloca
  103. # elif defined(__MRC__)
  104. void *alloca(unsigned);
  105. # else
  106. char *alloca();
  107. # endif
  108. #endif
  109. /**
  110. * The number of elements in an array.
  111. */
  112. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  113. #define SDL_TABLESIZE(table) SDL_arraysize(table)
  114. /**
  115. * Macro useful for building other macros with strings in them
  116. *
  117. * e.g. #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")
  118. */
  119. #define SDL_STRINGIFY_ARG(arg) #arg
  120. /**
  121. * \name Cast operators
  122. *
  123. * Use proper C++ casts when compiled as C++ to be compatible with the option
  124. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  125. */
  126. /* @{ */
  127. #ifdef __cplusplus
  128. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  129. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  130. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  131. #else
  132. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  133. #define SDL_static_cast(type, expression) ((type)(expression))
  134. #define SDL_const_cast(type, expression) ((type)(expression))
  135. #endif
  136. /* @} *//* Cast operators */
  137. /* Define a four character code as a Uint32 */
  138. #define SDL_FOURCC(A, B, C, D) \
  139. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  140. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  141. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  142. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  143. /**
  144. * \name Basic data types
  145. */
  146. /* @{ */
  147. #ifdef __CC_ARM
  148. /* ARM's compiler throws warnings if we use an enum: like "SDL_bool x = a < b;" */
  149. #define SDL_FALSE 0
  150. #define SDL_TRUE 1
  151. typedef int SDL_bool;
  152. #else
  153. typedef enum
  154. {
  155. SDL_FALSE = 0,
  156. SDL_TRUE = 1
  157. } SDL_bool;
  158. #endif
  159. /**
  160. * \brief A signed 8-bit integer type.
  161. */
  162. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  163. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  164. typedef int8_t Sint8;
  165. /**
  166. * \brief An unsigned 8-bit integer type.
  167. */
  168. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  169. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  170. typedef uint8_t Uint8;
  171. /**
  172. * \brief A signed 16-bit integer type.
  173. */
  174. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  175. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  176. typedef int16_t Sint16;
  177. /**
  178. * \brief An unsigned 16-bit integer type.
  179. */
  180. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  181. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  182. typedef uint16_t Uint16;
  183. /**
  184. * \brief A signed 32-bit integer type.
  185. */
  186. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  187. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  188. typedef int32_t Sint32;
  189. /**
  190. * \brief An unsigned 32-bit integer type.
  191. */
  192. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  193. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  194. typedef uint32_t Uint32;
  195. /**
  196. * \brief A signed 64-bit integer type.
  197. */
  198. #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
  199. #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
  200. typedef int64_t Sint64;
  201. /**
  202. * \brief An unsigned 64-bit integer type.
  203. */
  204. #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
  205. #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
  206. typedef uint64_t Uint64;
  207. /* @} *//* Basic data types */
  208. /* Make sure we have macros for printing width-based integers.
  209. * <stdint.h> should define these but this is not true all platforms.
  210. * (for example win32) */
  211. #ifndef SDL_PRIs64
  212. #ifdef PRIs64
  213. #define SDL_PRIs64 PRIs64
  214. #elif defined(__WIN32__)
  215. #define SDL_PRIs64 "I64d"
  216. #elif defined(__LINUX__) && defined(__LP64__)
  217. #define SDL_PRIs64 "ld"
  218. #else
  219. #define SDL_PRIs64 "lld"
  220. #endif
  221. #endif
  222. #ifndef SDL_PRIu64
  223. #ifdef PRIu64
  224. #define SDL_PRIu64 PRIu64
  225. #elif defined(__WIN32__)
  226. #define SDL_PRIu64 "I64u"
  227. #elif defined(__LINUX__) && defined(__LP64__)
  228. #define SDL_PRIu64 "lu"
  229. #else
  230. #define SDL_PRIu64 "llu"
  231. #endif
  232. #endif
  233. #ifndef SDL_PRIx64
  234. #ifdef PRIx64
  235. #define SDL_PRIx64 PRIx64
  236. #elif defined(__WIN32__)
  237. #define SDL_PRIx64 "I64x"
  238. #elif defined(__LINUX__) && defined(__LP64__)
  239. #define SDL_PRIx64 "lx"
  240. #else
  241. #define SDL_PRIx64 "llx"
  242. #endif
  243. #endif
  244. #ifndef SDL_PRIX64
  245. #ifdef PRIX64
  246. #define SDL_PRIX64 PRIX64
  247. #elif defined(__WIN32__)
  248. #define SDL_PRIX64 "I64X"
  249. #elif defined(__LINUX__) && defined(__LP64__)
  250. #define SDL_PRIX64 "lX"
  251. #else
  252. #define SDL_PRIX64 "llX"
  253. #endif
  254. #endif
  255. #ifndef SDL_PRIs32
  256. #ifdef PRId32
  257. #define SDL_PRIs32 PRId32
  258. #else
  259. #define SDL_PRIs32 "d"
  260. #endif
  261. #endif
  262. #ifndef SDL_PRIu32
  263. #ifdef PRIu32
  264. #define SDL_PRIu32 PRIu32
  265. #else
  266. #define SDL_PRIu32 "u"
  267. #endif
  268. #endif
  269. #ifndef SDL_PRIx32
  270. #ifdef PRIx32
  271. #define SDL_PRIx32 PRIx32
  272. #else
  273. #define SDL_PRIx32 "x"
  274. #endif
  275. #endif
  276. #ifndef SDL_PRIX32
  277. #ifdef PRIX32
  278. #define SDL_PRIX32 PRIX32
  279. #else
  280. #define SDL_PRIX32 "X"
  281. #endif
  282. #endif
  283. /* Annotations to help code analysis tools */
  284. #ifdef SDL_DISABLE_ANALYZE_MACROS
  285. #define SDL_IN_BYTECAP(x)
  286. #define SDL_INOUT_Z_CAP(x)
  287. #define SDL_OUT_Z_CAP(x)
  288. #define SDL_OUT_CAP(x)
  289. #define SDL_OUT_BYTECAP(x)
  290. #define SDL_OUT_Z_BYTECAP(x)
  291. #define SDL_PRINTF_FORMAT_STRING
  292. #define SDL_SCANF_FORMAT_STRING
  293. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  294. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  295. #else
  296. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  297. #include <sal.h>
  298. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  299. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  300. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  301. #define SDL_OUT_CAP(x) _Out_cap_(x)
  302. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  303. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  304. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  305. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  306. #else
  307. #define SDL_IN_BYTECAP(x)
  308. #define SDL_INOUT_Z_CAP(x)
  309. #define SDL_OUT_Z_CAP(x)
  310. #define SDL_OUT_CAP(x)
  311. #define SDL_OUT_BYTECAP(x)
  312. #define SDL_OUT_Z_BYTECAP(x)
  313. #define SDL_PRINTF_FORMAT_STRING
  314. #define SDL_SCANF_FORMAT_STRING
  315. #endif
  316. #if defined(__GNUC__)
  317. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  318. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  319. #else
  320. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  321. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  322. #endif
  323. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  324. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  325. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  326. /** \cond */
  327. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  328. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  329. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  330. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  331. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  332. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  333. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  334. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  335. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  336. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  337. /** \endcond */
  338. /* Check to make sure enums are the size of ints, for structure packing.
  339. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  340. enums having the size of an int must be enabled.
  341. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  342. */
  343. /** \cond */
  344. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  345. #if !defined(__ANDROID__) && !defined(__VITA__)
  346. /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
  347. typedef enum
  348. {
  349. DUMMY_ENUM_VALUE
  350. } SDL_DUMMY_ENUM;
  351. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  352. #endif
  353. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  354. /** \endcond */
  355. #include "begin_code.h"
  356. /* Set up for C function definitions, even when using C++ */
  357. #ifdef __cplusplus
  358. extern "C" {
  359. #endif
  360. #ifdef HAVE_ALLOCA
  361. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  362. #define SDL_stack_free(data)
  363. #else
  364. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  365. #define SDL_stack_free(data) SDL_free(data)
  366. #endif
  367. extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
  368. extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  369. extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
  370. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  371. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  372. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  373. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  374. typedef void (SDLCALL *SDL_free_func)(void *mem);
  375. /**
  376. * \brief Get the current set of SDL memory functions
  377. */
  378. extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  379. SDL_calloc_func *calloc_func,
  380. SDL_realloc_func *realloc_func,
  381. SDL_free_func *free_func);
  382. /**
  383. * \brief Replace SDL's memory allocation functions with a custom set
  384. *
  385. * \note If you are replacing SDL's memory functions, you should call
  386. * SDL_GetNumAllocations() and be very careful if it returns non-zero.
  387. * That means that your free function will be called with memory
  388. * allocated by the previous memory allocation functions.
  389. */
  390. extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  391. SDL_calloc_func calloc_func,
  392. SDL_realloc_func realloc_func,
  393. SDL_free_func free_func);
  394. /**
  395. * \brief Get the number of outstanding (unfreed) allocations
  396. */
  397. extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  398. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  399. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  400. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
  401. extern DECLSPEC int SDLCALL SDL_abs(int x);
  402. /* !!! FIXME: these have side effects. You probably shouldn't use them. */
  403. /* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
  404. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  405. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  406. extern DECLSPEC int SDLCALL SDL_isalpha(int x);
  407. extern DECLSPEC int SDLCALL SDL_isalnum(int x);
  408. extern DECLSPEC int SDLCALL SDL_isblank(int x);
  409. extern DECLSPEC int SDLCALL SDL_iscntrl(int x);
  410. extern DECLSPEC int SDLCALL SDL_isdigit(int x);
  411. extern DECLSPEC int SDLCALL SDL_isxdigit(int x);
  412. extern DECLSPEC int SDLCALL SDL_ispunct(int x);
  413. extern DECLSPEC int SDLCALL SDL_isspace(int x);
  414. extern DECLSPEC int SDLCALL SDL_isupper(int x);
  415. extern DECLSPEC int SDLCALL SDL_islower(int x);
  416. extern DECLSPEC int SDLCALL SDL_isprint(int x);
  417. extern DECLSPEC int SDLCALL SDL_isgraph(int x);
  418. extern DECLSPEC int SDLCALL SDL_toupper(int x);
  419. extern DECLSPEC int SDLCALL SDL_tolower(int x);
  420. extern DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  421. extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  422. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  423. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  424. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  425. /* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
  426. SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
  427. {
  428. #ifdef __APPLE__
  429. memset_pattern4(dst, &val, dwords * 4);
  430. #elif defined(__GNUC__) && defined(__i386__)
  431. int u0, u1, u2;
  432. __asm__ __volatile__ (
  433. "cld \n\t"
  434. "rep ; stosl \n\t"
  435. : "=&D" (u0), "=&a" (u1), "=&c" (u2)
  436. : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
  437. : "memory"
  438. );
  439. #else
  440. size_t _n = (dwords + 3) / 4;
  441. Uint32 *_p = SDL_static_cast(Uint32 *, dst);
  442. Uint32 _val = (val);
  443. if (dwords == 0)
  444. return;
  445. switch (dwords % 4)
  446. {
  447. case 0: do { *_p++ = _val; /* fallthrough */
  448. case 3: *_p++ = _val; /* fallthrough */
  449. case 2: *_p++ = _val; /* fallthrough */
  450. case 1: *_p++ = _val; /* fallthrough */
  451. } while ( --_n );
  452. }
  453. #endif
  454. }
  455. extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  456. extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  457. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  458. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  459. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  460. extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  461. extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr);
  462. extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  463. extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  464. extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  465. extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  466. extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t len);
  467. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  468. extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  469. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  470. extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  471. extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
  472. extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
  473. extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
  474. extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
  475. extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
  476. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
  477. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
  478. extern DECLSPEC char *SDLCALL SDL_strtokr(char *s1, const char *s2, char **saveptr);
  479. extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  480. extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
  481. extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  482. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
  483. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  484. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  485. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  486. extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
  487. extern DECLSPEC double SDLCALL SDL_atof(const char *str);
  488. extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  489. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  490. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  491. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  492. extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  493. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  494. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  495. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  496. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
  497. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  498. extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
  499. extern DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) SDL_PRINTF_VARARG_FUNC(3);
  500. extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
  501. #ifndef HAVE_M_PI
  502. #ifndef M_PI
  503. #define M_PI 3.14159265358979323846264338327950288 /**< pi */
  504. #endif
  505. #endif
  506. extern DECLSPEC double SDLCALL SDL_acos(double x);
  507. extern DECLSPEC float SDLCALL SDL_acosf(float x);
  508. extern DECLSPEC double SDLCALL SDL_asin(double x);
  509. extern DECLSPEC float SDLCALL SDL_asinf(float x);
  510. extern DECLSPEC double SDLCALL SDL_atan(double x);
  511. extern DECLSPEC float SDLCALL SDL_atanf(float x);
  512. extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
  513. extern DECLSPEC float SDLCALL SDL_atan2f(float x, float y);
  514. extern DECLSPEC double SDLCALL SDL_ceil(double x);
  515. extern DECLSPEC float SDLCALL SDL_ceilf(float x);
  516. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  517. extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  518. extern DECLSPEC double SDLCALL SDL_cos(double x);
  519. extern DECLSPEC float SDLCALL SDL_cosf(float x);
  520. extern DECLSPEC double SDLCALL SDL_exp(double x);
  521. extern DECLSPEC float SDLCALL SDL_expf(float x);
  522. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  523. extern DECLSPEC float SDLCALL SDL_fabsf(float x);
  524. extern DECLSPEC double SDLCALL SDL_floor(double x);
  525. extern DECLSPEC float SDLCALL SDL_floorf(float x);
  526. extern DECLSPEC double SDLCALL SDL_trunc(double x);
  527. extern DECLSPEC float SDLCALL SDL_truncf(float x);
  528. extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  529. extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  530. extern DECLSPEC double SDLCALL SDL_log(double x);
  531. extern DECLSPEC float SDLCALL SDL_logf(float x);
  532. extern DECLSPEC double SDLCALL SDL_log10(double x);
  533. extern DECLSPEC float SDLCALL SDL_log10f(float x);
  534. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  535. extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
  536. extern DECLSPEC double SDLCALL SDL_round(double x);
  537. extern DECLSPEC float SDLCALL SDL_roundf(float x);
  538. extern DECLSPEC long SDLCALL SDL_lround(double x);
  539. extern DECLSPEC long SDLCALL SDL_lroundf(float x);
  540. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  541. extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  542. extern DECLSPEC double SDLCALL SDL_sin(double x);
  543. extern DECLSPEC float SDLCALL SDL_sinf(float x);
  544. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  545. extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
  546. extern DECLSPEC double SDLCALL SDL_tan(double x);
  547. extern DECLSPEC float SDLCALL SDL_tanf(float x);
  548. /* The SDL implementation of iconv() returns these error codes */
  549. #define SDL_ICONV_ERROR (size_t)-1
  550. #define SDL_ICONV_E2BIG (size_t)-2
  551. #define SDL_ICONV_EILSEQ (size_t)-3
  552. #define SDL_ICONV_EINVAL (size_t)-4
  553. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  554. typedef struct _SDL_iconv_t *SDL_iconv_t;
  555. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  556. const char *fromcode);
  557. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  558. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  559. size_t * inbytesleft, char **outbuf,
  560. size_t * outbytesleft);
  561. /**
  562. * This function converts a string between encodings in one pass, returning a
  563. * string that must be freed with SDL_free() or NULL on error.
  564. */
  565. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  566. const char *fromcode,
  567. const char *inbuf,
  568. size_t inbytesleft);
  569. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  570. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  571. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  572. /* force builds using Clang's static analysis tools to use literal C runtime
  573. here, since there are possibly tests that are ineffective otherwise. */
  574. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  575. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  576. #ifndef HAVE_STRLCPY
  577. size_t strlcpy(char* dst, const char* src, size_t size);
  578. #endif
  579. /* The analyzer knows about strlcat even when the system doesn't provide it */
  580. #ifndef HAVE_STRLCAT
  581. size_t strlcat(char* dst, const char* src, size_t size);
  582. #endif
  583. #define SDL_malloc malloc
  584. #define SDL_calloc calloc
  585. #define SDL_realloc realloc
  586. #define SDL_free free
  587. #define SDL_memset memset
  588. #define SDL_memcpy memcpy
  589. #define SDL_memmove memmove
  590. #define SDL_memcmp memcmp
  591. #define SDL_strlcpy strlcpy
  592. #define SDL_strlcat strlcat
  593. #define SDL_strlen strlen
  594. #define SDL_wcslen wcslen
  595. #define SDL_wcslcpy wcslcpy
  596. #define SDL_wcslcat wcslcat
  597. #define SDL_strdup strdup
  598. #define SDL_wcsdup wcsdup
  599. #define SDL_strchr strchr
  600. #define SDL_strrchr strrchr
  601. #define SDL_strstr strstr
  602. #define SDL_wcsstr wcsstr
  603. #define SDL_strtokr strtok_r
  604. #define SDL_strcmp strcmp
  605. #define SDL_wcscmp wcscmp
  606. #define SDL_strncmp strncmp
  607. #define SDL_wcsncmp wcsncmp
  608. #define SDL_strcasecmp strcasecmp
  609. #define SDL_strncasecmp strncasecmp
  610. #define SDL_sscanf sscanf
  611. #define SDL_vsscanf vsscanf
  612. #define SDL_snprintf snprintf
  613. #define SDL_vsnprintf vsnprintf
  614. #endif
  615. SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
  616. {
  617. return SDL_memcpy(dst, src, dwords * 4);
  618. }
  619. /* Ends C function definitions when using C++ */
  620. #ifdef __cplusplus
  621. }
  622. #endif
  623. #include "close_code.h"
  624. #endif /* SDL_stdinc_h_ */
  625. /* vi: set ts=4 sw=4 expandtab: */