SDL_stdinc.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
  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. * \brief This is a general header that includes C language support.
  22. */
  23. #ifndef SDL_stdinc_h_
  24. #define SDL_stdinc_h_
  25. #include <SDL3/SDL_platform_defines.h>
  26. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  27. #include <inttypes.h>
  28. #endif
  29. #include <stdarg.h>
  30. #include <stdint.h>
  31. #include <wchar.h>
  32. #if !defined(alloca)
  33. # if defined(HAVE_ALLOCA_H)
  34. # include <alloca.h>
  35. # elif defined(__GNUC__)
  36. # define alloca __builtin_alloca
  37. # elif defined(_MSC_VER)
  38. # include <malloc.h>
  39. # define alloca _alloca
  40. # elif defined(__WATCOMC__)
  41. # include <malloc.h>
  42. # elif defined(__BORLANDC__)
  43. # include <malloc.h>
  44. # elif defined(__DMC__)
  45. # include <stdlib.h>
  46. # elif defined(__AIX__)
  47. #pragma alloca
  48. # elif defined(__MRC__)
  49. void *alloca(unsigned);
  50. # else
  51. char *alloca();
  52. # endif
  53. #endif
  54. #ifdef SIZE_MAX
  55. # define SDL_SIZE_MAX SIZE_MAX
  56. #else
  57. # define SDL_SIZE_MAX ((size_t) -1)
  58. #endif
  59. /**
  60. * Check if the compiler supports a given builtin.
  61. * Supported by virtually all clang versions and recent gcc. Use this
  62. * instead of checking the clang version if possible.
  63. */
  64. #ifdef __has_builtin
  65. #define SDL_HAS_BUILTIN(x) __has_builtin(x)
  66. #else
  67. #define SDL_HAS_BUILTIN(x) 0
  68. #endif
  69. /**
  70. * The number of elements in an array.
  71. */
  72. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  73. #define SDL_TABLESIZE(table) SDL_arraysize(table)
  74. /**
  75. * Macro useful for building other macros with strings in them
  76. *
  77. * e.g. #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")
  78. */
  79. #define SDL_STRINGIFY_ARG(arg) #arg
  80. /**
  81. * \name Cast operators
  82. *
  83. * Use proper C++ casts when compiled as C++ to be compatible with the option
  84. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  85. */
  86. /* @{ */
  87. #ifdef __cplusplus
  88. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  89. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  90. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  91. #else
  92. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  93. #define SDL_static_cast(type, expression) ((type)(expression))
  94. #define SDL_const_cast(type, expression) ((type)(expression))
  95. #endif
  96. /* @} *//* Cast operators */
  97. /* Define a four character code as a Uint32 */
  98. #define SDL_FOURCC(A, B, C, D) \
  99. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  100. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  101. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  102. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  103. /**
  104. * \name Basic data types
  105. */
  106. /* @{ */
  107. #ifdef __CC_ARM
  108. /* ARM's compiler throws warnings if we use an enum: like "SDL_bool x = a < b;" */
  109. #define SDL_FALSE 0
  110. #define SDL_TRUE 1
  111. typedef int SDL_bool;
  112. #else
  113. typedef enum
  114. {
  115. SDL_FALSE = 0,
  116. SDL_TRUE = 1
  117. } SDL_bool;
  118. #endif
  119. /**
  120. * \brief A signed 8-bit integer type.
  121. */
  122. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  123. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  124. typedef int8_t Sint8;
  125. /**
  126. * \brief An unsigned 8-bit integer type.
  127. */
  128. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  129. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  130. typedef uint8_t Uint8;
  131. /**
  132. * \brief A signed 16-bit integer type.
  133. */
  134. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  135. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  136. typedef int16_t Sint16;
  137. /**
  138. * \brief An unsigned 16-bit integer type.
  139. */
  140. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  141. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  142. typedef uint16_t Uint16;
  143. /**
  144. * \brief A signed 32-bit integer type.
  145. */
  146. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  147. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  148. typedef int32_t Sint32;
  149. /**
  150. * \brief An unsigned 32-bit integer type.
  151. */
  152. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  153. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  154. typedef uint32_t Uint32;
  155. /**
  156. * \brief A signed 64-bit integer type.
  157. */
  158. #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
  159. #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
  160. typedef int64_t Sint64;
  161. /**
  162. * \brief An unsigned 64-bit integer type.
  163. */
  164. #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
  165. #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
  166. typedef uint64_t Uint64;
  167. /* @} *//* Basic data types */
  168. /**
  169. * \name Floating-point constants
  170. */
  171. /* @{ */
  172. #ifdef FLT_EPSILON
  173. #define SDL_FLT_EPSILON FLT_EPSILON
  174. #else
  175. #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
  176. #endif
  177. /* @} *//* Floating-point constants */
  178. /* Make sure we have macros for printing width-based integers.
  179. * <stdint.h> should define these but this is not true all platforms.
  180. * (for example win32) */
  181. #ifndef SDL_PRIs64
  182. #ifdef PRIs64
  183. #define SDL_PRIs64 PRIs64
  184. #elif defined(__WIN32__) || defined(__GDK__)
  185. #define SDL_PRIs64 "I64d"
  186. #elif defined(__LP64__) && !defined(__APPLE__)
  187. #define SDL_PRIs64 "ld"
  188. #else
  189. #define SDL_PRIs64 "lld"
  190. #endif
  191. #endif
  192. #ifndef SDL_PRIu64
  193. #ifdef PRIu64
  194. #define SDL_PRIu64 PRIu64
  195. #elif defined(__WIN32__) || defined(__GDK__)
  196. #define SDL_PRIu64 "I64u"
  197. #elif defined(__LP64__) && !defined(__APPLE__)
  198. #define SDL_PRIu64 "lu"
  199. #else
  200. #define SDL_PRIu64 "llu"
  201. #endif
  202. #endif
  203. #ifndef SDL_PRIx64
  204. #ifdef PRIx64
  205. #define SDL_PRIx64 PRIx64
  206. #elif defined(__WIN32__) || defined(__GDK__)
  207. #define SDL_PRIx64 "I64x"
  208. #elif defined(__LP64__) && !defined(__APPLE__)
  209. #define SDL_PRIx64 "lx"
  210. #else
  211. #define SDL_PRIx64 "llx"
  212. #endif
  213. #endif
  214. #ifndef SDL_PRIX64
  215. #ifdef PRIX64
  216. #define SDL_PRIX64 PRIX64
  217. #elif defined(__WIN32__) || defined(__GDK__)
  218. #define SDL_PRIX64 "I64X"
  219. #elif defined(__LP64__) && !defined(__APPLE__)
  220. #define SDL_PRIX64 "lX"
  221. #else
  222. #define SDL_PRIX64 "llX"
  223. #endif
  224. #endif
  225. #ifndef SDL_PRIs32
  226. #ifdef PRId32
  227. #define SDL_PRIs32 PRId32
  228. #else
  229. #define SDL_PRIs32 "d"
  230. #endif
  231. #endif
  232. #ifndef SDL_PRIu32
  233. #ifdef PRIu32
  234. #define SDL_PRIu32 PRIu32
  235. #else
  236. #define SDL_PRIu32 "u"
  237. #endif
  238. #endif
  239. #ifndef SDL_PRIx32
  240. #ifdef PRIx32
  241. #define SDL_PRIx32 PRIx32
  242. #else
  243. #define SDL_PRIx32 "x"
  244. #endif
  245. #endif
  246. #ifndef SDL_PRIX32
  247. #ifdef PRIX32
  248. #define SDL_PRIX32 PRIX32
  249. #else
  250. #define SDL_PRIX32 "X"
  251. #endif
  252. #endif
  253. /* Annotations to help code analysis tools */
  254. #ifdef SDL_DISABLE_ANALYZE_MACROS
  255. #define SDL_IN_BYTECAP(x)
  256. #define SDL_INOUT_Z_CAP(x)
  257. #define SDL_OUT_Z_CAP(x)
  258. #define SDL_OUT_CAP(x)
  259. #define SDL_OUT_BYTECAP(x)
  260. #define SDL_OUT_Z_BYTECAP(x)
  261. #define SDL_PRINTF_FORMAT_STRING
  262. #define SDL_SCANF_FORMAT_STRING
  263. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  264. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  265. #else
  266. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  267. #include <sal.h>
  268. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  269. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  270. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  271. #define SDL_OUT_CAP(x) _Out_cap_(x)
  272. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  273. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  274. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  275. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  276. #else
  277. #define SDL_IN_BYTECAP(x)
  278. #define SDL_INOUT_Z_CAP(x)
  279. #define SDL_OUT_Z_CAP(x)
  280. #define SDL_OUT_CAP(x)
  281. #define SDL_OUT_BYTECAP(x)
  282. #define SDL_OUT_Z_BYTECAP(x)
  283. #define SDL_PRINTF_FORMAT_STRING
  284. #define SDL_SCANF_FORMAT_STRING
  285. #endif
  286. #if defined(__GNUC__)
  287. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  288. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  289. #else
  290. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  291. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  292. #endif
  293. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  294. #ifndef SDL_COMPILE_TIME_ASSERT
  295. #if defined(__cplusplus)
  296. #if (__cplusplus >= 201103L)
  297. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  298. #endif
  299. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  300. #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
  301. #endif
  302. #endif /* !SDL_COMPILE_TIME_ASSERT */
  303. #ifndef SDL_COMPILE_TIME_ASSERT
  304. /* universal, but may trigger -Wunused-local-typedefs */
  305. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  306. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  307. #endif
  308. /** \cond */
  309. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  310. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  311. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  312. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  313. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  314. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  315. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  316. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  317. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  318. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  319. /** \endcond */
  320. /* Check to make sure enums are the size of ints, for structure packing.
  321. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  322. enums having the size of an int must be enabled.
  323. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  324. */
  325. /** \cond */
  326. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  327. #if !defined(__ANDROID__) && !defined(__VITA__) && !defined(__3DS__)
  328. /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
  329. typedef enum
  330. {
  331. DUMMY_ENUM_VALUE
  332. } SDL_DUMMY_ENUM;
  333. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  334. #endif
  335. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  336. /** \endcond */
  337. #include <SDL3/SDL_begin_code.h>
  338. /* Set up for C function definitions, even when using C++ */
  339. #ifdef __cplusplus
  340. extern "C" {
  341. #endif
  342. #ifdef HAVE_ALLOCA
  343. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  344. #define SDL_stack_free(data)
  345. #else
  346. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  347. #define SDL_stack_free(data) SDL_free(data)
  348. #endif
  349. extern DECLSPEC SDL_MALLOC void *SDLCALL SDL_malloc(size_t size);
  350. extern DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  351. extern DECLSPEC SDL_ALLOC_SIZE(2) void *SDLCALL SDL_realloc(void *mem, size_t size);
  352. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  353. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  354. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  355. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  356. typedef void (SDLCALL *SDL_free_func)(void *mem);
  357. /**
  358. * Get the original set of SDL memory functions
  359. *
  360. * \param malloc_func filled with malloc function
  361. * \param calloc_func filled with calloc function
  362. * \param realloc_func filled with realloc function
  363. * \param free_func filled with free function
  364. *
  365. * \since This function is available since SDL 3.0.0.
  366. */
  367. extern DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
  368. SDL_calloc_func *calloc_func,
  369. SDL_realloc_func *realloc_func,
  370. SDL_free_func *free_func);
  371. /**
  372. * Get the current set of SDL memory functions
  373. *
  374. * \param malloc_func filled with malloc function
  375. * \param calloc_func filled with calloc function
  376. * \param realloc_func filled with realloc function
  377. * \param free_func filled with free function
  378. *
  379. * \since This function is available since SDL 3.0.0.
  380. */
  381. extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  382. SDL_calloc_func *calloc_func,
  383. SDL_realloc_func *realloc_func,
  384. SDL_free_func *free_func);
  385. /**
  386. * Replace SDL's memory allocation functions with a custom set
  387. *
  388. * \param malloc_func custom malloc function
  389. * \param calloc_func custom calloc function
  390. * \param realloc_func custom realloc function
  391. * \param free_func custom free function
  392. * \returns 0 on success or a negative error code on failure; call
  393. * SDL_GetError() for more information.
  394. *
  395. * \since This function is available since SDL 3.0.0.
  396. */
  397. extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  398. SDL_calloc_func calloc_func,
  399. SDL_realloc_func realloc_func,
  400. SDL_free_func free_func);
  401. /**
  402. * Allocate memory aligned to a specific value
  403. *
  404. * If `alignment` is less than the size of `void *`, then it will be increased
  405. * to match that.
  406. *
  407. * The returned memory address will be a multiple of the alignment value, and
  408. * the amount of memory allocated will be a multiple of the alignment value.
  409. *
  410. * The memory returned by this function must be freed with SDL_aligned_free()
  411. *
  412. * \param alignment the alignment requested
  413. * \param size the size to allocate
  414. * \returns a pointer to the aligned memory
  415. *
  416. * \since This function is available since SDL 3.0.0.
  417. *
  418. * \sa SDL_aligned_free
  419. */
  420. extern DECLSPEC SDL_MALLOC void *SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
  421. /**
  422. * Free memory allocated by SDL_aligned_alloc()
  423. *
  424. * \since This function is available since SDL 3.0.0.
  425. *
  426. * \sa SDL_aligned_alloc
  427. */
  428. extern DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
  429. /**
  430. * Get the number of outstanding (unfreed) allocations
  431. *
  432. * \returns the number of allocations
  433. *
  434. * \since This function is available since SDL 3.0.0.
  435. */
  436. extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  437. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  438. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  439. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (const void *, const void *));
  440. extern DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (const void *, const void *));
  441. extern DECLSPEC int SDLCALL SDL_abs(int x);
  442. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  443. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  444. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  445. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  446. extern DECLSPEC int SDLCALL SDL_isalpha(int x);
  447. extern DECLSPEC int SDLCALL SDL_isalnum(int x);
  448. extern DECLSPEC int SDLCALL SDL_isblank(int x);
  449. extern DECLSPEC int SDLCALL SDL_iscntrl(int x);
  450. extern DECLSPEC int SDLCALL SDL_isdigit(int x);
  451. extern DECLSPEC int SDLCALL SDL_isxdigit(int x);
  452. extern DECLSPEC int SDLCALL SDL_ispunct(int x);
  453. extern DECLSPEC int SDLCALL SDL_isspace(int x);
  454. extern DECLSPEC int SDLCALL SDL_isupper(int x);
  455. extern DECLSPEC int SDLCALL SDL_islower(int x);
  456. extern DECLSPEC int SDLCALL SDL_isprint(int x);
  457. extern DECLSPEC int SDLCALL SDL_isgraph(int x);
  458. extern DECLSPEC int SDLCALL SDL_toupper(int x);
  459. extern DECLSPEC int SDLCALL SDL_tolower(int x);
  460. extern DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  461. extern DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  462. extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  463. extern DECLSPEC void *SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  464. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  465. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  466. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  467. #define SDL_copyp(dst, src) \
  468. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  469. SDL_memcpy((dst), (src), sizeof (*(src)))
  470. extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  471. extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  472. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  473. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  474. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  475. extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  476. extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr);
  477. extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  478. extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  479. extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  480. extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  481. extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t len);
  482. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  483. extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  484. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  485. extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  486. extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strdup(const char *str);
  487. extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
  488. extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
  489. extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
  490. extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
  491. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
  492. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
  493. extern DECLSPEC char *SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  494. extern DECLSPEC char *SDLCALL SDL_strtokr(char *s1, const char *s2, char **saveptr);
  495. extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  496. extern DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  497. extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
  498. extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  499. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
  500. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  501. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  502. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  503. extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
  504. extern DECLSPEC double SDLCALL SDL_atof(const char *str);
  505. extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  506. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  507. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  508. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  509. extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  510. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  511. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  512. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  513. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
  514. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  515. extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
  516. 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);
  517. extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
  518. extern DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  519. extern DECLSPEC int SDLCALL SDL_vasprintf(char **strp, const char *fmt, va_list ap);
  520. #ifndef SDL_PI_D
  521. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  522. #endif
  523. #ifndef SDL_PI_F
  524. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  525. #endif
  526. /**
  527. * Use this function to compute arc cosine of `x`.
  528. *
  529. * The definition of `y = acos(x)` is `x = cos(y)`.
  530. *
  531. * Domain: `-1 <= x <= 1`
  532. *
  533. * Range: `0 <= y <= Pi`
  534. *
  535. * \param x floating point value, in radians.
  536. * \returns arc cosine of `x`.
  537. *
  538. * \since This function is available since SDL 3.0.0.
  539. */
  540. extern DECLSPEC double SDLCALL SDL_acos(double x);
  541. extern DECLSPEC float SDLCALL SDL_acosf(float x);
  542. extern DECLSPEC double SDLCALL SDL_asin(double x);
  543. extern DECLSPEC float SDLCALL SDL_asinf(float x);
  544. extern DECLSPEC double SDLCALL SDL_atan(double x);
  545. extern DECLSPEC float SDLCALL SDL_atanf(float x);
  546. extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  547. extern DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  548. extern DECLSPEC double SDLCALL SDL_ceil(double x);
  549. extern DECLSPEC float SDLCALL SDL_ceilf(float x);
  550. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  551. extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  552. extern DECLSPEC double SDLCALL SDL_cos(double x);
  553. extern DECLSPEC float SDLCALL SDL_cosf(float x);
  554. extern DECLSPEC double SDLCALL SDL_exp(double x);
  555. extern DECLSPEC float SDLCALL SDL_expf(float x);
  556. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  557. extern DECLSPEC float SDLCALL SDL_fabsf(float x);
  558. extern DECLSPEC double SDLCALL SDL_floor(double x);
  559. extern DECLSPEC float SDLCALL SDL_floorf(float x);
  560. extern DECLSPEC double SDLCALL SDL_trunc(double x);
  561. extern DECLSPEC float SDLCALL SDL_truncf(float x);
  562. extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  563. extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  564. extern DECLSPEC double SDLCALL SDL_log(double x);
  565. extern DECLSPEC float SDLCALL SDL_logf(float x);
  566. extern DECLSPEC double SDLCALL SDL_log10(double x);
  567. extern DECLSPEC float SDLCALL SDL_log10f(float x);
  568. extern DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  569. extern DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  570. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  571. extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
  572. extern DECLSPEC double SDLCALL SDL_round(double x);
  573. extern DECLSPEC float SDLCALL SDL_roundf(float x);
  574. extern DECLSPEC long SDLCALL SDL_lround(double x);
  575. extern DECLSPEC long SDLCALL SDL_lroundf(float x);
  576. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  577. extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  578. extern DECLSPEC double SDLCALL SDL_sin(double x);
  579. extern DECLSPEC float SDLCALL SDL_sinf(float x);
  580. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  581. extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
  582. extern DECLSPEC double SDLCALL SDL_tan(double x);
  583. extern DECLSPEC float SDLCALL SDL_tanf(float x);
  584. /* The SDL implementation of iconv() returns these error codes */
  585. #define SDL_ICONV_ERROR (size_t)-1
  586. #define SDL_ICONV_E2BIG (size_t)-2
  587. #define SDL_ICONV_EILSEQ (size_t)-3
  588. #define SDL_ICONV_EINVAL (size_t)-4
  589. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  590. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  591. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  592. const char *fromcode);
  593. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  594. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  595. size_t * inbytesleft, char **outbuf,
  596. size_t * outbytesleft);
  597. /**
  598. * This function converts a string between encodings in one pass, returning a
  599. * string that must be freed with SDL_free() or NULL on error.
  600. *
  601. * \since This function is available since SDL 3.0.0.
  602. */
  603. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  604. const char *fromcode,
  605. const char *inbuf,
  606. size_t inbytesleft);
  607. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  608. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  609. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  610. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  611. /* force builds using Clang's static analysis tools to use literal C runtime
  612. here, since there are possibly tests that are ineffective otherwise. */
  613. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  614. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  615. #ifndef HAVE_STRLCPY
  616. size_t strlcpy(char* dst, const char* src, size_t size);
  617. #endif
  618. /* The analyzer knows about strlcat even when the system doesn't provide it */
  619. #ifndef HAVE_STRLCAT
  620. size_t strlcat(char* dst, const char* src, size_t size);
  621. #endif
  622. #define SDL_malloc malloc
  623. #define SDL_calloc calloc
  624. #define SDL_realloc realloc
  625. #define SDL_free free
  626. #define SDL_memset memset
  627. #define SDL_memcpy memcpy
  628. #define SDL_memmove memmove
  629. #define SDL_memcmp memcmp
  630. #define SDL_strlcpy strlcpy
  631. #define SDL_strlcat strlcat
  632. #define SDL_strlen strlen
  633. #define SDL_wcslen wcslen
  634. #define SDL_wcslcpy wcslcpy
  635. #define SDL_wcslcat wcslcat
  636. #define SDL_strdup strdup
  637. #define SDL_wcsdup wcsdup
  638. #define SDL_strchr strchr
  639. #define SDL_strrchr strrchr
  640. #define SDL_strstr strstr
  641. #define SDL_wcsstr wcsstr
  642. #define SDL_strtokr strtok_r
  643. #define SDL_strcmp strcmp
  644. #define SDL_wcscmp wcscmp
  645. #define SDL_strncmp strncmp
  646. #define SDL_wcsncmp wcsncmp
  647. #define SDL_strcasecmp strcasecmp
  648. #define SDL_strncasecmp strncasecmp
  649. #define SDL_sscanf sscanf
  650. #define SDL_vsscanf vsscanf
  651. #define SDL_snprintf snprintf
  652. #define SDL_vsnprintf vsnprintf
  653. #endif
  654. SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
  655. {
  656. return SDL_memcpy(dst, src, dwords * 4);
  657. }
  658. /**
  659. * If a * b would overflow, return -1. Otherwise store a * b via ret
  660. * and return 0.
  661. *
  662. * \since This function is available since SDL 3.0.0.
  663. */
  664. SDL_FORCE_INLINE int SDL_size_mul_overflow (size_t a,
  665. size_t b,
  666. size_t *ret)
  667. {
  668. if (a != 0 && b > SDL_SIZE_MAX / a) {
  669. return -1;
  670. }
  671. *ret = a * b;
  672. return 0;
  673. }
  674. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  675. /* This needs to be wrapped in an inline rather than being a direct #define,
  676. * because __builtin_mul_overflow() is type-generic, but we want to be
  677. * consistent about interpreting a and b as size_t. */
  678. SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a,
  679. size_t b,
  680. size_t *ret)
  681. {
  682. return __builtin_mul_overflow(a, b, ret) == 0 ? 0 : -1;
  683. }
  684. #define SDL_size_mul_overflow(a, b, ret) (SDL_size_mul_overflow_builtin(a, b, ret))
  685. #endif
  686. /**
  687. * If a + b would overflow, return -1. Otherwise store a + b via ret
  688. * and return 0.
  689. *
  690. * \since This function is available since SDL 3.0.0.
  691. */
  692. SDL_FORCE_INLINE int SDL_size_add_overflow (size_t a,
  693. size_t b,
  694. size_t *ret)
  695. {
  696. if (b > SDL_SIZE_MAX - a) {
  697. return -1;
  698. }
  699. *ret = a + b;
  700. return 0;
  701. }
  702. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  703. /* This needs to be wrapped in an inline rather than being a direct #define,
  704. * the same as the call to __builtin_mul_overflow() above. */
  705. SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a,
  706. size_t b,
  707. size_t *ret)
  708. {
  709. return __builtin_add_overflow(a, b, ret) == 0 ? 0 : -1;
  710. }
  711. #define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret))
  712. #endif
  713. /* This is a generic function pointer which should be cast to the type you expect */
  714. #ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
  715. typedef void *SDL_FunctionPointer;
  716. #else
  717. typedef void (*SDL_FunctionPointer)(void);
  718. #endif
  719. /* Ends C function definitions when using C++ */
  720. #ifdef __cplusplus
  721. }
  722. #endif
  723. #include <SDL3/SDL_close_code.h>
  724. #endif /* SDL_stdinc_h_ */