SDL 3.0
SDL_stdinc.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * \file SDL_stdinc.h
24 *
25 * This is a general header that includes C language support. It implements
26 * a subset of the C runtime: these should all behave the same way as their
27 * C runtime equivalents, but with an SDL_ prefix.
28 */
29
30#ifndef SDL_stdinc_h_
31#define SDL_stdinc_h_
32
34
35#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
36#include <inttypes.h>
37#endif
38#include <stdarg.h>
39#include <stdint.h>
40#include <string.h>
41#include <wchar.h>
42
43#ifndef SDL_DISABLE_ALLOCA
44# ifndef alloca
45# ifdef HAVE_ALLOCA_H
46# include <alloca.h>
47# elif defined(SDL_PLATFORM_NETBSD)
48# if defined(__STRICT_ANSI__)
49# define SDL_DISABLE_ALLOCA
50# else
51# include <stdlib.h>
52# endif
53# elif defined(__GNUC__)
54# define alloca __builtin_alloca
55# elif defined(_MSC_VER)
56# include <malloc.h>
57# define alloca _alloca
58# elif defined(__WATCOMC__)
59# include <malloc.h>
60# elif defined(__BORLANDC__)
61# include <malloc.h>
62# elif defined(__DMC__)
63# include <stdlib.h>
64# elif defined(SDL_PLATFORM_AIX)
65# pragma alloca
66# elif defined(__MRC__)
67void *alloca(unsigned);
68# else
69void *alloca(size_t);
70# endif
71# endif
72#endif
73
74#ifdef SIZE_MAX
75# define SDL_SIZE_MAX SIZE_MAX
76#else
77# define SDL_SIZE_MAX ((size_t) -1)
78#endif
79
80/**
81 * Check if the compiler supports a given builtin.
82 * Supported by virtually all clang versions and recent gcc. Use this
83 * instead of checking the clang version if possible.
84 */
85#ifdef __has_builtin
86#define SDL_HAS_BUILTIN(x) __has_builtin(x)
87#else
88#define SDL_HAS_BUILTIN(x) 0
89#endif
90
91/**
92 * The number of elements in an array.
93 *
94 * NOTE: This macro double-evaluates the argument, so you should never have
95 * side effects in the parameter.
96 *
97 * \since This macro is available since SDL 3.0.0.
98 */
99#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
100
101/**
102 * Macro useful for building other macros with strings in them.
103 *
104 * For example:
105 *
106 * ```c
107 * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
108 * ```
109 *
110 * \since This macro is available since SDL 3.0.0.
111 */
112#define SDL_STRINGIFY_ARG(arg) #arg
113
114/**
115 * \name Cast operators
116 *
117 * Use proper C++ casts when compiled as C++ to be compatible with the option
118 * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
119 */
120/* @{ */
121#ifdef __cplusplus
122#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
123#define SDL_static_cast(type, expression) static_cast<type>(expression)
124#define SDL_const_cast(type, expression) const_cast<type>(expression)
125#else
126#define SDL_reinterpret_cast(type, expression) ((type)(expression))
127#define SDL_static_cast(type, expression) ((type)(expression))
128#define SDL_const_cast(type, expression) ((type)(expression))
129#endif
130/* @} *//* Cast operators */
131
132/* Define a four character code as a Uint32 */
133#define SDL_FOURCC(A, B, C, D) \
134 ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
135 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
136 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
137 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
138
139/**
140 * \name Basic data types
141 */
142/* @{ */
143
144/**
145 * A boolean false.
146 *
147 * \since This macro is available since SDL 3.0.0.
148 *
149 * \sa SDL_bool
150 */
151#define SDL_FALSE 0
152
153/**
154 * A boolean true.
155 *
156 * \since This macro is available since SDL 3.0.0.
157 *
158 * \sa SDL_bool
159 */
160#define SDL_TRUE 1
161
162/**
163 * A boolean type: true or false.
164 *
165 * \since This datatype is available since SDL 3.0.0.
166 *
167 * \sa SDL_TRUE
168 * \sa SDL_FALSE
169 */
170typedef int SDL_bool;
171
172/**
173 * A signed 8-bit integer type.
174 *
175 * \since This macro is available since SDL 3.0.0.
176 */
177#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
178#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
179typedef int8_t Sint8;
180
181/**
182 * An unsigned 8-bit integer type.
183 *
184 * \since This macro is available since SDL 3.0.0.
185 */
186#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
187#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
188typedef uint8_t Uint8;
189
190/**
191 * A signed 16-bit integer type.
192 *
193 * \since This macro is available since SDL 3.0.0.
194 */
195#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
196#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
197typedef int16_t Sint16;
198
199/**
200 * An unsigned 16-bit integer type.
201 *
202 * \since This macro is available since SDL 3.0.0.
203 */
204#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
205#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
206typedef uint16_t Uint16;
207
208/**
209 * A signed 32-bit integer type.
210 *
211 * \since This macro is available since SDL 3.0.0.
212 */
213#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
214#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
215typedef int32_t Sint32;
216
217/**
218 * An unsigned 32-bit integer type.
219 *
220 * \since This macro is available since SDL 3.0.0.
221 */
222#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
223#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
224typedef uint32_t Uint32;
225
226/**
227 * A signed 64-bit integer type.
228 *
229 * \since This macro is available since SDL 3.0.0.
230 */
231#define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
232#define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
233typedef int64_t Sint64;
234
235/**
236 * An unsigned 64-bit integer type.
237 *
238 * \since This macro is available since SDL 3.0.0.
239 */
240#define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
241#define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
242typedef uint64_t Uint64;
243
244/**
245 * SDL times are signed, 64-bit integers representing nanoseconds since the
246 * Unix epoch (Jan 1, 1970).
247 *
248 * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
249 * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
250 * SDL_TimeToWindows() and SDL_TimeFromWindows().
251 *
252 * \since This macro is available since SDL 3.0.0.
253 */
254#define SDL_MAX_TIME SDL_MAX_SINT64
255#define SDL_MIN_TIME SDL_MIN_SINT64
257
258/* @} *//* Basic data types */
259
260/**
261 * \name Floating-point constants
262 */
263/* @{ */
264
265#ifdef FLT_EPSILON
266#define SDL_FLT_EPSILON FLT_EPSILON
267#else
268#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
269#endif
270
271/* @} *//* Floating-point constants */
272
273/* Make sure we have macros for printing width-based integers.
274 * <stdint.h> should define these but this is not true all platforms.
275 * (for example win32) */
276#ifndef SDL_PRIs64
277#ifdef PRIs64
278#define SDL_PRIs64 PRIs64
279#elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
280#define SDL_PRIs64 "I64d"
281#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
282#define SDL_PRIs64 "ld"
283#else
284#define SDL_PRIs64 "lld"
285#endif
286#endif
287#ifndef SDL_PRIu64
288#ifdef PRIu64
289#define SDL_PRIu64 PRIu64
290#elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
291#define SDL_PRIu64 "I64u"
292#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
293#define SDL_PRIu64 "lu"
294#else
295#define SDL_PRIu64 "llu"
296#endif
297#endif
298#ifndef SDL_PRIx64
299#ifdef PRIx64
300#define SDL_PRIx64 PRIx64
301#elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
302#define SDL_PRIx64 "I64x"
303#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
304#define SDL_PRIx64 "lx"
305#else
306#define SDL_PRIx64 "llx"
307#endif
308#endif
309#ifndef SDL_PRIX64
310#ifdef PRIX64
311#define SDL_PRIX64 PRIX64
312#elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
313#define SDL_PRIX64 "I64X"
314#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
315#define SDL_PRIX64 "lX"
316#else
317#define SDL_PRIX64 "llX"
318#endif
319#endif
320#ifndef SDL_PRIs32
321#ifdef PRId32
322#define SDL_PRIs32 PRId32
323#else
324#define SDL_PRIs32 "d"
325#endif
326#endif
327#ifndef SDL_PRIu32
328#ifdef PRIu32
329#define SDL_PRIu32 PRIu32
330#else
331#define SDL_PRIu32 "u"
332#endif
333#endif
334#ifndef SDL_PRIx32
335#ifdef PRIx32
336#define SDL_PRIx32 PRIx32
337#else
338#define SDL_PRIx32 "x"
339#endif
340#endif
341#ifndef SDL_PRIX32
342#ifdef PRIX32
343#define SDL_PRIX32 PRIX32
344#else
345#define SDL_PRIX32 "X"
346#endif
347#endif
348
349/* Annotations to help code analysis tools */
350#ifdef SDL_DISABLE_ANALYZE_MACROS
351#define SDL_IN_BYTECAP(x)
352#define SDL_INOUT_Z_CAP(x)
353#define SDL_OUT_Z_CAP(x)
354#define SDL_OUT_CAP(x)
355#define SDL_OUT_BYTECAP(x)
356#define SDL_OUT_Z_BYTECAP(x)
357#define SDL_PRINTF_FORMAT_STRING
358#define SDL_SCANF_FORMAT_STRING
359#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
360#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
361#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
362#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
363#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
364#define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
365#else
366#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
367#include <sal.h>
368
369#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
370#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
371#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
372#define SDL_OUT_CAP(x) _Out_cap_(x)
373#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
374#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
375
376#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
377#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
378#else
379#define SDL_IN_BYTECAP(x)
380#define SDL_INOUT_Z_CAP(x)
381#define SDL_OUT_Z_CAP(x)
382#define SDL_OUT_CAP(x)
383#define SDL_OUT_BYTECAP(x)
384#define SDL_OUT_Z_BYTECAP(x)
385#define SDL_PRINTF_FORMAT_STRING
386#define SDL_SCANF_FORMAT_STRING
387#endif
388#ifdef __GNUC__
389#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
390#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
391#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
392#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
393#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
394#define SDL_WSCANF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wscanf__, fmtargnumber, fmtargnumber+1 ))) */
395#else
396#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
397#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
398#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
399#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
400#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
401#define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
402#endif
403#endif /* SDL_DISABLE_ANALYZE_MACROS */
404
405#ifndef SDL_COMPILE_TIME_ASSERT
406#ifdef __cplusplus
407#if (__cplusplus >= 201103L)
408#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
409#endif
410#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
411#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
412#endif
413#endif /* !SDL_COMPILE_TIME_ASSERT */
414
415#ifndef SDL_COMPILE_TIME_ASSERT
416/* universal, but may trigger -Wunused-local-typedefs */
417#define SDL_COMPILE_TIME_ASSERT(name, x) \
418 typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
419#endif
420
421/** \cond */
422#ifndef DOXYGEN_SHOULD_IGNORE_THIS
423SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
424SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
425SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
426SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
427SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
428SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
429SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
430SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
431#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
432/** \endcond */
433
434/* Check to make sure enums are the size of ints, for structure packing.
435 For both Watcom C/C++ and Borland C/C++ the compiler option that makes
436 enums having the size of an int must be enabled.
437 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
438*/
439
440/** \cond */
441#ifndef DOXYGEN_SHOULD_IGNORE_THIS
442#if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
443/* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
444typedef enum SDL_DUMMY_ENUM
445{
446 DUMMY_ENUM_VALUE
447} SDL_DUMMY_ENUM;
448
449SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
450#endif
451#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
452/** \endcond */
453
454#include <SDL3/SDL_begin_code.h>
455/* Set up for C function definitions, even when using C++ */
456#ifdef __cplusplus
457extern "C" {
458#endif
459
460#ifndef SDL_DISABLE_ALLOCA
461#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
462#define SDL_stack_free(data)
463#else
464#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
465#define SDL_stack_free(data) SDL_free(data)
466#endif
467
468extern DECLSPEC SDL_MALLOC void *SDLCALL SDL_malloc(size_t size);
469extern DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
470extern DECLSPEC SDL_ALLOC_SIZE(2) void *SDLCALL SDL_realloc(void *mem, size_t size);
471extern DECLSPEC void SDLCALL SDL_free(void *mem);
472
473typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
474typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
475typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
476typedef void (SDLCALL *SDL_free_func)(void *mem);
477
478/**
479 * Get the original set of SDL memory functions.
480 *
481 * \param malloc_func filled with malloc function
482 * \param calloc_func filled with calloc function
483 * \param realloc_func filled with realloc function
484 * \param free_func filled with free function
485 *
486 * \since This function is available since SDL 3.0.0.
487 */
488extern DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
489 SDL_calloc_func *calloc_func,
490 SDL_realloc_func *realloc_func,
491 SDL_free_func *free_func);
492
493/**
494 * Get the current set of SDL memory functions.
495 *
496 * \param malloc_func filled with malloc function
497 * \param calloc_func filled with calloc function
498 * \param realloc_func filled with realloc function
499 * \param free_func filled with free function
500 *
501 * \since This function is available since SDL 3.0.0.
502 */
503extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
504 SDL_calloc_func *calloc_func,
505 SDL_realloc_func *realloc_func,
506 SDL_free_func *free_func);
507
508/**
509 * Replace SDL's memory allocation functions with a custom set.
510 *
511 * \param malloc_func custom malloc function
512 * \param calloc_func custom calloc function
513 * \param realloc_func custom realloc function
514 * \param free_func custom free function
515 * \returns 0 on success or a negative error code on failure; call
516 * SDL_GetError() for more information.
517 *
518 * \since This function is available since SDL 3.0.0.
519 */
520extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
521 SDL_calloc_func calloc_func,
522 SDL_realloc_func realloc_func,
523 SDL_free_func free_func);
524
525/**
526 * Allocate memory aligned to a specific value.
527 *
528 * If `alignment` is less than the size of `void *`, then it will be increased
529 * to match that.
530 *
531 * The returned memory address will be a multiple of the alignment value, and
532 * the amount of memory allocated will be a multiple of the alignment value.
533 *
534 * The memory returned by this function must be freed with SDL_aligned_free()
535 *
536 * \param alignment the alignment requested
537 * \param size the size to allocate
538 * \returns a pointer to the aligned memory
539 *
540 * \since This function is available since SDL 3.0.0.
541 *
542 * \sa SDL_aligned_free
543 */
544extern DECLSPEC SDL_MALLOC void *SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
545
546/**
547 * Free memory allocated by SDL_aligned_alloc().
548 *
549 * \since This function is available since SDL 3.0.0.
550 *
551 * \sa SDL_aligned_alloc
552 */
553extern DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
554
555/**
556 * Get the number of outstanding (unfreed) allocations.
557 *
558 * \returns the number of allocations
559 *
560 * \since This function is available since SDL 3.0.0.
561 */
562extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
563
564extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
565extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
566
567extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (const void *, const void *));
568extern DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (const void *, const void *));
569
570extern DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (void *, const void *, const void *), void *userdata);
571extern DECLSPEC void * SDLCALL SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (void *, const void *, const void *), void *userdata);
572
573extern DECLSPEC int SDLCALL SDL_abs(int x);
574
575/* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
576#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
577#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
578#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
579
580/**
581 * Query if a character is alphabetic (a letter).
582 *
583 * **WARNING**: Regardless of system locale, this will only treat ASCII values
584 * for English 'a-z' and 'A-Z' as true.
585 *
586 * \param x character value to check.
587 * \returns non-zero if x falls within the character class, zero otherwise.
588 *
589 * \threadsafety It is safe to call this function from any thread.
590 *
591 * \since This function is available since SDL 3.0.0.
592 */
593extern DECLSPEC int SDLCALL SDL_isalpha(int x);
594
595/**
596 * Query if a character is alphabetic (a letter) or a number.
597 *
598 * **WARNING**: Regardless of system locale, this will only treat ASCII values
599 * for English 'a-z', 'A-Z', and '0-9' as true.
600 *
601 * \param x character value to check.
602 * \returns non-zero if x falls within the character class, zero otherwise.
603 *
604 * \threadsafety It is safe to call this function from any thread.
605 *
606 * \since This function is available since SDL 3.0.0.
607 */
608extern DECLSPEC int SDLCALL SDL_isalnum(int x);
609
610/**
611 * Report if a character is blank (a space or tab).
612 *
613 * **WARNING**: Regardless of system locale, this will only treat ASCII values
614 * 0x20 (space) or 0x9 (tab) as true.
615 *
616 * \param x character value to check.
617 * \returns non-zero if x falls within the character class, zero otherwise.
618 *
619 * \threadsafety It is safe to call this function from any thread.
620 *
621 * \since This function is available since SDL 3.0.0.
622 */
623extern DECLSPEC int SDLCALL SDL_isblank(int x);
624
625/**
626 * Report if a character is a control character.
627 *
628 * **WARNING**: Regardless of system locale, this will only treat ASCII values
629 * 0 through 0x1F, and 0x7F, as true.
630 *
631 * \param x character value to check.
632 * \returns non-zero if x falls within the character class, zero otherwise.
633 *
634 * \threadsafety It is safe to call this function from any thread.
635 *
636 * \since This function is available since SDL 3.0.0.
637 */
638extern DECLSPEC int SDLCALL SDL_iscntrl(int x);
639
640/**
641 * Report if a character is a numeric digit.
642 *
643 * **WARNING**: Regardless of system locale, this will only treat ASCII values
644 * '0' (0x30) through '9' (0x39), as true.
645 *
646 * \param x character value to check.
647 * \returns non-zero if x falls within the character class, zero otherwise.
648 *
649 * \threadsafety It is safe to call this function from any thread.
650 *
651 * \since This function is available since SDL 3.0.0.
652 */
653extern DECLSPEC int SDLCALL SDL_isdigit(int x);
654
655/**
656 * Report if a character is a hexadecimal digit.
657 *
658 * **WARNING**: Regardless of system locale, this will only treat ASCII values
659 * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
660 *
661 * \param x character value to check.
662 * \returns non-zero if x falls within the character class, zero otherwise.
663 *
664 * \threadsafety It is safe to call this function from any thread.
665 *
666 * \since This function is available since SDL 3.0.0.
667 */
668extern DECLSPEC int SDLCALL SDL_isxdigit(int x);
669
670/**
671 * Report if a character is a punctuation mark.
672 *
673 * **WARNING**: Regardless of system locale, this is equivalent to
674 * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
675 *
676 * \param x character value to check.
677 * \returns non-zero if x falls within the character class, zero otherwise.
678 *
679 * \threadsafety It is safe to call this function from any thread.
680 *
681 * \since This function is available since SDL 3.0.0.
682 *
683 * \sa SDL_isgraph
684 * \sa SDL_isalnum
685 */
686extern DECLSPEC int SDLCALL SDL_ispunct(int x);
687
688/**
689 * Report if a character is whitespace.
690 *
691 * **WARNING**: Regardless of system locale, this will only treat the
692 * following ASCII values as true:
693 *
694 * - space (0x20)
695 * - tab (0x09)
696 * - newline (0x0A)
697 * - vertical tab (0x0B)
698 * - form feed (0x0C)
699 * - return (0x0D)
700 *
701 * \param x character value to check.
702 * \returns non-zero if x falls within the character class, zero otherwise.
703 *
704 * \threadsafety It is safe to call this function from any thread.
705 *
706 * \since This function is available since SDL 3.0.0.
707 */
708extern DECLSPEC int SDLCALL SDL_isspace(int x);
709
710/**
711 * Report if a character is upper case.
712 *
713 * **WARNING**: Regardless of system locale, this will only treat ASCII values
714 * 'A' through 'Z' as true.
715 *
716 * \param x character value to check.
717 * \returns non-zero if x falls within the character class, zero otherwise.
718 *
719 * \threadsafety It is safe to call this function from any thread.
720 *
721 * \since This function is available since SDL 3.0.0.
722 */
723extern DECLSPEC int SDLCALL SDL_isupper(int x);
724
725/**
726 * Report if a character is lower case.
727 *
728 * **WARNING**: Regardless of system locale, this will only treat ASCII values
729 * 'a' through 'z' as true.
730 *
731 * \param x character value to check.
732 * \returns non-zero if x falls within the character class, zero otherwise.
733 *
734 * \threadsafety It is safe to call this function from any thread.
735 *
736 * \since This function is available since SDL 3.0.0.
737 */
738extern DECLSPEC int SDLCALL SDL_islower(int x);
739
740/**
741 * Report if a character is "printable".
742 *
743 * Be advised that "printable" has a definition that goes back to text
744 * terminals from the dawn of computing, making this a sort of special case
745 * function that is not suitable for Unicode (or most any) text management.
746 *
747 * **WARNING**: Regardless of system locale, this will only treat ASCII values
748 * ' ' (0x20) through '~' (0x7E) as true.
749 *
750 * \param x character value to check.
751 * \returns non-zero if x falls within the character class, zero otherwise.
752 *
753 * \threadsafety It is safe to call this function from any thread.
754 *
755 * \since This function is available since SDL 3.0.0.
756 */
757extern DECLSPEC int SDLCALL SDL_isprint(int x);
758
759/**
760 * Report if a character is any "printable" except space.
761 *
762 * Be advised that "printable" has a definition that goes back to text
763 * terminals from the dawn of computing, making this a sort of special case
764 * function that is not suitable for Unicode (or most any) text management.
765 *
766 * **WARNING**: Regardless of system locale, this is equivalent to
767 * `(SDL_isprint(x)) && ((x) != ' ')`.
768 *
769 * \param x character value to check.
770 * \returns non-zero if x falls within the character class, zero otherwise.
771 *
772 * \threadsafety It is safe to call this function from any thread.
773 *
774 * \since This function is available since SDL 3.0.0.
775 *
776 * \sa SDL_isprint
777 */
778extern DECLSPEC int SDLCALL SDL_isgraph(int x);
779
780/**
781 * Convert low-ASCII English letters to uppercase.
782 *
783 * **WARNING**: Regardless of system locale, this will only convert ASCII
784 * values 'a' through 'z' to uppercase.
785 *
786 * This function returns the uppercase equivalent of `x`. If a character
787 * cannot be converted, or is already uppercase, this function returns `x`.
788 *
789 * \param x character value to check.
790 * \returns Capitalized version of x, or x if no conversion available.
791 *
792 * \threadsafety It is safe to call this function from any thread.
793 *
794 * \since This function is available since SDL 3.0.0.
795 */
796extern DECLSPEC int SDLCALL SDL_toupper(int x);
797
798/**
799 * Convert low-ASCII English letters to lowercase.
800 *
801 * **WARNING**: Regardless of system locale, this will only convert ASCII
802 * values 'A' through 'Z' to lowercase.
803 *
804 * This function returns the lowercase equivalent of `x`. If a character
805 * cannot be converted, or is already lowercase, this function returns `x`.
806 *
807 * \param x character value to check.
808 * \returns Lowercase version of x, or x if no conversion available.
809 *
810 * \threadsafety It is safe to call this function from any thread.
811 *
812 * \since This function is available since SDL 3.0.0.
813 */
814extern DECLSPEC int SDLCALL SDL_tolower(int x);
815
816extern DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
817extern DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
818
819extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
820
821/* Take advantage of compiler optimizations for memcpy */
822#ifndef SDL_SLOW_MEMCPY
823#ifdef SDL_memcpy
824#undef SDL_memcpy
825#endif
826#define SDL_memcpy memcpy
827#endif
828
829#define SDL_copyp(dst, src) \
830 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
831 SDL_memcpy((dst), (src), sizeof(*(src)))
832
833extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
834
835/* Take advantage of compiler optimizations for memmove */
836#ifndef SDL_SLOW_MEMMOVE
837#ifdef SDL_memmove
838#undef SDL_memmove
839#endif
840#define SDL_memmove memmove
841#endif
842
843extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
844extern DECLSPEC void *SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
845
846/* Take advantage of compiler optimizations for memset */
847#ifndef SDL_SLOW_MEMSET
848#ifdef SDL_memset
849#undef SDL_memset
850#endif
851#define SDL_memset memset
852#endif
853
854#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
855#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
856#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
857
858extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
859
860extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
861extern DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
862extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
863extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
864extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr);
865extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
866extern DECLSPEC wchar_t *SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
867
868/**
869 * Compare two null-terminated wide strings.
870 *
871 * This only compares wchar_t values until it hits a null-terminating
872 * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
873 * depending on your platform's wchar_t size), or uses valid Unicode values.
874 *
875 * \param str1 The first string to compare. NULL is not permitted!
876 * \param str2 The second string to compare. NULL is not permitted!
877 * \returns less than zero if str1 is "less than" str2, greater than zero if
878 * str1 is "greater than" str2, and zero if the strings match
879 * exactly.
880 *
881 * \threadsafety It is safe to call this function from any thread.
882 *
883 * \since This function is available since SDL 3.0.0.
884 */
885extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
886
887/**
888 * Compare two wide strings up to a number of wchar_t values.
889 *
890 * This only compares wchar_t values; it does not care if the string is
891 * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
892 * or uses valid Unicode values.
893 *
894 * Note that while this function is intended to be used with UTF-16 (or
895 * UTF-32, depending on your platform's definition of wchar_t), it is
896 * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
897 * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
898 * sequence, it will only compare a portion of the final character.
899 *
900 * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
901 * match to this number of wide chars (or both have matched to a
902 * null-terminator character before this count), they will be considered
903 * equal.
904 *
905 * \param str1 The first string to compare. NULL is not permitted!
906 * \param str2 The second string to compare. NULL is not permitted!
907 * \param maxlen The maximum number of wchar_t to compare.
908 * \returns less than zero if str1 is "less than" str2, greater than zero if
909 * str1 is "greater than" str2, and zero if the strings match
910 * exactly.
911 *
912 * \threadsafety It is safe to call this function from any thread.
913 *
914 * \since This function is available since SDL 3.0.0.
915 */
916extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
917
918/**
919 * Compare two null-terminated wide strings, case-insensitively.
920 *
921 * This will work with Unicode strings, using a technique called
922 * "case-folding" to handle the vast majority of case-sensitive human
923 * languages regardless of system locale. It can deal with expanding values: a
924 * German Eszett character can compare against two ASCII 's' chars and be
925 * considered a match, for example. A notable exception: it does not handle
926 * the Turkish 'i' character; human language is complicated!
927 *
928 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
929 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
930 * handles Unicode, it expects the string to be well-formed and not a
931 * null-terminated string of arbitrary bytes. Characters that are not valid
932 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
933 * CHARACTER), which is to say two strings of random bits may turn out to
934 * match if they convert to the same amount of replacement characters.
935 *
936 * \param str1 The first string to compare. NULL is not permitted!
937 * \param str2 The second string to compare. NULL is not permitted!
938 * \returns less than zero if str1 is "less than" str2, greater than zero if
939 * str1 is "greater than" str2, and zero if the strings match
940 * exactly.
941 *
942 * \threadsafety It is safe to call this function from any thread.
943 *
944 * \since This function is available since SDL 3.0.0.
945 */
946extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
947
948/**
949 * Compare two wide strings, case-insensitively, up to a number of wchar_t.
950 *
951 * This will work with Unicode strings, using a technique called
952 * "case-folding" to handle the vast majority of case-sensitive human
953 * languages regardless of system locale. It can deal with expanding values: a
954 * German Eszett character can compare against two ASCII 's' chars and be
955 * considered a match, for example. A notable exception: it does not handle
956 * the Turkish 'i' character; human language is complicated!
957 *
958 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
959 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
960 * handles Unicode, it expects the string to be well-formed and not a
961 * null-terminated string of arbitrary bytes. Characters that are not valid
962 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
963 * CHARACTER), which is to say two strings of random bits may turn out to
964 * match if they convert to the same amount of replacement characters.
965 *
966 * Note that while this function might deal with variable-sized characters,
967 * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
968 * multi-byte UTF-16 sequence, it may convert a portion of the final character
969 * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
970 * to overflow a buffer.
971 *
972 * `maxlen` specifies a maximum number of wchar_t values to compare; if the
973 * strings match to this number of wchar_t (or both have matched to a
974 * null-terminator character before this number of bytes), they will be
975 * considered equal.
976 *
977 * \param str1 The first string to compare. NULL is not permitted!
978 * \param str2 The second string to compare. NULL is not permitted!
979 * \param maxlen The maximum number of wchar_t values to compare.
980 * \returns less than zero if str1 is "less than" str2, greater than zero if
981 * str1 is "greater than" str2, and zero if the strings match
982 * exactly.
983 *
984 * \threadsafety It is safe to call this function from any thread.
985 *
986 * \since This function is available since SDL 3.0.0.
987 */
988extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
989
990extern DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
991
992extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
993extern DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
994extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
995extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
996extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
997extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strdup(const char *str);
998extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strndup(const char *str, size_t maxlen);
999extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
1000
1001/**
1002 * Convert a string to uppercase.
1003 *
1004 * **WARNING**: Regardless of system locale, this will only convert ASCII
1005 * values 'A' through 'Z' to uppercase.
1006 *
1007 * This function operates on a null-terminated string of bytes--even if it is
1008 * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
1009 * uppercase equivalents in-place, returning the original `str` pointer.
1010 *
1011 * \threadsafety It is safe to call this function from any thread.
1012 *
1013 * \since This function is available since SDL 3.0.0.
1014 *
1015 * \sa SDL_strlwr
1016 */
1017extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
1018
1019/**
1020 * Convert a string to lowercase.
1021 *
1022 * **WARNING**: Regardless of system locale, this will only convert ASCII
1023 * values 'A' through 'Z' to lowercase.
1024 *
1025 * This function operates on a null-terminated string of bytes--even if it is
1026 * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
1027 * lowercase equivalents in-place, returning the original `str` pointer.
1028 *
1029 * \param str The string to convert in-place.
1030 * \returns The `str` pointer passed into this function.
1031 *
1032 * \threadsafety It is safe to call this function from any thread.
1033 *
1034 * \since This function is available since SDL 3.0.0.
1035 *
1036 * \sa SDL_strupr
1037 */
1038extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
1039
1040extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
1041extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
1042extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
1043extern DECLSPEC char *SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
1044extern DECLSPEC char *SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
1045extern DECLSPEC char *SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
1046extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
1047extern DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
1048
1049extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
1050extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
1051extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
1052extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
1053extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
1054extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
1055
1056extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
1057extern DECLSPEC double SDLCALL SDL_atof(const char *str);
1058extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
1059extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
1060extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
1061extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
1062extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
1063
1064/**
1065 * Compare two null-terminated UTF-8 strings.
1066 *
1067 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
1068 * since effectively this function just compares bytes until it hits a
1069 * null-terminating character. Also due to the nature of UTF-8, this can be
1070 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
1071 *
1072 * \param str1 The first string to compare. NULL is not permitted!
1073 * \param str2 The second string to compare. NULL is not permitted!
1074 * \returns less than zero if str1 is "less than" str2, greater than zero if
1075 * str1 is "greater than" str2, and zero if the strings match
1076 * exactly.
1077 *
1078 * \threadsafety It is safe to call this function from any thread.
1079 *
1080 * \since This function is available since SDL 3.0.0.
1081 */
1082extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
1083
1084/**
1085 * Compare two UTF-8 strings up to a number of bytes.
1086 *
1087 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
1088 * since effectively this function just compares bytes until it hits a
1089 * null-terminating character. Also due to the nature of UTF-8, this can be
1090 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
1091 *
1092 * Note that while this function is intended to be used with UTF-8, it is
1093 * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
1094 * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
1095 * compare a portion of the final character.
1096 *
1097 * `maxlen` specifies a maximum number of bytes to compare; if the strings
1098 * match to this number of bytes (or both have matched to a null-terminator
1099 * character before this number of bytes), they will be considered equal.
1100 *
1101 * \param str1 The first string to compare. NULL is not permitted!
1102 * \param str2 The second string to compare. NULL is not permitted!
1103 * \param maxlen The maximum number of _bytes_ to compare.
1104 * \returns less than zero if str1 is "less than" str2, greater than zero if
1105 * str1 is "greater than" str2, and zero if the strings match
1106 * exactly.
1107 *
1108 * \threadsafety It is safe to call this function from any thread.
1109 *
1110 * \since This function is available since SDL 3.0.0.
1111 */
1112extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
1113
1114/**
1115 * Compare two null-terminated UTF-8 strings, case-insensitively.
1116 *
1117 * This will work with Unicode strings, using a technique called
1118 * "case-folding" to handle the vast majority of case-sensitive human
1119 * languages regardless of system locale. It can deal with expanding values: a
1120 * German Eszett character can compare against two ASCII 's' chars and be
1121 * considered a match, for example. A notable exception: it does not handle
1122 * the Turkish 'i' character; human language is complicated!
1123 *
1124 * Since this handles Unicode, it expects the string to be well-formed UTF-8
1125 * and not a null-terminated string of arbitrary bytes. Bytes that are not
1126 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
1127 * CHARACTER), which is to say two strings of random bits may turn out to
1128 * match if they convert to the same amount of replacement characters.
1129 *
1130 * \param str1 The first string to compare. NULL is not permitted!
1131 * \param str2 The second string to compare. NULL is not permitted!
1132 * \returns less than zero if str1 is "less than" str2, greater than zero if
1133 * str1 is "greater than" str2, and zero if the strings match
1134 * exactly.
1135 *
1136 * \threadsafety It is safe to call this function from any thread.
1137 *
1138 * \since This function is available since SDL 3.0.0.
1139 */
1140extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
1141
1142
1143/**
1144 * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
1145 *
1146 * This will work with Unicode strings, using a technique called
1147 * "case-folding" to handle the vast majority of case-sensitive human
1148 * languages regardless of system locale. It can deal with expanding values: a
1149 * German Eszett character can compare against two ASCII 's' chars and be
1150 * considered a match, for example. A notable exception: it does not handle
1151 * the Turkish 'i' character; human language is complicated!
1152 *
1153 * Since this handles Unicode, it expects the string to be well-formed UTF-8
1154 * and not a null-terminated string of arbitrary bytes. Bytes that are not
1155 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
1156 * CHARACTER), which is to say two strings of random bits may turn out to
1157 * match if they convert to the same amount of replacement characters.
1158 *
1159 * Note that while this function is intended to be used with UTF-8, `maxlen`
1160 * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
1161 * UTF-8 sequence, it may convert a portion of the final character to one or
1162 * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
1163 * a buffer.
1164 *
1165 * `maxlen` specifies a maximum number of bytes to compare; if the strings
1166 * match to this number of bytes (or both have matched to a null-terminator
1167 * character before this number of bytes), they will be considered equal.
1168 *
1169 * \param str1 The first string to compare. NULL is not permitted!
1170 * \param str2 The second string to compare. NULL is not permitted!
1171 * \param maxlen The maximum number of bytes to compare.
1172 * \returns less than zero if str1 is "less than" str2, greater than zero if
1173 * str1 is "greater than" str2, and zero if the strings match
1174 * exactly.
1175 *
1176 * \threadsafety It is safe to call this function from any thread.
1177 *
1178 * \since This function is available since SDL 3.0.0.
1179 */
1180extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
1181
1182extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
1183extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
1184extern 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);
1185extern DECLSPEC int SDLCALL SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ... ) SDL_WPRINTF_VARARG_FUNC(3);
1186extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
1187extern DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap);
1188extern DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
1189extern DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
1190
1191#ifndef SDL_PI_D
1192#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
1193#endif
1194#ifndef SDL_PI_F
1195#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
1196#endif
1197
1198/**
1199 * Compute the arc cosine of `x`.
1200 *
1201 * The definition of `y = acos(x)` is `x = cos(y)`.
1202 *
1203 * Domain: `-1 <= x <= 1`
1204 *
1205 * Range: `0 <= y <= Pi`
1206 *
1207 * This function operates on double-precision floating point values, use
1208 * SDL_acosf for single-precision floats.
1209 *
1210 * This function may use a different approximation across different versions,
1211 * platforms and configurations. i.e, it can return a different value given
1212 * the same input on different machines or operating systems, or if SDL is
1213 * updated.
1214 *
1215 * \param x floating point value
1216 * \returns arc cosine of `x`, in radians
1217 *
1218 * \threadsafety It is safe to call this function from any thread.
1219 *
1220 * \since This function is available since SDL 3.0.0.
1221 *
1222 * \sa SDL_acosf
1223 * \sa SDL_asin
1224 * \sa SDL_cos
1225 */
1226extern DECLSPEC double SDLCALL SDL_acos(double x);
1227
1228/**
1229 * Compute the arc cosine of `x`.
1230 *
1231 * The definition of `y = acos(x)` is `x = cos(y)`.
1232 *
1233 * Domain: `-1 <= x <= 1`
1234 *
1235 * Range: `0 <= y <= Pi`
1236 *
1237 * This function operates on single-precision floating point values, use
1238 * SDL_acos for double-precision floats.
1239 *
1240 * This function may use a different approximation across different versions,
1241 * platforms and configurations. i.e, it can return a different value given
1242 * the same input on different machines or operating systems, or if SDL is
1243 * updated.
1244 *
1245 * \param x floating point value.
1246 * \returns arc cosine of `x`, in radians
1247 *
1248 * \since This function is available since SDL 3.0.0.
1249 *
1250 * \sa SDL_acos
1251 * \sa SDL_asinf
1252 * \sa SDL_cosf
1253 */
1254extern DECLSPEC float SDLCALL SDL_acosf(float x);
1255
1256/**
1257 * Compute the arc sine of `x`.
1258 *
1259 * The definition of `y = asin(x)` is `x = sin(y)`.
1260 *
1261 * Domain: `-1 <= x <= 1`
1262 *
1263 * Range: `-Pi/2 <= y <= Pi/2`
1264 *
1265 * This function operates on double-precision floating point values, use
1266 * SDL_asinf for single-precision floats.
1267 *
1268 * This function may use a different approximation across different versions,
1269 * platforms and configurations. i.e, it can return a different value given
1270 * the same input on different machines or operating systems, or if SDL is
1271 * updated.
1272 *
1273 * \param x floating point value.
1274 * \returns arc sine of `x`, in radians.
1275 *
1276 * \since This function is available since SDL 3.0.0.
1277 *
1278 * \sa SDL_asinf
1279 * \sa SDL_acos
1280 * \sa SDL_sin
1281 */
1282extern DECLSPEC double SDLCALL SDL_asin(double x);
1283
1284/**
1285 * Compute the arc sine of `x`.
1286 *
1287 * The definition of `y = asin(x)` is `x = sin(y)`.
1288 *
1289 * Domain: `-1 <= x <= 1`
1290 *
1291 * Range: `-Pi/2 <= y <= Pi/2`
1292 *
1293 * This function operates on single-precision floating point values, use
1294 * SDL_asin for double-precision floats.
1295 *
1296 * This function may use a different approximation across different versions,
1297 * platforms and configurations. i.e, it can return a different value given
1298 * the same input on different machines or operating systems, or if SDL is
1299 * updated.
1300 *
1301 * \param x floating point value.
1302 * \returns arc sine of `x`, in radians.
1303 *
1304 * \since This function is available since SDL 3.0.0.
1305 *
1306 * \sa SDL_asin
1307 * \sa SDL_acosf
1308 * \sa SDL_sinf
1309 */
1310extern DECLSPEC float SDLCALL SDL_asinf(float x);
1311
1312/**
1313 * Compute the arc tangent of `x`.
1314 *
1315 * The definition of `y = atan(x)` is `x = tan(y)`.
1316 *
1317 * Domain: `-INF <= x <= INF`
1318 *
1319 * Range: `-Pi/2 <= y <= Pi/2`
1320 *
1321 * This function operates on double-precision floating point values, use
1322 * SDL_atanf for single-precision floats.
1323 *
1324 * To calculate the arc tangent of y / x, use SDL_atan2.
1325 *
1326 * This function may use a different approximation across different versions,
1327 * platforms and configurations. i.e, it can return a different value given
1328 * the same input on different machines or operating systems, or if SDL is
1329 * updated.
1330 *
1331 * \param x floating point value.
1332 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
1333 *
1334 * \since This function is available since SDL 3.0.0.
1335 *
1336 * \sa SDL_atanf
1337 * \sa SDL_atan2
1338 * \sa SDL_tan
1339 */
1340extern DECLSPEC double SDLCALL SDL_atan(double x);
1341
1342/**
1343 * Compute the arc tangent of `x`.
1344 *
1345 * The definition of `y = atan(x)` is `x = tan(y)`.
1346 *
1347 * Domain: `-INF <= x <= INF`
1348 *
1349 * Range: `-Pi/2 <= y <= Pi/2`
1350 *
1351 * This function operates on single-precision floating point values, use
1352 * SDL_atan for dboule-precision floats.
1353 *
1354 * To calculate the arc tangent of y / x, use SDL_atan2f.
1355 *
1356 * This function may use a different approximation across different versions,
1357 * platforms and configurations. i.e, it can return a different value given
1358 * the same input on different machines or operating systems, or if SDL is
1359 * updated.
1360 *
1361 * \param x floating point value.
1362 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`
1363 *
1364 * \since This function is available since SDL 3.0.0.
1365 *
1366 * \sa SDL_atan
1367 * \sa SDL_atan2f
1368 * \sa SDL_tanf
1369 */
1370extern DECLSPEC float SDLCALL SDL_atanf(float x);
1371
1372/**
1373 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
1374 * the result's quadrant.
1375 *
1376 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
1377 * of z is determined based on the signs of x and y.
1378 *
1379 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
1380 *
1381 * Range: `-Pi/2 <= y <= Pi/2`
1382 *
1383 * This function operates on double-precision floating point values, use
1384 * SDL_atan2f for single-precision floats.
1385 *
1386 * To calculate the arc tangent of a single value, use SDL_atan.
1387 *
1388 * This function may use a different approximation across different versions,
1389 * platforms and configurations. i.e, it can return a different value given
1390 * the same input on different machines or operating systems, or if SDL is
1391 * updated.
1392 *
1393 * \param x floating point value of the denominator (x coordinate).
1394 * \param y floating point value of the numerator (y coordinate)
1395 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
1396 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
1397 *
1398 * \since This function is available since SDL 3.0.0.
1399 *
1400 * \sa SDL_atan2f
1401 * \sa SDL_atan
1402 * \sa SDL_tan
1403 */
1404extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
1405
1406/**
1407 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
1408 * the result's quadrant.
1409 *
1410 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
1411 * of z is determined based on the signs of x and y.
1412 *
1413 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
1414 *
1415 * Range: `-Pi/2 <= y <= Pi/2`
1416 *
1417 * This function operates on single-precision floating point values, use
1418 * SDL_atan2 for double-precision floats.
1419 *
1420 * To calculate the arc tangent of a single value, use SDL_atanf.
1421 *
1422 * This function may use a different approximation across different versions,
1423 * platforms and configurations. i.e, it can return a different value given
1424 * the same input on different machines or operating systems, or if SDL is
1425 * updated.
1426 *
1427 * \param x floating point value of the denominator (x coordinate).
1428 * \param y floating point value of the numerator (y coordinate)
1429 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
1430 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
1431 *
1432 * \since This function is available since SDL 3.0.0.
1433 *
1434 * \sa SDL_atan2f
1435 * \sa SDL_atan
1436 * \sa SDL_tan
1437 */
1438extern DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
1439
1440/**
1441 * Compute the ceiling of `x`.
1442 *
1443 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
1444 * rounded up to the nearest integer.
1445 *
1446 * Domain: `-INF <= x <= INF`
1447 *
1448 * Range: `-INF <= y <= INF`, y integer
1449 *
1450 * This function operates on double-precision floating point values, use
1451 * SDL_ceilf for single-precision floats.
1452 *
1453 * \param x floating point value
1454 * \returns the ceiling of `x`
1455 *
1456 * \since This function is available since SDL 3.0.0.
1457 *
1458 * \sa SDL_ceilf
1459 * \sa SDL_floor
1460 * \sa SDL_trunc
1461 * \sa SDL_round
1462 * \sa SDL_lround
1463 */
1464extern DECLSPEC double SDLCALL SDL_ceil(double x);
1465
1466/**
1467 * Compute the ceiling of `x`.
1468 *
1469 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
1470 * rounded up to the nearest integer.
1471 *
1472 * Domain: `-INF <= x <= INF`
1473 *
1474 * Range: `-INF <= y <= INF`, y integer
1475 *
1476 * This function operates on single-precision floating point values, use
1477 * SDL_ceil for double-precision floats.
1478 *
1479 * \param x floating point value
1480 * \returns the ceiling of `x`
1481 *
1482 * \since This function is available since SDL 3.0.0.
1483 *
1484 * \sa SDL_ceil
1485 * \sa SDL_floorf
1486 * \sa SDL_truncf
1487 * \sa SDL_roundf
1488 * \sa SDL_lroundf
1489 */
1490extern DECLSPEC float SDLCALL SDL_ceilf(float x);
1491
1492/**
1493 * Copy the sign of one floating-point value to another.
1494 *
1495 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
1496 *
1497 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
1498 *
1499 * Range: `-INF <= z <= INF`
1500 *
1501 * This function operates on double-precision floating point values, use
1502 * SDL_copysignf for single-precision floats.
1503 *
1504 * \param x floating point value to use as the magnitude
1505 * \param y floating point value to use as the sign
1506 * \returns the floating point value with the sign of y and the magnitude of x
1507 *
1508 * \since This function is available since SDL 3.0.0.
1509 *
1510 * \sa SDL_copysignf
1511 * \sa SDL_fabs
1512 */
1513extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
1514
1515/**
1516 * Copy the sign of one floating-point value to another.
1517 *
1518 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
1519 *
1520 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
1521 *
1522 * Range: `-INF <= z <= INF`
1523 *
1524 * This function operates on single-precision floating point values, use
1525 * SDL_copysign for double-precision floats.
1526 *
1527 * \param x floating point value to use as the magnitude
1528 * \param y floating point value to use as the sign
1529 * \returns the floating point value with the sign of y and the magnitude of x
1530 *
1531 * \since This function is available since SDL 3.0.0.
1532 *
1533 * \sa SDL_copysignf
1534 * \sa SDL_fabsf
1535 */
1536extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
1537
1538/**
1539 * Compute the cosine of `x`.
1540 *
1541 * Domain: `-INF <= x <= INF`
1542 *
1543 * Range: `-1 <= y <= 1`
1544 *
1545 * This function operates on double-precision floating point values, use
1546 * SDL_cosf for single-precision floats.
1547 *
1548 * This function may use a different approximation across different versions,
1549 * platforms and configurations. i.e, it can return a different value given
1550 * the same input on different machines or operating systems, or if SDL is
1551 * updated.
1552 *
1553 * \param x floating point value, in radians
1554 * \returns cosine of `x`
1555 *
1556 * \since This function is available since SDL 3.0.0.
1557 *
1558 * \sa SDL_cosf
1559 * \sa SDL_acos
1560 * \sa SDL_sin
1561 */
1562extern DECLSPEC double SDLCALL SDL_cos(double x);
1563
1564/**
1565 * Compute the cosine of `x`.
1566 *
1567 * Domain: `-INF <= x <= INF`
1568 *
1569 * Range: `-1 <= y <= 1`
1570 *
1571 * This function operates on single-precision floating point values, use
1572 * SDL_cos for double-precision floats.
1573 *
1574 * This function may use a different approximation across different versions,
1575 * platforms and configurations. i.e, it can return a different value given
1576 * the same input on different machines or operating systems, or if SDL is
1577 * updated.
1578 *
1579 * \param x floating point value, in radians
1580 * \returns cosine of `x`
1581 *
1582 * \since This function is available since SDL 3.0.0.
1583 *
1584 * \sa SDL_cos
1585 * \sa SDL_acosf
1586 * \sa SDL_sinf
1587 */
1588extern DECLSPEC float SDLCALL SDL_cosf(float x);
1589
1590/**
1591 * Compute the exponential of `x`.
1592 *
1593 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
1594 * natural logarithm. The inverse is the natural logarithm, SDL_log.
1595 *
1596 * Domain: `-INF <= x <= INF`
1597 *
1598 * Range: `0 <= y <= INF`
1599 *
1600 * The output will overflow if `exp(x)` is too large to be represented.
1601 *
1602 * This function operates on double-precision floating point values, use
1603 * SDL_expf for single-precision floats.
1604 *
1605 * This function may use a different approximation across different versions,
1606 * platforms and configurations. i.e, it can return a different value given
1607 * the same input on different machines or operating systems, or if SDL is
1608 * updated.
1609 *
1610 * \param x floating point value
1611 * \returns value of `e^x`
1612 *
1613 * \since This function is available since SDL 3.0.0.
1614 *
1615 * \sa SDL_expf
1616 * \sa SDL_log
1617 */
1618extern DECLSPEC double SDLCALL SDL_exp(double x);
1619
1620/**
1621 * Compute the exponential of `x`.
1622 *
1623 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
1624 * natural logarithm. The inverse is the natural logarithm, SDL_logf.
1625 *
1626 * Domain: `-INF <= x <= INF`
1627 *
1628 * Range: `0 <= y <= INF`
1629 *
1630 * The output will overflow if `exp(x)` is too large to be represented.
1631 *
1632 * This function operates on single-precision floating point values, use
1633 * SDL_exp for double-precision floats.
1634 *
1635 * This function may use a different approximation across different versions,
1636 * platforms and configurations. i.e, it can return a different value given
1637 * the same input on different machines or operating systems, or if SDL is
1638 * updated.
1639 *
1640 * \param x floating point value
1641 * \returns value of `e^x`
1642 *
1643 * \since This function is available since SDL 3.0.0.
1644 *
1645 * \sa SDL_exp
1646 * \sa SDL_logf
1647 */
1648extern DECLSPEC float SDLCALL SDL_expf(float x);
1649
1650/**
1651 * Compute the absolute value of `x`
1652 *
1653 * Domain: `-INF <= x <= INF`
1654 *
1655 * Range: `0 <= y <= INF`
1656 *
1657 * This function operates on double-precision floating point values, use
1658 * SDL_copysignf for single-precision floats.
1659 *
1660 * \param x floating point value to use as the magnitude
1661 * \returns the absolute value of `x`
1662 *
1663 * \since This function is available since SDL 3.0.0.
1664 *
1665 * \sa SDL_fabsf
1666 */
1667extern DECLSPEC double SDLCALL SDL_fabs(double x);
1668
1669/**
1670 * Compute the absolute value of `x`
1671 *
1672 * Domain: `-INF <= x <= INF`
1673 *
1674 * Range: `0 <= y <= INF`
1675 *
1676 * This function operates on single-precision floating point values, use
1677 * SDL_copysignf for double-precision floats.
1678 *
1679 * \param x floating point value to use as the magnitude
1680 * \returns the absolute value of `x`
1681 *
1682 * \since This function is available since SDL 3.0.0.
1683 *
1684 * \sa SDL_fabs
1685 */
1686extern DECLSPEC float SDLCALL SDL_fabsf(float x);
1687
1688/**
1689 * Compute the floor of `x`.
1690 *
1691 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
1692 * rounded down to the nearest integer.
1693 *
1694 * Domain: `-INF <= x <= INF`
1695 *
1696 * Range: `-INF <= y <= INF`, y integer
1697 *
1698 * This function operates on double-precision floating point values, use
1699 * SDL_floorf for single-precision floats.
1700 *
1701 * \param x floating point value
1702 * \returns the floor of `x`
1703 *
1704 * \since This function is available since SDL 3.0.0.
1705 *
1706 * \sa SDL_floorf
1707 * \sa SDL_ceil
1708 * \sa SDL_trunc
1709 * \sa SDL_round
1710 * \sa SDL_lround
1711 */
1712extern DECLSPEC double SDLCALL SDL_floor(double x);
1713
1714/**
1715 * Compute the floor of `x`.
1716 *
1717 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
1718 * rounded down to the nearest integer.
1719 *
1720 * Domain: `-INF <= x <= INF`
1721 *
1722 * Range: `-INF <= y <= INF`, y integer
1723 *
1724 * This function operates on single-precision floating point values, use
1725 * SDL_floorf for double-precision floats.
1726 *
1727 * \param x floating point value
1728 * \returns the floor of `x`
1729 *
1730 * \since This function is available since SDL 3.0.0.
1731 *
1732 * \sa SDL_floor
1733 * \sa SDL_ceilf
1734 * \sa SDL_truncf
1735 * \sa SDL_roundf
1736 * \sa SDL_lroundf
1737 */
1738extern DECLSPEC float SDLCALL SDL_floorf(float x);
1739
1740/**
1741 * Truncate `x` to an integer.
1742 *
1743 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
1744 * the fractional part of `x`, leaving only the integer part.
1745 *
1746 * Domain: `-INF <= x <= INF`
1747 *
1748 * Range: `-INF <= y <= INF`, y integer
1749 *
1750 * This function operates on double-precision floating point values, use
1751 * SDL_truncf for single-precision floats.
1752 *
1753 * \param x floating point value
1754 * \returns `x` truncated to an integer
1755 *
1756 * \since This function is available since SDL 3.0.0.
1757 *
1758 * \sa SDL_truncf
1759 * \sa SDL_fmod
1760 * \sa SDL_ceil
1761 * \sa SDL_floor
1762 * \sa SDL_round
1763 * \sa SDL_lround
1764 */
1765extern DECLSPEC double SDLCALL SDL_trunc(double x);
1766
1767/**
1768 * Truncate `x` to an integer.
1769 *
1770 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
1771 * the fractional part of `x`, leaving only the integer part.
1772 *
1773 * Domain: `-INF <= x <= INF`
1774 *
1775 * Range: `-INF <= y <= INF`, y integer
1776 *
1777 * This function operates on single-precision floating point values, use
1778 * SDL_truncf for double-precision floats.
1779 *
1780 * \param x floating point value
1781 * \returns `x` truncated to an integer
1782 *
1783 * \since This function is available since SDL 3.0.0.
1784 *
1785 * \sa SDL_trunc
1786 * \sa SDL_fmodf
1787 * \sa SDL_ceilf
1788 * \sa SDL_floorf
1789 * \sa SDL_roundf
1790 * \sa SDL_lroundf
1791 */
1792extern DECLSPEC float SDLCALL SDL_truncf(float x);
1793
1794/**
1795 * Return the floating-point remainder of `x / y`
1796 *
1797 * Divides `x` by `y`, and returns the remainder.
1798 *
1799 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
1800 *
1801 * Range: `-y <= z <= y`
1802 *
1803 * This function operates on double-precision floating point values, use
1804 * SDL_fmodf for single-precision floats.
1805 *
1806 * \param x the numerator
1807 * \param y the denominator. Must not be 0.
1808 * \returns the remainder of `x / y`
1809 *
1810 * \since This function is available since SDL 3.0.0.
1811 *
1812 * \sa SDL_fmodf
1813 * \sa SDL_modf
1814 * \sa SDL_trunc
1815 * \sa SDL_ceil
1816 * \sa SDL_floor
1817 * \sa SDL_round
1818 * \sa SDL_lround
1819 */
1820extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
1821
1822/**
1823 * Return the floating-point remainder of `x / y`
1824 *
1825 * Divides `x` by `y`, and returns the remainder.
1826 *
1827 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
1828 *
1829 * Range: `-y <= z <= y`
1830 *
1831 * This function operates on single-precision floating point values, use
1832 * SDL_fmod for single-precision floats.
1833 *
1834 * \param x the numerator
1835 * \param y the denominator. Must not be 0.
1836 * \returns the remainder of `x / y`
1837 *
1838 * \since This function is available since SDL 3.0.0.
1839 *
1840 * \sa SDL_fmod
1841 * \sa SDL_truncf
1842 * \sa SDL_modff
1843 * \sa SDL_ceilf
1844 * \sa SDL_floorf
1845 * \sa SDL_roundf
1846 * \sa SDL_lroundf
1847 */
1848extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
1849
1850/**
1851 * Compute the natural logarithm of `x`.
1852 *
1853 * Domain: `0 < x <= INF`
1854 *
1855 * Range: `-INF <= y <= INF`
1856 *
1857 * It is an error for `x` to be less than or equal to 0.
1858 *
1859 * This function operates on double-precision floating point values, use
1860 * SDL_logf for single-precision floats.
1861 *
1862 * This function may use a different approximation across different versions,
1863 * platforms and configurations. i.e, it can return a different value given
1864 * the same input on different machines or operating systems, or if SDL is
1865 * updated.
1866 *
1867 * \param x floating point value. Must be greater than 0.
1868 * \returns the natural logarithm of `x`
1869 *
1870 * \since This function is available since SDL 3.0.0.
1871 *
1872 * \sa SDL_logf
1873 * \sa SDL_log10
1874 * \sa SDL_exp
1875 */
1876extern DECLSPEC double SDLCALL SDL_log(double x);
1877
1878/**
1879 * Compute the natural logarithm of `x`.
1880 *
1881 * Domain: `0 < x <= INF`
1882 *
1883 * Range: `-INF <= y <= INF`
1884 *
1885 * It is an error for `x` to be less than or equal to 0.
1886 *
1887 * This function operates on single-precision floating point values, use
1888 * SDL_log for double-precision floats.
1889 *
1890 * This function may use a different approximation across different versions,
1891 * platforms and configurations. i.e, it can return a different value given
1892 * the same input on different machines or operating systems, or if SDL is
1893 * updated.
1894 *
1895 * \param x floating point value. Must be greater than 0.
1896 * \returns the natural logarithm of `x`
1897 *
1898 * \since This function is available since SDL 3.0.0.
1899 *
1900 * \sa SDL_log
1901 * \sa SDL_expf
1902 */
1903extern DECLSPEC float SDLCALL SDL_logf(float x);
1904
1905/**
1906 * Compute the base-10 logarithm of `x`.
1907 *
1908 * Domain: `0 < x <= INF`
1909 *
1910 * Range: `-INF <= y <= INF`
1911 *
1912 * It is an error for `x` to be less than or equal to 0.
1913 *
1914 * This function operates on double-precision floating point values, use
1915 * SDL_log10f for single-precision floats.
1916 *
1917 * This function may use a different approximation across different versions,
1918 * platforms and configurations. i.e, it can return a different value given
1919 * the same input on different machines or operating systems, or if SDL is
1920 * updated.
1921 *
1922 * \param x floating point value. Must be greater than 0.
1923 * \returns the logarithm of `x`
1924 *
1925 * \since This function is available since SDL 3.0.0.
1926 *
1927 * \sa SDL_log10f
1928 * \sa SDL_log
1929 * \sa SDL_pow
1930 */
1931extern DECLSPEC double SDLCALL SDL_log10(double x);
1932
1933/**
1934 * Compute the base-10 logarithm of `x`.
1935 *
1936 * Domain: `0 < x <= INF`
1937 *
1938 * Range: `-INF <= y <= INF`
1939 *
1940 * It is an error for `x` to be less than or equal to 0.
1941 *
1942 * This function operates on single-precision floating point values, use
1943 * SDL_log10 for double-precision floats.
1944 *
1945 * This function may use a different approximation across different versions,
1946 * platforms and configurations. i.e, it can return a different value given
1947 * the same input on different machines or operating systems, or if SDL is
1948 * updated.
1949 *
1950 * \param x floating point value. Must be greater than 0.
1951 * \returns the logarithm of `x`
1952 *
1953 * \since This function is available since SDL 3.0.0.
1954 *
1955 * \sa SDL_log10
1956 * \sa SDL_logf
1957 * \sa SDL_powf
1958 */
1959extern DECLSPEC float SDLCALL SDL_log10f(float x);
1960
1961/**
1962 * Split `x` into integer and fractional parts
1963 *
1964 * This function operates on double-precision floating point values, use
1965 * SDL_modff for single-precision floats.
1966 *
1967 * \param x floating point value
1968 * \param y output pointer to store the integer part of `x`
1969 * \returns the fractional part of `x`
1970 *
1971 * \since This function is available since SDL 3.0.0.
1972 *
1973 * \sa SDL_modff
1974 * \sa SDL_trunc
1975 * \sa SDL_fmod
1976 */
1977extern DECLSPEC double SDLCALL SDL_modf(double x, double *y);
1978
1979/**
1980 * Split `x` into integer and fractional parts
1981 *
1982 * This function operates on single-precision floating point values, use
1983 * SDL_modf for double-precision floats.
1984 *
1985 * \param x floating point value
1986 * \param y output pointer to store the integer part of `x`
1987 * \returns the fractional part of `x`
1988 *
1989 * \since This function is available since SDL 3.0.0.
1990 *
1991 * \sa SDL_modf
1992 * \sa SDL_truncf
1993 * \sa SDL_fmodf
1994 */
1995extern DECLSPEC float SDLCALL SDL_modff(float x, float *y);
1996
1997/**
1998 * Raise `x` to the power `y`
1999 *
2000 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2001 *
2002 * Range: `-INF <= z <= INF`
2003 *
2004 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
2005 * instead.
2006 *
2007 * This function operates on double-precision floating point values, use
2008 * SDL_powf for single-precision floats.
2009 *
2010 * This function may use a different approximation across different versions,
2011 * platforms and configurations. i.e, it can return a different value given
2012 * the same input on different machines or operating systems, or if SDL is
2013 * updated.
2014 *
2015 * \param x the base
2016 * \param y the exponent
2017 * \returns `x` raised to the power `y`
2018 *
2019 * \since This function is available since SDL 3.0.0.
2020 *
2021 * \sa SDL_powf
2022 * \sa SDL_exp
2023 * \sa SDL_log
2024 */
2025extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
2026
2027/**
2028 * Raise `x` to the power `y`
2029 *
2030 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2031 *
2032 * Range: `-INF <= z <= INF`
2033 *
2034 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
2035 * instead.
2036 *
2037 * This function operates on single-precision floating point values, use
2038 * SDL_powf for double-precision floats.
2039 *
2040 * This function may use a different approximation across different versions,
2041 * platforms and configurations. i.e, it can return a different value given
2042 * the same input on different machines or operating systems, or if SDL is
2043 * updated.
2044 *
2045 * \param x the base
2046 * \param y the exponent
2047 * \returns `x` raised to the power `y`
2048 *
2049 * \since This function is available since SDL 3.0.0.
2050 *
2051 * \sa SDL_pow
2052 * \sa SDL_expf
2053 * \sa SDL_logf
2054 */
2055extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
2056
2057/**
2058 * Round `x` to the nearest integer.
2059 *
2060 * Rounds `x` to the nearest integer. Values halfway between integers will be
2061 * rounded away from zero.
2062 *
2063 * Domain: `-INF <= x <= INF`
2064 *
2065 * Range: `-INF <= y <= INF`, y integer
2066 *
2067 * This function operates on double-precision floating point values, use
2068 * SDL_roundf for single-precision floats. To get the result as an integer
2069 * type, use SDL_lround.
2070 *
2071 * \param x floating point value
2072 * \returns the nearest integer to `x`
2073 *
2074 * \since This function is available since SDL 3.0.0.
2075 *
2076 * \sa SDL_roundf
2077 * \sa SDL_lround
2078 * \sa SDL_floor
2079 * \sa SDL_ceil
2080 * \sa SDL_trunc
2081 */
2082extern DECLSPEC double SDLCALL SDL_round(double x);
2083
2084/**
2085 * Round `x` to the nearest integer.
2086 *
2087 * Rounds `x` to the nearest integer. Values halfway between integers will be
2088 * rounded away from zero.
2089 *
2090 * Domain: `-INF <= x <= INF`
2091 *
2092 * Range: `-INF <= y <= INF`, y integer
2093 *
2094 * This function operates on double-precision floating point values, use
2095 * SDL_roundf for single-precision floats. To get the result as an integer
2096 * type, use SDL_lroundf.
2097 *
2098 * \param x floating point value
2099 * \returns the nearest integer to `x`
2100 *
2101 * \since This function is available since SDL 3.0.0.
2102 *
2103 * \sa SDL_round
2104 * \sa SDL_lroundf
2105 * \sa SDL_floorf
2106 * \sa SDL_ceilf
2107 * \sa SDL_truncf
2108 */
2109extern DECLSPEC float SDLCALL SDL_roundf(float x);
2110
2111/**
2112 * Round `x` to the nearest integer representable as a long
2113 *
2114 * Rounds `x` to the nearest integer. Values halfway between integers will be
2115 * rounded away from zero.
2116 *
2117 * Domain: `-INF <= x <= INF`
2118 *
2119 * Range: `MIN_LONG <= y <= MAX_LONG`
2120 *
2121 * This function operates on double-precision floating point values, use
2122 * SDL_lround for single-precision floats. To get the result as a
2123 * floating-point type, use SDL_round.
2124 *
2125 * \param x floating point value
2126 * \returns the nearest integer to `x`
2127 *
2128 * \since This function is available since SDL 3.0.0.
2129 *
2130 * \sa SDL_lroundf
2131 * \sa SDL_round
2132 * \sa SDL_floor
2133 * \sa SDL_ceil
2134 * \sa SDL_trunc
2135 */
2136extern DECLSPEC long SDLCALL SDL_lround(double x);
2137
2138/**
2139 * Round `x` to the nearest integer representable as a long
2140 *
2141 * Rounds `x` to the nearest integer. Values halfway between integers will be
2142 * rounded away from zero.
2143 *
2144 * Domain: `-INF <= x <= INF`
2145 *
2146 * Range: `MIN_LONG <= y <= MAX_LONG`
2147 *
2148 * This function operates on single-precision floating point values, use
2149 * SDL_lroundf for double-precision floats. To get the result as a
2150 * floating-point type, use SDL_roundf,
2151 *
2152 * \param x floating point value
2153 * \returns the nearest integer to `x`
2154 *
2155 * \since This function is available since SDL 3.0.0.
2156 *
2157 * \sa SDL_lround
2158 * \sa SDL_roundf
2159 * \sa SDL_floorf
2160 * \sa SDL_ceilf
2161 * \sa SDL_truncf
2162 */
2163extern DECLSPEC long SDLCALL SDL_lroundf(float x);
2164
2165/**
2166 * Scale `x` by an integer power of two.
2167 *
2168 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
2169 *
2170 * Domain: `-INF <= x <= INF`, `n` integer
2171 *
2172 * Range: `-INF <= y <= INF`
2173 *
2174 * This function operates on double-precision floating point values, use
2175 * SDL_scalbnf for single-precision floats.
2176 *
2177 * \param x floating point value to be scaled
2178 * \param n integer exponent
2179 * \returns `x * 2^n`
2180 *
2181 * \since This function is available since SDL 3.0.0.
2182 *
2183 * \sa SDL_scalbnf
2184 * \sa SDL_pow
2185 */
2186extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
2187
2188/**
2189 * Scale `x` by an integer power of two.
2190 *
2191 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
2192 *
2193 * Domain: `-INF <= x <= INF`, `n` integer
2194 *
2195 * Range: `-INF <= y <= INF`
2196 *
2197 * This function operates on single-precision floating point values, use
2198 * SDL_scalbn for double-precision floats.
2199 *
2200 * \param x floating point value to be scaled
2201 * \param n integer exponent
2202 * \returns `x * 2^n`
2203 *
2204 * \since This function is available since SDL 3.0.0.
2205 *
2206 * \sa SDL_scalbn
2207 * \sa SDL_powf
2208 */
2209extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
2210
2211/**
2212 * Compute the sine of `x`.
2213 *
2214 * Domain: `-INF <= x <= INF`
2215 *
2216 * Range: `-1 <= y <= 1`
2217 *
2218 * This function operates on double-precision floating point values, use
2219 * SDL_sinf for single-precision floats.
2220 *
2221 * This function may use a different approximation across different versions,
2222 * platforms and configurations. i.e, it can return a different value given
2223 * the same input on different machines or operating systems, or if SDL is
2224 * updated.
2225 *
2226 * \param x floating point value, in radians
2227 * \returns sine of `x`
2228 *
2229 * \since This function is available since SDL 3.0.0.
2230 *
2231 * \sa SDL_sinf
2232 * \sa SDL_asin
2233 * \sa SDL_cos
2234 */
2235extern DECLSPEC double SDLCALL SDL_sin(double x);
2236
2237/**
2238 * Compute the sine of `x`.
2239 *
2240 * Domain: `-INF <= x <= INF`
2241 *
2242 * Range: `-1 <= y <= 1`
2243 *
2244 * This function operates on single-precision floating point values, use
2245 * SDL_sinf for double-precision floats.
2246 *
2247 * This function may use a different approximation across different versions,
2248 * platforms and configurations. i.e, it can return a different value given
2249 * the same input on different machines or operating systems, or if SDL is
2250 * updated.
2251 *
2252 * \param x floating point value, in radians
2253 * \returns sine of `x`
2254 *
2255 * \since This function is available since SDL 3.0.0.
2256 *
2257 * \sa SDL_sin
2258 * \sa SDL_asinf
2259 * \sa SDL_cosf
2260 */
2261extern DECLSPEC float SDLCALL SDL_sinf(float x);
2262
2263/**
2264 * Compute the square root of `x`.
2265 *
2266 * Domain: `0 <= x <= INF`
2267 *
2268 * Range: `0 <= y <= INF`
2269 *
2270 * This function operates on double-precision floating point values, use
2271 * SDL_sqrtf for single-precision floats.
2272 *
2273 * This function may use a different approximation across different versions,
2274 * platforms and configurations. i.e, it can return a different value given
2275 * the same input on different machines or operating systems, or if SDL is
2276 * updated.
2277 *
2278 * \param x floating point value. Must be greater than or equal to 0.
2279 * \returns square root of `x`
2280 *
2281 * \since This function is available since SDL 3.0.0.
2282 *
2283 * \sa SDL_sqrtf
2284 */
2285extern DECLSPEC double SDLCALL SDL_sqrt(double x);
2286
2287/**
2288 * Compute the square root of `x`.
2289 *
2290 * Domain: `0 <= x <= INF`
2291 *
2292 * Range: `0 <= y <= INF`
2293 *
2294 * This function operates on single-precision floating point values, use
2295 * SDL_sqrt for double-precision floats.
2296 *
2297 * This function may use a different approximation across different versions,
2298 * platforms and configurations. i.e, it can return a different value given
2299 * the same input on different machines or operating systems, or if SDL is
2300 * updated.
2301 *
2302 * \param x floating point value. Must be greater than or equal to 0.
2303 * \returns square root of `x`
2304 *
2305 * \since This function is available since SDL 3.0.0.
2306 *
2307 * \sa SDL_sqrt
2308 */
2309extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
2310
2311/**
2312 * Compute the tangent of `x`.
2313 *
2314 * Domain: `-INF <= x <= INF`
2315 *
2316 * Range: `-INF <= y <= INF`
2317 *
2318 * This function operates on double-precision floating point values, use
2319 * SDL_tanf for single-precision floats.
2320 *
2321 * This function may use a different approximation across different versions,
2322 * platforms and configurations. i.e, it can return a different value given
2323 * the same input on different machines or operating systems, or if SDL is
2324 * updated.
2325 *
2326 * \param x floating point value, in radians
2327 * \returns tangent of `x`
2328 *
2329 * \since This function is available since SDL 3.0.0.
2330 *
2331 * \sa SDL_tanf
2332 * \sa SDL_sin
2333 * \sa SDL_cos
2334 * \sa SDL_atan
2335 * \sa SDL_atan2
2336 */
2337extern DECLSPEC double SDLCALL SDL_tan(double x);
2338
2339/**
2340 * Compute the tangent of `x`.
2341 *
2342 * Domain: `-INF <= x <= INF`
2343 *
2344 * Range: `-INF <= y <= INF`
2345 *
2346 * This function operates on single-precision floating point values, use
2347 * SDL_tanf for double-precision floats.
2348 *
2349 * This function may use a different approximation across different versions,
2350 * platforms and configurations. i.e, it can return a different value given
2351 * the same input on different machines or operating systems, or if SDL is
2352 * updated.
2353 *
2354 * \param x floating point value, in radians
2355 * \returns tangent of `x`
2356 *
2357 * \since This function is available since SDL 3.0.0.
2358 *
2359 * \sa SDL_tan
2360 * \sa SDL_sinf
2361 * \sa SDL_cosf
2362 * \sa SDL_atanf
2363 * \sa SDL_atan2f
2364 */
2365extern DECLSPEC float SDLCALL SDL_tanf(float x);
2366
2367/* The SDL implementation of iconv() returns these error codes */
2368#define SDL_ICONV_ERROR (size_t)-1
2369#define SDL_ICONV_E2BIG (size_t)-2
2370#define SDL_ICONV_EILSEQ (size_t)-3
2371#define SDL_ICONV_EINVAL (size_t)-4
2372
2373/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
2374typedef struct SDL_iconv_data_t *SDL_iconv_t;
2375extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
2376 const char *fromcode);
2377extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
2378extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
2379 size_t * inbytesleft, char **outbuf,
2380 size_t * outbytesleft);
2381
2382/**
2383 * This function converts a buffer or string between encodings in one pass,
2384 * returning a string that must be freed with SDL_free() or NULL on error.
2385 *
2386 * \since This function is available since SDL 3.0.0.
2387 */
2388extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
2389 const char *fromcode,
2390 const char *inbuf,
2391 size_t inbytesleft);
2392#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
2393#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
2394#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
2395#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
2396
2397/* force builds using Clang's static analysis tools to use literal C runtime
2398 here, since there are possibly tests that are ineffective otherwise. */
2399#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
2400
2401/* The analyzer knows about strlcpy even when the system doesn't provide it */
2402#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
2403size_t strlcpy(char* dst, const char* src, size_t size);
2404#endif
2405
2406/* The analyzer knows about strlcat even when the system doesn't provide it */
2407#if !defined(HAVE_STRLCAT) && !defined(strlcat)
2408size_t strlcat(char* dst, const char* src, size_t size);
2409#endif
2410
2411#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
2412size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
2413#endif
2414
2415#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
2416size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
2417#endif
2418
2419/* Starting LLVM 16, the analyser errors out if these functions do not have
2420 their prototype defined (clang-diagnostic-implicit-function-declaration) */
2421#include <stdlib.h>
2422#include <stdio.h>
2423
2424#define SDL_malloc malloc
2425#define SDL_calloc calloc
2426#define SDL_realloc realloc
2427#define SDL_free free
2428#ifndef SDL_memcpy
2429#define SDL_memcpy memcpy
2430#endif
2431#ifndef SDL_memmove
2432#define SDL_memmove memmove
2433#endif
2434#ifndef SDL_memset
2435#define SDL_memset memset
2436#endif
2437#define SDL_memcmp memcmp
2438#define SDL_strlcpy strlcpy
2439#define SDL_strlcat strlcat
2440#define SDL_strlen strlen
2441#define SDL_wcslen wcslen
2442#define SDL_wcslcpy wcslcpy
2443#define SDL_wcslcat wcslcat
2444#define SDL_strdup strdup
2445#define SDL_wcsdup wcsdup
2446#define SDL_strchr strchr
2447#define SDL_strrchr strrchr
2448#define SDL_strstr strstr
2449#define SDL_wcsstr wcsstr
2450#define SDL_strtok_r strtok_r
2451#define SDL_strcmp strcmp
2452#define SDL_wcscmp wcscmp
2453#define SDL_strncmp strncmp
2454#define SDL_wcsncmp wcsncmp
2455#define SDL_strcasecmp strcasecmp
2456#define SDL_strncasecmp strncasecmp
2457#define SDL_sscanf sscanf
2458#define SDL_vsscanf vsscanf
2459#define SDL_snprintf snprintf
2460#define SDL_vsnprintf vsnprintf
2461#endif
2462
2463/**
2464 * If a * b would overflow, return -1.
2465 *
2466 * Otherwise store a * b via ret and return 0.
2467 *
2468 * \since This function is available since SDL 3.0.0.
2469 */
2471 size_t b,
2472 size_t *ret)
2473{
2474 if (a != 0 && b > SDL_SIZE_MAX / a) {
2475 return -1;
2476 }
2477 *ret = a * b;
2478 return 0;
2479}
2480
2481#ifndef SDL_WIKI_DOCUMENTATION_SECTION
2482#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
2483/* This needs to be wrapped in an inline rather than being a direct #define,
2484 * because __builtin_mul_overflow() is type-generic, but we want to be
2485 * consistent about interpreting a and b as size_t. */
2486SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a,
2487 size_t b,
2488 size_t *ret)
2489{
2490 return __builtin_mul_overflow(a, b, ret) == 0 ? 0 : -1;
2491}
2492#define SDL_size_mul_overflow(a, b, ret) (SDL_size_mul_overflow_builtin(a, b, ret))
2493#endif
2494#endif
2495
2496/**
2497 * If a + b would overflow, return -1.
2498 *
2499 * Otherwise store a + b via ret and return 0.
2500 *
2501 * \since This function is available since SDL 3.0.0.
2502 */
2504 size_t b,
2505 size_t *ret)
2506{
2507 if (b > SDL_SIZE_MAX - a) {
2508 return -1;
2509 }
2510 *ret = a + b;
2511 return 0;
2512}
2513
2514#ifndef SDL_WIKI_DOCUMENTATION_SECTION
2515#if SDL_HAS_BUILTIN(__builtin_add_overflow)
2516/* This needs to be wrapped in an inline rather than being a direct #define,
2517 * the same as the call to __builtin_mul_overflow() above. */
2518SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a,
2519 size_t b,
2520 size_t *ret)
2521{
2522 return __builtin_add_overflow(a, b, ret) == 0 ? 0 : -1;
2523}
2524#define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret))
2525#endif
2526#endif
2527
2528/* This is a generic function pointer which should be cast to the type you expect */
2529#ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
2530typedef void *SDL_FunctionPointer;
2531#else
2532typedef void (*SDL_FunctionPointer)(void);
2533#endif
2534
2535/* Ends C function definitions when using C++ */
2536#ifdef __cplusplus
2537}
2538#endif
2539#include <SDL3/SDL_close_code.h>
2540
2541#endif /* SDL_stdinc_h_ */
#define SDL_ALLOC_SIZE(p)
#define SDL_ALLOC_SIZE2(p1, p2)
#define SDL_FORCE_INLINE
#define SDL_MALLOC
wchar_t * SDL_wcsdup(const wchar_t *wstr)
double SDL_sqrt(double x)
int SDL_atoi(const char *str)
#define SDL_memset
Definition SDL_stdinc.h:851
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
float SDL_tanf(float x)
char * SDL_strtok_r(char *s1, const char *s2, char **saveptr)
int SDL_isspace(int x)
int SDL_isalnum(int x)
char * SDL_strlwr(char *str)
struct SDL_iconv_data_t * SDL_iconv_t
wchar_t * SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
int SDL_tolower(int x)
float SDL_modff(float x, float *y)
double SDL_modf(double x, double *y)
void * SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int(*compare)(void *, const void *, const void *), void *userdata)
int SDL_abs(int x)
size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
void SDL_qsort_r(void *base, size_t nmemb, size_t size, int(*compare)(void *, const void *, const void *), void *userdata)
double SDL_tan(double x)
uint8_t Uint8
Definition SDL_stdinc.h:188
char * SDL_ltoa(long value, char *str, int radix)
int SDL_isxdigit(int x)
float SDL_ceilf(float x)
int64_t Sint64
Definition SDL_stdinc.h:233
void SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
void *(* SDL_malloc_func)(size_t size)
Definition SDL_stdinc.h:473
#define SDL_OUT_BYTECAP(x)
Definition SDL_stdinc.h:383
char * SDL_strrchr(const char *str, int c)
#define SDL_SIZE_MAX
Definition SDL_stdinc.h:77
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
uint16_t Uint16
Definition SDL_stdinc.h:206
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
void SDL_qsort(void *base, size_t nmemb, size_t size, int(*compare)(const void *, const void *))
float SDL_atanf(float x)
int SDL_isprint(int x)
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:397
int SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
char * SDL_itoa(int value, char *str, int radix)
float SDL_copysignf(float x, float y)
SDL_MALLOC char * SDL_strndup(const char *str, size_t maxlen)
char * SDL_strupr(char *str)
float SDL_acosf(float x)
int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
SDL_FORCE_INLINE int SDL_size_mul_overflow(size_t a, size_t b, size_t *ret)
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
char * SDL_strchr(const char *str, int c)
SDL_MALLOC void * SDL_aligned_alloc(size_t alignment, size_t size)
#define SDL_IN_BYTECAP(x)
Definition SDL_stdinc.h:379
int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
char * SDL_uitoa(unsigned int value, char *str, int radix)
void * alloca(size_t)
int SDL_isalpha(int x)
double SDL_round(double x)
long SDL_lround(double x)
int SDL_isdigit(int x)
int SDL_isblank(int x)
size_t SDL_strnlen(const char *str, size_t maxlen)
int SDL_iconv_close(SDL_iconv_t cd)
double SDL_sin(double x)
char * SDL_strcasestr(const char *haystack, const char *needle)
float SDL_scalbnf(float x, int n)
double SDL_pow(double x, double y)
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
float SDL_asinf(float x)
double SDL_asin(double x)
double SDL_acos(double x)
int8_t Sint8
Definition SDL_stdinc.h:179
wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
float SDL_sinf(float x)
int SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...) SDL_WPRINTF_VARARG_FUNC(3)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3)
#define SDL_SCANF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:399
double SDL_ceil(double x)
size_t SDL_utf8strnlen(const char *str, size_t bytes)
int SDL_strcasecmp(const char *str1, const char *str2)
void * SDL_memset4(void *dst, Uint32 val, size_t dwords)
#define SDL_SCANF_FORMAT_STRING
Definition SDL_stdinc.h:386
char * SDL_strstr(const char *haystack, const char *needle)
int SDL_GetNumAllocations(void)
double SDL_exp(double x)
size_t SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
double SDL_atan(double x)
float SDL_sqrtf(float x)
size_t SDL_wcslen(const wchar_t *wstr)
int32_t Sint32
Definition SDL_stdinc.h:215
int SDL_setenv(const char *name, const char *value, int overwrite)
size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
#define SDL_INOUT_Z_CAP(x)
Definition SDL_stdinc.h:380
double SDL_scalbn(double x, int n)
char * SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
int SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
char * SDL_getenv(const char *name)
double SDL_fmod(double x, double y)
char * SDL_lltoa(Sint64 value, char *str, int radix)
double SDL_fabs(double x)
Sint64 SDL_strtoll(const char *str, char **endp, int base)
int SDL_ispunct(int x)
float SDL_truncf(float x)
double SDL_log10(double x)
SDL_MALLOC size_t size
Definition SDL_stdinc.h:469
float SDL_expf(float x)
char * SDL_strrev(char *str)
double SDL_floor(double x)
int SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
long SDL_strtol(const char *str, char **endp, int base)
Uint32 SDL_crc32(Uint32 crc, const void *data, size_t len)
int SDL_islower(int x)
void SDL_aligned_free(void *mem)
float SDL_logf(float x)
int SDL_bool
Definition SDL_stdinc.h:170
float SDL_log10f(float x)
void(* SDL_free_func)(void *mem)
Definition SDL_stdinc.h:476
int SDL_memcmp(const void *s1, const void *s2, size_t len)
char * SDL_ulltoa(Uint64 value, char *str, int radix)
int16_t Sint16
Definition SDL_stdinc.h:197
float SDL_roundf(float x)
double SDL_strtod(const char *str, char **endp)
long SDL_lroundf(float x)
char * SDL_ultoa(unsigned long value, char *str, int radix)
double SDL_atof(const char *str)
char * SDL_strnstr(const char *haystack, const char *needle, size_t maxlen)
size_t SDL_wcsnlen(const wchar_t *wstr, size_t maxlen)
unsigned long SDL_strtoul(const char *str, char **endp, int base)
float SDL_floorf(float x)
int SDL_strcmp(const char *str1, const char *str2)
SDL_FORCE_INLINE int SDL_size_add_overflow(size_t a, size_t b, size_t *ret)
double SDL_cos(double x)
#define SDL_PRINTF_FORMAT_STRING
Definition SDL_stdinc.h:385
float SDL_fmodf(float x, float y)
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap)
void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
SDL_MALLOC void * SDL_malloc(size_t size)
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:396
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:417
float SDL_atan2f(float y, float x)
int SDL_isupper(int x)
long SDL_wcstol(const wchar_t *str, wchar_t **endp, int base)
float SDL_fabsf(float x)
uint64_t Uint64
Definition SDL_stdinc.h:242
SDL_MALLOC char * SDL_strdup(const char *str)
int SDL_iscntrl(int x)
#define SDL_memcpy
Definition SDL_stdinc.h:826
void SDL_free(void *mem)
void *(* SDL_calloc_func)(size_t nmemb, size_t size)
Definition SDL_stdinc.h:474
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:398
double SDL_atan2(double y, double x)
double SDL_log(double x)
void(* SDL_FunctionPointer)(void)
int SDL_toupper(int x)
uint32_t Uint32
Definition SDL_stdinc.h:224
float SDL_powf(float x, float y)
size_t SDL_strlen(const char *str)
#define SDL_memmove
Definition SDL_stdinc.h:840
Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len)
int SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(3)
float SDL_cosf(float x)
void * SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int(*compare)(const void *, const void *))
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
size_t SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
double SDL_copysign(double x, double y)
int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2)
Sint64 SDL_Time
Definition SDL_stdinc.h:256
void *(* SDL_realloc_func)(void *mem, size_t size)
Definition SDL_stdinc.h:475
size_t SDL_utf8strlen(const char *str)
int SDL_isgraph(int x)
int SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
#define SDL_OUT_Z_CAP(x)
Definition SDL_stdinc.h:381
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:400
Uint64 SDL_strtoull(const char *str, char **endp, int base)
double SDL_trunc(double x)