SDL_stdinc.h 23 KB

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