SDL_stdinc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. * Check if the compiler supports a given builtin.
  111. * Supported by virtually all clang versions and recent gcc. Use this
  112. * instead of checking the clang version if possible.
  113. */
  114. #ifdef __has_builtin
  115. #define _SDL_HAS_BUILTIN(x) __has_builtin(x)
  116. #else
  117. #define _SDL_HAS_BUILTIN(x) 0
  118. #endif
  119. /**
  120. * The number of elements in an array.
  121. */
  122. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  123. #define SDL_TABLESIZE(table) SDL_arraysize(table)
  124. /**
  125. * Macro useful for building other macros with strings in them
  126. *
  127. * e.g. #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")
  128. */
  129. #define SDL_STRINGIFY_ARG(arg) #arg
  130. /**
  131. * \name Cast operators
  132. *
  133. * Use proper C++ casts when compiled as C++ to be compatible with the option
  134. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  135. */
  136. /* @{ */
  137. #ifdef __cplusplus
  138. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  139. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  140. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  141. #else
  142. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  143. #define SDL_static_cast(type, expression) ((type)(expression))
  144. #define SDL_const_cast(type, expression) ((type)(expression))
  145. #endif
  146. /* @} *//* Cast operators */
  147. /* Define a four character code as a Uint32 */
  148. #define SDL_FOURCC(A, B, C, D) \
  149. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  150. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  151. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  152. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  153. /**
  154. * \name Basic data types
  155. */
  156. /* @{ */
  157. #ifdef __CC_ARM
  158. /* ARM's compiler throws warnings if we use an enum: like "SDL_bool x = a < b;" */
  159. #define SDL_FALSE 0
  160. #define SDL_TRUE 1
  161. typedef int SDL_bool;
  162. #else
  163. typedef enum
  164. {
  165. SDL_FALSE = 0,
  166. SDL_TRUE = 1
  167. } SDL_bool;
  168. #endif
  169. /**
  170. * \brief A signed 8-bit integer type.
  171. */
  172. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  173. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  174. typedef int8_t Sint8;
  175. /**
  176. * \brief An unsigned 8-bit integer type.
  177. */
  178. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  179. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  180. typedef uint8_t Uint8;
  181. /**
  182. * \brief A signed 16-bit integer type.
  183. */
  184. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  185. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  186. typedef int16_t Sint16;
  187. /**
  188. * \brief An unsigned 16-bit integer type.
  189. */
  190. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  191. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  192. typedef uint16_t Uint16;
  193. /**
  194. * \brief A signed 32-bit integer type.
  195. */
  196. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  197. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  198. typedef int32_t Sint32;
  199. /**
  200. * \brief An unsigned 32-bit integer type.
  201. */
  202. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  203. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  204. typedef uint32_t Uint32;
  205. /**
  206. * \brief A signed 64-bit integer type.
  207. */
  208. #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
  209. #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
  210. typedef int64_t Sint64;
  211. /**
  212. * \brief An unsigned 64-bit integer type.
  213. */
  214. #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
  215. #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
  216. typedef uint64_t Uint64;
  217. /* @} *//* Basic data types */
  218. /* Make sure we have macros for printing width-based integers.
  219. * <stdint.h> should define these but this is not true all platforms.
  220. * (for example win32) */
  221. #ifndef SDL_PRIs64
  222. #ifdef PRIs64
  223. #define SDL_PRIs64 PRIs64
  224. #elif defined(__WIN32__)
  225. #define SDL_PRIs64 "I64d"
  226. #elif defined(__LINUX__) && defined(__LP64__)
  227. #define SDL_PRIs64 "ld"
  228. #else
  229. #define SDL_PRIs64 "lld"
  230. #endif
  231. #endif
  232. #ifndef SDL_PRIu64
  233. #ifdef PRIu64
  234. #define SDL_PRIu64 PRIu64
  235. #elif defined(__WIN32__)
  236. #define SDL_PRIu64 "I64u"
  237. #elif defined(__LINUX__) && defined(__LP64__)
  238. #define SDL_PRIu64 "lu"
  239. #else
  240. #define SDL_PRIu64 "llu"
  241. #endif
  242. #endif
  243. #ifndef SDL_PRIx64
  244. #ifdef PRIx64
  245. #define SDL_PRIx64 PRIx64
  246. #elif defined(__WIN32__)
  247. #define SDL_PRIx64 "I64x"
  248. #elif defined(__LINUX__) && defined(__LP64__)
  249. #define SDL_PRIx64 "lx"
  250. #else
  251. #define SDL_PRIx64 "llx"
  252. #endif
  253. #endif
  254. #ifndef SDL_PRIX64
  255. #ifdef PRIX64
  256. #define SDL_PRIX64 PRIX64
  257. #elif defined(__WIN32__)
  258. #define SDL_PRIX64 "I64X"
  259. #elif defined(__LINUX__) && defined(__LP64__)
  260. #define SDL_PRIX64 "lX"
  261. #else
  262. #define SDL_PRIX64 "llX"
  263. #endif
  264. #endif
  265. #ifndef SDL_PRIs32
  266. #ifdef PRId32
  267. #define SDL_PRIs32 PRId32
  268. #else
  269. #define SDL_PRIs32 "d"
  270. #endif
  271. #endif
  272. #ifndef SDL_PRIu32
  273. #ifdef PRIu32
  274. #define SDL_PRIu32 PRIu32
  275. #else
  276. #define SDL_PRIu32 "u"
  277. #endif
  278. #endif
  279. #ifndef SDL_PRIx32
  280. #ifdef PRIx32
  281. #define SDL_PRIx32 PRIx32
  282. #else
  283. #define SDL_PRIx32 "x"
  284. #endif
  285. #endif
  286. #ifndef SDL_PRIX32
  287. #ifdef PRIX32
  288. #define SDL_PRIX32 PRIX32
  289. #else
  290. #define SDL_PRIX32 "X"
  291. #endif
  292. #endif
  293. /* Annotations to help code analysis tools */
  294. #ifdef SDL_DISABLE_ANALYZE_MACROS
  295. #define SDL_IN_BYTECAP(x)
  296. #define SDL_INOUT_Z_CAP(x)
  297. #define SDL_OUT_Z_CAP(x)
  298. #define SDL_OUT_CAP(x)
  299. #define SDL_OUT_BYTECAP(x)
  300. #define SDL_OUT_Z_BYTECAP(x)
  301. #define SDL_PRINTF_FORMAT_STRING
  302. #define SDL_SCANF_FORMAT_STRING
  303. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  304. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  305. #else
  306. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  307. #include <sal.h>
  308. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  309. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  310. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  311. #define SDL_OUT_CAP(x) _Out_cap_(x)
  312. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  313. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  314. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  315. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  316. #else
  317. #define SDL_IN_BYTECAP(x)
  318. #define SDL_INOUT_Z_CAP(x)
  319. #define SDL_OUT_Z_CAP(x)
  320. #define SDL_OUT_CAP(x)
  321. #define SDL_OUT_BYTECAP(x)
  322. #define SDL_OUT_Z_BYTECAP(x)
  323. #define SDL_PRINTF_FORMAT_STRING
  324. #define SDL_SCANF_FORMAT_STRING
  325. #endif
  326. #if defined(__GNUC__)
  327. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  328. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  329. #else
  330. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  331. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  332. #endif
  333. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  334. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  335. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  336. /** \cond */
  337. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  338. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  339. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  340. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  341. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  342. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  343. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  344. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  345. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  346. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  347. /** \endcond */
  348. /* Check to make sure enums are the size of ints, for structure packing.
  349. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  350. enums having the size of an int must be enabled.
  351. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  352. */
  353. /** \cond */
  354. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  355. #if !defined(__ANDROID__) && !defined(__VITA__)
  356. /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
  357. typedef enum
  358. {
  359. DUMMY_ENUM_VALUE
  360. } SDL_DUMMY_ENUM;
  361. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  362. #endif
  363. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  364. /** \endcond */
  365. #include "begin_code.h"
  366. /* Set up for C function definitions, even when using C++ */
  367. #ifdef __cplusplus
  368. extern "C" {
  369. #endif
  370. #ifdef HAVE_ALLOCA
  371. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  372. #define SDL_stack_free(data)
  373. #else
  374. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  375. #define SDL_stack_free(data) SDL_free(data)
  376. #endif
  377. extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
  378. extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  379. extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
  380. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  381. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  382. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  383. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  384. typedef void (SDLCALL *SDL_free_func)(void *mem);
  385. /**
  386. * Get the current set of SDL memory functions
  387. *
  388. * \since This function is available since SDL 2.0.7.
  389. */
  390. extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(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. * Replace SDL's memory allocation functions with a custom set
  396. *
  397. * \since This function is available since SDL 2.0.7.
  398. */
  399. extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  400. SDL_calloc_func calloc_func,
  401. SDL_realloc_func realloc_func,
  402. SDL_free_func free_func);
  403. /**
  404. * Get the number of outstanding (unfreed) allocations
  405. *
  406. * \since This function is available since SDL 2.0.7.
  407. */
  408. extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  409. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  410. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  411. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
  412. extern DECLSPEC int SDLCALL SDL_abs(int x);
  413. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  414. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  415. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  416. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  417. extern DECLSPEC int SDLCALL SDL_isalpha(int x);
  418. extern DECLSPEC int SDLCALL SDL_isalnum(int x);
  419. extern DECLSPEC int SDLCALL SDL_isblank(int x);
  420. extern DECLSPEC int SDLCALL SDL_iscntrl(int x);
  421. extern DECLSPEC int SDLCALL SDL_isdigit(int x);
  422. extern DECLSPEC int SDLCALL SDL_isxdigit(int x);
  423. extern DECLSPEC int SDLCALL SDL_ispunct(int x);
  424. extern DECLSPEC int SDLCALL SDL_isspace(int x);
  425. extern DECLSPEC int SDLCALL SDL_isupper(int x);
  426. extern DECLSPEC int SDLCALL SDL_islower(int x);
  427. extern DECLSPEC int SDLCALL SDL_isprint(int x);
  428. extern DECLSPEC int SDLCALL SDL_isgraph(int x);
  429. extern DECLSPEC int SDLCALL SDL_toupper(int x);
  430. extern DECLSPEC int SDLCALL SDL_tolower(int x);
  431. extern DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  432. extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  433. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  434. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  435. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  436. /* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
  437. SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
  438. {
  439. #ifdef __APPLE__
  440. memset_pattern4(dst, &val, dwords * 4);
  441. #elif defined(__GNUC__) && defined(__i386__)
  442. int u0, u1, u2;
  443. __asm__ __volatile__ (
  444. "cld \n\t"
  445. "rep ; stosl \n\t"
  446. : "=&D" (u0), "=&a" (u1), "=&c" (u2)
  447. : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
  448. : "memory"
  449. );
  450. #else
  451. size_t _n = (dwords + 3) / 4;
  452. Uint32 *_p = SDL_static_cast(Uint32 *, dst);
  453. Uint32 _val = (val);
  454. if (dwords == 0) {
  455. return;
  456. }
  457. switch (dwords % 4) {
  458. case 0: do { *_p++ = _val; SDL_FALLTHROUGH;
  459. case 3: *_p++ = _val; SDL_FALLTHROUGH;
  460. case 2: *_p++ = _val; SDL_FALLTHROUGH;
  461. case 1: *_p++ = _val;
  462. } while ( --_n );
  463. }
  464. #endif
  465. }
  466. extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  467. extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  468. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  469. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  470. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  471. extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  472. extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr);
  473. extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  474. extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  475. extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  476. extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  477. extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t len);
  478. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  479. extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  480. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  481. extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  482. extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
  483. extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
  484. extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
  485. extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
  486. extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
  487. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
  488. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
  489. extern DECLSPEC char *SDLCALL SDL_strtokr(char *s1, const char *s2, char **saveptr);
  490. extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  491. extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
  492. extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  493. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
  494. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  495. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  496. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  497. extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
  498. extern DECLSPEC double SDLCALL SDL_atof(const char *str);
  499. extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  500. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  501. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  502. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  503. extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  504. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  505. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  506. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  507. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
  508. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  509. extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
  510. 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);
  511. extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
  512. extern DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  513. extern DECLSPEC int SDLCALL SDL_vasprintf(char **strp, const char *fmt, va_list ap);
  514. #ifndef HAVE_M_PI
  515. #ifndef M_PI
  516. #define M_PI 3.14159265358979323846264338327950288 /**< pi */
  517. #endif
  518. #endif
  519. /**
  520. * Use this function to compute arc cosine of `x`.
  521. *
  522. * The definition of `y = acos(x)` is `x = cos(y)`.
  523. *
  524. * Domain: `-1 <= x <= 1`
  525. *
  526. * Range: `0 <= y <= Pi`
  527. *
  528. * \param x floating point value, in radians.
  529. * \returns arc cosine of `x`.
  530. *
  531. * \since This function is available since SDL 2.0.2.
  532. */
  533. extern DECLSPEC double SDLCALL SDL_acos(double x);
  534. extern DECLSPEC float SDLCALL SDL_acosf(float x);
  535. extern DECLSPEC double SDLCALL SDL_asin(double x);
  536. extern DECLSPEC float SDLCALL SDL_asinf(float x);
  537. extern DECLSPEC double SDLCALL SDL_atan(double x);
  538. extern DECLSPEC float SDLCALL SDL_atanf(float x);
  539. extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  540. extern DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  541. extern DECLSPEC double SDLCALL SDL_ceil(double x);
  542. extern DECLSPEC float SDLCALL SDL_ceilf(float x);
  543. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  544. extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  545. extern DECLSPEC double SDLCALL SDL_cos(double x);
  546. extern DECLSPEC float SDLCALL SDL_cosf(float x);
  547. extern DECLSPEC double SDLCALL SDL_exp(double x);
  548. extern DECLSPEC float SDLCALL SDL_expf(float x);
  549. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  550. extern DECLSPEC float SDLCALL SDL_fabsf(float x);
  551. extern DECLSPEC double SDLCALL SDL_floor(double x);
  552. extern DECLSPEC float SDLCALL SDL_floorf(float x);
  553. extern DECLSPEC double SDLCALL SDL_trunc(double x);
  554. extern DECLSPEC float SDLCALL SDL_truncf(float x);
  555. extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  556. extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  557. extern DECLSPEC double SDLCALL SDL_log(double x);
  558. extern DECLSPEC float SDLCALL SDL_logf(float x);
  559. extern DECLSPEC double SDLCALL SDL_log10(double x);
  560. extern DECLSPEC float SDLCALL SDL_log10f(float x);
  561. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  562. extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
  563. extern DECLSPEC double SDLCALL SDL_round(double x);
  564. extern DECLSPEC float SDLCALL SDL_roundf(float x);
  565. extern DECLSPEC long SDLCALL SDL_lround(double x);
  566. extern DECLSPEC long SDLCALL SDL_lroundf(float x);
  567. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  568. extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  569. extern DECLSPEC double SDLCALL SDL_sin(double x);
  570. extern DECLSPEC float SDLCALL SDL_sinf(float x);
  571. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  572. extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
  573. extern DECLSPEC double SDLCALL SDL_tan(double x);
  574. extern DECLSPEC float SDLCALL SDL_tanf(float x);
  575. /* The SDL implementation of iconv() returns these error codes */
  576. #define SDL_ICONV_ERROR (size_t)-1
  577. #define SDL_ICONV_E2BIG (size_t)-2
  578. #define SDL_ICONV_EILSEQ (size_t)-3
  579. #define SDL_ICONV_EINVAL (size_t)-4
  580. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  581. typedef struct _SDL_iconv_t *SDL_iconv_t;
  582. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  583. const char *fromcode);
  584. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  585. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  586. size_t * inbytesleft, char **outbuf,
  587. size_t * outbytesleft);
  588. /**
  589. * This function converts a string between encodings in one pass, returning a
  590. * string that must be freed with SDL_free() or NULL on error.
  591. *
  592. * \since This function is available since SDL 2.0.0.
  593. */
  594. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  595. const char *fromcode,
  596. const char *inbuf,
  597. size_t inbytesleft);
  598. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  599. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  600. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  601. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  602. /* force builds using Clang's static analysis tools to use literal C runtime
  603. here, since there are possibly tests that are ineffective otherwise. */
  604. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  605. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  606. #ifndef HAVE_STRLCPY
  607. size_t strlcpy(char* dst, const char* src, size_t size);
  608. #endif
  609. /* The analyzer knows about strlcat even when the system doesn't provide it */
  610. #ifndef HAVE_STRLCAT
  611. size_t strlcat(char* dst, const char* src, size_t size);
  612. #endif
  613. #define SDL_malloc malloc
  614. #define SDL_calloc calloc
  615. #define SDL_realloc realloc
  616. #define SDL_free free
  617. #define SDL_memset memset
  618. #define SDL_memcpy memcpy
  619. #define SDL_memmove memmove
  620. #define SDL_memcmp memcmp
  621. #define SDL_strlcpy strlcpy
  622. #define SDL_strlcat strlcat
  623. #define SDL_strlen strlen
  624. #define SDL_wcslen wcslen
  625. #define SDL_wcslcpy wcslcpy
  626. #define SDL_wcslcat wcslcat
  627. #define SDL_strdup strdup
  628. #define SDL_wcsdup wcsdup
  629. #define SDL_strchr strchr
  630. #define SDL_strrchr strrchr
  631. #define SDL_strstr strstr
  632. #define SDL_wcsstr wcsstr
  633. #define SDL_strtokr strtok_r
  634. #define SDL_strcmp strcmp
  635. #define SDL_wcscmp wcscmp
  636. #define SDL_strncmp strncmp
  637. #define SDL_wcsncmp wcsncmp
  638. #define SDL_strcasecmp strcasecmp
  639. #define SDL_strncasecmp strncasecmp
  640. #define SDL_sscanf sscanf
  641. #define SDL_vsscanf vsscanf
  642. #define SDL_snprintf snprintf
  643. #define SDL_vsnprintf vsnprintf
  644. #endif
  645. SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
  646. {
  647. return SDL_memcpy(dst, src, dwords * 4);
  648. }
  649. /* Ends C function definitions when using C++ */
  650. #ifdef __cplusplus
  651. }
  652. #endif
  653. #include "close_code.h"
  654. #endif /* SDL_stdinc_h_ */
  655. /* vi: set ts=4 sw=4 expandtab: */