🛠️🐜 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.

738 lines
26 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(__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. /**
  219. * \name Floating-point constants
  220. */
  221. /* @{ */
  222. #ifdef FLT_EPSILON
  223. #define SDL_FLT_EPSILON FLT_EPSILON
  224. #else
  225. #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
  226. #endif
  227. /* @} *//* Floating-point constants */
  228. /* Make sure we have macros for printing width-based integers.
  229. * <stdint.h> should define these but this is not true all platforms.
  230. * (for example win32) */
  231. #ifndef SDL_PRIs64
  232. #ifdef PRIs64
  233. #define SDL_PRIs64 PRIs64
  234. #elif defined(__WIN32__)
  235. #define SDL_PRIs64 "I64d"
  236. #elif defined(__LINUX__) && defined(__LP64__)
  237. #define SDL_PRIs64 "ld"
  238. #else
  239. #define SDL_PRIs64 "lld"
  240. #endif
  241. #endif
  242. #ifndef SDL_PRIu64
  243. #ifdef PRIu64
  244. #define SDL_PRIu64 PRIu64
  245. #elif defined(__WIN32__)
  246. #define SDL_PRIu64 "I64u"
  247. #elif defined(__LINUX__) && defined(__LP64__)
  248. #define SDL_PRIu64 "lu"
  249. #else
  250. #define SDL_PRIu64 "llu"
  251. #endif
  252. #endif
  253. #ifndef SDL_PRIx64
  254. #ifdef PRIx64
  255. #define SDL_PRIx64 PRIx64
  256. #elif defined(__WIN32__)
  257. #define SDL_PRIx64 "I64x"
  258. #elif defined(__LINUX__) && defined(__LP64__)
  259. #define SDL_PRIx64 "lx"
  260. #else
  261. #define SDL_PRIx64 "llx"
  262. #endif
  263. #endif
  264. #ifndef SDL_PRIX64
  265. #ifdef PRIX64
  266. #define SDL_PRIX64 PRIX64
  267. #elif defined(__WIN32__)
  268. #define SDL_PRIX64 "I64X"
  269. #elif defined(__LINUX__) && defined(__LP64__)
  270. #define SDL_PRIX64 "lX"
  271. #else
  272. #define SDL_PRIX64 "llX"
  273. #endif
  274. #endif
  275. #ifndef SDL_PRIs32
  276. #ifdef PRId32
  277. #define SDL_PRIs32 PRId32
  278. #else
  279. #define SDL_PRIs32 "d"
  280. #endif
  281. #endif
  282. #ifndef SDL_PRIu32
  283. #ifdef PRIu32
  284. #define SDL_PRIu32 PRIu32
  285. #else
  286. #define SDL_PRIu32 "u"
  287. #endif
  288. #endif
  289. #ifndef SDL_PRIx32
  290. #ifdef PRIx32
  291. #define SDL_PRIx32 PRIx32
  292. #else
  293. #define SDL_PRIx32 "x"
  294. #endif
  295. #endif
  296. #ifndef SDL_PRIX32
  297. #ifdef PRIX32
  298. #define SDL_PRIX32 PRIX32
  299. #else
  300. #define SDL_PRIX32 "X"
  301. #endif
  302. #endif
  303. /* Annotations to help code analysis tools */
  304. #ifdef SDL_DISABLE_ANALYZE_MACROS
  305. #define SDL_IN_BYTECAP(x)
  306. #define SDL_INOUT_Z_CAP(x)
  307. #define SDL_OUT_Z_CAP(x)
  308. #define SDL_OUT_CAP(x)
  309. #define SDL_OUT_BYTECAP(x)
  310. #define SDL_OUT_Z_BYTECAP(x)
  311. #define SDL_PRINTF_FORMAT_STRING
  312. #define SDL_SCANF_FORMAT_STRING
  313. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  314. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  315. #else
  316. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  317. #include <sal.h>
  318. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  319. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  320. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  321. #define SDL_OUT_CAP(x) _Out_cap_(x)
  322. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  323. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  324. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  325. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  326. #else
  327. #define SDL_IN_BYTECAP(x)
  328. #define SDL_INOUT_Z_CAP(x)
  329. #define SDL_OUT_Z_CAP(x)
  330. #define SDL_OUT_CAP(x)
  331. #define SDL_OUT_BYTECAP(x)
  332. #define SDL_OUT_Z_BYTECAP(x)
  333. #define SDL_PRINTF_FORMAT_STRING
  334. #define SDL_SCANF_FORMAT_STRING
  335. #endif
  336. #if defined(__GNUC__)
  337. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  338. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  339. #else
  340. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  341. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  342. #endif
  343. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  344. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  345. #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
  346. #elif defined(__cplusplus) && (__cplusplus >= 201103L)
  347. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  348. #else /* universal, but may trigger -Wunused-local-typedefs */
  349. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  350. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  351. #endif
  352. /** \cond */
  353. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  354. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  355. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  356. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  357. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  358. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  359. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  360. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  361. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  362. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  363. /** \endcond */
  364. /* Check to make sure enums are the size of ints, for structure packing.
  365. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  366. enums having the size of an int must be enabled.
  367. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  368. */
  369. /** \cond */
  370. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  371. #if !defined(__ANDROID__) && !defined(__VITA__)
  372. /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
  373. typedef enum
  374. {
  375. DUMMY_ENUM_VALUE
  376. } SDL_DUMMY_ENUM;
  377. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  378. #endif
  379. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  380. /** \endcond */
  381. #include "begin_code.h"
  382. /* Set up for C function definitions, even when using C++ */
  383. #ifdef __cplusplus
  384. extern "C" {
  385. #endif
  386. #ifdef HAVE_ALLOCA
  387. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  388. #define SDL_stack_free(data)
  389. #else
  390. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  391. #define SDL_stack_free(data) SDL_free(data)
  392. #endif
  393. extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
  394. extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  395. extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
  396. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  397. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  398. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  399. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  400. typedef void (SDLCALL *SDL_free_func)(void *mem);
  401. /**
  402. * Get the current set of SDL memory functions
  403. *
  404. * \since This function is available since SDL 2.0.7.
  405. */
  406. extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  407. SDL_calloc_func *calloc_func,
  408. SDL_realloc_func *realloc_func,
  409. SDL_free_func *free_func);
  410. /**
  411. * Replace SDL's memory allocation functions with a custom set
  412. *
  413. * \since This function is available since SDL 2.0.7.
  414. */
  415. extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  416. SDL_calloc_func calloc_func,
  417. SDL_realloc_func realloc_func,
  418. SDL_free_func free_func);
  419. /**
  420. * Get the number of outstanding (unfreed) allocations
  421. *
  422. * \since This function is available since SDL 2.0.7.
  423. */
  424. extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  425. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  426. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  427. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
  428. extern DECLSPEC int SDLCALL SDL_abs(int x);
  429. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  430. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  431. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  432. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  433. extern DECLSPEC int SDLCALL SDL_isalpha(int x);
  434. extern DECLSPEC int SDLCALL SDL_isalnum(int x);
  435. extern DECLSPEC int SDLCALL SDL_isblank(int x);
  436. extern DECLSPEC int SDLCALL SDL_iscntrl(int x);
  437. extern DECLSPEC int SDLCALL SDL_isdigit(int x);
  438. extern DECLSPEC int SDLCALL SDL_isxdigit(int x);
  439. extern DECLSPEC int SDLCALL SDL_ispunct(int x);
  440. extern DECLSPEC int SDLCALL SDL_isspace(int x);
  441. extern DECLSPEC int SDLCALL SDL_isupper(int x);
  442. extern DECLSPEC int SDLCALL SDL_islower(int x);
  443. extern DECLSPEC int SDLCALL SDL_isprint(int x);
  444. extern DECLSPEC int SDLCALL SDL_isgraph(int x);
  445. extern DECLSPEC int SDLCALL SDL_toupper(int x);
  446. extern DECLSPEC int SDLCALL SDL_tolower(int x);
  447. extern DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  448. extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  449. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  450. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  451. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  452. /* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
  453. SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
  454. {
  455. #ifdef __APPLE__
  456. memset_pattern4(dst, &val, dwords * 4);
  457. #elif defined(__GNUC__) && defined(__i386__)
  458. int u0, u1, u2;
  459. __asm__ __volatile__ (
  460. "cld \n\t"
  461. "rep ; stosl \n\t"
  462. : "=&D" (u0), "=&a" (u1), "=&c" (u2)
  463. : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
  464. : "memory"
  465. );
  466. #else
  467. size_t _n = (dwords + 3) / 4;
  468. Uint32 *_p = SDL_static_cast(Uint32 *, dst);
  469. Uint32 _val = (val);
  470. if (dwords == 0) {
  471. return;
  472. }
  473. switch (dwords % 4) {
  474. case 0: do { *_p++ = _val; SDL_FALLTHROUGH;
  475. case 3: *_p++ = _val; SDL_FALLTHROUGH;
  476. case 2: *_p++ = _val; SDL_FALLTHROUGH;
  477. case 1: *_p++ = _val;
  478. } while ( --_n );
  479. }
  480. #endif
  481. }
  482. extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  483. extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  484. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  485. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  486. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  487. extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  488. extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr);
  489. extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  490. extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  491. extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  492. extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  493. extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t len);
  494. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  495. extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  496. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  497. extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  498. extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
  499. extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
  500. extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
  501. extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
  502. extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
  503. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
  504. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
  505. extern DECLSPEC char *SDLCALL SDL_strtokr(char *s1, const char *s2, char **saveptr);
  506. extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  507. extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
  508. extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  509. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
  510. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  511. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  512. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  513. extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
  514. extern DECLSPEC double SDLCALL SDL_atof(const char *str);
  515. extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  516. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  517. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  518. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  519. extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  520. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  521. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  522. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  523. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
  524. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  525. extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
  526. 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);
  527. extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
  528. extern DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  529. extern DECLSPEC int SDLCALL SDL_vasprintf(char **strp, const char *fmt, va_list ap);
  530. #ifndef HAVE_M_PI
  531. #ifndef M_PI
  532. #define M_PI 3.14159265358979323846264338327950288 /**< pi */
  533. #endif
  534. #endif
  535. /**
  536. * Use this function to compute arc cosine of `x`.
  537. *
  538. * The definition of `y = acos(x)` is `x = cos(y)`.
  539. *
  540. * Domain: `-1 <= x <= 1`
  541. *
  542. * Range: `0 <= y <= Pi`
  543. *
  544. * \param x floating point value, in radians.
  545. * \returns arc cosine of `x`.
  546. *
  547. * \since This function is available since SDL 2.0.2.
  548. */
  549. extern DECLSPEC double SDLCALL SDL_acos(double x);
  550. extern DECLSPEC float SDLCALL SDL_acosf(float x);
  551. extern DECLSPEC double SDLCALL SDL_asin(double x);
  552. extern DECLSPEC float SDLCALL SDL_asinf(float x);
  553. extern DECLSPEC double SDLCALL SDL_atan(double x);
  554. extern DECLSPEC float SDLCALL SDL_atanf(float x);
  555. extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  556. extern DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  557. extern DECLSPEC double SDLCALL SDL_ceil(double x);
  558. extern DECLSPEC float SDLCALL SDL_ceilf(float x);
  559. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  560. extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  561. extern DECLSPEC double SDLCALL SDL_cos(double x);
  562. extern DECLSPEC float SDLCALL SDL_cosf(float x);
  563. extern DECLSPEC double SDLCALL SDL_exp(double x);
  564. extern DECLSPEC float SDLCALL SDL_expf(float x);
  565. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  566. extern DECLSPEC float SDLCALL SDL_fabsf(float x);
  567. extern DECLSPEC double SDLCALL SDL_floor(double x);
  568. extern DECLSPEC float SDLCALL SDL_floorf(float x);
  569. extern DECLSPEC double SDLCALL SDL_trunc(double x);
  570. extern DECLSPEC float SDLCALL SDL_truncf(float x);
  571. extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  572. extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  573. extern DECLSPEC double SDLCALL SDL_log(double x);
  574. extern DECLSPEC float SDLCALL SDL_logf(float x);
  575. extern DECLSPEC double SDLCALL SDL_log10(double x);
  576. extern DECLSPEC float SDLCALL SDL_log10f(float x);
  577. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  578. extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
  579. extern DECLSPEC double SDLCALL SDL_round(double x);
  580. extern DECLSPEC float SDLCALL SDL_roundf(float x);
  581. extern DECLSPEC long SDLCALL SDL_lround(double x);
  582. extern DECLSPEC long SDLCALL SDL_lroundf(float x);
  583. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  584. extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  585. extern DECLSPEC double SDLCALL SDL_sin(double x);
  586. extern DECLSPEC float SDLCALL SDL_sinf(float x);
  587. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  588. extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
  589. extern DECLSPEC double SDLCALL SDL_tan(double x);
  590. extern DECLSPEC float SDLCALL SDL_tanf(float x);
  591. /* The SDL implementation of iconv() returns these error codes */
  592. #define SDL_ICONV_ERROR (size_t)-1
  593. #define SDL_ICONV_E2BIG (size_t)-2
  594. #define SDL_ICONV_EILSEQ (size_t)-3
  595. #define SDL_ICONV_EINVAL (size_t)-4
  596. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  597. typedef struct _SDL_iconv_t *SDL_iconv_t;
  598. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  599. const char *fromcode);
  600. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  601. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  602. size_t * inbytesleft, char **outbuf,
  603. size_t * outbytesleft);
  604. /**
  605. * This function converts a string between encodings in one pass, returning a
  606. * string that must be freed with SDL_free() or NULL on error.
  607. *
  608. * \since This function is available since SDL 2.0.0.
  609. */
  610. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  611. const char *fromcode,
  612. const char *inbuf,
  613. size_t inbytesleft);
  614. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  615. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  616. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  617. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  618. /* force builds using Clang's static analysis tools to use literal C runtime
  619. here, since there are possibly tests that are ineffective otherwise. */
  620. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  621. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  622. #ifndef HAVE_STRLCPY
  623. size_t strlcpy(char* dst, const char* src, size_t size);
  624. #endif
  625. /* The analyzer knows about strlcat even when the system doesn't provide it */
  626. #ifndef HAVE_STRLCAT
  627. size_t strlcat(char* dst, const char* src, size_t size);
  628. #endif
  629. #define SDL_malloc malloc
  630. #define SDL_calloc calloc
  631. #define SDL_realloc realloc
  632. #define SDL_free free
  633. #define SDL_memset memset
  634. #define SDL_memcpy memcpy
  635. #define SDL_memmove memmove
  636. #define SDL_memcmp memcmp
  637. #define SDL_strlcpy strlcpy
  638. #define SDL_strlcat strlcat
  639. #define SDL_strlen strlen
  640. #define SDL_wcslen wcslen
  641. #define SDL_wcslcpy wcslcpy
  642. #define SDL_wcslcat wcslcat
  643. #define SDL_strdup strdup
  644. #define SDL_wcsdup wcsdup
  645. #define SDL_strchr strchr
  646. #define SDL_strrchr strrchr
  647. #define SDL_strstr strstr
  648. #define SDL_wcsstr wcsstr
  649. #define SDL_strtokr strtok_r
  650. #define SDL_strcmp strcmp
  651. #define SDL_wcscmp wcscmp
  652. #define SDL_strncmp strncmp
  653. #define SDL_wcsncmp wcsncmp
  654. #define SDL_strcasecmp strcasecmp
  655. #define SDL_strncasecmp strncasecmp
  656. #define SDL_sscanf sscanf
  657. #define SDL_vsscanf vsscanf
  658. #define SDL_snprintf snprintf
  659. #define SDL_vsnprintf vsnprintf
  660. #endif
  661. SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
  662. {
  663. return SDL_memcpy(dst, src, dwords * 4);
  664. }
  665. /* Ends C function definitions when using C++ */
  666. #ifdef __cplusplus
  667. }
  668. #endif
  669. #include "close_code.h"
  670. #endif /* SDL_stdinc_h_ */
  671. /* vi: set ts=4 sw=4 expandtab: */