🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

830 lines
29 KiB

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