SDL 3.0
SDL_stdinc.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2026 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 * # CategoryStdinc
24 *
25 * SDL provides its own implementation of some of the most important C runtime
26 * functions.
27 *
28 * Using these functions allows an app to have access to common C
29 * functionality without depending on a specific C runtime (or a C runtime at
30 * all). More importantly, the SDL implementations work identically across
31 * platforms, so apps can avoid surprises like snprintf() behaving differently
32 * between Windows and Linux builds, or itoa() only existing on some
33 * platforms.
34 *
35 * For many of the most common functions, like SDL_memcpy, SDL might just call
36 * through to the usual C runtime behind the scenes, if it makes sense to do
37 * so (if it's faster and always available/reliable on a given platform),
38 * reducing library size and offering the most optimized option.
39 *
40 * SDL also offers other C-runtime-adjacent functionality in this header that
41 * either isn't, strictly speaking, part of any C runtime standards, like
42 * SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better
43 * options, like SDL_strlcpy(), which functions as a safer form of strcpy().
44 */
45
46#ifndef SDL_stdinc_h_
47#define SDL_stdinc_h_
48
50
51#include <stdarg.h>
52#include <string.h>
53#include <wchar.h>
54
55#include <SDL3/SDL_begin_code.h>
56
57/* Most everything except Visual Studio 2008 and earlier has stdint.h now */
58#if defined(_MSC_VER) && (_MSC_VER < 1600)
59typedef signed __int8 int8_t;
60typedef unsigned __int8 uint8_t;
61typedef signed __int16 int16_t;
62typedef unsigned __int16 uint16_t;
63typedef signed __int32 int32_t;
64typedef unsigned __int32 uint32_t;
65typedef signed __int64 int64_t;
66typedef unsigned __int64 uint64_t;
67#ifndef _INTPTR_T_DEFINED
68#ifdef _WIN64
69typedef __int64 intptr_t;
70#else
71typedef int intptr_t;
72#endif
73#endif
74#ifndef _UINTPTR_T_DEFINED
75#ifdef _WIN64
76typedef unsigned __int64 uintptr_t;
77#else
78typedef unsigned int uintptr_t;
79#endif
80#endif
81#else
82#include <stdint.h>
83#endif
84
85#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
86 defined(SDL_INCLUDE_INTTYPES_H)
87#include <inttypes.h>
88#endif
89
90#ifndef __cplusplus
91#if defined(__has_include) && !defined(SDL_INCLUDE_STDBOOL_H)
92#if __has_include(<stdbool.h>)
93#define SDL_INCLUDE_STDBOOL_H
94#endif
95#endif
96#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
97 (defined(_MSC_VER) && (_MSC_VER >= 1910 /* Visual Studio 2017 */)) || \
98 defined(SDL_INCLUDE_STDBOOL_H)
99#include <stdbool.h>
100#elif !defined(__bool_true_false_are_defined) && !defined(bool)
101#define bool unsigned char
102#define false 0
103#define true 1
104#define __bool_true_false_are_defined 1
105#endif
106#endif /* !__cplusplus */
107
108#ifndef SDL_DISABLE_ALLOCA
109# ifndef alloca
110# ifdef HAVE_ALLOCA_H
111# include <alloca.h>
112# elif defined(SDL_PLATFORM_NETBSD)
113# if defined(__STRICT_ANSI__)
114# define SDL_DISABLE_ALLOCA
115# else
116# include <stdlib.h>
117# endif
118# elif defined(__GNUC__)
119# define alloca __builtin_alloca
120# elif defined(_MSC_VER)
121# include <malloc.h>
122# define alloca _alloca
123# elif defined(__WATCOMC__)
124# include <malloc.h>
125# elif defined(__BORLANDC__)
126# include <malloc.h>
127# elif defined(__DMC__)
128# include <stdlib.h>
129# elif defined(SDL_PLATFORM_AIX)
130# pragma alloca
131# elif defined(__MRC__)
132void *alloca(unsigned);
133# else
134void *alloca(size_t);
135# endif
136# endif
137#endif
138
139
140#ifdef SDL_WIKI_DOCUMENTATION_SECTION
141
142/**
143 * Don't let SDL use "long long" C types.
144 *
145 * SDL will define this if it believes the compiler doesn't understand the
146 * "long long" syntax for C datatypes. This can happen on older compilers.
147 *
148 * If _your_ compiler doesn't support "long long" but SDL doesn't know it, it
149 * is safe to define this yourself to build against the SDL headers.
150 *
151 * If this is defined, it will remove access to some C runtime support
152 * functions, like SDL_ulltoa and SDL_strtoll that refer to this datatype
153 * explicitly. The rest of SDL will still be available.
154 *
155 * SDL's own source code cannot be built with a compiler that has this
156 * defined, for various technical reasons.
157 */
158#define SDL_NOLONGLONG 1
159
160#elif defined(_MSC_VER) && (_MSC_VER < 1310) /* long long introduced in Visual Studio.NET 2003 */
161# define SDL_NOLONGLONG 1
162#endif
163
164
165#ifdef SDL_WIKI_DOCUMENTATION_SECTION
166
167/**
168 * The largest value that a `size_t` can hold for the target platform.
169 *
170 * `size_t` is generally the same size as a pointer in modern times, but this
171 * can get weird on very old and very esoteric machines. For example, on a
172 * 16-bit Intel 286, you might have a 32-bit "far" pointer (16-bit segment
173 * plus 16-bit offset), but `size_t` is 16 bits, because it can only deal with
174 * the offset into an individual segment.
175 *
176 * In modern times, it's generally expected to cover an entire linear address
177 * space. But be careful!
178 *
179 * \since This macro is available since SDL 3.2.0.
180 */
181#define SDL_SIZE_MAX SIZE_MAX
182
183#elif defined(SIZE_MAX)
184# define SDL_SIZE_MAX SIZE_MAX
185#else
186# define SDL_SIZE_MAX ((size_t) -1)
187#endif
188
189#ifndef SDL_COMPILE_TIME_ASSERT
190#ifdef SDL_WIKI_DOCUMENTATION_SECTION
191
192/**
193 * A compile-time assertion.
194 *
195 * This can check constant values _known to the compiler at build time_ for
196 * correctness, and end the compile with the error if they fail.
197 *
198 * Often times these are used to verify basic truths, like the size of a
199 * datatype is what is expected:
200 *
201 * ```c
202 * SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
203 * ```
204 *
205 * The `name` parameter must be a valid C symbol, and must be unique across
206 * all compile-time asserts in the same compilation unit (one run of the
207 * compiler), or the build might fail with cryptic errors on some targets.
208 * This is used with a C language trick that works on older compilers that
209 * don't support better assertion techniques.
210 *
211 * If you need an assertion that operates at runtime, on variable data, you
212 * should try SDL_assert instead.
213 *
214 * \param name a unique identifier for this assertion.
215 * \param x the value to test. Must be a boolean value.
216 *
217 * \threadsafety This macro doesn't generate any code to run.
218 *
219 * \since This macro is available since SDL 3.2.0.
220 *
221 * \sa SDL_assert
222 */
223#define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x)
224#elif defined(__cplusplus)
225/* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
226#if (__cplusplus >= 201103L)
227#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
228#endif
229#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
230#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
231#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
232#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
233#endif
234#endif /* !SDL_COMPILE_TIME_ASSERT */
235
236#ifndef SDL_COMPILE_TIME_ASSERT
237/* universal, but may trigger -Wunused-local-typedefs */
238#define SDL_COMPILE_TIME_ASSERT(name, x) \
239 typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
240#endif
241
242#ifdef SDL_WIKI_DOCUMENTATION_SECTION
243
244/**
245 * The number of elements in a static array.
246 *
247 * This will compile but return incorrect results for a pointer to an array;
248 * it has to be an array the compiler knows the size of.
249 *
250 * This macro looks like it double-evaluates the argument, but it does so
251 * inside of `sizeof`, so there are no side-effects here, as expressions do
252 * not actually run any code in these cases.
253 *
254 * \since This macro is available since SDL 3.2.0.
255 */
256#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) /* or `_Countof(array)` on recent gcc and clang */
257
258#else
259#if !defined(__cplusplus) && ((defined(__GNUC__) && __GNUC__ >= 16) || SDL_HAS_EXTENSION(c_countof)) \
260 && (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202500L)
261#define SDL_arraysize(array) _Countof(array)
262#else
263#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
264#endif
265#endif
266
267/**
268 * Macro useful for building other macros with strings in them.
269 *
270 * \param arg the text to turn into a string literal.
271 *
272 * \since This macro is available since SDL 3.2.0.
273 */
274#define SDL_STRINGIFY_ARG(arg) #arg
275
276/**
277 * \name Cast operators
278 *
279 * Use proper C++ casts when compiled as C++ to be compatible with the option
280 * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
281 */
282/* @{ */
283
284#ifdef SDL_WIKI_DOCUMENTATION_SECTION
285
286/**
287 * Handle a Reinterpret Cast properly whether using C or C++.
288 *
289 * If compiled as C++, this macro offers a proper C++ reinterpret_cast<>.
290 *
291 * If compiled as C, this macro does a normal C-style cast.
292 *
293 * This is helpful to avoid compiler warnings in C++.
294 *
295 * \param type the type to cast the expression to.
296 * \param expression the expression to cast to a different type.
297 * \returns `expression`, cast to `type`.
298 *
299 * \threadsafety It is safe to call this macro from any thread.
300 *
301 * \since This macro is available since SDL 3.2.0.
302 *
303 * \sa SDL_static_cast
304 * \sa SDL_const_cast
305 */
306#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */
307
308/**
309 * Handle a Static Cast properly whether using C or C++.
310 *
311 * If compiled as C++, this macro offers a proper C++ static_cast<>.
312 *
313 * If compiled as C, this macro does a normal C-style cast.
314 *
315 * This is helpful to avoid compiler warnings in C++.
316 *
317 * \param type the type to cast the expression to.
318 * \param expression the expression to cast to a different type.
319 * \returns `expression`, cast to `type`.
320 *
321 * \threadsafety It is safe to call this macro from any thread.
322 *
323 * \since This macro is available since SDL 3.2.0.
324 *
325 * \sa SDL_reinterpret_cast
326 * \sa SDL_const_cast
327 */
328#define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */
329
330/**
331 * Handle a Const Cast properly whether using C or C++.
332 *
333 * If compiled as C++, this macro offers a proper C++ const_cast<>.
334 *
335 * If compiled as C, this macro does a normal C-style cast.
336 *
337 * This is helpful to avoid compiler warnings in C++.
338 *
339 * \param type the type to cast the expression to.
340 * \param expression the expression to cast to a different type.
341 * \returns `expression`, cast to `type`.
342 *
343 * \threadsafety It is safe to call this macro from any thread.
344 *
345 * \since This macro is available since SDL 3.2.0.
346 *
347 * \sa SDL_reinterpret_cast
348 * \sa SDL_static_cast
349 */
350#define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */
351
352#elif defined(__cplusplus)
353#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
354#define SDL_static_cast(type, expression) static_cast<type>(expression)
355#define SDL_const_cast(type, expression) const_cast<type>(expression)
356#else
357#define SDL_reinterpret_cast(type, expression) ((type)(expression))
358#define SDL_static_cast(type, expression) ((type)(expression))
359#define SDL_const_cast(type, expression) ((type)(expression))
360#endif
361
362/* @} *//* Cast operators */
363
364/**
365 * Define a four character code as a Uint32.
366 *
367 * \param A the first ASCII character.
368 * \param B the second ASCII character.
369 * \param C the third ASCII character.
370 * \param D the fourth ASCII character.
371 * \returns the four characters converted into a Uint32, one character
372 * per-byte.
373 *
374 * \threadsafety It is safe to call this macro from any thread.
375 *
376 * \since This macro is available since SDL 3.2.0.
377 */
378#define SDL_FOURCC(A, B, C, D) \
379 ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
380 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
381 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
382 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
383
384#ifdef SDL_WIKI_DOCUMENTATION_SECTION
385
386/**
387 * Append the 64 bit integer suffix to a signed integer literal.
388 *
389 * This helps compilers that might believe a integer literal larger than
390 * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
391 * instead of `0xFFFFFFFF1` by itself.
392 *
393 * \since This macro is available since SDL 3.2.0.
394 *
395 * \sa SDL_UINT64_C
396 */
397#define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
398
399/**
400 * Append the 64 bit integer suffix to an unsigned integer literal.
401 *
402 * This helps compilers that might believe a integer literal larger than
403 * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
404 * instead of `0xFFFFFFFF1` by itself.
405 *
406 * \since This macro is available since SDL 3.2.0.
407 *
408 * \sa SDL_SINT64_C
409 */
410#define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
411
412#else /* !SDL_WIKI_DOCUMENTATION_SECTION */
413
414#ifndef SDL_SINT64_C
415#if defined(INT64_C)
416#define SDL_SINT64_C(c) INT64_C(c)
417#elif defined(_MSC_VER)
418#define SDL_SINT64_C(c) c ## i64
419#elif defined(__LP64__) || defined(_LP64)
420#define SDL_SINT64_C(c) c ## L
421#else
422#define SDL_SINT64_C(c) c ## LL
423#endif
424#endif /* !SDL_SINT64_C */
425
426#ifndef SDL_UINT64_C
427#if defined(UINT64_C)
428#define SDL_UINT64_C(c) UINT64_C(c)
429#elif defined(_MSC_VER)
430#define SDL_UINT64_C(c) c ## ui64
431#elif defined(__LP64__) || defined(_LP64)
432#define SDL_UINT64_C(c) c ## UL
433#else
434#define SDL_UINT64_C(c) c ## ULL
435#endif
436#endif /* !SDL_UINT64_C */
437
438#endif /* !SDL_WIKI_DOCUMENTATION_SECTION */
439
440/**
441 * \name Basic data types
442 */
443/* @{ */
444
445/**
446 * A signed 8-bit integer type.
447 *
448 * \since This macro is available since SDL 3.2.0.
449 */
450typedef int8_t Sint8;
451#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
452#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
453
454/**
455 * An unsigned 8-bit integer type.
456 *
457 * \since This macro is available since SDL 3.2.0.
458 */
459typedef uint8_t Uint8;
460#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
461#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
462
463/**
464 * A signed 16-bit integer type.
465 *
466 * \since This macro is available since SDL 3.2.0.
467 */
468typedef int16_t Sint16;
469#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
470#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
471
472/**
473 * An unsigned 16-bit integer type.
474 *
475 * \since This macro is available since SDL 3.2.0.
476 */
477typedef uint16_t Uint16;
478#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
479#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
480
481/**
482 * A signed 32-bit integer type.
483 *
484 * \since This macro is available since SDL 3.2.0.
485 */
486typedef int32_t Sint32;
487#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
488#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
489
490/**
491 * An unsigned 32-bit integer type.
492 *
493 * \since This macro is available since SDL 3.2.0.
494 */
495typedef uint32_t Uint32;
496#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
497#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
498
499/**
500 * A signed 64-bit integer type.
501 *
502 * \since This macro is available since SDL 3.2.0.
503 *
504 * \sa SDL_SINT64_C
505 */
506typedef int64_t Sint64;
507#define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
508#define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
509
510/**
511 * An unsigned 64-bit integer type.
512 *
513 * \since This macro is available since SDL 3.2.0.
514 *
515 * \sa SDL_UINT64_C
516 */
517typedef uint64_t Uint64;
518#define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
519#define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
520
521/**
522 * SDL times are signed, 64-bit integers representing nanoseconds since the
523 * Unix epoch (Jan 1, 1970).
524 *
525 * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
526 * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
527 * SDL_TimeToWindows() and SDL_TimeFromWindows().
528 *
529 * \since This datatype is available since SDL 3.2.0.
530 *
531 * \sa SDL_MAX_SINT64
532 * \sa SDL_MIN_SINT64
533 */
535#define SDL_MAX_TIME SDL_MAX_SINT64
536#define SDL_MIN_TIME SDL_MIN_SINT64
537
538/* @} *//* Basic data types */
539
540/**
541 * \name Floating-point constants
542 */
543/* @{ */
544
545#ifdef FLT_EPSILON
546#define SDL_FLT_EPSILON FLT_EPSILON
547#else
548
549/**
550 * Epsilon constant, used for comparing floating-point numbers.
551 *
552 * Equals by default to platform-defined `FLT_EPSILON`, or
553 * `1.1920928955078125e-07F` if that's not available.
554 *
555 * \since This macro is available since SDL 3.2.0.
556 */
557#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
558#endif
559
560/* @} *//* Floating-point constants */
561
562#ifdef SDL_WIKI_DOCUMENTATION_SECTION
563
564/**
565 * A printf-formatting string for an Sint64 value.
566 *
567 * Use it like this:
568 *
569 * ```c
570 * SDL_Log("There are %" SDL_PRIs64 " bottles of beer on the wall.", bottles);
571 * ```
572 *
573 * \since This macro is available since SDL 3.2.0.
574 */
575#define SDL_PRIs64 "lld"
576
577/**
578 * A printf-formatting string for a Uint64 value.
579 *
580 * Use it like this:
581 *
582 * ```c
583 * SDL_Log("There are %" SDL_PRIu64 " bottles of beer on the wall.", bottles);
584 * ```
585 *
586 * \since This macro is available since SDL 3.2.0.
587 */
588#define SDL_PRIu64 "llu"
589
590/**
591 * A printf-formatting string for a Uint64 value as lower-case hexadecimal.
592 *
593 * Use it like this:
594 *
595 * ```c
596 * SDL_Log("There are %" SDL_PRIx64 " bottles of beer on the wall.", bottles);
597 * ```
598 *
599 * \since This macro is available since SDL 3.2.0.
600 */
601#define SDL_PRIx64 "llx"
602
603/**
604 * A printf-formatting string for a Uint64 value as upper-case hexadecimal.
605 *
606 * Use it like this:
607 *
608 * ```c
609 * SDL_Log("There are %" SDL_PRIX64 " bottles of beer on the wall.", bottles);
610 * ```
611 *
612 * \since This macro is available since SDL 3.2.0.
613 */
614#define SDL_PRIX64 "llX"
615
616/**
617 * A printf-formatting string for an Sint32 value.
618 *
619 * Use it like this:
620 *
621 * ```c
622 * SDL_Log("There are %" SDL_PRIs32 " bottles of beer on the wall.", bottles);
623 * ```
624 *
625 * \since This macro is available since SDL 3.2.0.
626 */
627#define SDL_PRIs32 "d"
628
629/**
630 * A printf-formatting string for a Uint32 value.
631 *
632 * Use it like this:
633 *
634 * ```c
635 * SDL_Log("There are %" SDL_PRIu32 " bottles of beer on the wall.", bottles);
636 * ```
637 *
638 * \since This macro is available since SDL 3.2.0.
639 */
640#define SDL_PRIu32 "u"
641
642/**
643 * A printf-formatting string for a Uint32 value as lower-case hexadecimal.
644 *
645 * Use it like this:
646 *
647 * ```c
648 * SDL_Log("There are %" SDL_PRIx32 " bottles of beer on the wall.", bottles);
649 * ```
650 *
651 * \since This macro is available since SDL 3.2.0.
652 */
653#define SDL_PRIx32 "x"
654
655/**
656 * A printf-formatting string for a Uint32 value as upper-case hexadecimal.
657 *
658 * Use it like this:
659 *
660 * ```c
661 * SDL_Log("There are %" SDL_PRIX32 " bottles of beer on the wall.", bottles);
662 * ```
663 *
664 * \since This macro is available since SDL 3.2.0.
665 */
666#define SDL_PRIX32 "X"
667
668/**
669 * A printf-formatting string prefix for a `long long` value.
670 *
671 * This is just the prefix! You probably actually want SDL_PRILLd, SDL_PRILLu,
672 * SDL_PRILLx, or SDL_PRILLX instead.
673 *
674 * Use it like this:
675 *
676 * ```c
677 * SDL_Log("There are %" SDL_PRILL_PREFIX "d bottles of beer on the wall.", bottles);
678 * ```
679 *
680 * \since This macro is available since SDL 3.2.0.
681 */
682#define SDL_PRILL_PREFIX "ll"
683
684/**
685 * A printf-formatting string for a `long long` value.
686 *
687 * Use it like this:
688 *
689 * ```c
690 * SDL_Log("There are %" SDL_PRILLd " bottles of beer on the wall.", bottles);
691 * ```
692 *
693 * \since This macro is available since SDL 3.2.0.
694 */
695#define SDL_PRILLd SDL_PRILL_PREFIX "d"
696
697/**
698 * A printf-formatting string for a `unsigned long long` value.
699 *
700 * Use it like this:
701 *
702 * ```c
703 * SDL_Log("There are %" SDL_PRILLu " bottles of beer on the wall.", bottles);
704 * ```
705 *
706 * \since This macro is available since SDL 3.2.0.
707 */
708#define SDL_PRILLu SDL_PRILL_PREFIX "u"
709
710/**
711 * A printf-formatting string for an `unsigned long long` value as lower-case
712 * hexadecimal.
713 *
714 * Use it like this:
715 *
716 * ```c
717 * SDL_Log("There are %" SDL_PRILLx " bottles of beer on the wall.", bottles);
718 * ```
719 *
720 * \since This macro is available since SDL 3.2.0.
721 */
722#define SDL_PRILLx SDL_PRILL_PREFIX "x"
723
724/**
725 * A printf-formatting string for an `unsigned long long` value as upper-case
726 * hexadecimal.
727 *
728 * Use it like this:
729 *
730 * ```c
731 * SDL_Log("There are %" SDL_PRILLX " bottles of beer on the wall.", bottles);
732 * ```
733 *
734 * \since This macro is available since SDL 3.2.0.
735 */
736#define SDL_PRILLX SDL_PRILL_PREFIX "X"
737
738/**
739 * A printf-formatting string prefix for a `size_t` value.
740 *
741 * This is just the prefix! You probably actually want SDL_PRISZu, SDL_PRISZx,
742 * or SDL_PRISZX instead.
743 *
744 * Use it like this:
745 *
746 * ```c
747 * SDL_Log("There are %" SDL_PRISZ_PREFIX "u bottles of beer on the wall.", bottles);
748 * ```
749 *
750 * \since This macro is available since SDL 3.6.0.
751 */
752#define SDL_PRISZ_PREFIX "z"
753
754/**
755 * A printf-formatting string for a `size_t` value.
756 *
757 * Use it like this:
758 *
759 * ```c
760 * SDL_Log("There are %" SDL_PRISZu " bottles of beer on the wall.", bottles);
761 * ```
762 *
763 * \since This macro is available since SDL 3.6.0.
764 */
765#define SDL_PRISZu SDL_PRISZ_PREFIX "u"
766
767/**
768 * A printf-formatting string for an `size_t` value as lower-case hexadecimal.
769 *
770 * Use it like this:
771 *
772 * ```c
773 * SDL_Log("There are %" SDL_PRISZx " bottles of beer on the wall.", bottles);
774 * ```
775 *
776 * \since This macro is available since SDL 3.6.0.
777 */
778#define SDL_PRISZx SDL_PRISZ_PREFIX "x"
779
780/**
781 * A printf-formatting string for an `size_t` value as upper-case hexadecimal.
782 *
783 * Use it like this:
784 *
785 * ```c
786 * SDL_Log("There are %" SDL_PRISZX " bottles of beer on the wall.", bottles);
787 * ```
788 *
789 * \since This macro is available since SDL 3.6.0.
790 */
791#define SDL_PRISZX SDL_PRISZ_PREFIX "X"
792#endif /* SDL_WIKI_DOCUMENTATION_SECTION */
793
794/* Make sure we have macros for printing width-based integers.
795 * <inttypes.h> should define these but this is not true all platforms.
796 * (for example win32) */
797#ifndef SDL_PRIs64
798#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)
799#define SDL_PRIs64 "I64d"
800#elif defined(PRId64)
801#define SDL_PRIs64 PRId64
802#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
803#define SDL_PRIs64 "ld"
804#else
805#define SDL_PRIs64 "lld"
806#endif
807#endif
808#ifndef SDL_PRIu64
809#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)
810#define SDL_PRIu64 "I64u"
811#elif defined(PRIu64)
812#define SDL_PRIu64 PRIu64
813#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
814#define SDL_PRIu64 "lu"
815#else
816#define SDL_PRIu64 "llu"
817#endif
818#endif
819#ifndef SDL_PRIx64
820#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)
821#define SDL_PRIx64 "I64x"
822#elif defined(PRIx64)
823#define SDL_PRIx64 PRIx64
824#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
825#define SDL_PRIx64 "lx"
826#else
827#define SDL_PRIx64 "llx"
828#endif
829#endif
830#ifndef SDL_PRIX64
831#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)
832#define SDL_PRIX64 "I64X"
833#elif defined(PRIX64)
834#define SDL_PRIX64 PRIX64
835#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
836#define SDL_PRIX64 "lX"
837#else
838#define SDL_PRIX64 "llX"
839#endif
840#endif
841#ifndef SDL_PRIs32
842#ifdef PRId32
843#define SDL_PRIs32 PRId32
844#else
845#define SDL_PRIs32 "d"
846#endif
847#endif
848#ifndef SDL_PRIu32
849#ifdef PRIu32
850#define SDL_PRIu32 PRIu32
851#else
852#define SDL_PRIu32 "u"
853#endif
854#endif
855#ifndef SDL_PRIx32
856#ifdef PRIx32
857#define SDL_PRIx32 PRIx32
858#else
859#define SDL_PRIx32 "x"
860#endif
861#endif
862#ifndef SDL_PRIX32
863#ifdef PRIX32
864#define SDL_PRIX32 PRIX32
865#else
866#define SDL_PRIX32 "X"
867#endif
868#endif
869/* Specifically for the `long long` -- SDL-specific. */
870#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)
871#ifndef SDL_NOLONGLONG
872SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */
873#endif
874#define SDL_PRILL_PREFIX "I64"
875#else
876#define SDL_PRILL_PREFIX "ll"
877#endif
878#ifndef SDL_PRILLd
879#define SDL_PRILLd SDL_PRILL_PREFIX "d"
880#endif
881#ifndef SDL_PRILLu
882#define SDL_PRILLu SDL_PRILL_PREFIX "u"
883#endif
884#ifndef SDL_PRILLx
885#define SDL_PRILLx SDL_PRILL_PREFIX "x"
886#endif
887#ifndef SDL_PRILLX
888#define SDL_PRILLX SDL_PRILL_PREFIX "X"
889#endif
890/* Specifically for `size_t` -- SDL-specific. */
891#if defined(SDL_PLATFORM_CYGWIN)
892#define SDL_PRISZ_PREFIX "z"
893#elif defined(_WIN64)
894#define SDL_PRISZ_PREFIX "I64"
895#elif defined(SDL_PLATFORM_WIN32)
896#define SDL_PRISZ_PREFIX "I32"
897#else
898#define SDL_PRISZ_PREFIX "z"
899#endif
900#ifndef SDL_PRISZu
901#define SDL_PRISZu SDL_PRISZ_PREFIX "u"
902#endif
903#ifndef SDL_PRISZx
904#define SDL_PRISZx SDL_PRISZ_PREFIX "x"
905#endif
906#ifndef SDL_PRISZX
907#define SDL_PRISZX SDL_PRISZ_PREFIX "X"
908#endif
909
910/* Annotations to help code analysis tools */
911#ifdef SDL_WIKI_DOCUMENTATION_SECTION
912
913/**
914 * Macro that annotates function params with input buffer size.
915 *
916 * If we were to annotate `memcpy`:
917 *
918 * ```c
919 * void *memcpy(void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
920 * ```
921 *
922 * This notes that `src` should be `len` bytes in size and is only read by the
923 * function. The compiler or other analysis tools can warn when this doesn't
924 * appear to be the case.
925 *
926 * On compilers without this annotation mechanism, this is defined to nothing.
927 *
928 * \since This macro is available since SDL 3.2.0.
929 */
930#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
931
932/**
933 * Macro that annotates function params with input/output string buffer size.
934 *
935 * If we were to annotate `strlcat`:
936 *
937 * ```c
938 * size_t strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
939 * ```
940 *
941 * This notes that `dst` is a null-terminated C string, should be `maxlen`
942 * bytes in size, and is both read from and written to by the function. The
943 * compiler or other analysis tools can warn when this doesn't appear to be
944 * the case.
945 *
946 * On compilers without this annotation mechanism, this is defined to nothing.
947 *
948 * \since This macro is available since SDL 3.2.0.
949 */
950#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
951
952/**
953 * Macro that annotates function params with output string buffer size.
954 *
955 * If we were to annotate `snprintf`:
956 *
957 * ```c
958 * int snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, ...);
959 * ```
960 *
961 * This notes that `text` is a null-terminated C string, should be `maxlen`
962 * bytes in size, and is only written to by the function. The compiler or
963 * other analysis tools can warn when this doesn't appear to be the case.
964 *
965 * On compilers without this annotation mechanism, this is defined to nothing.
966 *
967 * \since This macro is available since SDL 3.2.0.
968 */
969#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
970
971/**
972 * Macro that annotates function params with output buffer size.
973 *
974 * If we were to annotate `wcsncpy`:
975 *
976 * ```c
977 * char *wcscpy(SDL_OUT_CAP(bufsize) wchar_t *dst, const wchar_t *src, size_t bufsize);
978 * ```
979 *
980 * This notes that `dst` should have a capacity of `bufsize` wchar_t in size,
981 * and is only written to by the function. The compiler or other analysis
982 * tools can warn when this doesn't appear to be the case.
983 *
984 * This operates on counts of objects, not bytes. Use SDL_OUT_BYTECAP for
985 * bytes.
986 *
987 * On compilers without this annotation mechanism, this is defined to nothing.
988 *
989 * \since This macro is available since SDL 3.2.0.
990 */
991#define SDL_OUT_CAP(x) _Out_cap_(x)
992
993/**
994 * Macro that annotates function params with output buffer size.
995 *
996 * If we were to annotate `memcpy`:
997 *
998 * ```c
999 * void *memcpy(SDL_OUT_BYTECAP(bufsize) void *dst, const void *src, size_t bufsize);
1000 * ```
1001 *
1002 * This notes that `dst` should have a capacity of `bufsize` bytes in size,
1003 * and is only written to by the function. The compiler or other analysis
1004 * tools can warn when this doesn't appear to be the case.
1005 *
1006 * On compilers without this annotation mechanism, this is defined to nothing.
1007 *
1008 * \since This macro is available since SDL 3.2.0.
1009 */
1010#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
1011
1012/**
1013 * Macro that annotates function params with output buffer string size.
1014 *
1015 * If we were to annotate `strcpy`:
1016 *
1017 * ```c
1018 * char *strcpy(SDL_OUT_Z_BYTECAP(bufsize) char *dst, const char *src, size_t bufsize);
1019 * ```
1020 *
1021 * This notes that `dst` should have a capacity of `bufsize` bytes in size,
1022 * and a zero-terminated string is written to it by the function. The compiler
1023 * or other analysis tools can warn when this doesn't appear to be the case.
1024 *
1025 * On compilers without this annotation mechanism, this is defined to nothing.
1026 *
1027 * \since This macro is available since SDL 3.2.0.
1028 */
1029#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
1030
1031/**
1032 * Macro that annotates function params as printf-style format strings.
1033 *
1034 * If we were to annotate `fprintf`:
1035 *
1036 * ```c
1037 * int fprintf(FILE *f, SDL_PRINTF_FORMAT_STRING const char *fmt, ...);
1038 * ```
1039 *
1040 * This notes that `fmt` should be a printf-style format string. The compiler
1041 * or other analysis tools can warn when this doesn't appear to be the case.
1042 *
1043 * On compilers without this annotation mechanism, this is defined to nothing.
1044 *
1045 * \since This macro is available since SDL 3.2.0.
1046 */
1047#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
1048
1049/**
1050 * Macro that annotates function params as scanf-style format strings.
1051 *
1052 * If we were to annotate `fscanf`:
1053 *
1054 * ```c
1055 * int fscanf(FILE *f, SDL_SCANF_FORMAT_STRING const char *fmt, ...);
1056 * ```
1057 *
1058 * This notes that `fmt` should be a scanf-style format string. The compiler
1059 * or other analysis tools can warn when this doesn't appear to be the case.
1060 *
1061 * On compilers without this annotation mechanism, this is defined to nothing.
1062 *
1063 * \since This macro is available since SDL 3.2.0.
1064 */
1065#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
1066
1067/**
1068 * Macro that annotates a vararg function that operates like printf.
1069 *
1070 * If we were to annotate `fprintf`:
1071 *
1072 * ```c
1073 * int fprintf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
1074 * ```
1075 *
1076 * This notes that the second parameter should be a printf-style format
1077 * string, followed by `...`. The compiler or other analysis tools can warn
1078 * when this doesn't appear to be the case.
1079 *
1080 * On compilers without this annotation mechanism, this is defined to nothing.
1081 *
1082 * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
1083 * between them will cover at least Visual Studio, GCC, and Clang.
1084 *
1085 * \since This macro is available since SDL 3.2.0.
1086 */
1087#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
1088
1089/**
1090 * Macro that annotates a va_list function that operates like printf.
1091 *
1092 * If we were to annotate `vfprintf`:
1093 *
1094 * ```c
1095 * int vfprintf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
1096 * ```
1097 *
1098 * This notes that the second parameter should be a printf-style format
1099 * string, followed by a va_list. The compiler or other analysis tools can
1100 * warn when this doesn't appear to be the case.
1101 *
1102 * On compilers without this annotation mechanism, this is defined to nothing.
1103 *
1104 * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
1105 * between them will cover at least Visual Studio, GCC, and Clang.
1106 *
1107 * \since This macro is available since SDL 3.2.0.
1108 */
1109#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
1110
1111/**
1112 * Macro that annotates a vararg function that operates like scanf.
1113 *
1114 * If we were to annotate `fscanf`:
1115 *
1116 * ```c
1117 * int fscanf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNCV(2);
1118 * ```
1119 *
1120 * This notes that the second parameter should be a scanf-style format string,
1121 * followed by `...`. The compiler or other analysis tools can warn when this
1122 * doesn't appear to be the case.
1123 *
1124 * On compilers without this annotation mechanism, this is defined to nothing.
1125 *
1126 * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
1127 * between them will cover at least Visual Studio, GCC, and Clang.
1128 *
1129 * \since This macro is available since SDL 3.2.0.
1130 */
1131#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
1132
1133/**
1134 * Macro that annotates a va_list function that operates like scanf.
1135 *
1136 * If we were to annotate `vfscanf`:
1137 *
1138 * ```c
1139 * int vfscanf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
1140 * ```
1141 *
1142 * This notes that the second parameter should be a scanf-style format string,
1143 * followed by a va_list. The compiler or other analysis tools can warn when
1144 * this doesn't appear to be the case.
1145 *
1146 * On compilers without this annotation mechanism, this is defined to nothing.
1147 *
1148 * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
1149 * between them will cover at least Visual Studio, GCC, and Clang.
1150 *
1151 * \since This macro is available since SDL 3.2.0.
1152 */
1153#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
1154
1155/**
1156 * Macro that annotates a vararg function that operates like wprintf.
1157 *
1158 * If we were to annotate `fwprintf`:
1159 *
1160 * ```c
1161 * int fwprintf(FILE *f, const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(2);
1162 * ```
1163 *
1164 * This notes that the second parameter should be a wprintf-style format wide
1165 * string, followed by `...`. The compiler or other analysis tools can warn
1166 * when this doesn't appear to be the case.
1167 *
1168 * On compilers without this annotation mechanism, this is defined to nothing.
1169 *
1170 * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
1171 * between them will cover at least Visual Studio, GCC, and Clang.
1172 *
1173 * \since This macro is available since SDL 3.2.0.
1174 */
1175#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
1176
1177/**
1178 * Macro that annotates a va_list function that operates like wprintf.
1179 *
1180 * If we were to annotate `vfwprintf`:
1181 *
1182 * ```c
1183 * int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNC(2);
1184 * ```
1185 *
1186 * This notes that the second parameter should be a wprintf-style format wide
1187 * string, followed by a va_list. The compiler or other analysis tools can
1188 * warn when this doesn't appear to be the case.
1189 *
1190 * On compilers without this annotation mechanism, this is defined to nothing.
1191 *
1192 * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
1193 * between them will cover at least Visual Studio, GCC, and Clang.
1194 *
1195 * \since This macro is available since SDL 3.2.0.
1196 */
1197#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
1198
1199#elif defined(SDL_DISABLE_ANALYZE_MACROS)
1200#define SDL_IN_BYTECAP(x)
1201#define SDL_INOUT_Z_CAP(x)
1202#define SDL_OUT_Z_CAP(x)
1203#define SDL_OUT_CAP(x)
1204#define SDL_OUT_BYTECAP(x)
1205#define SDL_OUT_Z_BYTECAP(x)
1206#define SDL_PRINTF_FORMAT_STRING
1207#define SDL_SCANF_FORMAT_STRING
1208#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
1209#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
1210#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
1211#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
1212#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
1213#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
1214#else
1215#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
1216#include <sal.h>
1217
1218#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
1219#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
1220#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
1221#define SDL_OUT_CAP(x) _Out_cap_(x)
1222#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
1223#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
1224
1225#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
1226#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
1227#else
1228#define SDL_IN_BYTECAP(x)
1229#define SDL_INOUT_Z_CAP(x)
1230#define SDL_OUT_Z_CAP(x)
1231#define SDL_OUT_CAP(x)
1232#define SDL_OUT_BYTECAP(x)
1233#define SDL_OUT_Z_BYTECAP(x)
1234#define SDL_PRINTF_FORMAT_STRING
1235#define SDL_SCANF_FORMAT_STRING
1236#endif
1237#if defined(__GNUC__) || defined(__clang__)
1238#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
1239#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
1240#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
1241#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
1242#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
1243#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
1244#else
1245#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
1246#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
1247#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
1248#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
1249#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
1250#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
1251#endif
1252#endif /* SDL_DISABLE_ANALYZE_MACROS */
1253
1254/** \cond */
1255#ifndef DOXYGEN_SHOULD_IGNORE_THIS
1256SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1);
1257SDL_COMPILE_TIME_ASSERT(uint8_size, sizeof(Uint8) == 1);
1258SDL_COMPILE_TIME_ASSERT(sint8_size, sizeof(Sint8) == 1);
1259SDL_COMPILE_TIME_ASSERT(uint16_size, sizeof(Uint16) == 2);
1260SDL_COMPILE_TIME_ASSERT(sint16_size, sizeof(Sint16) == 2);
1261SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
1262SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4);
1263SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8);
1264SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8);
1265#ifndef SDL_NOLONGLONG
1266SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long));
1267SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long));
1268#endif
1269typedef struct SDL_alignment_test
1270{
1271 Uint8 a;
1272 void *b;
1273} SDL_alignment_test;
1274SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
1275SDL_COMPILE_TIME_ASSERT(two_s_complement, SDL_static_cast(int, ~SDL_static_cast(int, 0)) == SDL_static_cast(int, -1));
1276#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
1277/** \endcond */
1278
1279/* Check to make sure enums are the size of ints, for structure packing.
1280 For both Watcom C/C++ and Borland C/C++ the compiler option that makes
1281 enums having the size of an int must be enabled.
1282 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
1283*/
1284
1285/** \cond */
1286#ifndef DOXYGEN_SHOULD_IGNORE_THIS
1287#if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
1288/* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
1289typedef enum SDL_DUMMY_ENUM
1290{
1291 DUMMY_ENUM_VALUE
1292} SDL_DUMMY_ENUM;
1293
1294SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
1295#endif
1296#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
1297/** \endcond */
1298
1299/* Set up for C function definitions, even when using C++ */
1300#ifdef __cplusplus
1301extern "C" {
1302#endif
1303
1304/**
1305 * A macro to initialize an SDL interface.
1306 *
1307 * This macro will initialize an SDL interface structure and should be called
1308 * before you fill out the fields with your implementation.
1309 *
1310 * You can use it like this:
1311 *
1312 * ```c
1313 * SDL_IOStreamInterface iface;
1314 *
1315 * SDL_INIT_INTERFACE(&iface);
1316 *
1317 * // Fill in the interface function pointers with your implementation
1318 * iface.seek = ...
1319 *
1320 * stream = SDL_OpenIO(&iface, NULL);
1321 * ```
1322 *
1323 * If you are using designated initializers, you can use the size of the
1324 * interface as the version, e.g.
1325 *
1326 * ```c
1327 * SDL_IOStreamInterface iface = {
1328 * .version = sizeof(iface),
1329 * .seek = ...
1330 * };
1331 * stream = SDL_OpenIO(&iface, NULL);
1332 * ```
1333 *
1334 * \threadsafety It is safe to call this macro from any thread.
1335 *
1336 * \since This macro is available since SDL 3.2.0.
1337 *
1338 * \sa SDL_IOStreamInterface
1339 * \sa SDL_StorageInterface
1340 * \sa SDL_VirtualJoystickDesc
1341 */
1342#define SDL_INIT_INTERFACE(iface) \
1343 do { \
1344 SDL_zerop(iface); \
1345 (iface)->version = sizeof(*(iface)); \
1346 } while (0)
1347
1348
1349#ifdef SDL_WIKI_DOCUMENTATION_SECTION
1350
1351/**
1352 * Allocate memory on the stack (maybe).
1353 *
1354 * If SDL knows how to access alloca() on the current platform, it will use it
1355 * to stack-allocate memory here. If it doesn't, it will use SDL_malloc() to
1356 * heap-allocate memory.
1357 *
1358 * Since this might not be stack memory at all, it's important that you check
1359 * the returned pointer for NULL, and that you call SDL_stack_free on the
1360 * memory when done with it. Since this might be stack memory, it's important
1361 * that you don't allocate large amounts of it, or allocate in a loop without
1362 * returning from the function, so the stack doesn't overflow.
1363 *
1364 * \param type the datatype of the memory to allocate.
1365 * \param count the number of `type` objects to allocate.
1366 * \returns newly-allocated memory, or NULL on failure.
1367 *
1368 * \threadsafety It is safe to call this macro from any thread.
1369 *
1370 * \since This macro is available since SDL 3.2.0.
1371 *
1372 * \sa SDL_stack_free
1373 */
1374#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
1375
1376/**
1377 * Free memory previously allocated with SDL_stack_alloc.
1378 *
1379 * If SDL used alloca() to allocate this memory, this macro does nothing
1380 * (other than insert `((void)(data)` so the compiler sees an expression) and
1381 * the allocated memory will be automatically released when the function that
1382 * called SDL_stack_alloc() returns. If SDL used SDL_malloc(), it will
1383 * SDL_free the memory immediately.
1384 *
1385 * \param data the pointer, from SDL_stack_alloc(), to free.
1386 *
1387 * \threadsafety It is safe to call this macro from any thread.
1388 *
1389 * \since This macro is available since SDL 3.2.0.
1390 *
1391 * \sa SDL_stack_alloc
1392 */
1393#define SDL_stack_free(data) ((void)(data))
1394#elif !defined(SDL_DISABLE_ALLOCA)
1395#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
1396#define SDL_stack_free(data) ((void)(data))
1397#else
1398#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
1399#define SDL_stack_free(data) SDL_free(data)
1400#endif
1401
1402/**
1403 * Allocate uninitialized memory.
1404 *
1405 * The allocated memory returned by this function must be freed with
1406 * SDL_free().
1407 *
1408 * If `size` is 0, it will be set to 1.
1409 *
1410 * If the allocation is successful, the returned pointer is guaranteed to be
1411 * aligned to either the *fundamental alignment* (`alignof(max_align_t)` in
1412 * C11 and later) or `2 * sizeof(void *)`, whichever is smaller. Use
1413 * SDL_aligned_alloc() if you need to allocate memory aligned to an alignment
1414 * greater than this guarantee.
1415 *
1416 * \param size the size to allocate.
1417 * \returns a pointer to the allocated memory, or NULL if allocation failed.
1418 *
1419 * \threadsafety It is safe to call this function from any thread.
1420 *
1421 * \since This function is available since SDL 3.2.0.
1422 *
1423 * \sa SDL_free
1424 * \sa SDL_calloc
1425 * \sa SDL_realloc
1426 * \sa SDL_aligned_alloc
1427 */
1428extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
1429
1430/**
1431 * Allocate a zero-initialized array.
1432 *
1433 * The memory returned by this function must be freed with SDL_free().
1434 *
1435 * If either of `nmemb` or `size` is 0, they will both be set to 1.
1436 *
1437 * If the allocation is successful, the returned pointer is guaranteed to be
1438 * aligned to either the *fundamental alignment* (`alignof(max_align_t)` in
1439 * C11 and later) or `2 * sizeof(void *)`, whichever is smaller. Use
1440 * SDL_aligned_alloc_zero() if you need to allocate memory aligned to an
1441 * alignment greater than this guarantee.
1442 *
1443 * \param nmemb the number of elements in the array.
1444 * \param size the size of each element of the array.
1445 * \returns a pointer to the allocated array, or NULL if allocation failed.
1446 *
1447 * \threadsafety It is safe to call this function from any thread.
1448 *
1449 * \since This function is available since SDL 3.2.0.
1450 *
1451 * \sa SDL_free
1452 * \sa SDL_malloc
1453 * \sa SDL_realloc
1454 */
1455extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
1456
1457/**
1458 * Change the size of allocated memory.
1459 *
1460 * The memory returned by this function must be freed with SDL_free().
1461 *
1462 * If `size` is 0, it will be set to 1. Note that this is unlike some other C
1463 * runtime `realloc` implementations, which may treat `realloc(mem, 0)` the
1464 * same way as `free(mem)`.
1465 *
1466 * If `mem` is NULL, the behavior of this function is equivalent to
1467 * SDL_malloc(). Otherwise, the function can have one of three possible
1468 * outcomes:
1469 *
1470 * - If it returns the same pointer as `mem`, it means that `mem` was resized
1471 * in place without freeing.
1472 * - If it returns a different non-NULL pointer, it means that `mem` was freed
1473 * and cannot be dereferenced anymore.
1474 * - If it returns NULL (indicating failure), then `mem` will remain valid and
1475 * must still be freed with SDL_free().
1476 *
1477 * If the allocation is successfully resized, the returned pointer is
1478 * guaranteed to be aligned to either the *fundamental alignment*
1479 * (`alignof(max_align_t)` in C11 and later) or `2 * sizeof(void *)`,
1480 * whichever is smaller.
1481 *
1482 * \param mem a pointer to allocated memory to reallocate, or NULL.
1483 * \param size the new size of the memory.
1484 * \returns a pointer to the newly allocated memory, or NULL if allocation
1485 * failed.
1486 *
1487 * \threadsafety It is safe to call this function from any thread.
1488 *
1489 * \since This function is available since SDL 3.2.0.
1490 *
1491 * \sa SDL_free
1492 * \sa SDL_malloc
1493 * \sa SDL_calloc
1494 */
1495extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
1496
1497/**
1498 * Free allocated memory.
1499 *
1500 * The pointer is no longer valid after this call and cannot be dereferenced
1501 * anymore.
1502 *
1503 * If `mem` is NULL, this function does nothing.
1504 *
1505 * \param mem a pointer to allocated memory, or NULL.
1506 *
1507 * \threadsafety It is safe to call this function from any thread.
1508 *
1509 * \since This function is available since SDL 3.2.0.
1510 *
1511 * \sa SDL_malloc
1512 * \sa SDL_calloc
1513 * \sa SDL_realloc
1514 */
1515extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
1516
1517/**
1518 * A callback used to implement SDL_malloc().
1519 *
1520 * SDL will always ensure that the passed `size` is greater than 0.
1521 *
1522 * \param size the size to allocate.
1523 * \returns a pointer to the allocated memory, or NULL if allocation failed.
1524 *
1525 * \threadsafety It should be safe to call this callback from any thread.
1526 *
1527 * \since This datatype is available since SDL 3.2.0.
1528 *
1529 * \sa SDL_malloc
1530 * \sa SDL_GetOriginalMemoryFunctions
1531 * \sa SDL_GetMemoryFunctions
1532 * \sa SDL_SetMemoryFunctions
1533 */
1534typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
1535
1536/**
1537 * A callback used to implement SDL_calloc().
1538 *
1539 * SDL will always ensure that the passed `nmemb` and `size` are both greater
1540 * than 0.
1541 *
1542 * \param nmemb the number of elements in the array.
1543 * \param size the size of each element of the array.
1544 * \returns a pointer to the allocated array, or NULL if allocation failed.
1545 *
1546 * \threadsafety It should be safe to call this callback from any thread.
1547 *
1548 * \since This datatype is available since SDL 3.2.0.
1549 *
1550 * \sa SDL_calloc
1551 * \sa SDL_GetOriginalMemoryFunctions
1552 * \sa SDL_GetMemoryFunctions
1553 * \sa SDL_SetMemoryFunctions
1554 */
1555typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
1556
1557/**
1558 * A callback used to implement SDL_realloc().
1559 *
1560 * SDL will always ensure that the passed `size` is greater than 0.
1561 *
1562 * \param mem a pointer to allocated memory to reallocate, or NULL.
1563 * \param size the new size of the memory.
1564 * \returns a pointer to the newly allocated memory, or NULL if allocation
1565 * failed.
1566 *
1567 * \threadsafety It should be safe to call this callback from any thread.
1568 *
1569 * \since This datatype is available since SDL 3.2.0.
1570 *
1571 * \sa SDL_realloc
1572 * \sa SDL_GetOriginalMemoryFunctions
1573 * \sa SDL_GetMemoryFunctions
1574 * \sa SDL_SetMemoryFunctions
1575 */
1576typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
1577
1578/**
1579 * A callback used to implement SDL_free().
1580 *
1581 * SDL will always ensure that the passed `mem` is a non-NULL pointer.
1582 *
1583 * \param mem a pointer to allocated memory.
1584 *
1585 * \threadsafety It should be safe to call this callback from any thread.
1586 *
1587 * \since This datatype is available since SDL 3.2.0.
1588 *
1589 * \sa SDL_free
1590 * \sa SDL_GetOriginalMemoryFunctions
1591 * \sa SDL_GetMemoryFunctions
1592 * \sa SDL_SetMemoryFunctions
1593 */
1594typedef void (SDLCALL *SDL_free_func)(void *mem);
1595
1596/**
1597 * Get the original set of SDL memory functions.
1598 *
1599 * This is what SDL_malloc and friends will use by default, if there has been
1600 * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
1601 * runtime's `malloc` functions behind the scenes! Different platforms and
1602 * build configurations might do any number of unexpected things.
1603 *
1604 * \param malloc_func filled with malloc function.
1605 * \param calloc_func filled with calloc function.
1606 * \param realloc_func filled with realloc function.
1607 * \param free_func filled with free function.
1608 *
1609 * \threadsafety It is safe to call this function from any thread.
1610 *
1611 * \since This function is available since SDL 3.2.0.
1612 */
1613extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
1614 SDL_calloc_func *calloc_func,
1615 SDL_realloc_func *realloc_func,
1616 SDL_free_func *free_func);
1617
1618/**
1619 * Get the current set of SDL memory functions.
1620 *
1621 * \param malloc_func filled with malloc function.
1622 * \param calloc_func filled with calloc function.
1623 * \param realloc_func filled with realloc function.
1624 * \param free_func filled with free function.
1625 *
1626 * \threadsafety This does not hold a lock, so do not call this in the
1627 * unlikely event of a background thread calling
1628 * SDL_SetMemoryFunctions simultaneously.
1629 *
1630 * \since This function is available since SDL 3.2.0.
1631 *
1632 * \sa SDL_SetMemoryFunctions
1633 * \sa SDL_GetOriginalMemoryFunctions
1634 */
1635extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
1636 SDL_calloc_func *calloc_func,
1637 SDL_realloc_func *realloc_func,
1638 SDL_free_func *free_func);
1639
1640/**
1641 * Replace SDL's memory allocation functions with a custom set.
1642 *
1643 * It is not safe to call this function once any allocations have been made,
1644 * as future calls to SDL_free will use the new allocator, even if they came
1645 * from an SDL_malloc made with the old one!
1646 *
1647 * If used, usually this needs to be the first call made into the SDL library,
1648 * if not the very first thing done at program startup time.
1649 *
1650 * It is legal to call this with all 4 parameters set to NULL, which will
1651 * restore the original memory functions without having to query them with
1652 * SDL_GetOriginalMemoryFunctions() first.
1653 *
1654 * \param malloc_func custom malloc function.
1655 * \param calloc_func custom calloc function.
1656 * \param realloc_func custom realloc function.
1657 * \param free_func custom free function.
1658 * \returns true on success or false on failure. This only fails if there is a
1659 * mix of NULL and non-NULL parameters. Failure will not set an error
1660 * message (which allocates memory) so do _not_ call SDL_GetError()
1661 * in response to a failure here.
1662 *
1663 * \threadsafety It is safe to call this function from any thread, but one
1664 * should not replace the memory functions once any allocations
1665 * are made!
1666 *
1667 * \since This function is available since SDL 3.2.0.
1668 *
1669 * \sa SDL_GetMemoryFunctions
1670 * \sa SDL_GetOriginalMemoryFunctions
1671 */
1672extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
1673 SDL_calloc_func calloc_func,
1674 SDL_realloc_func realloc_func,
1675 SDL_free_func free_func);
1676
1677/**
1678 * Allocate memory aligned to a specific alignment.
1679 *
1680 * The memory returned by this function must be freed with SDL_aligned_free(),
1681 * _not_ SDL_free().
1682 *
1683 * If `alignment` is less than the size of `void *`, it will be increased to
1684 * match that.
1685 *
1686 * The returned memory address will be a multiple of the alignment value, and
1687 * the size of the memory allocated will be a multiple of the alignment value.
1688 *
1689 * \param alignment the alignment of the memory.
1690 * \param size the size to allocate.
1691 * \returns a pointer to the aligned memory, or NULL if allocation failed.
1692 *
1693 * \threadsafety It is safe to call this function from any thread.
1694 *
1695 * \since This function is available since SDL 3.2.0.
1696 *
1697 * \sa SDL_aligned_free
1698 */
1699extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
1700
1701/**
1702 * Allocate zero-initialized memory aligned to a specific alignment.
1703 *
1704 * The memory returned by this function must be freed with SDL_aligned_free(),
1705 * _not_ SDL_free().
1706 *
1707 * If `alignment` is less than the size of `void *`, it will be increased to
1708 * match that.
1709 *
1710 * The returned memory address will be a multiple of the alignment value, and
1711 * the size of the memory allocated will be a multiple of the alignment value.
1712 *
1713 * \param alignment the alignment of the memory.
1714 * \param size the size to allocate.
1715 * \returns a pointer to the aligned memory, or NULL if allocation failed.
1716 *
1717 * \threadsafety It is safe to call this function from any thread.
1718 *
1719 * \since This function is available since SDL 3.6.0.
1720 *
1721 * \sa SDL_aligned_free
1722 */
1723extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc_zero(size_t alignment, size_t size);
1724
1725/**
1726 * Free memory allocated by SDL_aligned_alloc().
1727 *
1728 * The pointer is no longer valid after this call and cannot be dereferenced
1729 * anymore.
1730 *
1731 * If `mem` is NULL, this function does nothing.
1732 *
1733 * \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
1734 *
1735 * \threadsafety It is safe to call this function from any thread.
1736 *
1737 * \since This function is available since SDL 3.2.0.
1738 *
1739 * \sa SDL_aligned_alloc
1740 */
1741extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
1742
1743/**
1744 * Get the number of outstanding (unfreed) allocations.
1745 *
1746 * \returns the number of allocations or -1 if allocation counting is
1747 * disabled.
1748 *
1749 * \threadsafety It is safe to call this function from any thread.
1750 *
1751 * \since This function is available since SDL 3.2.0.
1752 */
1753extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
1754
1755/**
1756 * A thread-safe set of environment variables
1757 *
1758 * \since This struct is available since SDL 3.2.0.
1759 *
1760 * \sa SDL_GetEnvironment
1761 * \sa SDL_CreateEnvironment
1762 * \sa SDL_GetEnvironmentVariable
1763 * \sa SDL_GetEnvironmentVariables
1764 * \sa SDL_SetEnvironmentVariable
1765 * \sa SDL_UnsetEnvironmentVariable
1766 * \sa SDL_DestroyEnvironment
1767 */
1769
1770/**
1771 * Get the process environment.
1772 *
1773 * This is initialized at application start and is not affected by setenv()
1774 * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
1775 * SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
1776 * SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
1777 * in the C runtime environment after SDL_Quit().
1778 *
1779 * \returns a pointer to the environment for the process or NULL on failure;
1780 * call SDL_GetError() for more information.
1781 *
1782 * \threadsafety It is safe to call this function from any thread.
1783 *
1784 * \since This function is available since SDL 3.2.0.
1785 *
1786 * \sa SDL_GetEnvironmentVariable
1787 * \sa SDL_GetEnvironmentVariables
1788 * \sa SDL_SetEnvironmentVariable
1789 * \sa SDL_UnsetEnvironmentVariable
1790 */
1791extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
1792
1793/**
1794 * Create a set of environment variables
1795 *
1796 * \param populated true to initialize it from the C runtime environment,
1797 * false to create an empty environment.
1798 * \returns a pointer to the new environment or NULL on failure; call
1799 * SDL_GetError() for more information.
1800 *
1801 * \threadsafety If `populated` is false, it is safe to call this function
1802 * from any thread, otherwise it is safe if no other threads are
1803 * calling setenv() or unsetenv()
1804 *
1805 * \since This function is available since SDL 3.2.0.
1806 *
1807 * \sa SDL_GetEnvironmentVariable
1808 * \sa SDL_GetEnvironmentVariables
1809 * \sa SDL_SetEnvironmentVariable
1810 * \sa SDL_UnsetEnvironmentVariable
1811 * \sa SDL_DestroyEnvironment
1812 */
1813extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
1814
1815/**
1816 * Get the value of a variable in the environment.
1817 *
1818 * \param env the environment to query.
1819 * \param name the name of the variable to get.
1820 * \returns a pointer to the value of the variable or NULL if it can't be
1821 * found.
1822 *
1823 * \threadsafety It is safe to call this function from any thread.
1824 *
1825 * \since This function is available since SDL 3.2.0.
1826 *
1827 * \sa SDL_GetEnvironment
1828 * \sa SDL_CreateEnvironment
1829 * \sa SDL_GetEnvironmentVariables
1830 * \sa SDL_SetEnvironmentVariable
1831 * \sa SDL_UnsetEnvironmentVariable
1832 */
1833extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
1834
1835/**
1836 * Get all variables in the environment.
1837 *
1838 * \param env the environment to query.
1839 * \returns a NULL terminated array of pointers to environment variables in
1840 * the form "variable=value" or NULL on failure; call SDL_GetError()
1841 * for more information. This is a single allocation that should be
1842 * freed with SDL_free() when it is no longer needed.
1843 *
1844 * \threadsafety It is safe to call this function from any thread.
1845 *
1846 * \since This function is available since SDL 3.2.0.
1847 *
1848 * \sa SDL_GetEnvironment
1849 * \sa SDL_CreateEnvironment
1850 * \sa SDL_GetEnvironmentVariable
1851 * \sa SDL_SetEnvironmentVariable
1852 * \sa SDL_UnsetEnvironmentVariable
1853 */
1854extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
1855
1856/**
1857 * Set the value of a variable in the environment.
1858 *
1859 * \param env the environment to modify.
1860 * \param name the name of the variable to set.
1861 * \param value the value of the variable to set.
1862 * \param overwrite true to overwrite the variable if it exists, false to
1863 * return success without setting the variable if it already
1864 * exists.
1865 * \returns true on success or false on failure; call SDL_GetError() for more
1866 * information.
1867 *
1868 * \threadsafety It is safe to call this function from any thread.
1869 *
1870 * \since This function is available since SDL 3.2.0.
1871 *
1872 * \sa SDL_GetEnvironment
1873 * \sa SDL_CreateEnvironment
1874 * \sa SDL_GetEnvironmentVariable
1875 * \sa SDL_GetEnvironmentVariables
1876 * \sa SDL_UnsetEnvironmentVariable
1877 */
1878extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
1879
1880/**
1881 * Clear a variable from the environment.
1882 *
1883 * \param env the environment to modify.
1884 * \param name the name of the variable to unset.
1885 * \returns true on success or false on failure; call SDL_GetError() for more
1886 * information.
1887 *
1888 * \threadsafety It is safe to call this function from any thread.
1889 *
1890 * \since This function is available since SDL 3.2.0.
1891 *
1892 * \sa SDL_GetEnvironment
1893 * \sa SDL_CreateEnvironment
1894 * \sa SDL_GetEnvironmentVariable
1895 * \sa SDL_GetEnvironmentVariables
1896 * \sa SDL_SetEnvironmentVariable
1897 * \sa SDL_UnsetEnvironmentVariable
1898 */
1899extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
1900
1901/**
1902 * Destroy a set of environment variables.
1903 *
1904 * \param env the environment to destroy.
1905 *
1906 * \threadsafety It is safe to call this function from any thread, as long as
1907 * the environment is no longer in use.
1908 *
1909 * \since This function is available since SDL 3.2.0.
1910 *
1911 * \sa SDL_CreateEnvironment
1912 */
1913extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
1914
1915/**
1916 * Get the value of a variable in the environment.
1917 *
1918 * The name of the variable is case sensitive on all platforms.
1919 *
1920 * This function uses SDL's cached copy of the environment and is thread-safe.
1921 *
1922 * \param name the name of the variable to get.
1923 * \returns a pointer to the value of the variable or NULL if it can't be
1924 * found.
1925 *
1926 * \threadsafety It is safe to call this function from any thread.
1927 *
1928 * \since This function is available since SDL 3.2.0.
1929 */
1930extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
1931
1932/**
1933 * Get the value of a variable in the environment.
1934 *
1935 * This function bypasses SDL's cached copy of the environment and is not
1936 * thread-safe.
1937 *
1938 * On some platforms, this may make case-insensitive matches, while other
1939 * platforms are case-sensitive. It is best to be precise with strings used
1940 * for queries through this interface. SDL_getenv is always case-sensitive,
1941 * however.
1942 *
1943 * \param name the name of the variable to get.
1944 * \returns a pointer to the value of the variable or NULL if it can't be
1945 * found.
1946 *
1947 * \threadsafety This function is not thread safe, consider using SDL_getenv()
1948 * instead.
1949 *
1950 * \since This function is available since SDL 3.2.0.
1951 *
1952 * \sa SDL_getenv
1953 */
1954extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
1955
1956/**
1957 * Set the value of a variable in the environment.
1958 *
1959 * \param name the name of the variable to set.
1960 * \param value the value of the variable to set.
1961 * \param overwrite 1 to overwrite the variable if it exists, 0 to return
1962 * success without setting the variable if it already exists.
1963 * \returns 0 on success, -1 on error.
1964 *
1965 * \threadsafety This function is not thread safe, consider using
1966 * SDL_SetEnvironmentVariable() instead.
1967 *
1968 * \since This function is available since SDL 3.2.0.
1969 *
1970 * \sa SDL_SetEnvironmentVariable
1971 */
1972extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
1973
1974/**
1975 * Clear a variable from the environment.
1976 *
1977 * \param name the name of the variable to unset.
1978 * \returns 0 on success, -1 on error.
1979 *
1980 * \threadsafety This function is not thread safe, consider using
1981 * SDL_UnsetEnvironmentVariable() instead.
1982 *
1983 * \since This function is available since SDL 3.2.0.
1984 *
1985 * \sa SDL_UnsetEnvironmentVariable
1986 */
1987extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
1988
1989/**
1990 * A callback used with SDL sorting and binary search functions.
1991 *
1992 * \param a a pointer to the first element being compared.
1993 * \param b a pointer to the second element being compared.
1994 * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
1995 * before `a`, 0 if they are equal. If two elements are equal, their
1996 * order in the sorted array is undefined.
1997 *
1998 * \since This callback is available since SDL 3.2.0.
1999 *
2000 * \sa SDL_bsearch
2001 * \sa SDL_qsort
2002 */
2003typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
2004
2005/**
2006 * Sort an array.
2007 *
2008 * For example:
2009 *
2010 * ```c
2011 * typedef struct {
2012 * int key;
2013 * const char *string;
2014 * } data;
2015 *
2016 * int SDLCALL compare(const void *a, const void *b)
2017 * {
2018 * const data *A = (const data *)a;
2019 * const data *B = (const data *)b;
2020 *
2021 * if (A->n < B->n) {
2022 * return -1;
2023 * } else if (B->n < A->n) {
2024 * return 1;
2025 * } else {
2026 * return 0;
2027 * }
2028 * }
2029 *
2030 * data values[] = {
2031 * { 3, "third" }, { 1, "first" }, { 2, "second" }
2032 * };
2033 *
2034 * SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
2035 * ```
2036 *
2037 * \param base a pointer to the start of the array.
2038 * \param nmemb the number of elements in the array.
2039 * \param size the size of the elements in the array.
2040 * \param compare a function used to compare elements in the array.
2041 *
2042 * \threadsafety It is safe to call this function from any thread.
2043 *
2044 * \since This function is available since SDL 3.2.0.
2045 *
2046 * \sa SDL_bsearch
2047 * \sa SDL_qsort_r
2048 */
2049extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
2050
2051/**
2052 * Perform a binary search on a previously sorted array.
2053 *
2054 * For example:
2055 *
2056 * ```c
2057 * typedef struct {
2058 * int key;
2059 * const char *string;
2060 * } data;
2061 *
2062 * int SDLCALL compare(const void *a, const void *b)
2063 * {
2064 * const data *A = (const data *)a;
2065 * const data *B = (const data *)b;
2066 *
2067 * if (A->n < B->n) {
2068 * return -1;
2069 * } else if (B->n < A->n) {
2070 * return 1;
2071 * } else {
2072 * return 0;
2073 * }
2074 * }
2075 *
2076 * data values[] = {
2077 * { 1, "first" }, { 2, "second" }, { 3, "third" }
2078 * };
2079 * data key = { 2, NULL };
2080 *
2081 * data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
2082 * ```
2083 *
2084 * \param key a pointer to a key equal to the element being searched for.
2085 * \param base a pointer to the start of the array.
2086 * \param nmemb the number of elements in the array.
2087 * \param size the size of the elements in the array.
2088 * \param compare a function used to compare elements in the array.
2089 * \returns a pointer to the matching element in the array, or NULL if not
2090 * found.
2091 *
2092 * \threadsafety It is safe to call this function from any thread.
2093 *
2094 * \since This function is available since SDL 3.2.0.
2095 *
2096 * \sa SDL_bsearch_r
2097 * \sa SDL_qsort
2098 */
2099extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
2100
2101/**
2102 * A callback used with SDL sorting and binary search functions.
2103 *
2104 * \param userdata the `userdata` pointer passed to the sort function.
2105 * \param a a pointer to the first element being compared.
2106 * \param b a pointer to the second element being compared.
2107 * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
2108 * before `a`, 0 if they are equal. If two elements are equal, their
2109 * order in the sorted array is undefined.
2110 *
2111 * \since This callback is available since SDL 3.2.0.
2112 *
2113 * \sa SDL_qsort_r
2114 * \sa SDL_bsearch_r
2115 */
2116typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
2117
2118/**
2119 * Sort an array, passing a userdata pointer to the compare function.
2120 *
2121 * For example:
2122 *
2123 * ```c
2124 * typedef enum {
2125 * sort_increasing,
2126 * sort_decreasing,
2127 * } sort_method;
2128 *
2129 * typedef struct {
2130 * int key;
2131 * const char *string;
2132 * } data;
2133 *
2134 * int SDLCALL compare(const void *userdata, const void *a, const void *b)
2135 * {
2136 * sort_method method = (sort_method)(uintptr_t)userdata;
2137 * const data *A = (const data *)a;
2138 * const data *B = (const data *)b;
2139 *
2140 * if (A->key < B->key) {
2141 * return (method == sort_increasing) ? -1 : 1;
2142 * } else if (B->key < A->key) {
2143 * return (method == sort_increasing) ? 1 : -1;
2144 * } else {
2145 * return 0;
2146 * }
2147 * }
2148 *
2149 * data values[] = {
2150 * { 3, "third" }, { 1, "first" }, { 2, "second" }
2151 * };
2152 *
2153 * SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
2154 * ```
2155 *
2156 * \param base a pointer to the start of the array.
2157 * \param nmemb the number of elements in the array.
2158 * \param size the size of the elements in the array.
2159 * \param compare a function used to compare elements in the array.
2160 * \param userdata a pointer to pass to the compare function.
2161 *
2162 * \threadsafety It is safe to call this function from any thread.
2163 *
2164 * \since This function is available since SDL 3.2.0.
2165 *
2166 * \sa SDL_bsearch_r
2167 * \sa SDL_qsort
2168 */
2169extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
2170
2171/**
2172 * Perform a binary search on a previously sorted array, passing a userdata
2173 * pointer to the compare function.
2174 *
2175 * For example:
2176 *
2177 * ```c
2178 * typedef enum {
2179 * sort_increasing,
2180 * sort_decreasing,
2181 * } sort_method;
2182 *
2183 * typedef struct {
2184 * int key;
2185 * const char *string;
2186 * } data;
2187 *
2188 * int SDLCALL compare(const void *userdata, const void *a, const void *b)
2189 * {
2190 * sort_method method = (sort_method)(uintptr_t)userdata;
2191 * const data *A = (const data *)a;
2192 * const data *B = (const data *)b;
2193 *
2194 * if (A->key < B->key) {
2195 * return (method == sort_increasing) ? -1 : 1;
2196 * } else if (B->key < A->key) {
2197 * return (method == sort_increasing) ? 1 : -1;
2198 * } else {
2199 * return 0;
2200 * }
2201 * }
2202 *
2203 * data values[] = {
2204 * { 1, "first" }, { 2, "second" }, { 3, "third" }
2205 * };
2206 * data key = { 2, NULL };
2207 *
2208 * data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
2209 * ```
2210 *
2211 * \param key a pointer to a key equal to the element being searched for.
2212 * \param base a pointer to the start of the array.
2213 * \param nmemb the number of elements in the array.
2214 * \param size the size of the elements in the array.
2215 * \param compare a function used to compare elements in the array.
2216 * \param userdata a pointer to pass to the compare function.
2217 * \returns a pointer to the matching element in the array, or NULL if not
2218 * found.
2219 *
2220 * \threadsafety It is safe to call this function from any thread.
2221 *
2222 * \since This function is available since SDL 3.2.0.
2223 *
2224 * \sa SDL_bsearch
2225 * \sa SDL_qsort_r
2226 */
2227extern SDL_DECLSPEC void * SDLCALL SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
2228
2229/**
2230 * Compute the absolute value of `x`.
2231 *
2232 * \param x an integer value.
2233 * \returns the absolute value of x.
2234 *
2235 * \threadsafety It is safe to call this function from any thread.
2236 *
2237 * \since This function is available since SDL 3.2.0.
2238 */
2239extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
2240
2241/**
2242 * Return the lesser of two values.
2243 *
2244 * This is a helper macro that might be more clear than writing out the
2245 * comparisons directly, and works with any type that can be compared with the
2246 * `<` operator. However, it double-evaluates both its parameters, so do not
2247 * use expressions with side-effects here.
2248 *
2249 * \param x the first value to compare.
2250 * \param y the second value to compare.
2251 * \returns the lesser of `x` and `y`.
2252 *
2253 * \threadsafety It is safe to call this macro from any thread.
2254 *
2255 * \since This macro is available since SDL 3.2.0.
2256 */
2257#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
2258
2259/**
2260 * Return the greater of two values.
2261 *
2262 * This is a helper macro that might be more clear than writing out the
2263 * comparisons directly, and works with any type that can be compared with the
2264 * `>` operator. However, it double-evaluates both its parameters, so do not
2265 * use expressions with side-effects here.
2266 *
2267 * \param x the first value to compare.
2268 * \param y the second value to compare.
2269 * \returns the greater of `x` and `y`.
2270 *
2271 * \threadsafety It is safe to call this macro from any thread.
2272 *
2273 * \since This macro is available since SDL 3.2.0.
2274 */
2275#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
2276
2277/**
2278 * Return a value clamped to a range.
2279 *
2280 * If `x` is outside the range a values between `a` and `b`, the returned
2281 * value will be `a` or `b` as appropriate. Otherwise, `x` is returned.
2282 *
2283 * This macro will produce incorrect results if `b` is less than `a`.
2284 *
2285 * This is a helper macro that might be more clear than writing out the
2286 * comparisons directly, and works with any type that can be compared with the
2287 * `<` and `>` operators. However, it double-evaluates all its parameters, so
2288 * do not use expressions with side-effects here.
2289 *
2290 * \param x the value to compare.
2291 * \param a the low end value.
2292 * \param b the high end value.
2293 * \returns x, clamped between a and b.
2294 *
2295 * \threadsafety It is safe to call this macro from any thread.
2296 *
2297 * \since This macro is available since SDL 3.2.0.
2298 */
2299#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
2300
2301/**
2302 * Query if a character is alphabetic (a letter).
2303 *
2304 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2305 * for English 'a-z' and 'A-Z' as true.
2306 *
2307 * \param x character value to check.
2308 * \returns non-zero if x falls within the character class, zero otherwise.
2309 *
2310 * \threadsafety It is safe to call this function from any thread.
2311 *
2312 * \since This function is available since SDL 3.2.0.
2313 */
2314extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
2315
2316/**
2317 * Query if a character is alphabetic (a letter) or a number.
2318 *
2319 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2320 * for English 'a-z', 'A-Z', and '0-9' as true.
2321 *
2322 * \param x character value to check.
2323 * \returns non-zero if x falls within the character class, zero otherwise.
2324 *
2325 * \threadsafety It is safe to call this function from any thread.
2326 *
2327 * \since This function is available since SDL 3.2.0.
2328 */
2329extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
2330
2331/**
2332 * Report if a character is blank (a space or tab).
2333 *
2334 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2335 * 0x20 (space) or 0x9 (tab) as true.
2336 *
2337 * \param x character value to check.
2338 * \returns non-zero if x falls within the character class, zero otherwise.
2339 *
2340 * \threadsafety It is safe to call this function from any thread.
2341 *
2342 * \since This function is available since SDL 3.2.0.
2343 */
2344extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
2345
2346/**
2347 * Report if a character is a control character.
2348 *
2349 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2350 * 0 through 0x1F, and 0x7F, as true.
2351 *
2352 * \param x character value to check.
2353 * \returns non-zero if x falls within the character class, zero otherwise.
2354 *
2355 * \threadsafety It is safe to call this function from any thread.
2356 *
2357 * \since This function is available since SDL 3.2.0.
2358 */
2359extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
2360
2361/**
2362 * Report if a character is a numeric digit.
2363 *
2364 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2365 * '0' (0x30) through '9' (0x39), as true.
2366 *
2367 * \param x character value to check.
2368 * \returns non-zero if x falls within the character class, zero otherwise.
2369 *
2370 * \threadsafety It is safe to call this function from any thread.
2371 *
2372 * \since This function is available since SDL 3.2.0.
2373 */
2374extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
2375
2376/**
2377 * Report if a character is a hexadecimal digit.
2378 *
2379 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2380 * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
2381 *
2382 * \param x character value to check.
2383 * \returns non-zero if x falls within the character class, zero otherwise.
2384 *
2385 * \threadsafety It is safe to call this function from any thread.
2386 *
2387 * \since This function is available since SDL 3.2.0.
2388 */
2389extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
2390
2391/**
2392 * Report if a character is a punctuation mark.
2393 *
2394 * **WARNING**: Regardless of system locale, this is equivalent to
2395 * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
2396 *
2397 * \param x character value to check.
2398 * \returns non-zero if x falls within the character class, zero otherwise.
2399 *
2400 * \threadsafety It is safe to call this function from any thread.
2401 *
2402 * \since This function is available since SDL 3.2.0.
2403 *
2404 * \sa SDL_isgraph
2405 * \sa SDL_isalnum
2406 */
2407extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
2408
2409/**
2410 * Report if a character is whitespace.
2411 *
2412 * **WARNING**: Regardless of system locale, this will only treat the
2413 * following ASCII values as true:
2414 *
2415 * - space (0x20)
2416 * - tab (0x09)
2417 * - newline (0x0A)
2418 * - vertical tab (0x0B)
2419 * - form feed (0x0C)
2420 * - return (0x0D)
2421 *
2422 * \param x character value to check.
2423 * \returns non-zero if x falls within the character class, zero otherwise.
2424 *
2425 * \threadsafety It is safe to call this function from any thread.
2426 *
2427 * \since This function is available since SDL 3.2.0.
2428 */
2429extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
2430
2431/**
2432 * Report if a character is upper case.
2433 *
2434 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2435 * 'A' through 'Z' as true.
2436 *
2437 * \param x character value to check.
2438 * \returns non-zero if x falls within the character class, zero otherwise.
2439 *
2440 * \threadsafety It is safe to call this function from any thread.
2441 *
2442 * \since This function is available since SDL 3.2.0.
2443 */
2444extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
2445
2446/**
2447 * Report if a character is lower case.
2448 *
2449 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2450 * 'a' through 'z' as true.
2451 *
2452 * \param x character value to check.
2453 * \returns non-zero if x falls within the character class, zero otherwise.
2454 *
2455 * \threadsafety It is safe to call this function from any thread.
2456 *
2457 * \since This function is available since SDL 3.2.0.
2458 */
2459extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
2460
2461/**
2462 * Report if a character is "printable".
2463 *
2464 * Be advised that "printable" has a definition that goes back to text
2465 * terminals from the dawn of computing, making this a sort of special case
2466 * function that is not suitable for Unicode (or most any) text management.
2467 *
2468 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2469 * ' ' (0x20) through '~' (0x7E) as true.
2470 *
2471 * \param x character value to check.
2472 * \returns non-zero if x falls within the character class, zero otherwise.
2473 *
2474 * \threadsafety It is safe to call this function from any thread.
2475 *
2476 * \since This function is available since SDL 3.2.0.
2477 */
2478extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
2479
2480/**
2481 * Report if a character is any "printable" except space.
2482 *
2483 * Be advised that "printable" has a definition that goes back to text
2484 * terminals from the dawn of computing, making this a sort of special case
2485 * function that is not suitable for Unicode (or most any) text management.
2486 *
2487 * **WARNING**: Regardless of system locale, this is equivalent to
2488 * `(SDL_isprint(x)) && ((x) != ' ')`.
2489 *
2490 * \param x character value to check.
2491 * \returns non-zero if x falls within the character class, zero otherwise.
2492 *
2493 * \threadsafety It is safe to call this function from any thread.
2494 *
2495 * \since This function is available since SDL 3.2.0.
2496 *
2497 * \sa SDL_isprint
2498 */
2499extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
2500
2501/**
2502 * Convert low-ASCII English letters to uppercase.
2503 *
2504 * **WARNING**: Regardless of system locale, this will only convert ASCII
2505 * values 'a' through 'z' to uppercase.
2506 *
2507 * This function returns the uppercase equivalent of `x`. If a character
2508 * cannot be converted, or is already uppercase, this function returns `x`.
2509 *
2510 * \param x character value to check.
2511 * \returns capitalized version of x, or x if no conversion available.
2512 *
2513 * \threadsafety It is safe to call this function from any thread.
2514 *
2515 * \since This function is available since SDL 3.2.0.
2516 */
2517extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
2518
2519/**
2520 * Convert low-ASCII English letters to lowercase.
2521 *
2522 * **WARNING**: Regardless of system locale, this will only convert ASCII
2523 * values 'A' through 'Z' to lowercase.
2524 *
2525 * This function returns the lowercase equivalent of `x`. If a character
2526 * cannot be converted, or is already lowercase, this function returns `x`.
2527 *
2528 * \param x character value to check.
2529 * \returns lowercase version of x, or x if no conversion available.
2530 *
2531 * \threadsafety It is safe to call this function from any thread.
2532 *
2533 * \since This function is available since SDL 3.2.0.
2534 */
2535extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
2536
2537/**
2538 * Calculate a CRC-16 value.
2539 *
2540 * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
2541 *
2542 * This function can be called multiple times, to stream data to be
2543 * checksummed in blocks. Each call must provide the previous CRC-16 return
2544 * value to be updated with the next block. The first call to this function
2545 * for a set of blocks should pass in a zero CRC value.
2546 *
2547 * \param crc the current checksum for this data set, or 0 for a new data set.
2548 * \param data a new block of data to add to the checksum.
2549 * \param len the size, in bytes, of the new block of data.
2550 * \returns a CRC-16 checksum value of all blocks in the data set.
2551 *
2552 * \threadsafety It is safe to call this function from any thread.
2553 *
2554 * \since This function is available since SDL 3.2.0.
2555 */
2556extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
2557
2558/**
2559 * Calculate a CRC-32 value.
2560 *
2561 * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
2562 *
2563 * This function can be called multiple times, to stream data to be
2564 * checksummed in blocks. Each call must provide the previous CRC-32 return
2565 * value to be updated with the next block. The first call to this function
2566 * for a set of blocks should pass in a zero CRC value.
2567 *
2568 * \param crc the current checksum for this data set, or 0 for a new data set.
2569 * \param data a new block of data to add to the checksum.
2570 * \param len the size, in bytes, of the new block of data.
2571 * \returns a CRC-32 checksum value of all blocks in the data set.
2572 *
2573 * \threadsafety It is safe to call this function from any thread.
2574 *
2575 * \since This function is available since SDL 3.2.0.
2576 */
2577extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
2578
2579/**
2580 * Calculate a 32-bit MurmurHash3 value for a block of data.
2581 *
2582 * https://en.wikipedia.org/wiki/MurmurHash
2583 *
2584 * A seed may be specified, which changes the final results consistently, but
2585 * this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous
2586 * result from this function back into itself as the next seed value to
2587 * calculate a hash in chunks; it won't produce the same hash as it would if
2588 * the same data was provided in a single call.
2589 *
2590 * If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not
2591 * cryptographically secure, so it shouldn't be used for hashing top-secret
2592 * data.
2593 *
2594 * \param data the data to be hashed.
2595 * \param len the size of data, in bytes.
2596 * \param seed a value that alters the final hash value.
2597 * \returns a Murmur3 32-bit hash value.
2598 *
2599 * \threadsafety It is safe to call this function from any thread.
2600 *
2601 * \since This function is available since SDL 3.2.0.
2602 */
2603extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed);
2604
2605/**
2606 * Copy non-overlapping memory.
2607 *
2608 * The memory regions must not overlap. If they do, use SDL_memmove() instead.
2609 *
2610 * \param dst The destination memory region. Must not be NULL, and must not
2611 * overlap with `src`.
2612 * \param src The source memory region. Must not be NULL, and must not overlap
2613 * with `dst`.
2614 * \param len The length in bytes of both `dst` and `src`.
2615 * \returns `dst`.
2616 *
2617 * \threadsafety It is safe to call this function from any thread.
2618 *
2619 * \since This function is available since SDL 3.2.0.
2620 *
2621 * \sa SDL_memmove
2622 */
2623extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
2624
2625/* Take advantage of compiler optimizations for memcpy */
2626#ifndef SDL_SLOW_MEMCPY
2627#ifdef SDL_memcpy
2628#undef SDL_memcpy
2629#endif
2630#define SDL_memcpy memcpy
2631#endif
2632
2633
2634/**
2635 * A macro to copy memory between objects, with basic type checking.
2636 *
2637 * SDL_memcpy and SDL_memmove do not care where you copy memory to and from,
2638 * which can lead to bugs. This macro aims to avoid most of those bugs by
2639 * making sure that the source and destination are both pointers to objects
2640 * that are the same size. It does not check that the objects are the same
2641 * _type_, just that the copy will not overflow either object.
2642 *
2643 * The size check happens at compile time, and the compiler will throw an
2644 * error if the objects are different sizes.
2645 *
2646 * Generally this is intended to copy a single object, not an array.
2647 *
2648 * This macro looks like it double-evaluates its parameters, but the extras
2649 * them are in `sizeof` sections, which generate no code nor side-effects.
2650 *
2651 * \param dst a pointer to the destination object. Must not be NULL.
2652 * \param src a pointer to the source object. Must not be NULL.
2653 *
2654 * \threadsafety It is safe to call this function from any thread.
2655 *
2656 * \since This function is available since SDL 3.2.0.
2657 */
2658#define SDL_copyp(dst, src) \
2659 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
2660 SDL_memcpy((dst), (src), sizeof(*(src)))
2661
2662/**
2663 * Copy memory ranges that might overlap.
2664 *
2665 * It is okay for the memory regions to overlap. If you are confident that the
2666 * regions never overlap, using SDL_memcpy() may improve performance.
2667 *
2668 * \param dst The destination memory region. Must not be NULL.
2669 * \param src The source memory region. Must not be NULL.
2670 * \param len The length in bytes of both `dst` and `src`.
2671 * \returns `dst`.
2672 *
2673 * \threadsafety It is safe to call this function from any thread.
2674 *
2675 * \since This function is available since SDL 3.2.0.
2676 *
2677 * \sa SDL_memcpy
2678 */
2679extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
2680
2681/* Take advantage of compiler optimizations for memmove */
2682#ifndef SDL_SLOW_MEMMOVE
2683#ifdef SDL_memmove
2684#undef SDL_memmove
2685#endif
2686#define SDL_memmove memmove
2687#endif
2688
2689/**
2690 * Initialize all bytes of buffer of memory to a specific value.
2691 *
2692 * This function will set `len` bytes, pointed to by `dst`, to the value
2693 * specified in `c`.
2694 *
2695 * Despite `c` being an `int` instead of a `char`, this only operates on
2696 * bytes; `c` must be a value between 0 and 255, inclusive.
2697 *
2698 * \param dst the destination memory region. Must not be NULL.
2699 * \param c the byte value to set.
2700 * \param len the length, in bytes, to set in `dst`.
2701 * \returns `dst`.
2702 *
2703 * \threadsafety It is safe to call this function from any thread.
2704 *
2705 * \since This function is available since SDL 3.2.0.
2706 */
2707extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
2708
2709/**
2710 * Initialize all 32-bit words of buffer of memory to a specific value.
2711 *
2712 * This function will set a buffer of `dwords` Uint32 values, pointed to by
2713 * `dst`, to the value specified in `val`.
2714 *
2715 * Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited
2716 * to a range of 0-255.
2717 *
2718 * \param dst the destination memory region. Must not be NULL.
2719 * \param val the Uint32 value to set.
2720 * \param dwords the number of Uint32 values to set in `dst`.
2721 * \returns `dst`.
2722 *
2723 * \threadsafety It is safe to call this function from any thread.
2724 *
2725 * \since This function is available since SDL 3.2.0.
2726 */
2727extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
2728
2729/* Take advantage of compiler optimizations for memset */
2730#ifndef SDL_SLOW_MEMSET
2731#ifdef SDL_memset
2732#undef SDL_memset
2733#endif
2734#define SDL_memset memset
2735#endif
2736
2737/**
2738 * Clear an object's memory to zero.
2739 *
2740 * This is wrapper over SDL_memset that handles calculating the object size,
2741 * so there's no chance of copy/paste errors, and the code is cleaner.
2742 *
2743 * This requires an object, not a pointer to an object, nor an array.
2744 *
2745 * \param x the object to clear.
2746 *
2747 * \threadsafety It is safe to call this macro from any thread.
2748 *
2749 * \since This macro is available since SDL 3.2.0.
2750 *
2751 * \sa SDL_zerop
2752 * \sa SDL_zeroa
2753 */
2754#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
2755
2756/**
2757 * Clear an object's memory to zero, using a pointer.
2758 *
2759 * This is wrapper over SDL_memset that handles calculating the object size,
2760 * so there's no chance of copy/paste errors, and the code is cleaner.
2761 *
2762 * This requires a pointer to an object, not an object itself, nor an array.
2763 *
2764 * \param x a pointer to the object to clear.
2765 *
2766 * \threadsafety It is safe to call this macro from any thread.
2767 *
2768 * \since This macro is available since SDL 3.2.0.
2769 *
2770 * \sa SDL_zero
2771 * \sa SDL_zeroa
2772 */
2773#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
2774
2775/**
2776 * Clear an array's memory to zero.
2777 *
2778 * This is wrapper over SDL_memset that handles calculating the array size, so
2779 * there's no chance of copy/paste errors, and the code is cleaner.
2780 *
2781 * This requires an array, not an object, nor a pointer to an object.
2782 *
2783 * \param x an array to clear.
2784 *
2785 * \threadsafety It is safe to call this macro from any thread.
2786 *
2787 * \since This macro is available since SDL 3.2.0.
2788 *
2789 * \sa SDL_zero
2790 * \sa SDL_zerop
2791 */
2792#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
2793
2794
2795/**
2796 * Compare two buffers of memory.
2797 *
2798 * \param s1 the first buffer to compare. NULL is not permitted!
2799 * \param s2 the second buffer to compare. NULL is not permitted!
2800 * \param len the number of bytes to compare between the buffers.
2801 * \returns less than zero if s1 is "less than" s2, greater than zero if s1 is
2802 * "greater than" s2, and zero if the buffers match exactly for `len`
2803 * bytes.
2804 *
2805 * \threadsafety It is safe to call this function from any thread.
2806 *
2807 * \since This function is available since SDL 3.2.0.
2808 */
2809extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
2810
2811/**
2812 * This works exactly like wcslen() but doesn't require access to a C runtime.
2813 *
2814 * Counts the number of wchar_t values in `wstr`, excluding the null
2815 * terminator.
2816 *
2817 * Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
2818 * this counts wchar_t values in a string, even if the string's encoding is of
2819 * variable width, like UTF-16.
2820 *
2821 * Also be aware that wchar_t is different sizes on different platforms (4
2822 * bytes on Linux, 2 on Windows, etc).
2823 *
2824 * \param wstr The null-terminated wide string to read. Must not be NULL.
2825 * \returns the length (in wchar_t values, excluding the null terminator) of
2826 * `wstr`.
2827 *
2828 * \threadsafety It is safe to call this function from any thread.
2829 *
2830 * \since This function is available since SDL 3.2.0.
2831 *
2832 * \sa SDL_wcsnlen
2833 * \sa SDL_utf8strlen
2834 * \sa SDL_utf8strnlen
2835 */
2836extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
2837
2838/**
2839 * This works exactly like wcsnlen() but doesn't require access to a C
2840 * runtime.
2841 *
2842 * Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
2843 * null terminator.
2844 *
2845 * Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
2846 * this counts wchar_t values in a string, even if the string's encoding is of
2847 * variable width, like UTF-16.
2848 *
2849 * Also be aware that wchar_t is different sizes on different platforms (4
2850 * bytes on Linux, 2 on Windows, etc).
2851 *
2852 * Also, `maxlen` is a count of wide characters, not bytes!
2853 *
2854 * \param wstr The null-terminated wide string to read. Must not be NULL.
2855 * \param maxlen The maximum amount of wide characters to count.
2856 * \returns the length (in wide characters, excluding the null terminator) of
2857 * `wstr` but never more than `maxlen`.
2858 *
2859 * \threadsafety It is safe to call this function from any thread.
2860 *
2861 * \since This function is available since SDL 3.2.0.
2862 *
2863 * \sa SDL_wcslen
2864 * \sa SDL_utf8strlen
2865 * \sa SDL_utf8strnlen
2866 */
2867extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
2868
2869/**
2870 * Copy a wide string.
2871 *
2872 * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
2873 * appends a null terminator.
2874 *
2875 * `src` and `dst` must not overlap.
2876 *
2877 * If `maxlen` is 0, no wide characters are copied and no null terminator is
2878 * written.
2879 *
2880 * \param dst The destination buffer. Must not be NULL, and must not overlap
2881 * with `src`.
2882 * \param src The null-terminated wide string to copy. Must not be NULL, and
2883 * must not overlap with `dst`.
2884 * \param maxlen The length (in wide characters) of the destination buffer.
2885 * \returns the length (in wide characters, excluding the null terminator) of
2886 * `src`.
2887 *
2888 * \threadsafety It is safe to call this function from any thread.
2889 *
2890 * \since This function is available since SDL 3.2.0.
2891 *
2892 * \sa SDL_wcslcat
2893 */
2894extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
2895
2896/**
2897 * Concatenate wide strings.
2898 *
2899 * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
2900 * from `src` to the end of the wide string in `dst`, then appends a null
2901 * terminator.
2902 *
2903 * `src` and `dst` must not overlap.
2904 *
2905 * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
2906 * unmodified.
2907 *
2908 * \param dst The destination buffer already containing the first
2909 * null-terminated wide string. Must not be NULL and must not
2910 * overlap with `src`.
2911 * \param src The second null-terminated wide string. Must not be NULL, and
2912 * must not overlap with `dst`.
2913 * \param maxlen The length (in wide characters) of the destination buffer.
2914 * \returns the length (in wide characters, excluding the null terminator) of
2915 * the string in `dst` plus the length of `src`.
2916 *
2917 * \threadsafety It is safe to call this function from any thread.
2918 *
2919 * \since This function is available since SDL 3.2.0.
2920 *
2921 * \sa SDL_wcslcpy
2922 */
2923extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
2924
2925/**
2926 * Allocate a copy of a wide string.
2927 *
2928 * This allocates enough space for a null-terminated copy of `wstr`, using
2929 * SDL_malloc, and then makes a copy of the string into this space.
2930 *
2931 * The returned string is owned by the caller, and should be passed to
2932 * SDL_free when no longer needed.
2933 *
2934 * \param wstr the string to copy.
2935 * \returns a pointer to the newly-allocated wide string.
2936 *
2937 * \threadsafety It is safe to call this function from any thread.
2938 *
2939 * \since This function is available since SDL 3.2.0.
2940 */
2941extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
2942
2943/**
2944 * Search a wide string for the first instance of a specific substring.
2945 *
2946 * The search ends once it finds the requested substring, or a null terminator
2947 * byte to end the string.
2948 *
2949 * Note that this looks for strings of _wide characters_, not _codepoints_, so
2950 * it's legal to search for malformed and incomplete UTF-16 sequences.
2951 *
2952 * \param haystack the wide string to search. Must not be NULL.
2953 * \param needle the wide string to search for. Must not be NULL.
2954 * \returns a pointer to the first instance of `needle` in the string, or NULL
2955 * if not found.
2956 *
2957 * \threadsafety It is safe to call this function from any thread.
2958 *
2959 * \since This function is available since SDL 3.2.0.
2960 */
2961extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
2962
2963/**
2964 * Search a wide string, up to n wide chars, for the first instance of a
2965 * specific substring.
2966 *
2967 * The search ends once it finds the requested substring, or a null terminator
2968 * value to end the string, or `maxlen` wide character have been examined. It
2969 * is possible to use this function on a wide string without a null
2970 * terminator.
2971 *
2972 * Note that this looks for strings of _wide characters_, not _codepoints_, so
2973 * it's legal to search for malformed and incomplete UTF-16 sequences.
2974 *
2975 * \param haystack the wide string to search. Must not be NULL.
2976 * \param needle the wide string to search for. Must not be NULL.
2977 * \param maxlen the maximum number of wide characters to search in
2978 * `haystack`.
2979 * \returns a pointer to the first instance of `needle` in the string, or NULL
2980 * if not found.
2981 *
2982 * \threadsafety It is safe to call this function from any thread.
2983 *
2984 * \since This function is available since SDL 3.2.0.
2985 */
2986extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
2987
2988/**
2989 * Compare two null-terminated wide strings.
2990 *
2991 * This only compares wchar_t values until it hits a null-terminating
2992 * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
2993 * depending on your platform's wchar_t size), or uses valid Unicode values.
2994 *
2995 * \param str1 the first string to compare. NULL is not permitted!
2996 * \param str2 the second string to compare. NULL is not permitted!
2997 * \returns less than zero if str1 is "less than" str2, greater than zero if
2998 * str1 is "greater than" str2, and zero if the strings match
2999 * exactly.
3000 *
3001 * \threadsafety It is safe to call this function from any thread.
3002 *
3003 * \since This function is available since SDL 3.2.0.
3004 */
3005extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
3006
3007/**
3008 * Compare two wide strings up to a number of wchar_t values.
3009 *
3010 * This only compares wchar_t values; it does not care if the string is
3011 * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
3012 * or uses valid Unicode values.
3013 *
3014 * Note that while this function is intended to be used with UTF-16 (or
3015 * UTF-32, depending on your platform's definition of wchar_t), it is
3016 * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
3017 * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
3018 * sequence, it will only compare a portion of the final character.
3019 *
3020 * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
3021 * match to this number of wide chars (or both have matched to a
3022 * null-terminator character before this count), they will be considered
3023 * equal.
3024 *
3025 * \param str1 the first string to compare. NULL is not permitted!
3026 * \param str2 the second string to compare. NULL is not permitted!
3027 * \param maxlen the maximum number of wchar_t to compare.
3028 * \returns less than zero if str1 is "less than" str2, greater than zero if
3029 * str1 is "greater than" str2, and zero if the strings match
3030 * exactly.
3031 *
3032 * \threadsafety It is safe to call this function from any thread.
3033 *
3034 * \since This function is available since SDL 3.2.0.
3035 */
3036extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
3037
3038/**
3039 * Compare two null-terminated wide strings, case-insensitively.
3040 *
3041 * This will work with Unicode strings, using a technique called
3042 * "case-folding" to handle the vast majority of case-sensitive human
3043 * languages regardless of system locale. It can deal with expanding values: a
3044 * German Eszett character can compare against two ASCII 's' chars and be
3045 * considered a match, for example. A notable exception: it does not handle
3046 * the Turkish 'i' character; human language is complicated!
3047 *
3048 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
3049 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
3050 * handles Unicode, it expects the string to be well-formed and not a
3051 * null-terminated string of arbitrary bytes. Characters that are not valid
3052 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
3053 * CHARACTER), which is to say two strings of random bits may turn out to
3054 * match if they convert to the same amount of replacement characters.
3055 *
3056 * \param str1 the first string to compare. NULL is not permitted!
3057 * \param str2 the second string to compare. NULL is not permitted!
3058 * \returns less than zero if str1 is "less than" str2, greater than zero if
3059 * str1 is "greater than" str2, and zero if the strings match
3060 * exactly.
3061 *
3062 * \threadsafety It is safe to call this function from any thread.
3063 *
3064 * \since This function is available since SDL 3.2.0.
3065 */
3066extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
3067
3068/**
3069 * Compare two wide strings, case-insensitively, up to a number of wchar_t.
3070 *
3071 * This will work with Unicode strings, using a technique called
3072 * "case-folding" to handle the vast majority of case-sensitive human
3073 * languages regardless of system locale. It can deal with expanding values: a
3074 * German Eszett character can compare against two ASCII 's' chars and be
3075 * considered a match, for example. A notable exception: it does not handle
3076 * the Turkish 'i' character; human language is complicated!
3077 *
3078 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
3079 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
3080 * handles Unicode, it expects the string to be well-formed and not a
3081 * null-terminated string of arbitrary bytes. Characters that are not valid
3082 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
3083 * CHARACTER), which is to say two strings of random bits may turn out to
3084 * match if they convert to the same amount of replacement characters.
3085 *
3086 * Note that while this function might deal with variable-sized characters,
3087 * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
3088 * multi-byte UTF-16 sequence, it may convert a portion of the final character
3089 * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
3090 * to overflow a buffer.
3091 *
3092 * `maxlen` specifies a maximum number of wchar_t values to compare; if the
3093 * strings match to this number of wchar_t (or both have matched to a
3094 * null-terminator character before this number of bytes), they will be
3095 * considered equal.
3096 *
3097 * \param str1 the first string to compare. NULL is not permitted!
3098 * \param str2 the second string to compare. NULL is not permitted!
3099 * \param maxlen the maximum number of wchar_t values to compare.
3100 * \returns less than zero if str1 is "less than" str2, greater than zero if
3101 * str1 is "greater than" str2, and zero if the strings match
3102 * exactly.
3103 *
3104 * \threadsafety It is safe to call this function from any thread.
3105 *
3106 * \since This function is available since SDL 3.2.0.
3107 */
3108extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
3109
3110/**
3111 * Parse a `long` from a wide string.
3112 *
3113 * If `str` starts with whitespace, then those whitespace characters are
3114 * skipped before attempting to parse the number.
3115 *
3116 * If the parsed number does not fit inside a `long`, the result is clamped to
3117 * the minimum and maximum representable `long` values.
3118 *
3119 * \param str The null-terminated wide string to read. Must not be NULL.
3120 * \param endp If not NULL, the address of the first invalid wide character
3121 * (i.e. the next character after the parsed number) will be
3122 * written to this pointer.
3123 * \param base The base of the integer to read. Supported values are 0 and 2
3124 * to 36 inclusive. If 0, the base will be inferred from the
3125 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3126 * otherwise).
3127 * \returns the parsed `long`, or 0 if no number could be parsed.
3128 *
3129 * \threadsafety It is safe to call this function from any thread.
3130 *
3131 * \since This function is available since SDL 3.2.0.
3132 *
3133 * \sa SDL_strtol
3134 */
3135extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
3136
3137/**
3138 * Parse an `unsigned long` from a wide string.
3139 *
3140 * If `str` starts with whitespace, then those whitespace characters are
3141 * skipped before attempting to parse the number.
3142 *
3143 * If the parsed number does not fit inside an `unsigned long`, the result is
3144 * clamped to the minimum and maximum representable `unsigned long` values.
3145 *
3146 * \param str The null-terminated wide string to read. Must not be NULL.
3147 * \param endp If not NULL, the address of the first invalid wide character
3148 * (i.e. the next character after the parsed number) will be
3149 * written to this pointer.
3150 * \param base The base of the integer to read. Supported values are 0 and 2
3151 * to 36 inclusive. If 0, the base will be inferred from the
3152 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3153 * otherwise).
3154 * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
3155 *
3156 * \threadsafety It is safe to call this function from any thread.
3157 *
3158 * \since This function is available since SDL 3.6.0.
3159 *
3160 * \sa SDL_strtoul
3161 */
3162extern SDL_DECLSPEC unsigned long SDLCALL SDL_wcstoul(const wchar_t *str, wchar_t **endp, int base);
3163
3164#ifndef SDL_NOLONGLONG
3165
3166/**
3167 * Parse a `long long` from a wide string.
3168 *
3169 * If `str` starts with whitespace, then those whitespace characters are
3170 * skipped before attempting to parse the number.
3171 *
3172 * If the parsed number does not fit inside a `long long`, the result is
3173 * clamped to the minimum and maximum representable `long long` values.
3174 *
3175 * \param str The null-terminated wide string to read. Must not be NULL.
3176 * \param endp If not NULL, the address of the first invalid wide character
3177 * (i.e. the next character after the parsed number) will be
3178 * written to this pointer.
3179 * \param base The base of the integer to read. Supported values are 0 and 2
3180 * to 36 inclusive. If 0, the base will be inferred from the
3181 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3182 * otherwise).
3183 * \returns the parsed `long long`, or 0 if no number could be parsed.
3184 *
3185 * \threadsafety It is safe to call this function from any thread.
3186 *
3187 * \since This function is available since SDL 3.6.0.
3188 *
3189 * \sa SDL_strtoll
3190 */
3191extern SDL_DECLSPEC long long SDLCALL SDL_wcstoll(const wchar_t *str, wchar_t **endp, int base);
3192
3193/**
3194 * Parse an `unsigned long long` from a wide string.
3195 *
3196 * If `str` starts with whitespace, then those whitespace characters are
3197 * skipped before attempting to parse the number.
3198 *
3199 * If the parsed number does not fit inside an `unsigned long long`, the
3200 * result is clamped to the minimum and maximum representable `unsigned long
3201 * long` values.
3202 *
3203 * \param str The null-terminated wide string to read. Must not be NULL.
3204 * \param endp If not NULL, the address of the first invalid wide character
3205 * (i.e. the next character after the parsed number) will be
3206 * written to this pointer.
3207 * \param base The base of the integer to read. Supported values are 0 and 2
3208 * to 36 inclusive. If 0, the base will be inferred from the
3209 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3210 * otherwise).
3211 * \returns the parsed `unsigned long long`, or 0 if no number could be
3212 * parsed.
3213 *
3214 * \threadsafety It is safe to call this function from any thread.
3215 *
3216 * \since This function is available since SDL 3.6.0.
3217 *
3218 * \sa SDL_strtoull
3219 */
3220extern SDL_DECLSPEC unsigned long long SDLCALL SDL_wcstoull(const wchar_t *str, wchar_t **endp, int base);
3221
3222#endif /* !SDL_NOLONGLONG */
3223
3224/**
3225 * This works exactly like strlen() but doesn't require access to a C runtime.
3226 *
3227 * Counts the bytes in `str`, excluding the null terminator.
3228 *
3229 * If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
3230 *
3231 * \param str The null-terminated string to read. Must not be NULL.
3232 * \returns the length (in bytes, excluding the null terminator) of `str`.
3233 *
3234 * \threadsafety It is safe to call this function from any thread.
3235 *
3236 * \since This function is available since SDL 3.2.0.
3237 *
3238 * \sa SDL_strnlen
3239 * \sa SDL_utf8strlen
3240 * \sa SDL_utf8strnlen
3241 */
3242extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
3243
3244/**
3245 * This works exactly like strnlen() but doesn't require access to a C
3246 * runtime.
3247 *
3248 * Counts up to a maximum of `maxlen` bytes in `str`, excluding the null
3249 * terminator.
3250 *
3251 * If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().
3252 *
3253 * \param str The null-terminated string to read. Must not be NULL.
3254 * \param maxlen The maximum amount of bytes to count.
3255 * \returns the length (in bytes, excluding the null terminator) of `src` but
3256 * never more than `maxlen`.
3257 *
3258 * \threadsafety It is safe to call this function from any thread.
3259 *
3260 * \since This function is available since SDL 3.2.0.
3261 *
3262 * \sa SDL_strlen
3263 * \sa SDL_utf8strlen
3264 * \sa SDL_utf8strnlen
3265 */
3266extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
3267
3268/**
3269 * Copy a string.
3270 *
3271 * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
3272 * then appends a null terminator.
3273 *
3274 * If `maxlen` is 0, no characters are copied and no null terminator is
3275 * written.
3276 *
3277 * If you want to copy an UTF-8 string but need to ensure that multi-byte
3278 * sequences are not truncated, consider using SDL_utf8strlcpy().
3279 *
3280 * \param dst The destination buffer. Must not be NULL, and must not overlap
3281 * with `src`.
3282 * \param src The null-terminated string to copy. Must not be NULL, and must
3283 * not overlap with `dst`.
3284 * \param maxlen The length (in characters) of the destination buffer.
3285 * \returns the length (in characters, excluding the null terminator) of
3286 * `src`.
3287 *
3288 * \threadsafety It is safe to call this function from any thread.
3289 *
3290 * \since This function is available since SDL 3.2.0.
3291 *
3292 * \sa SDL_strlcat
3293 * \sa SDL_utf8strlcpy
3294 */
3295extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
3296
3297/**
3298 * Copy an UTF-8 string.
3299 *
3300 * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
3301 * also ensuring that the string written to `dst` does not end in a truncated
3302 * multi-byte sequence. Finally, it appends a null terminator.
3303 *
3304 * `src` and `dst` must not overlap.
3305 *
3306 * Note that unlike SDL_strlcpy(), this function returns the number of bytes
3307 * written, not the length of `src`.
3308 *
3309 * \param dst The destination buffer. Must not be NULL, and must not overlap
3310 * with `src`.
3311 * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
3312 * must not overlap with `dst`.
3313 * \param dst_bytes The length (in bytes) of the destination buffer. Must not
3314 * be 0.
3315 * \returns the number of bytes written, excluding the null terminator.
3316 *
3317 * \threadsafety It is safe to call this function from any thread.
3318 *
3319 * \since This function is available since SDL 3.2.0.
3320 *
3321 * \sa SDL_strlcpy
3322 */
3323extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
3324
3325/**
3326 * Concatenate strings.
3327 *
3328 * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
3329 * `src` to the end of the string in `dst`, then appends a null terminator.
3330 *
3331 * `src` and `dst` must not overlap.
3332 *
3333 * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
3334 * unmodified.
3335 *
3336 * \param dst The destination buffer already containing the first
3337 * null-terminated string. Must not be NULL and must not overlap
3338 * with `src`.
3339 * \param src The second null-terminated string. Must not be NULL, and must
3340 * not overlap with `dst`.
3341 * \param maxlen The length (in characters) of the destination buffer.
3342 * \returns the length (in characters, excluding the null terminator) of the
3343 * string in `dst` plus the length of `src`.
3344 *
3345 * \threadsafety It is safe to call this function from any thread.
3346 *
3347 * \since This function is available since SDL 3.2.0.
3348 *
3349 * \sa SDL_strlcpy
3350 */
3351extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
3352
3353/**
3354 * Allocate a copy of a string.
3355 *
3356 * This allocates enough space for a null-terminated copy of `str`, using
3357 * SDL_malloc, and then makes a copy of the string into this space.
3358 *
3359 * The returned string is owned by the caller, and should be passed to
3360 * SDL_free when no longer needed.
3361 *
3362 * \param str the string to copy.
3363 * \returns a pointer to the newly-allocated string.
3364 *
3365 * \threadsafety It is safe to call this function from any thread.
3366 *
3367 * \since This function is available since SDL 3.2.0.
3368 */
3369extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
3370
3371/**
3372 * Allocate a copy of a string, up to n characters.
3373 *
3374 * This allocates enough space for a null-terminated copy of `str`, up to
3375 * `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into
3376 * this space.
3377 *
3378 * If the string is longer than `maxlen` bytes, the returned string will be
3379 * `maxlen` bytes long, plus a null-terminator character that isn't included
3380 * in the count.
3381 *
3382 * The returned string is owned by the caller, and should be passed to
3383 * SDL_free when no longer needed.
3384 *
3385 * \param str the string to copy.
3386 * \param maxlen the maximum length of the copied string, not counting the
3387 * null-terminator character.
3388 * \returns a pointer to the newly-allocated string.
3389 *
3390 * \threadsafety It is safe to call this function from any thread.
3391 *
3392 * \since This function is available since SDL 3.2.0.
3393 */
3394extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
3395
3396/**
3397 * Reverse a string's contents.
3398 *
3399 * This reverses a null-terminated string in-place. Only the content of the
3400 * string is reversed; the null-terminator character remains at the end of the
3401 * reversed string.
3402 *
3403 * **WARNING**: This function reverses the _bytes_ of the string, not the
3404 * codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
3405 * will ruin the string data. You should only use this function on strings
3406 * that are completely comprised of low ASCII characters.
3407 *
3408 * \param str the string to reverse.
3409 * \returns `str`.
3410 *
3411 * \threadsafety It is safe to call this function from any thread.
3412 *
3413 * \since This function is available since SDL 3.2.0.
3414 */
3415extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
3416
3417/**
3418 * Convert a string to uppercase.
3419 *
3420 * **WARNING**: Regardless of system locale, this will only convert ASCII
3421 * values 'a' through 'z' to uppercase.
3422 *
3423 * This function operates on a null-terminated string of bytes--even if it is
3424 * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
3425 * uppercase equivalents in-place, returning the original `str` pointer.
3426 *
3427 * \param str the string to convert in-place. Can not be NULL.
3428 * \returns the `str` pointer passed into this function.
3429 *
3430 * \threadsafety It is safe to call this function from any thread.
3431 *
3432 * \since This function is available since SDL 3.2.0.
3433 *
3434 * \sa SDL_strlwr
3435 */
3436extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
3437
3438/**
3439 * Convert a string to lowercase.
3440 *
3441 * **WARNING**: Regardless of system locale, this will only convert ASCII
3442 * values 'A' through 'Z' to lowercase.
3443 *
3444 * This function operates on a null-terminated string of bytes--even if it is
3445 * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
3446 * lowercase equivalents in-place, returning the original `str` pointer.
3447 *
3448 * \param str the string to convert in-place. Can not be NULL.
3449 * \returns the `str` pointer passed into this function.
3450 *
3451 * \threadsafety It is safe to call this function from any thread.
3452 *
3453 * \since This function is available since SDL 3.2.0.
3454 *
3455 * \sa SDL_strupr
3456 */
3457extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
3458
3459/**
3460 * Search a string for the first instance of a specific byte.
3461 *
3462 * The search ends once it finds the requested byte value, or a null
3463 * terminator byte to end the string.
3464 *
3465 * Note that this looks for _bytes_, not _characters_, so you cannot match
3466 * against a Unicode codepoint > 255, regardless of character encoding.
3467 *
3468 * \param str the string to search. Must not be NULL.
3469 * \param c the byte value to search for.
3470 * \returns a pointer to the first instance of `c` in the string, or NULL if
3471 * not found.
3472 *
3473 * \threadsafety It is safe to call this function from any thread.
3474 *
3475 * \since This function is available since SDL 3.2.0.
3476 */
3477extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
3478
3479/**
3480 * Search a string for the last instance of a specific byte.
3481 *
3482 * The search must go until it finds a null terminator byte to end the string.
3483 *
3484 * Note that this looks for _bytes_, not _characters_, so you cannot match
3485 * against a Unicode codepoint > 255, regardless of character encoding.
3486 *
3487 * \param str the string to search. Must not be NULL.
3488 * \param c the byte value to search for.
3489 * \returns a pointer to the last instance of `c` in the string, or NULL if
3490 * not found.
3491 *
3492 * \threadsafety It is safe to call this function from any thread.
3493 *
3494 * \since This function is available since SDL 3.2.0.
3495 */
3496extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
3497
3498/**
3499 * Search a string for the first instance of a specific substring.
3500 *
3501 * The search ends once it finds the requested substring, or a null terminator
3502 * byte to end the string.
3503 *
3504 * Note that this looks for strings of _bytes_, not _characters_, so it's
3505 * legal to search for malformed and incomplete UTF-8 sequences.
3506 *
3507 * \param haystack the string to search. Must not be NULL.
3508 * \param needle the string to search for. Must not be NULL.
3509 * \returns a pointer to the first instance of `needle` in the string, or NULL
3510 * if not found.
3511 *
3512 * \threadsafety It is safe to call this function from any thread.
3513 *
3514 * \since This function is available since SDL 3.2.0.
3515 */
3516extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
3517
3518/**
3519 * Search a string, up to n bytes, for the first instance of a specific
3520 * substring.
3521 *
3522 * The search ends once it finds the requested substring, or a null terminator
3523 * byte to end the string, or `maxlen` bytes have been examined. It is
3524 * possible to use this function on a string without a null terminator.
3525 *
3526 * Note that this looks for strings of _bytes_, not _characters_, so it's
3527 * legal to search for malformed and incomplete UTF-8 sequences.
3528 *
3529 * \param haystack the string to search. Must not be NULL.
3530 * \param needle the string to search for. Must not be NULL.
3531 * \param maxlen the maximum number of bytes to search in `haystack`.
3532 * \returns a pointer to the first instance of `needle` in the string, or NULL
3533 * if not found.
3534 *
3535 * \threadsafety It is safe to call this function from any thread.
3536 *
3537 * \since This function is available since SDL 3.2.0.
3538 */
3539extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
3540
3541/**
3542 * Search a UTF-8 string for the first instance of a specific substring,
3543 * case-insensitively.
3544 *
3545 * This will work with Unicode strings, using a technique called
3546 * "case-folding" to handle the vast majority of case-sensitive human
3547 * languages regardless of system locale. It can deal with expanding values: a
3548 * German Eszett character can compare against two ASCII 's' chars and be
3549 * considered a match, for example. A notable exception: it does not handle
3550 * the Turkish 'i' character; human language is complicated!
3551 *
3552 * Since this handles Unicode, it expects the strings to be well-formed UTF-8
3553 * and not a null-terminated string of arbitrary bytes. Bytes that are not
3554 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
3555 * CHARACTER), which is to say two strings of random bits may turn out to
3556 * match if they convert to the same amount of replacement characters.
3557 *
3558 * \param haystack the string to search. Must not be NULL.
3559 * \param needle the string to search for. Must not be NULL.
3560 * \returns a pointer to the first instance of `needle` in the string, or NULL
3561 * if not found.
3562 *
3563 * \threadsafety It is safe to call this function from any thread.
3564 *
3565 * \since This function is available since SDL 3.2.0.
3566 */
3567extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
3568
3569/**
3570 * This works exactly like strtok_r() but doesn't require access to a C
3571 * runtime.
3572 *
3573 * Break a string up into a series of tokens.
3574 *
3575 * To start tokenizing a new string, `str` should be the non-NULL address of
3576 * the string to start tokenizing. Future calls to get the next token from the
3577 * same string should specify a NULL.
3578 *
3579 * Note that this function will overwrite pieces of `str` with null chars to
3580 * split it into tokens. This function cannot be used with const/read-only
3581 * strings!
3582 *
3583 * `saveptr` just needs to point to a `char *` that can be overwritten; SDL
3584 * will use this to save tokenizing state between calls. It is initialized if
3585 * `str` is non-NULL, and used to resume tokenizing when `str` is NULL.
3586 *
3587 * \param str the string to tokenize, or NULL to continue tokenizing.
3588 * \param delim the delimiter string that separates tokens.
3589 * \param saveptr pointer to a char *, used for ongoing state.
3590 * \returns A pointer to the next token, or NULL if no tokens remain.
3591 *
3592 * \threadsafety It is safe to call this function from any thread.
3593 *
3594 * \since This function is available since SDL 3.2.0.
3595 */
3596extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr);
3597
3598/**
3599 * Count the number of codepoints in a UTF-8 string.
3600 *
3601 * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
3602 * terminator.
3603 *
3604 * If you need to count the bytes in a string instead, consider using
3605 * SDL_strlen().
3606 *
3607 * Since this handles Unicode, it expects the strings to be well-formed UTF-8
3608 * and not a null-terminated string of arbitrary bytes. Bytes that are not
3609 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
3610 * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
3611 * count by several replacement characters.
3612 *
3613 * \param str The null-terminated UTF-8 string to read. Must not be NULL.
3614 * \returns The length (in codepoints, excluding the null terminator) of
3615 * `src`.
3616 *
3617 * \threadsafety It is safe to call this function from any thread.
3618 *
3619 * \since This function is available since SDL 3.2.0.
3620 *
3621 * \sa SDL_utf8strnlen
3622 * \sa SDL_strlen
3623 */
3624extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
3625
3626/**
3627 * Count the number of codepoints in a UTF-8 string, up to n bytes.
3628 *
3629 * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
3630 * terminator.
3631 *
3632 * If you need to count the bytes in a string instead, consider using
3633 * SDL_strnlen().
3634 *
3635 * The counting stops at `bytes` bytes (not codepoints!). This seems
3636 * counterintuitive, but makes it easy to express the total size of the
3637 * string's buffer.
3638 *
3639 * Since this handles Unicode, it expects the strings to be well-formed UTF-8
3640 * and not a null-terminated string of arbitrary bytes. Bytes that are not
3641 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
3642 * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
3643 * count by several replacement characters.
3644 *
3645 * \param str The null-terminated UTF-8 string to read. Must not be NULL.
3646 * \param bytes The maximum amount of bytes to count.
3647 * \returns The length (in codepoints, excluding the null terminator) of `src`
3648 * but never more than `maxlen`.
3649 *
3650 * \threadsafety It is safe to call this function from any thread.
3651 *
3652 * \since This function is available since SDL 3.2.0.
3653 *
3654 * \sa SDL_utf8strlen
3655 * \sa SDL_strnlen
3656 */
3657extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
3658
3659/**
3660 * Convert an integer into a string.
3661 *
3662 * This requires a radix to specified for string format. Specifying 10
3663 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3664 * to 36.
3665 *
3666 * Note that this function will overflow a buffer if `str` is not large enough
3667 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3668 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3669 * much more space than you expect to use (and don't forget possible negative
3670 * signs, null terminator bytes, etc).
3671 *
3672 * \param value the integer to convert.
3673 * \param str the buffer to write the string into.
3674 * \param radix the radix to use for string generation.
3675 * \returns `str`.
3676 *
3677 * \threadsafety It is safe to call this function from any thread.
3678 *
3679 * \since This function is available since SDL 3.2.0.
3680 *
3681 * \sa SDL_uitoa
3682 * \sa SDL_ltoa
3683 * \sa SDL_lltoa
3684 */
3685extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
3686
3687/**
3688 * Convert an unsigned integer into a string.
3689 *
3690 * This requires a radix to specified for string format. Specifying 10
3691 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3692 * to 36.
3693 *
3694 * Note that this function will overflow a buffer if `str` is not large enough
3695 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3696 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3697 * much more space than you expect to use (and don't forget null terminator
3698 * bytes, etc).
3699 *
3700 * \param value the unsigned integer to convert.
3701 * \param str the buffer to write the string into.
3702 * \param radix the radix to use for string generation.
3703 * \returns `str`.
3704 *
3705 * \threadsafety It is safe to call this function from any thread.
3706 *
3707 * \since This function is available since SDL 3.2.0.
3708 *
3709 * \sa SDL_itoa
3710 * \sa SDL_ultoa
3711 * \sa SDL_ulltoa
3712 */
3713extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
3714
3715/**
3716 * Convert a long integer into a string.
3717 *
3718 * This requires a radix to specified for string format. Specifying 10
3719 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3720 * to 36.
3721 *
3722 * Note that this function will overflow a buffer if `str` is not large enough
3723 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3724 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3725 * much more space than you expect to use (and don't forget possible negative
3726 * signs, null terminator bytes, etc).
3727 *
3728 * \param value the long integer to convert.
3729 * \param str the buffer to write the string into.
3730 * \param radix the radix to use for string generation.
3731 * \returns `str`.
3732 *
3733 * \threadsafety It is safe to call this function from any thread.
3734 *
3735 * \since This function is available since SDL 3.2.0.
3736 *
3737 * \sa SDL_ultoa
3738 * \sa SDL_itoa
3739 * \sa SDL_lltoa
3740 */
3741extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
3742
3743/**
3744 * Convert an unsigned long integer into a string.
3745 *
3746 * This requires a radix to specified for string format. Specifying 10
3747 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3748 * to 36.
3749 *
3750 * Note that this function will overflow a buffer if `str` is not large enough
3751 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3752 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3753 * much more space than you expect to use (and don't forget null terminator
3754 * bytes, etc).
3755 *
3756 * \param value the unsigned long integer to convert.
3757 * \param str the buffer to write the string into.
3758 * \param radix the radix to use for string generation.
3759 * \returns `str`.
3760 *
3761 * \threadsafety It is safe to call this function from any thread.
3762 *
3763 * \since This function is available since SDL 3.2.0.
3764 *
3765 * \sa SDL_ltoa
3766 * \sa SDL_uitoa
3767 * \sa SDL_ulltoa
3768 */
3769extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
3770
3771#ifndef SDL_NOLONGLONG
3772
3773/**
3774 * Convert a long long integer into a string.
3775 *
3776 * This requires a radix to specified for string format. Specifying 10
3777 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3778 * to 36.
3779 *
3780 * Note that this function will overflow a buffer if `str` is not large enough
3781 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3782 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3783 * much more space than you expect to use (and don't forget possible negative
3784 * signs, null terminator bytes, etc).
3785 *
3786 * \param value the long long integer to convert.
3787 * \param str the buffer to write the string into.
3788 * \param radix the radix to use for string generation.
3789 * \returns `str`.
3790 *
3791 * \threadsafety It is safe to call this function from any thread.
3792 *
3793 * \since This function is available since SDL 3.2.0.
3794 *
3795 * \sa SDL_ulltoa
3796 * \sa SDL_itoa
3797 * \sa SDL_ltoa
3798 */
3799extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
3800
3801/**
3802 * Convert an unsigned long long integer into a string.
3803 *
3804 * This requires a radix to specified for string format. Specifying 10
3805 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3806 * to 36.
3807 *
3808 * Note that this function will overflow a buffer if `str` is not large enough
3809 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3810 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3811 * much more space than you expect to use (and don't forget null terminator
3812 * bytes, etc).
3813 *
3814 * \param value the unsigned long long integer to convert.
3815 * \param str the buffer to write the string into.
3816 * \param radix the radix to use for string generation.
3817 * \returns `str`.
3818 *
3819 * \threadsafety It is safe to call this function from any thread.
3820 *
3821 * \since This function is available since SDL 3.2.0.
3822 *
3823 * \sa SDL_lltoa
3824 * \sa SDL_uitoa
3825 * \sa SDL_ultoa
3826 */
3827extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
3828#endif
3829
3830/**
3831 * Parse an `int` from a string.
3832 *
3833 * The result of calling `SDL_atoi(str)` is equivalent to
3834 * `(int)SDL_strtol(str, NULL, 10)`.
3835 *
3836 * \param str The null-terminated string to read. Must not be NULL.
3837 * \returns the parsed `int`.
3838 *
3839 * \threadsafety It is safe to call this function from any thread.
3840 *
3841 * \since This function is available since SDL 3.2.0.
3842 *
3843 * \sa SDL_atof
3844 * \sa SDL_strtol
3845 * \sa SDL_strtoul
3846 * \sa SDL_strtoll
3847 * \sa SDL_strtoull
3848 * \sa SDL_strtod
3849 * \sa SDL_itoa
3850 */
3851extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
3852
3853/**
3854 * Parse a `double` from a string.
3855 *
3856 * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
3857 * NULL)`.
3858 *
3859 * \param str The null-terminated string to read. Must not be NULL.
3860 * \returns the parsed `double`.
3861 *
3862 * \threadsafety It is safe to call this function from any thread.
3863 *
3864 * \since This function is available since SDL 3.2.0.
3865 *
3866 * \sa SDL_atoi
3867 * \sa SDL_strtol
3868 * \sa SDL_strtoul
3869 * \sa SDL_strtoll
3870 * \sa SDL_strtoull
3871 * \sa SDL_strtod
3872 */
3873extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
3874
3875/**
3876 * Parse a `long` from a string.
3877 *
3878 * If `str` starts with whitespace, then those whitespace characters are
3879 * skipped before attempting to parse the number.
3880 *
3881 * If the parsed number does not fit inside a `long`, the result is clamped to
3882 * the minimum and maximum representable `long` values.
3883 *
3884 * \param str The null-terminated string to read. Must not be NULL.
3885 * \param endp If not NULL, the address of the first invalid character (i.e.
3886 * the next character after the parsed number) will be written to
3887 * this pointer.
3888 * \param base The base of the integer to read. Supported values are 0 and 2
3889 * to 36 inclusive. If 0, the base will be inferred from the
3890 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3891 * otherwise).
3892 * \returns the parsed `long`, or 0 if no number could be parsed.
3893 *
3894 * \threadsafety It is safe to call this function from any thread.
3895 *
3896 * \since This function is available since SDL 3.2.0.
3897 *
3898 * \sa SDL_atoi
3899 * \sa SDL_atof
3900 * \sa SDL_strtoul
3901 * \sa SDL_strtoll
3902 * \sa SDL_strtoull
3903 * \sa SDL_strtod
3904 * \sa SDL_ltoa
3905 * \sa SDL_wcstol
3906 */
3907extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
3908
3909/**
3910 * Parse an `unsigned long` from a string.
3911 *
3912 * If `str` starts with whitespace, then those whitespace characters are
3913 * skipped before attempting to parse the number.
3914 *
3915 * If the parsed number does not fit inside an `unsigned long`, the result is
3916 * clamped to the maximum representable `unsigned long` value.
3917 *
3918 * \param str The null-terminated string to read. Must not be NULL.
3919 * \param endp If not NULL, the address of the first invalid character (i.e.
3920 * the next character after the parsed number) will be written to
3921 * this pointer.
3922 * \param base The base of the integer to read. Supported values are 0 and 2
3923 * to 36 inclusive. If 0, the base will be inferred from the
3924 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3925 * otherwise).
3926 * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
3927 *
3928 * \threadsafety It is safe to call this function from any thread.
3929 *
3930 * \since This function is available since SDL 3.2.0.
3931 *
3932 * \sa SDL_atoi
3933 * \sa SDL_atof
3934 * \sa SDL_strtol
3935 * \sa SDL_strtoll
3936 * \sa SDL_strtoull
3937 * \sa SDL_strtod
3938 * \sa SDL_ultoa
3939 */
3940extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
3941
3942#ifndef SDL_NOLONGLONG
3943
3944/**
3945 * Parse a `long long` from a string.
3946 *
3947 * If `str` starts with whitespace, then those whitespace characters are
3948 * skipped before attempting to parse the number.
3949 *
3950 * If the parsed number does not fit inside a `long long`, the result is
3951 * clamped to the minimum and maximum representable `long long` values.
3952 *
3953 * \param str The null-terminated string to read. Must not be NULL.
3954 * \param endp If not NULL, the address of the first invalid character (i.e.
3955 * the next character after the parsed number) will be written to
3956 * this pointer.
3957 * \param base The base of the integer to read. Supported values are 0 and 2
3958 * to 36 inclusive. If 0, the base will be inferred from the
3959 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3960 * otherwise).
3961 * \returns the parsed `long long`, or 0 if no number could be parsed.
3962 *
3963 * \threadsafety It is safe to call this function from any thread.
3964 *
3965 * \since This function is available since SDL 3.2.0.
3966 *
3967 * \sa SDL_atoi
3968 * \sa SDL_atof
3969 * \sa SDL_strtol
3970 * \sa SDL_strtoul
3971 * \sa SDL_strtoull
3972 * \sa SDL_strtod
3973 * \sa SDL_lltoa
3974 */
3975extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
3976
3977/**
3978 * Parse an `unsigned long long` from a string.
3979 *
3980 * If `str` starts with whitespace, then those whitespace characters are
3981 * skipped before attempting to parse the number.
3982 *
3983 * If the parsed number does not fit inside an `unsigned long long`, the
3984 * result is clamped to the maximum representable `unsigned long long` value.
3985 *
3986 * \param str The null-terminated string to read. Must not be NULL.
3987 * \param endp If not NULL, the address of the first invalid character (i.e.
3988 * the next character after the parsed number) will be written to
3989 * this pointer.
3990 * \param base The base of the integer to read. Supported values are 0 and 2
3991 * to 36 inclusive. If 0, the base will be inferred from the
3992 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3993 * otherwise).
3994 * \returns the parsed `unsigned long long`, or 0 if no number could be
3995 * parsed.
3996 *
3997 * \threadsafety It is safe to call this function from any thread.
3998 *
3999 * \since This function is available since SDL 3.2.0.
4000 *
4001 * \sa SDL_atoi
4002 * \sa SDL_atof
4003 * \sa SDL_strtol
4004 * \sa SDL_strtoll
4005 * \sa SDL_strtoul
4006 * \sa SDL_strtod
4007 * \sa SDL_ulltoa
4008 */
4009extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
4010#endif
4011
4012/**
4013 * Parse a `double` from a string.
4014 *
4015 * This function makes fewer guarantees than the C runtime `strtod`:
4016 *
4017 * - Only decimal notation is guaranteed to be supported. The handling of
4018 * scientific and hexadecimal notation is unspecified.
4019 * - Whether or not INF and NAN can be parsed is unspecified.
4020 * - The precision of the result is unspecified.
4021 *
4022 * \param str the null-terminated string to read. Must not be NULL.
4023 * \param endp if not NULL, the address of the first invalid character (i.e.
4024 * the next character after the parsed number) will be written to
4025 * this pointer.
4026 * \returns the parsed `double`, or 0 if no number could be parsed.
4027 *
4028 * \threadsafety It is safe to call this function from any thread.
4029 *
4030 * \since This function is available since SDL 3.2.0.
4031 *
4032 * \sa SDL_atoi
4033 * \sa SDL_atof
4034 * \sa SDL_strtol
4035 * \sa SDL_strtoll
4036 * \sa SDL_strtoul
4037 * \sa SDL_strtoull
4038 */
4039extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
4040
4041/**
4042 * Compare two null-terminated UTF-8 strings.
4043 *
4044 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
4045 * since effectively this function just compares bytes until it hits a
4046 * null-terminating character. Also due to the nature of UTF-8, this can be
4047 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
4048 *
4049 * \param str1 the first string to compare. NULL is not permitted!
4050 * \param str2 the second string to compare. NULL is not permitted!
4051 * \returns less than zero if str1 is "less than" str2, greater than zero if
4052 * str1 is "greater than" str2, and zero if the strings match
4053 * exactly.
4054 *
4055 * \threadsafety It is safe to call this function from any thread.
4056 *
4057 * \since This function is available since SDL 3.2.0.
4058 */
4059extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
4060
4061/**
4062 * Compare two UTF-8 strings up to a number of bytes.
4063 *
4064 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
4065 * since effectively this function just compares bytes until it hits a
4066 * null-terminating character. Also due to the nature of UTF-8, this can be
4067 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
4068 *
4069 * Note that while this function is intended to be used with UTF-8, it is
4070 * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
4071 * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
4072 * compare a portion of the final character.
4073 *
4074 * `maxlen` specifies a maximum number of bytes to compare; if the strings
4075 * match to this number of bytes (or both have matched to a null-terminator
4076 * character before this number of bytes), they will be considered equal.
4077 *
4078 * \param str1 the first string to compare. NULL is not permitted!
4079 * \param str2 the second string to compare. NULL is not permitted!
4080 * \param maxlen the maximum number of _bytes_ to compare.
4081 * \returns less than zero if str1 is "less than" str2, greater than zero if
4082 * str1 is "greater than" str2, and zero if the strings match
4083 * exactly.
4084 *
4085 * \threadsafety It is safe to call this function from any thread.
4086 *
4087 * \since This function is available since SDL 3.2.0.
4088 */
4089extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
4090
4091/**
4092 * Compare two null-terminated UTF-8 strings, case-insensitively.
4093 *
4094 * This will work with Unicode strings, using a technique called
4095 * "case-folding" to handle the vast majority of case-sensitive human
4096 * languages regardless of system locale. It can deal with expanding values: a
4097 * German Eszett character can compare against two ASCII 's' chars and be
4098 * considered a match, for example. A notable exception: it does not handle
4099 * the Turkish 'i' character; human language is complicated!
4100 *
4101 * Since this handles Unicode, it expects the string to be well-formed UTF-8
4102 * and not a null-terminated string of arbitrary bytes. Bytes that are not
4103 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
4104 * CHARACTER), which is to say two strings of random bits may turn out to
4105 * match if they convert to the same amount of replacement characters.
4106 *
4107 * \param str1 the first string to compare. NULL is not permitted!
4108 * \param str2 the second string to compare. NULL is not permitted!
4109 * \returns less than zero if str1 is "less than" str2, greater than zero if
4110 * str1 is "greater than" str2, and zero if the strings match
4111 * exactly.
4112 *
4113 * \threadsafety It is safe to call this function from any thread.
4114 *
4115 * \since This function is available since SDL 3.2.0.
4116 */
4117extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
4118
4119
4120/**
4121 * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
4122 *
4123 * This will work with Unicode strings, using a technique called
4124 * "case-folding" to handle the vast majority of case-sensitive human
4125 * languages regardless of system locale. It can deal with expanding values: a
4126 * German Eszett character can compare against two ASCII 's' chars and be
4127 * considered a match, for example. A notable exception: it does not handle
4128 * the Turkish 'i' character; human language is complicated!
4129 *
4130 * Since this handles Unicode, it expects the string to be well-formed UTF-8
4131 * and not a null-terminated string of arbitrary bytes. Bytes that are not
4132 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
4133 * CHARACTER), which is to say two strings of random bits may turn out to
4134 * match if they convert to the same amount of replacement characters.
4135 *
4136 * Note that while this function is intended to be used with UTF-8, `maxlen`
4137 * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
4138 * UTF-8 sequence, it may convert a portion of the final character to one or
4139 * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
4140 * a buffer.
4141 *
4142 * `maxlen` specifies a maximum number of bytes to compare; if the strings
4143 * match to this number of bytes (or both have matched to a null-terminator
4144 * character before this number of bytes), they will be considered equal.
4145 *
4146 * \param str1 the first string to compare. NULL is not permitted!
4147 * \param str2 the second string to compare. NULL is not permitted!
4148 * \param maxlen the maximum number of bytes to compare.
4149 * \returns less than zero if str1 is "less than" str2, greater than zero if
4150 * str1 is "greater than" str2, and zero if the strings match
4151 * exactly.
4152 *
4153 * \threadsafety It is safe to call this function from any thread.
4154 *
4155 * \since This function is available since SDL 3.2.0.
4156 */
4157extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
4158
4159/**
4160 * Searches a string for the first occurrence of any character contained in a
4161 * breakset, and returns a pointer from the string to that character.
4162 *
4163 * \param str The null-terminated string to be searched. Must not be NULL, and
4164 * must not overlap with `breakset`.
4165 * \param breakset A null-terminated string containing the list of characters
4166 * to look for. Must not be NULL, and must not overlap with
4167 * `str`.
4168 * \returns A pointer to the location, in str, of the first occurrence of a
4169 * character present in the breakset, or NULL if none is found.
4170 *
4171 * \threadsafety It is safe to call this function from any thread.
4172 *
4173 * \since This function is available since SDL 3.2.0.
4174 */
4175extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
4176
4177/**
4178 * The Unicode REPLACEMENT CHARACTER codepoint.
4179 *
4180 * SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they
4181 * encounter a UTF-8 string with encoding errors.
4182 *
4183 * This tends to render as something like a question mark in most places.
4184 *
4185 * \since This macro is available since SDL 3.2.0.
4186 *
4187 * \sa SDL_StepBackUTF8
4188 * \sa SDL_StepUTF8
4189 */
4190#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
4191
4192/**
4193 * Decode a UTF-8 string, one Unicode codepoint at a time.
4194 *
4195 * This will return the first Unicode codepoint in the UTF-8 encoded string in
4196 * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
4197 *
4198 * It will not access more than `*pslen` bytes from the string. `*pslen` will
4199 * be adjusted, as well, subtracting the number of bytes consumed.
4200 *
4201 * `pslen` is allowed to be NULL, in which case the string _must_ be
4202 * NULL-terminated, as the function will blindly read until it sees the NULL
4203 * char.
4204 *
4205 * If `*pslen` is zero, it assumes the end of string is reached and returns a
4206 * zero codepoint regardless of the contents of the string buffer.
4207 *
4208 * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
4209 * zero, it will not advance `*pstr` or `*pslen` at all.
4210 *
4211 * Generally this function is called in a loop until it returns zero,
4212 * adjusting its parameters each iteration.
4213 *
4214 * If an invalid UTF-8 sequence is encountered, this function returns
4215 * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
4216 * (which is to say, a multibyte sequence might produce several
4217 * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
4218 * UTF-8 sequence).
4219 *
4220 * Several things can generate invalid UTF-8 sequences, including overlong
4221 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
4222 * refer to
4223 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
4224 * for details.
4225 *
4226 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
4227 * \param pslen a pointer to the number of bytes in the string, to be read and
4228 * adjusted. NULL is allowed.
4229 * \returns the first Unicode codepoint in the string.
4230 *
4231 * \threadsafety It is safe to call this function from any thread.
4232 *
4233 * \since This function is available since SDL 3.2.0.
4234 */
4235extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
4236
4237/**
4238 * Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
4239 *
4240 * This will go to the start of the previous Unicode codepoint in the string,
4241 * move `*pstr` to that location and return that codepoint.
4242 *
4243 * If `*pstr` is already at the start of the string), it will not advance
4244 * `*pstr` at all.
4245 *
4246 * Generally this function is called in a loop until it returns zero,
4247 * adjusting its parameter each iteration.
4248 *
4249 * If an invalid UTF-8 sequence is encountered, this function returns
4250 * SDL_INVALID_UNICODE_CODEPOINT.
4251 *
4252 * Several things can generate invalid UTF-8 sequences, including overlong
4253 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
4254 * refer to
4255 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
4256 * for details.
4257 *
4258 * \param start a pointer to the beginning of the UTF-8 string.
4259 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
4260 * \returns the previous Unicode codepoint in the string.
4261 *
4262 * \threadsafety It is safe to call this function from any thread.
4263 *
4264 * \since This function is available since SDL 3.2.0.
4265 */
4266extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr);
4267
4268/**
4269 * Convert a single Unicode codepoint to UTF-8.
4270 *
4271 * The buffer pointed to by `dst` must be at least 4 bytes long, as this
4272 * function may generate between 1 and 4 bytes of output.
4273 *
4274 * This function returns the first byte _after_ the newly-written UTF-8
4275 * sequence, which is useful for encoding multiple codepoints in a loop, or
4276 * knowing where to write a NULL-terminator character to end the string (in
4277 * either case, plan to have a buffer of _more_ than 4 bytes!).
4278 *
4279 * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
4280 * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
4281 * codepoint instead, and not set an error.
4282 *
4283 * If `dst` is NULL, this returns NULL immediately without writing to the
4284 * pointer and without setting an error.
4285 *
4286 * \param codepoint a Unicode codepoint to convert to UTF-8.
4287 * \param dst the location to write the encoded UTF-8. Must point to at least
4288 * 4 bytes!
4289 * \returns the first byte past the newly-written UTF-8 sequence.
4290 *
4291 * \threadsafety It is safe to call this function from any thread.
4292 *
4293 * \since This function is available since SDL 3.2.0.
4294 */
4295extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
4296
4297/**
4298 * This works exactly like sscanf() but doesn't require access to a C runtime.
4299 *
4300 * Scan a string, matching a format string, converting each '%' item and
4301 * storing it to pointers provided through variable arguments.
4302 *
4303 * \param text the string to scan. Must not be NULL.
4304 * \param fmt a printf-style format string. Must not be NULL.
4305 * \param ... a list of pointers to values to be filled in with scanned items.
4306 * \returns the number of items that matched the format string.
4307 *
4308 * \threadsafety It is safe to call this function from any thread.
4309 *
4310 * \since This function is available since SDL 3.2.0.
4311 */
4312extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
4313
4314/**
4315 * This works exactly like vsscanf() but doesn't require access to a C
4316 * runtime.
4317 *
4318 * Functions identically to SDL_sscanf(), except it takes a `va_list` instead
4319 * of using `...` variable arguments.
4320 *
4321 * \param text the string to scan. Must not be NULL.
4322 * \param fmt a printf-style format string. Must not be NULL.
4323 * \param ap a `va_list` of pointers to values to be filled in with scanned
4324 * items.
4325 * \returns the number of items that matched the format string.
4326 *
4327 * \threadsafety It is safe to call this function from any thread.
4328 *
4329 * \since This function is available since SDL 3.2.0.
4330 */
4331extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
4332
4333/**
4334 * This works exactly like snprintf() but doesn't require access to a C
4335 * runtime.
4336 *
4337 * Format a string of up to `maxlen`-1 bytes, converting each '%' item with
4338 * values provided through variable arguments.
4339 *
4340 * While some C runtimes differ on how to deal with too-large strings, this
4341 * function null-terminates the output, by treating the null-terminator as
4342 * part of the `maxlen` count. Note that if `maxlen` is zero, however, no
4343 * bytes will be written at all.
4344 *
4345 * This function returns the number of _bytes_ (not _characters_) that should
4346 * be written, excluding the null-terminator character. If this returns a
4347 * number >= `maxlen`, it means the output string was truncated. A negative
4348 * return value means an error occurred.
4349 *
4350 * Referencing the output string's pointer with a format item is undefined
4351 * behavior.
4352 *
4353 * \param text the buffer to write the string into. Must not be NULL.
4354 * \param maxlen the maximum bytes to write, including the null-terminator.
4355 * \param fmt a printf-style format string. Must not be NULL.
4356 * \param ... a list of values to be used with the format string.
4357 * \returns the number of bytes that should be written, not counting the
4358 * null-terminator char, or a negative value on error.
4359 *
4360 * \threadsafety It is safe to call this function from any thread.
4361 *
4362 * \since This function is available since SDL 3.2.0.
4363 */
4364extern SDL_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);
4365
4366/**
4367 * This works exactly like swprintf() but doesn't require access to a C
4368 * runtime.
4369 *
4370 * Format a wide string of up to `maxlen`-1 wchar_t values, converting each
4371 * '%' item with values provided through variable arguments.
4372 *
4373 * While some C runtimes differ on how to deal with too-large strings, this
4374 * function null-terminates the output, by treating the null-terminator as
4375 * part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide
4376 * characters will be written at all.
4377 *
4378 * This function returns the number of _wide characters_ (not _codepoints_)
4379 * that should be written, excluding the null-terminator character. If this
4380 * returns a number >= `maxlen`, it means the output string was truncated. A
4381 * negative return value means an error occurred.
4382 *
4383 * Referencing the output string's pointer with a format item is undefined
4384 * behavior.
4385 *
4386 * \param text the buffer to write the wide string into. Must not be NULL.
4387 * \param maxlen the maximum wchar_t values to write, including the
4388 * null-terminator.
4389 * \param fmt a printf-style format string. Must not be NULL.
4390 * \param ... a list of values to be used with the format string.
4391 * \returns the number of wide characters that should be written, not counting
4392 * the null-terminator char, or a negative value on error.
4393 *
4394 * \threadsafety It is safe to call this function from any thread.
4395 *
4396 * \since This function is available since SDL 3.2.0.
4397 */
4398extern SDL_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);
4399
4400/**
4401 * This works exactly like vsnprintf() but doesn't require access to a C
4402 * runtime.
4403 *
4404 * Functions identically to SDL_snprintf(), except it takes a `va_list`
4405 * instead of using `...` variable arguments.
4406 *
4407 * \param text the buffer to write the string into. Must not be NULL.
4408 * \param maxlen the maximum bytes to write, including the null-terminator.
4409 * \param fmt a printf-style format string. Must not be NULL.
4410 * \param ap a `va_list` values to be used with the format string.
4411 * \returns the number of bytes that should be written, not counting the
4412 * null-terminator char, or a negative value on error.
4413 *
4414 * \threadsafety It is safe to call this function from any thread.
4415 *
4416 * \since This function is available since SDL 3.2.0.
4417 */
4418extern SDL_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);
4419
4420/**
4421 * This works exactly like vswprintf() but doesn't require access to a C
4422 * runtime.
4423 *
4424 * Functions identically to SDL_swprintf(), except it takes a `va_list`
4425 * instead of using `...` variable arguments.
4426 *
4427 * \param text the buffer to write the string into. Must not be NULL.
4428 * \param maxlen the maximum wide characters to write, including the
4429 * null-terminator.
4430 * \param fmt a printf-style format wide string. Must not be NULL.
4431 * \param ap a `va_list` values to be used with the format string.
4432 * \returns the number of wide characters that should be written, not counting
4433 * the null-terminator char, or a negative value on error.
4434 *
4435 * \threadsafety It is safe to call this function from any thread.
4436 *
4437 * \since This function is available since SDL 3.2.0.
4438 */
4439extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3);
4440
4441/**
4442 * This works exactly like asprintf() but doesn't require access to a C
4443 * runtime.
4444 *
4445 * Functions identically to SDL_snprintf(), except it allocates a buffer large
4446 * enough to hold the output string on behalf of the caller.
4447 *
4448 * On success, this function returns the number of bytes (not characters)
4449 * comprising the output string, not counting the null-terminator character,
4450 * and sets `*strp` to the newly-allocated string.
4451 *
4452 * On error, this function returns a negative number, and the value of `*strp`
4453 * is undefined.
4454 *
4455 * The returned string is owned by the caller, and should be passed to
4456 * SDL_free when no longer needed.
4457 *
4458 * \param strp on output, is set to the new string. Must not be NULL.
4459 * \param fmt a printf-style format string. Must not be NULL.
4460 * \param ... a list of values to be used with the format string.
4461 * \returns the number of bytes in the newly-allocated string, not counting
4462 * the null-terminator char, or a negative value on error.
4463 *
4464 * \threadsafety It is safe to call this function from any thread.
4465 *
4466 * \since This function is available since SDL 3.2.0.
4467 */
4468extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
4469
4470/**
4471 * This works exactly like vasprintf() but doesn't require access to a C
4472 * runtime.
4473 *
4474 * Functions identically to SDL_asprintf(), except it takes a `va_list`
4475 * instead of using `...` variable arguments.
4476 *
4477 * \param strp on output, is set to the new string. Must not be NULL.
4478 * \param fmt a printf-style format string. Must not be NULL.
4479 * \param ap a `va_list` values to be used with the format string.
4480 * \returns the number of bytes in the newly-allocated string, not counting
4481 * the null-terminator char, or a negative value on error.
4482 *
4483 * \threadsafety It is safe to call this function from any thread.
4484 *
4485 * \since This function is available since SDL 3.2.0.
4486 */
4487extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
4488
4489/**
4490 * Seeds the pseudo-random number generator.
4491 *
4492 * Reusing the seed number will cause SDL_rand() to repeat the same stream of
4493 * 'random' numbers.
4494 *
4495 * \param seed the value to use as a random number seed, or 0 to use
4496 * SDL_GetPerformanceCounter().
4497 *
4498 * \threadsafety This should be called on the same thread that calls
4499 * SDL_rand()
4500 *
4501 * \since This function is available since SDL 3.2.0.
4502 *
4503 * \sa SDL_rand
4504 * \sa SDL_rand_bits
4505 * \sa SDL_randf
4506 */
4507extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
4508
4509/**
4510 * Generate a pseudo-random number less than n for positive n
4511 *
4512 * The method used is faster and of better quality than `rand() % n`. Odds are
4513 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
4514 * much worse as n gets bigger.
4515 *
4516 * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
4517 * 1..6
4518 *
4519 * If you want to generate a pseudo-random number in the full range of Sint32,
4520 * you should use: (Sint32)SDL_rand_bits()
4521 *
4522 * If you want reproducible output, be sure to initialize with SDL_srand()
4523 * first.
4524 *
4525 * There are no guarantees as to the quality of the random sequence produced,
4526 * and this should not be used for security (cryptography, passwords) or where
4527 * money is on the line (loot-boxes, casinos). There are many random number
4528 * libraries available with different characteristics and you should pick one
4529 * of those to meet any serious needs.
4530 *
4531 * \param n the number of possible outcomes. n must be positive.
4532 * \returns a random value in the range of [0 .. n-1].
4533 *
4534 * \threadsafety All calls should be made from a single thread
4535 *
4536 * \since This function is available since SDL 3.2.0.
4537 *
4538 * \sa SDL_srand
4539 * \sa SDL_randf
4540 */
4541extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
4542
4543/**
4544 * Generate a uniform pseudo-random floating point number less than 1.0
4545 *
4546 * If you want reproducible output, be sure to initialize with SDL_srand()
4547 * first.
4548 *
4549 * There are no guarantees as to the quality of the random sequence produced,
4550 * and this should not be used for security (cryptography, passwords) or where
4551 * money is on the line (loot-boxes, casinos). There are many random number
4552 * libraries available with different characteristics and you should pick one
4553 * of those to meet any serious needs.
4554 *
4555 * \returns a random value in the range of [0.0, 1.0).
4556 *
4557 * \threadsafety All calls should be made from a single thread
4558 *
4559 * \since This function is available since SDL 3.2.0.
4560 *
4561 * \sa SDL_srand
4562 * \sa SDL_rand
4563 */
4564extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
4565
4566/**
4567 * Generate 32 pseudo-random bits.
4568 *
4569 * You likely want to use SDL_rand() to get a pseudo-random number instead.
4570 *
4571 * There are no guarantees as to the quality of the random sequence produced,
4572 * and this should not be used for security (cryptography, passwords) or where
4573 * money is on the line (loot-boxes, casinos). There are many random number
4574 * libraries available with different characteristics and you should pick one
4575 * of those to meet any serious needs.
4576 *
4577 * \returns a random value in the range of [0-SDL_MAX_UINT32].
4578 *
4579 * \threadsafety All calls should be made from a single thread
4580 *
4581 * \since This function is available since SDL 3.2.0.
4582 *
4583 * \sa SDL_rand
4584 * \sa SDL_randf
4585 * \sa SDL_srand
4586 */
4587extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
4588
4589/**
4590 * Generate a pseudo-random number less than n for positive n
4591 *
4592 * The method used is faster and of better quality than `rand() % n`. Odds are
4593 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
4594 * much worse as n gets bigger.
4595 *
4596 * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
4597 * 0..5 to 1..6
4598 *
4599 * If you want to generate a pseudo-random number in the full range of Sint32,
4600 * you should use: (Sint32)SDL_rand_bits_r(state)
4601 *
4602 * There are no guarantees as to the quality of the random sequence produced,
4603 * and this should not be used for security (cryptography, passwords) or where
4604 * money is on the line (loot-boxes, casinos). There are many random number
4605 * libraries available with different characteristics and you should pick one
4606 * of those to meet any serious needs.
4607 *
4608 * \param state a pointer to the current random number state, this may not be
4609 * NULL.
4610 * \param n the number of possible outcomes. n must be positive.
4611 * \returns a random value in the range of [0 .. n-1].
4612 *
4613 * \threadsafety This function is thread-safe, as long as the state pointer
4614 * isn't shared between threads.
4615 *
4616 * \since This function is available since SDL 3.2.0.
4617 *
4618 * \sa SDL_rand
4619 * \sa SDL_rand_bits_r
4620 * \sa SDL_randf_r
4621 */
4622extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
4623
4624/**
4625 * Generate a uniform pseudo-random floating point number less than 1.0
4626 *
4627 * There are no guarantees as to the quality of the random sequence produced,
4628 * and this should not be used for security (cryptography, passwords) or where
4629 * money is on the line (loot-boxes, casinos). There are many random number
4630 * libraries available with different characteristics and you should pick one
4631 * of those to meet any serious needs.
4632 *
4633 * \param state a pointer to the current random number state, this may not be
4634 * NULL.
4635 * \returns a random value in the range of [0.0, 1.0).
4636 *
4637 * \threadsafety This function is thread-safe, as long as the state pointer
4638 * isn't shared between threads.
4639 *
4640 * \since This function is available since SDL 3.2.0.
4641 *
4642 * \sa SDL_rand_bits_r
4643 * \sa SDL_rand_r
4644 * \sa SDL_randf
4645 */
4646extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
4647
4648/**
4649 * Generate 32 pseudo-random bits.
4650 *
4651 * You likely want to use SDL_rand_r() to get a pseudo-random number instead.
4652 *
4653 * There are no guarantees as to the quality of the random sequence produced,
4654 * and this should not be used for security (cryptography, passwords) or where
4655 * money is on the line (loot-boxes, casinos). There are many random number
4656 * libraries available with different characteristics and you should pick one
4657 * of those to meet any serious needs.
4658 *
4659 * \param state a pointer to the current random number state, this may not be
4660 * NULL.
4661 * \returns a random value in the range of [0-SDL_MAX_UINT32].
4662 *
4663 * \threadsafety This function is thread-safe, as long as the state pointer
4664 * isn't shared between threads.
4665 *
4666 * \since This function is available since SDL 3.2.0.
4667 *
4668 * \sa SDL_rand_r
4669 * \sa SDL_randf_r
4670 */
4671extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
4672
4673#ifndef SDL_PI_D
4674
4675/**
4676 * The value of Pi, as a double-precision floating point literal.
4677 *
4678 * \since This macro is available since SDL 3.2.0.
4679 *
4680 * \sa SDL_PI_F
4681 */
4682#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
4683#endif
4684
4685#ifndef SDL_PI_F
4686
4687/**
4688 * The value of Pi, as a single-precision floating point literal.
4689 *
4690 * \since This macro is available since SDL 3.2.0.
4691 *
4692 * \sa SDL_PI_D
4693 */
4694#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
4695#endif
4696
4697/**
4698 * Compute the arc cosine of `x`.
4699 *
4700 * The definition of `y = acos(x)` is `x = cos(y)`.
4701 *
4702 * Domain: `-1 <= x <= 1`
4703 *
4704 * Range: `0 <= y <= Pi`
4705 *
4706 * This function operates on double-precision floating point values, use
4707 * SDL_acosf for single-precision floats.
4708 *
4709 * This function may use a different approximation across different versions,
4710 * platforms and configurations. i.e, it can return a different value given
4711 * the same input on different machines or operating systems, or if SDL is
4712 * updated.
4713 *
4714 * \param x floating point value.
4715 * \returns arc cosine of `x`, in radians.
4716 *
4717 * \threadsafety It is safe to call this function from any thread.
4718 *
4719 * \since This function is available since SDL 3.2.0.
4720 *
4721 * \sa SDL_acosf
4722 * \sa SDL_asin
4723 * \sa SDL_cos
4724 */
4725extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
4726
4727/**
4728 * Compute the arc cosine of `x`.
4729 *
4730 * The definition of `y = acos(x)` is `x = cos(y)`.
4731 *
4732 * Domain: `-1 <= x <= 1`
4733 *
4734 * Range: `0 <= y <= Pi`
4735 *
4736 * This function operates on single-precision floating point values, use
4737 * SDL_acos for double-precision floats.
4738 *
4739 * This function may use a different approximation across different versions,
4740 * platforms and configurations. i.e, it can return a different value given
4741 * the same input on different machines or operating systems, or if SDL is
4742 * updated.
4743 *
4744 * \param x floating point value.
4745 * \returns arc cosine of `x`, in radians.
4746 *
4747 * \threadsafety It is safe to call this function from any thread.
4748 *
4749 * \since This function is available since SDL 3.2.0.
4750 *
4751 * \sa SDL_acos
4752 * \sa SDL_asinf
4753 * \sa SDL_cosf
4754 */
4755extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
4756
4757/**
4758 * Compute the arc sine of `x`.
4759 *
4760 * The definition of `y = asin(x)` is `x = sin(y)`.
4761 *
4762 * Domain: `-1 <= x <= 1`
4763 *
4764 * Range: `-Pi/2 <= y <= Pi/2`
4765 *
4766 * This function operates on double-precision floating point values, use
4767 * SDL_asinf for single-precision floats.
4768 *
4769 * This function may use a different approximation across different versions,
4770 * platforms and configurations. i.e, it can return a different value given
4771 * the same input on different machines or operating systems, or if SDL is
4772 * updated.
4773 *
4774 * \param x floating point value.
4775 * \returns arc sine of `x`, in radians.
4776 *
4777 * \threadsafety It is safe to call this function from any thread.
4778 *
4779 * \since This function is available since SDL 3.2.0.
4780 *
4781 * \sa SDL_asinf
4782 * \sa SDL_acos
4783 * \sa SDL_sin
4784 */
4785extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
4786
4787/**
4788 * Compute the arc sine of `x`.
4789 *
4790 * The definition of `y = asin(x)` is `x = sin(y)`.
4791 *
4792 * Domain: `-1 <= x <= 1`
4793 *
4794 * Range: `-Pi/2 <= y <= Pi/2`
4795 *
4796 * This function operates on single-precision floating point values, use
4797 * SDL_asin for double-precision floats.
4798 *
4799 * This function may use a different approximation across different versions,
4800 * platforms and configurations. i.e, it can return a different value given
4801 * the same input on different machines or operating systems, or if SDL is
4802 * updated.
4803 *
4804 * \param x floating point value.
4805 * \returns arc sine of `x`, in radians.
4806 *
4807 * \threadsafety It is safe to call this function from any thread.
4808 *
4809 * \since This function is available since SDL 3.2.0.
4810 *
4811 * \sa SDL_asin
4812 * \sa SDL_acosf
4813 * \sa SDL_sinf
4814 */
4815extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
4816
4817/**
4818 * Compute the arc tangent of `x`.
4819 *
4820 * The definition of `y = atan(x)` is `x = tan(y)`.
4821 *
4822 * Domain: `-INF <= x <= INF`
4823 *
4824 * Range: `-Pi/2 <= y <= Pi/2`
4825 *
4826 * This function operates on double-precision floating point values, use
4827 * SDL_atanf for single-precision floats.
4828 *
4829 * To calculate the arc tangent of y / x, use SDL_atan2.
4830 *
4831 * This function may use a different approximation across different versions,
4832 * platforms and configurations. i.e, it can return a different value given
4833 * the same input on different machines or operating systems, or if SDL is
4834 * updated.
4835 *
4836 * \param x floating point value.
4837 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
4838 *
4839 * \threadsafety It is safe to call this function from any thread.
4840 *
4841 * \since This function is available since SDL 3.2.0.
4842 *
4843 * \sa SDL_atanf
4844 * \sa SDL_atan2
4845 * \sa SDL_tan
4846 */
4847extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
4848
4849/**
4850 * Compute the arc tangent of `x`.
4851 *
4852 * The definition of `y = atan(x)` is `x = tan(y)`.
4853 *
4854 * Domain: `-INF <= x <= INF`
4855 *
4856 * Range: `-Pi/2 <= y <= Pi/2`
4857 *
4858 * This function operates on single-precision floating point values, use
4859 * SDL_atan for dboule-precision floats.
4860 *
4861 * To calculate the arc tangent of y / x, use SDL_atan2f.
4862 *
4863 * This function may use a different approximation across different versions,
4864 * platforms and configurations. i.e, it can return a different value given
4865 * the same input on different machines or operating systems, or if SDL is
4866 * updated.
4867 *
4868 * \param x floating point value.
4869 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
4870 *
4871 * \threadsafety It is safe to call this function from any thread.
4872 *
4873 * \since This function is available since SDL 3.2.0.
4874 *
4875 * \sa SDL_atan
4876 * \sa SDL_atan2f
4877 * \sa SDL_tanf
4878 */
4879extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
4880
4881/**
4882 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
4883 * the result's quadrant.
4884 *
4885 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
4886 * of z is determined based on the signs of x and y.
4887 *
4888 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
4889 *
4890 * Range: `-Pi <= z <= Pi`
4891 *
4892 * This function operates on double-precision floating point values, use
4893 * SDL_atan2f for single-precision floats.
4894 *
4895 * To calculate the arc tangent of a single value, use SDL_atan.
4896 *
4897 * This function may use a different approximation across different versions,
4898 * platforms and configurations. i.e, it can return a different value given
4899 * the same input on different machines or operating systems, or if SDL is
4900 * updated.
4901 *
4902 * \param y floating point value of the numerator (y coordinate).
4903 * \param x floating point value of the denominator (x coordinate).
4904 * \returns arc tangent of `y / x` in radians, or, if `x = 0`, either `-Pi/2`,
4905 * `0`, or `Pi/2`, depending on the value of `y`.
4906 *
4907 * \threadsafety It is safe to call this function from any thread.
4908 *
4909 * \since This function is available since SDL 3.2.0.
4910 *
4911 * \sa SDL_atan2f
4912 * \sa SDL_atan
4913 * \sa SDL_tan
4914 */
4915extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
4916
4917/**
4918 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
4919 * the result's quadrant.
4920 *
4921 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
4922 * of z is determined based on the signs of x and y.
4923 *
4924 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
4925 *
4926 * Range: `-Pi <= y <= Pi`
4927 *
4928 * This function operates on single-precision floating point values, use
4929 * SDL_atan2 for double-precision floats.
4930 *
4931 * To calculate the arc tangent of a single value, use SDL_atanf.
4932 *
4933 * This function may use a different approximation across different versions,
4934 * platforms and configurations. i.e, it can return a different value given
4935 * the same input on different machines or operating systems, or if SDL is
4936 * updated.
4937 *
4938 * \param y floating point value of the numerator (y coordinate).
4939 * \param x floating point value of the denominator (x coordinate).
4940 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
4941 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
4942 *
4943 * \threadsafety It is safe to call this function from any thread.
4944 *
4945 * \since This function is available since SDL 3.2.0.
4946 *
4947 * \sa SDL_atan2
4948 * \sa SDL_atan
4949 * \sa SDL_tan
4950 */
4951extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
4952
4953/**
4954 * Compute the ceiling of `x`.
4955 *
4956 * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
4957 * rounded up to the nearest integer.
4958 *
4959 * Domain: `-INF <= x <= INF`
4960 *
4961 * Range: `-INF <= y <= INF`, y integer
4962 *
4963 * This function operates on double-precision floating point values, use
4964 * SDL_ceilf for single-precision floats.
4965 *
4966 * \param x floating point value.
4967 * \returns the ceiling of `x`.
4968 *
4969 * \threadsafety It is safe to call this function from any thread.
4970 *
4971 * \since This function is available since SDL 3.2.0.
4972 *
4973 * \sa SDL_ceilf
4974 * \sa SDL_floor
4975 * \sa SDL_trunc
4976 * \sa SDL_round
4977 * \sa SDL_lround
4978 */
4979extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
4980
4981/**
4982 * Compute the ceiling of `x`.
4983 *
4984 * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
4985 * rounded up to the nearest integer.
4986 *
4987 * Domain: `-INF <= x <= INF`
4988 *
4989 * Range: `-INF <= y <= INF`, y integer
4990 *
4991 * This function operates on single-precision floating point values, use
4992 * SDL_ceil for double-precision floats.
4993 *
4994 * \param x floating point value.
4995 * \returns the ceiling of `x`.
4996 *
4997 * \threadsafety It is safe to call this function from any thread.
4998 *
4999 * \since This function is available since SDL 3.2.0.
5000 *
5001 * \sa SDL_ceil
5002 * \sa SDL_floorf
5003 * \sa SDL_truncf
5004 * \sa SDL_roundf
5005 * \sa SDL_lroundf
5006 */
5007extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
5008
5009/**
5010 * Copy the sign of one floating-point value to another.
5011 *
5012 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
5013 *
5014 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
5015 *
5016 * Range: `-INF <= z <= INF`
5017 *
5018 * This function operates on double-precision floating point values, use
5019 * SDL_copysignf for single-precision floats.
5020 *
5021 * \param x floating point value to use as the magnitude.
5022 * \param y floating point value to use as the sign.
5023 * \returns the floating point value with the sign of y and the magnitude of
5024 * x.
5025 *
5026 * \threadsafety It is safe to call this function from any thread.
5027 *
5028 * \since This function is available since SDL 3.2.0.
5029 *
5030 * \sa SDL_copysignf
5031 * \sa SDL_fabs
5032 */
5033extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
5034
5035/**
5036 * Copy the sign of one floating-point value to another.
5037 *
5038 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
5039 *
5040 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
5041 *
5042 * Range: `-INF <= z <= INF`
5043 *
5044 * This function operates on single-precision floating point values, use
5045 * SDL_copysign for double-precision floats.
5046 *
5047 * \param x floating point value to use as the magnitude.
5048 * \param y floating point value to use as the sign.
5049 * \returns the floating point value with the sign of y and the magnitude of
5050 * x.
5051 *
5052 * \threadsafety It is safe to call this function from any thread.
5053 *
5054 * \since This function is available since SDL 3.2.0.
5055 *
5056 * \sa SDL_copysign
5057 * \sa SDL_fabsf
5058 */
5059extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
5060
5061/**
5062 * Compute the cosine of `x`.
5063 *
5064 * Domain: `-INF <= x <= INF`
5065 *
5066 * Range: `-1 <= y <= 1`
5067 *
5068 * This function operates on double-precision floating point values, use
5069 * SDL_cosf for single-precision floats.
5070 *
5071 * This function may use a different approximation across different versions,
5072 * platforms and configurations. i.e, it can return a different value given
5073 * the same input on different machines or operating systems, or if SDL is
5074 * updated.
5075 *
5076 * \param x floating point value, in radians.
5077 * \returns cosine of `x`.
5078 *
5079 * \threadsafety It is safe to call this function from any thread.
5080 *
5081 * \since This function is available since SDL 3.2.0.
5082 *
5083 * \sa SDL_cosf
5084 * \sa SDL_acos
5085 * \sa SDL_sin
5086 */
5087extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
5088
5089/**
5090 * Compute the cosine of `x`.
5091 *
5092 * Domain: `-INF <= x <= INF`
5093 *
5094 * Range: `-1 <= y <= 1`
5095 *
5096 * This function operates on single-precision floating point values, use
5097 * SDL_cos for double-precision floats.
5098 *
5099 * This function may use a different approximation across different versions,
5100 * platforms and configurations. i.e, it can return a different value given
5101 * the same input on different machines or operating systems, or if SDL is
5102 * updated.
5103 *
5104 * \param x floating point value, in radians.
5105 * \returns cosine of `x`.
5106 *
5107 * \threadsafety It is safe to call this function from any thread.
5108 *
5109 * \since This function is available since SDL 3.2.0.
5110 *
5111 * \sa SDL_cos
5112 * \sa SDL_acosf
5113 * \sa SDL_sinf
5114 */
5115extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
5116
5117/**
5118 * Compute the exponential of `x`.
5119 *
5120 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
5121 * natural logarithm. The inverse is the natural logarithm, SDL_log.
5122 *
5123 * Domain: `-INF <= x <= INF`
5124 *
5125 * Range: `0 <= y <= INF`
5126 *
5127 * The output will overflow if `exp(x)` is too large to be represented.
5128 *
5129 * This function operates on double-precision floating point values, use
5130 * SDL_expf for single-precision floats.
5131 *
5132 * This function may use a different approximation across different versions,
5133 * platforms and configurations. i.e, it can return a different value given
5134 * the same input on different machines or operating systems, or if SDL is
5135 * updated.
5136 *
5137 * \param x floating point value.
5138 * \returns value of `e^x`.
5139 *
5140 * \threadsafety It is safe to call this function from any thread.
5141 *
5142 * \since This function is available since SDL 3.2.0.
5143 *
5144 * \sa SDL_expf
5145 * \sa SDL_log
5146 */
5147extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
5148
5149/**
5150 * Compute the exponential of `x`.
5151 *
5152 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
5153 * natural logarithm. The inverse is the natural logarithm, SDL_logf.
5154 *
5155 * Domain: `-INF <= x <= INF`
5156 *
5157 * Range: `0 <= y <= INF`
5158 *
5159 * The output will overflow if `exp(x)` is too large to be represented.
5160 *
5161 * This function operates on single-precision floating point values, use
5162 * SDL_exp for double-precision floats.
5163 *
5164 * This function may use a different approximation across different versions,
5165 * platforms and configurations. i.e, it can return a different value given
5166 * the same input on different machines or operating systems, or if SDL is
5167 * updated.
5168 *
5169 * \param x floating point value.
5170 * \returns value of `e^x`.
5171 *
5172 * \threadsafety It is safe to call this function from any thread.
5173 *
5174 * \since This function is available since SDL 3.2.0.
5175 *
5176 * \sa SDL_exp
5177 * \sa SDL_logf
5178 */
5179extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
5180
5181/**
5182 * Compute the absolute value of `x`
5183 *
5184 * Domain: `-INF <= x <= INF`
5185 *
5186 * Range: `0 <= y <= INF`
5187 *
5188 * This function operates on double-precision floating point values, use
5189 * SDL_fabsf for single-precision floats.
5190 *
5191 * \param x floating point value to use as the magnitude.
5192 * \returns the absolute value of `x`.
5193 *
5194 * \threadsafety It is safe to call this function from any thread.
5195 *
5196 * \since This function is available since SDL 3.2.0.
5197 *
5198 * \sa SDL_fabsf
5199 */
5200extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
5201
5202/**
5203 * Compute the absolute value of `x`
5204 *
5205 * Domain: `-INF <= x <= INF`
5206 *
5207 * Range: `0 <= y <= INF`
5208 *
5209 * This function operates on single-precision floating point values, use
5210 * SDL_fabs for double-precision floats.
5211 *
5212 * \param x floating point value to use as the magnitude.
5213 * \returns the absolute value of `x`.
5214 *
5215 * \threadsafety It is safe to call this function from any thread.
5216 *
5217 * \since This function is available since SDL 3.2.0.
5218 *
5219 * \sa SDL_fabs
5220 */
5221extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
5222
5223/**
5224 * Compute the floor of `x`.
5225 *
5226 * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
5227 * rounded down to the nearest integer.
5228 *
5229 * Domain: `-INF <= x <= INF`
5230 *
5231 * Range: `-INF <= y <= INF`, y integer
5232 *
5233 * This function operates on double-precision floating point values, use
5234 * SDL_floorf for single-precision floats.
5235 *
5236 * \param x floating point value.
5237 * \returns the floor of `x`.
5238 *
5239 * \threadsafety It is safe to call this function from any thread.
5240 *
5241 * \since This function is available since SDL 3.2.0.
5242 *
5243 * \sa SDL_floorf
5244 * \sa SDL_ceil
5245 * \sa SDL_trunc
5246 * \sa SDL_round
5247 * \sa SDL_lround
5248 */
5249extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
5250
5251/**
5252 * Compute the floor of `x`.
5253 *
5254 * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
5255 * rounded down to the nearest integer.
5256 *
5257 * Domain: `-INF <= x <= INF`
5258 *
5259 * Range: `-INF <= y <= INF`, y integer
5260 *
5261 * This function operates on single-precision floating point values, use
5262 * SDL_floor for double-precision floats.
5263 *
5264 * \param x floating point value.
5265 * \returns the floor of `x`.
5266 *
5267 * \threadsafety It is safe to call this function from any thread.
5268 *
5269 * \since This function is available since SDL 3.2.0.
5270 *
5271 * \sa SDL_floor
5272 * \sa SDL_ceilf
5273 * \sa SDL_truncf
5274 * \sa SDL_roundf
5275 * \sa SDL_lroundf
5276 */
5277extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
5278
5279/**
5280 * Truncate `x` to an integer.
5281 *
5282 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
5283 * the fractional part of `x`, leaving only the integer part.
5284 *
5285 * Domain: `-INF <= x <= INF`
5286 *
5287 * Range: `-INF <= y <= INF`, y integer
5288 *
5289 * This function operates on double-precision floating point values, use
5290 * SDL_truncf for single-precision floats.
5291 *
5292 * \param x floating point value.
5293 * \returns `x` truncated to an integer.
5294 *
5295 * \threadsafety It is safe to call this function from any thread.
5296 *
5297 * \since This function is available since SDL 3.2.0.
5298 *
5299 * \sa SDL_truncf
5300 * \sa SDL_fmod
5301 * \sa SDL_ceil
5302 * \sa SDL_floor
5303 * \sa SDL_round
5304 * \sa SDL_lround
5305 */
5306extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
5307
5308/**
5309 * Truncate `x` to an integer.
5310 *
5311 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
5312 * the fractional part of `x`, leaving only the integer part.
5313 *
5314 * Domain: `-INF <= x <= INF`
5315 *
5316 * Range: `-INF <= y <= INF`, y integer
5317 *
5318 * This function operates on single-precision floating point values, use
5319 * SDL_trunc for double-precision floats.
5320 *
5321 * \param x floating point value.
5322 * \returns `x` truncated to an integer.
5323 *
5324 * \threadsafety It is safe to call this function from any thread.
5325 *
5326 * \since This function is available since SDL 3.2.0.
5327 *
5328 * \sa SDL_trunc
5329 * \sa SDL_fmodf
5330 * \sa SDL_ceilf
5331 * \sa SDL_floorf
5332 * \sa SDL_roundf
5333 * \sa SDL_lroundf
5334 */
5335extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
5336
5337/**
5338 * Return the floating-point remainder of `x / y`
5339 *
5340 * Divides `x` by `y`, and returns the remainder.
5341 *
5342 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
5343 *
5344 * Range: `-y <= z <= y`
5345 *
5346 * This function operates on double-precision floating point values, use
5347 * SDL_fmodf for single-precision floats.
5348 *
5349 * \param x the numerator.
5350 * \param y the denominator. Must not be 0.
5351 * \returns the remainder of `x / y`.
5352 *
5353 * \threadsafety It is safe to call this function from any thread.
5354 *
5355 * \since This function is available since SDL 3.2.0.
5356 *
5357 * \sa SDL_fmodf
5358 * \sa SDL_modf
5359 * \sa SDL_trunc
5360 * \sa SDL_ceil
5361 * \sa SDL_floor
5362 * \sa SDL_round
5363 * \sa SDL_lround
5364 */
5365extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
5366
5367/**
5368 * Return the floating-point remainder of `x / y`
5369 *
5370 * Divides `x` by `y`, and returns the remainder.
5371 *
5372 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
5373 *
5374 * Range: `-y <= z <= y`
5375 *
5376 * This function operates on single-precision floating point values, use
5377 * SDL_fmod for double-precision floats.
5378 *
5379 * \param x the numerator.
5380 * \param y the denominator. Must not be 0.
5381 * \returns the remainder of `x / y`.
5382 *
5383 * \threadsafety It is safe to call this function from any thread.
5384 *
5385 * \since This function is available since SDL 3.2.0.
5386 *
5387 * \sa SDL_fmod
5388 * \sa SDL_truncf
5389 * \sa SDL_modff
5390 * \sa SDL_ceilf
5391 * \sa SDL_floorf
5392 * \sa SDL_roundf
5393 * \sa SDL_lroundf
5394 */
5395extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
5396
5397/**
5398 * Return whether the value is infinity.
5399 *
5400 * \param x double-precision floating point value.
5401 * \returns non-zero if the value is infinity, 0 otherwise.
5402 *
5403 * \threadsafety It is safe to call this function from any thread.
5404 *
5405 * \since This function is available since SDL 3.2.0.
5406 *
5407 * \sa SDL_isinff
5408 */
5409extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
5410
5411/**
5412 * Return whether the value is infinity.
5413 *
5414 * \param x floating point value.
5415 * \returns non-zero if the value is infinity, 0 otherwise.
5416 *
5417 * \threadsafety It is safe to call this function from any thread.
5418 *
5419 * \since This function is available since SDL 3.2.0.
5420 *
5421 * \sa SDL_isinf
5422 */
5423extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
5424
5425/**
5426 * Return whether the value is NaN.
5427 *
5428 * \param x double-precision floating point value.
5429 * \returns non-zero if the value is NaN, 0 otherwise.
5430 *
5431 * \threadsafety It is safe to call this function from any thread.
5432 *
5433 * \since This function is available since SDL 3.2.0.
5434 *
5435 * \sa SDL_isnanf
5436 */
5437extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
5438
5439/**
5440 * Return whether the value is NaN.
5441 *
5442 * \param x floating point value.
5443 * \returns non-zero if the value is NaN, 0 otherwise.
5444 *
5445 * \threadsafety It is safe to call this function from any thread.
5446 *
5447 * \since This function is available since SDL 3.2.0.
5448 *
5449 * \sa SDL_isnan
5450 */
5451extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
5452
5453/**
5454 * Compute the natural logarithm of `x`.
5455 *
5456 * Domain: `0 < x <= INF`
5457 *
5458 * Range: `-INF <= y <= INF`
5459 *
5460 * It is an error for `x` to be less than or equal to 0.
5461 *
5462 * This function operates on double-precision floating point values, use
5463 * SDL_logf for single-precision floats.
5464 *
5465 * This function may use a different approximation across different versions,
5466 * platforms and configurations. i.e, it can return a different value given
5467 * the same input on different machines or operating systems, or if SDL is
5468 * updated.
5469 *
5470 * \param x floating point value. Must be greater than 0.
5471 * \returns the natural logarithm of `x`.
5472 *
5473 * \threadsafety It is safe to call this function from any thread.
5474 *
5475 * \since This function is available since SDL 3.2.0.
5476 *
5477 * \sa SDL_logf
5478 * \sa SDL_log10
5479 * \sa SDL_exp
5480 */
5481extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
5482
5483/**
5484 * Compute the natural logarithm of `x`.
5485 *
5486 * Domain: `0 < x <= INF`
5487 *
5488 * Range: `-INF <= y <= INF`
5489 *
5490 * It is an error for `x` to be less than or equal to 0.
5491 *
5492 * This function operates on single-precision floating point values, use
5493 * SDL_log for double-precision floats.
5494 *
5495 * This function may use a different approximation across different versions,
5496 * platforms and configurations. i.e, it can return a different value given
5497 * the same input on different machines or operating systems, or if SDL is
5498 * updated.
5499 *
5500 * \param x floating point value. Must be greater than 0.
5501 * \returns the natural logarithm of `x`.
5502 *
5503 * \threadsafety It is safe to call this function from any thread.
5504 *
5505 * \since This function is available since SDL 3.2.0.
5506 *
5507 * \sa SDL_log
5508 * \sa SDL_expf
5509 */
5510extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
5511
5512/**
5513 * Compute the base-10 logarithm of `x`.
5514 *
5515 * Domain: `0 < x <= INF`
5516 *
5517 * Range: `-INF <= y <= INF`
5518 *
5519 * It is an error for `x` to be less than or equal to 0.
5520 *
5521 * This function operates on double-precision floating point values, use
5522 * SDL_log10f for single-precision floats.
5523 *
5524 * This function may use a different approximation across different versions,
5525 * platforms and configurations. i.e, it can return a different value given
5526 * the same input on different machines or operating systems, or if SDL is
5527 * updated.
5528 *
5529 * \param x floating point value. Must be greater than 0.
5530 * \returns the logarithm of `x`.
5531 *
5532 * \threadsafety It is safe to call this function from any thread.
5533 *
5534 * \since This function is available since SDL 3.2.0.
5535 *
5536 * \sa SDL_log10f
5537 * \sa SDL_log
5538 * \sa SDL_pow
5539 */
5540extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
5541
5542/**
5543 * Compute the base-10 logarithm of `x`.
5544 *
5545 * Domain: `0 < x <= INF`
5546 *
5547 * Range: `-INF <= y <= INF`
5548 *
5549 * It is an error for `x` to be less than or equal to 0.
5550 *
5551 * This function operates on single-precision floating point values, use
5552 * SDL_log10 for double-precision floats.
5553 *
5554 * This function may use a different approximation across different versions,
5555 * platforms and configurations. i.e, it can return a different value given
5556 * the same input on different machines or operating systems, or if SDL is
5557 * updated.
5558 *
5559 * \param x floating point value. Must be greater than 0.
5560 * \returns the logarithm of `x`.
5561 *
5562 * \threadsafety It is safe to call this function from any thread.
5563 *
5564 * \since This function is available since SDL 3.2.0.
5565 *
5566 * \sa SDL_log10
5567 * \sa SDL_logf
5568 * \sa SDL_powf
5569 */
5570extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
5571
5572/**
5573 * Split `x` into integer and fractional parts
5574 *
5575 * This function operates on double-precision floating point values, use
5576 * SDL_modff for single-precision floats.
5577 *
5578 * \param x floating point value.
5579 * \param y output pointer to store the integer part of `x`.
5580 * \returns the fractional part of `x`.
5581 *
5582 * \threadsafety It is safe to call this function from any thread.
5583 *
5584 * \since This function is available since SDL 3.2.0.
5585 *
5586 * \sa SDL_modff
5587 * \sa SDL_trunc
5588 * \sa SDL_fmod
5589 */
5590extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
5591
5592/**
5593 * Split `x` into integer and fractional parts
5594 *
5595 * This function operates on single-precision floating point values, use
5596 * SDL_modf for double-precision floats.
5597 *
5598 * \param x floating point value.
5599 * \param y output pointer to store the integer part of `x`.
5600 * \returns the fractional part of `x`.
5601 *
5602 * \threadsafety It is safe to call this function from any thread.
5603 *
5604 * \since This function is available since SDL 3.2.0.
5605 *
5606 * \sa SDL_modf
5607 * \sa SDL_truncf
5608 * \sa SDL_fmodf
5609 */
5610extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
5611
5612/**
5613 * Raise `x` to the power `y`
5614 *
5615 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
5616 *
5617 * Range: `-INF <= z <= INF`
5618 *
5619 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
5620 * instead.
5621 *
5622 * This function operates on double-precision floating point values, use
5623 * SDL_powf for single-precision floats.
5624 *
5625 * This function may use a different approximation across different versions,
5626 * platforms and configurations. i.e, it can return a different value given
5627 * the same input on different machines or operating systems, or if SDL is
5628 * updated.
5629 *
5630 * \param x the base.
5631 * \param y the exponent.
5632 * \returns `x` raised to the power `y`.
5633 *
5634 * \threadsafety It is safe to call this function from any thread.
5635 *
5636 * \since This function is available since SDL 3.2.0.
5637 *
5638 * \sa SDL_powf
5639 * \sa SDL_exp
5640 * \sa SDL_log
5641 */
5642extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
5643
5644/**
5645 * Raise `x` to the power `y`
5646 *
5647 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
5648 *
5649 * Range: `-INF <= z <= INF`
5650 *
5651 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
5652 * instead.
5653 *
5654 * This function operates on single-precision floating point values, use
5655 * SDL_pow for double-precision floats.
5656 *
5657 * This function may use a different approximation across different versions,
5658 * platforms and configurations. i.e, it can return a different value given
5659 * the same input on different machines or operating systems, or if SDL is
5660 * updated.
5661 *
5662 * \param x the base.
5663 * \param y the exponent.
5664 * \returns `x` raised to the power `y`.
5665 *
5666 * \threadsafety It is safe to call this function from any thread.
5667 *
5668 * \since This function is available since SDL 3.2.0.
5669 *
5670 * \sa SDL_pow
5671 * \sa SDL_expf
5672 * \sa SDL_logf
5673 */
5674extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
5675
5676/**
5677 * Round `x` to the nearest integer.
5678 *
5679 * Rounds `x` to the nearest integer. Values halfway between integers will be
5680 * rounded away from zero.
5681 *
5682 * Domain: `-INF <= x <= INF`
5683 *
5684 * Range: `-INF <= y <= INF`, y integer
5685 *
5686 * This function operates on double-precision floating point values, use
5687 * SDL_roundf for single-precision floats. To get the result as an integer
5688 * type, use SDL_lround.
5689 *
5690 * \param x floating point value.
5691 * \returns the nearest integer to `x`.
5692 *
5693 * \threadsafety It is safe to call this function from any thread.
5694 *
5695 * \since This function is available since SDL 3.2.0.
5696 *
5697 * \sa SDL_roundf
5698 * \sa SDL_lround
5699 * \sa SDL_floor
5700 * \sa SDL_ceil
5701 * \sa SDL_trunc
5702 */
5703extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
5704
5705/**
5706 * Round `x` to the nearest integer.
5707 *
5708 * Rounds `x` to the nearest integer. Values halfway between integers will be
5709 * rounded away from zero.
5710 *
5711 * Domain: `-INF <= x <= INF`
5712 *
5713 * Range: `-INF <= y <= INF`, y integer
5714 *
5715 * This function operates on single-precision floating point values, use
5716 * SDL_round for double-precision floats. To get the result as an integer
5717 * type, use SDL_lroundf.
5718 *
5719 * \param x floating point value.
5720 * \returns the nearest integer to `x`.
5721 *
5722 * \threadsafety It is safe to call this function from any thread.
5723 *
5724 * \since This function is available since SDL 3.2.0.
5725 *
5726 * \sa SDL_round
5727 * \sa SDL_lroundf
5728 * \sa SDL_floorf
5729 * \sa SDL_ceilf
5730 * \sa SDL_truncf
5731 */
5732extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
5733
5734/**
5735 * Round `x` to the nearest integer representable as a long
5736 *
5737 * Rounds `x` to the nearest integer. Values halfway between integers will be
5738 * rounded away from zero.
5739 *
5740 * Domain: `-INF <= x <= INF`
5741 *
5742 * Range: `MIN_LONG <= y <= MAX_LONG`
5743 *
5744 * This function operates on double-precision floating point values, use
5745 * SDL_lroundf for single-precision floats. To get the result as a
5746 * floating-point type, use SDL_round.
5747 *
5748 * \param x floating point value.
5749 * \returns the nearest integer to `x`.
5750 *
5751 * \threadsafety It is safe to call this function from any thread.
5752 *
5753 * \since This function is available since SDL 3.2.0.
5754 *
5755 * \sa SDL_lroundf
5756 * \sa SDL_round
5757 * \sa SDL_floor
5758 * \sa SDL_ceil
5759 * \sa SDL_trunc
5760 */
5761extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
5762
5763/**
5764 * Round `x` to the nearest integer representable as a long
5765 *
5766 * Rounds `x` to the nearest integer. Values halfway between integers will be
5767 * rounded away from zero.
5768 *
5769 * Domain: `-INF <= x <= INF`
5770 *
5771 * Range: `MIN_LONG <= y <= MAX_LONG`
5772 *
5773 * This function operates on single-precision floating point values, use
5774 * SDL_lround for double-precision floats. To get the result as a
5775 * floating-point type, use SDL_roundf.
5776 *
5777 * \param x floating point value.
5778 * \returns the nearest integer to `x`.
5779 *
5780 * \threadsafety It is safe to call this function from any thread.
5781 *
5782 * \since This function is available since SDL 3.2.0.
5783 *
5784 * \sa SDL_lround
5785 * \sa SDL_roundf
5786 * \sa SDL_floorf
5787 * \sa SDL_ceilf
5788 * \sa SDL_truncf
5789 */
5790extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
5791
5792/**
5793 * Scale `x` by an integer power of two.
5794 *
5795 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
5796 *
5797 * Domain: `-INF <= x <= INF`, `n` integer
5798 *
5799 * Range: `-INF <= y <= INF`
5800 *
5801 * This function operates on double-precision floating point values, use
5802 * SDL_scalbnf for single-precision floats.
5803 *
5804 * \param x floating point value to be scaled.
5805 * \param n integer exponent.
5806 * \returns `x * 2^n`.
5807 *
5808 * \threadsafety It is safe to call this function from any thread.
5809 *
5810 * \since This function is available since SDL 3.2.0.
5811 *
5812 * \sa SDL_scalbnf
5813 * \sa SDL_pow
5814 */
5815extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
5816
5817/**
5818 * Scale `x` by an integer power of two.
5819 *
5820 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
5821 *
5822 * Domain: `-INF <= x <= INF`, `n` integer
5823 *
5824 * Range: `-INF <= y <= INF`
5825 *
5826 * This function operates on single-precision floating point values, use
5827 * SDL_scalbn for double-precision floats.
5828 *
5829 * \param x floating point value to be scaled.
5830 * \param n integer exponent.
5831 * \returns `x * 2^n`.
5832 *
5833 * \threadsafety It is safe to call this function from any thread.
5834 *
5835 * \since This function is available since SDL 3.2.0.
5836 *
5837 * \sa SDL_scalbn
5838 * \sa SDL_powf
5839 */
5840extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
5841
5842/**
5843 * Compute the sine of `x`.
5844 *
5845 * Domain: `-INF <= x <= INF`
5846 *
5847 * Range: `-1 <= y <= 1`
5848 *
5849 * This function operates on double-precision floating point values, use
5850 * SDL_sinf for single-precision floats.
5851 *
5852 * This function may use a different approximation across different versions,
5853 * platforms and configurations. i.e, it can return a different value given
5854 * the same input on different machines or operating systems, or if SDL is
5855 * updated.
5856 *
5857 * \param x floating point value, in radians.
5858 * \returns sine of `x`.
5859 *
5860 * \threadsafety It is safe to call this function from any thread.
5861 *
5862 * \since This function is available since SDL 3.2.0.
5863 *
5864 * \sa SDL_sinf
5865 * \sa SDL_asin
5866 * \sa SDL_cos
5867 */
5868extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
5869
5870/**
5871 * Compute the sine of `x`.
5872 *
5873 * Domain: `-INF <= x <= INF`
5874 *
5875 * Range: `-1 <= y <= 1`
5876 *
5877 * This function operates on single-precision floating point values, use
5878 * SDL_sin for double-precision floats.
5879 *
5880 * This function may use a different approximation across different versions,
5881 * platforms and configurations. i.e, it can return a different value given
5882 * the same input on different machines or operating systems, or if SDL is
5883 * updated.
5884 *
5885 * \param x floating point value, in radians.
5886 * \returns sine of `x`.
5887 *
5888 * \threadsafety It is safe to call this function from any thread.
5889 *
5890 * \since This function is available since SDL 3.2.0.
5891 *
5892 * \sa SDL_sin
5893 * \sa SDL_asinf
5894 * \sa SDL_cosf
5895 */
5896extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
5897
5898/**
5899 * Compute the square root of `x`.
5900 *
5901 * Domain: `0 <= x <= INF`
5902 *
5903 * Range: `0 <= y <= INF`
5904 *
5905 * This function operates on double-precision floating point values, use
5906 * SDL_sqrtf for single-precision floats.
5907 *
5908 * This function may use a different approximation across different versions,
5909 * platforms and configurations. i.e, it can return a different value given
5910 * the same input on different machines or operating systems, or if SDL is
5911 * updated.
5912 *
5913 * \param x floating point value. Must be greater than or equal to 0.
5914 * \returns square root of `x`.
5915 *
5916 * \threadsafety It is safe to call this function from any thread.
5917 *
5918 * \since This function is available since SDL 3.2.0.
5919 *
5920 * \sa SDL_sqrtf
5921 */
5922extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
5923
5924/**
5925 * Compute the square root of `x`.
5926 *
5927 * Domain: `0 <= x <= INF`
5928 *
5929 * Range: `0 <= y <= INF`
5930 *
5931 * This function operates on single-precision floating point values, use
5932 * SDL_sqrt for double-precision floats.
5933 *
5934 * This function may use a different approximation across different versions,
5935 * platforms and configurations. i.e, it can return a different value given
5936 * the same input on different machines or operating systems, or if SDL is
5937 * updated.
5938 *
5939 * \param x floating point value. Must be greater than or equal to 0.
5940 * \returns square root of `x`.
5941 *
5942 * \threadsafety It is safe to call this function from any thread.
5943 *
5944 * \since This function is available since SDL 3.2.0.
5945 *
5946 * \sa SDL_sqrt
5947 */
5948extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
5949
5950/**
5951 * Compute the tangent of `x`.
5952 *
5953 * Domain: `-INF <= x <= INF`
5954 *
5955 * Range: `-INF <= y <= INF`
5956 *
5957 * This function operates on double-precision floating point values, use
5958 * SDL_tanf for single-precision floats.
5959 *
5960 * This function may use a different approximation across different versions,
5961 * platforms and configurations. i.e, it can return a different value given
5962 * the same input on different machines or operating systems, or if SDL is
5963 * updated.
5964 *
5965 * \param x floating point value, in radians.
5966 * \returns tangent of `x`.
5967 *
5968 * \threadsafety It is safe to call this function from any thread.
5969 *
5970 * \since This function is available since SDL 3.2.0.
5971 *
5972 * \sa SDL_tanf
5973 * \sa SDL_sin
5974 * \sa SDL_cos
5975 * \sa SDL_atan
5976 * \sa SDL_atan2
5977 */
5978extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
5979
5980/**
5981 * Compute the tangent of `x`.
5982 *
5983 * Domain: `-INF <= x <= INF`
5984 *
5985 * Range: `-INF <= y <= INF`
5986 *
5987 * This function operates on single-precision floating point values, use
5988 * SDL_tan for double-precision floats.
5989 *
5990 * This function may use a different approximation across different versions,
5991 * platforms and configurations. i.e, it can return a different value given
5992 * the same input on different machines or operating systems, or if SDL is
5993 * updated.
5994 *
5995 * \param x floating point value, in radians.
5996 * \returns tangent of `x`.
5997 *
5998 * \threadsafety It is safe to call this function from any thread.
5999 *
6000 * \since This function is available since SDL 3.2.0.
6001 *
6002 * \sa SDL_tan
6003 * \sa SDL_sinf
6004 * \sa SDL_cosf
6005 * \sa SDL_atanf
6006 * \sa SDL_atan2f
6007 */
6008extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
6009
6010/**
6011 * An opaque handle representing string encoding conversion state.
6012 *
6013 * \since This datatype is available since SDL 3.2.0.
6014 *
6015 * \sa SDL_iconv_open
6016 */
6017typedef struct SDL_iconv_data_t *SDL_iconv_t;
6018
6019/**
6020 * This function allocates a context for the specified character set
6021 * conversion.
6022 *
6023 * \param tocode The target character encoding, must not be NULL.
6024 * \param fromcode The source character encoding, must not be NULL.
6025 * \returns a handle that must be freed with SDL_iconv_close, or
6026 * SDL_ICONV_ERROR on failure.
6027 *
6028 * \threadsafety It is safe to call this function from any thread.
6029 *
6030 * \since This function is available since SDL 3.2.0.
6031 *
6032 * \sa SDL_iconv
6033 * \sa SDL_iconv_close
6034 * \sa SDL_iconv_string
6035 */
6036extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
6037 const char *fromcode);
6038
6039/**
6040 * This function frees a context used for character set conversion.
6041 *
6042 * \param cd The character set conversion handle.
6043 * \returns 0 on success, or -1 on failure.
6044 *
6045 * \threadsafety It is safe to call this function from any thread.
6046 *
6047 * \since This function is available since SDL 3.2.0.
6048 *
6049 * \sa SDL_iconv
6050 * \sa SDL_iconv_open
6051 * \sa SDL_iconv_string
6052 */
6053extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
6054
6055/**
6056 * This function converts text between encodings, reading from and writing to
6057 * a buffer.
6058 *
6059 * It returns the number of successful conversions on success. On error,
6060 * SDL_ICONV_E2BIG is returned when the output buffer is too small, or
6061 * SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered,
6062 * or SDL_ICONV_EINVAL is returned when an incomplete input sequence is
6063 * encountered.
6064 *
6065 * On exit:
6066 *
6067 * - inbuf will point to the beginning of the next multibyte sequence. On
6068 * error, this is the location of the problematic input sequence. On
6069 * success, this is the end of the input sequence.
6070 * - inbytesleft will be set to the number of bytes left to convert, which
6071 * will be 0 on success.
6072 * - outbuf will point to the location where to store the next output byte.
6073 * - outbytesleft will be set to the number of bytes left in the output
6074 * buffer.
6075 *
6076 * \param cd The character set conversion context, created in
6077 * SDL_iconv_open().
6078 * \param inbuf Address of variable that points to the first character of the
6079 * input sequence.
6080 * \param inbytesleft The number of bytes in the input buffer.
6081 * \param outbuf Address of variable that points to the output buffer.
6082 * \param outbytesleft The number of bytes in the output buffer.
6083 * \returns the number of conversions on success, or a negative error code.
6084 *
6085 * \threadsafety Do not use the same SDL_iconv_t from two threads at once.
6086 *
6087 * \since This function is available since SDL 3.2.0.
6088 *
6089 * \sa SDL_iconv_open
6090 * \sa SDL_iconv_close
6091 * \sa SDL_iconv_string
6092 */
6093extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
6094 size_t *inbytesleft, char **outbuf,
6095 size_t *outbytesleft);
6096
6097#define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
6098#define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
6099#define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
6100#define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
6101
6102
6103/**
6104 * Helper function to convert a string's encoding in one call.
6105 *
6106 * This function converts a buffer or string between encodings in one pass.
6107 *
6108 * The string does not need to be NULL-terminated; this function operates on
6109 * the number of bytes specified in `inbytesleft` whether there is a NULL
6110 * character anywhere in the buffer.
6111 *
6112 * The returned string is owned by the caller, and should be passed to
6113 * SDL_free when no longer needed.
6114 *
6115 * \param tocode the character encoding of the output string. Examples are
6116 * "UTF-8", "UCS-4", etc.
6117 * \param fromcode the character encoding of data in `inbuf`.
6118 * \param inbuf the string to convert to a different encoding.
6119 * \param inbytesleft the size of the input string _in bytes_.
6120 * \returns a new string, converted to the new encoding, or NULL on error.
6121 *
6122 * \threadsafety It is safe to call this function from any thread.
6123 *
6124 * \since This function is available since SDL 3.2.0.
6125 *
6126 * \sa SDL_iconv_open
6127 * \sa SDL_iconv_close
6128 * \sa SDL_iconv
6129 */
6130extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
6131 const char *fromcode,
6132 const char *inbuf,
6133 size_t inbytesleft);
6134
6135/* Some helper macros for common SDL_iconv_string cases... */
6136
6137/**
6138 * Convert a UTF-8 string to the current locale's character encoding.
6139 *
6140 * This is a helper macro that might be more clear than calling
6141 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6142 * do not use an expression with side-effects here.
6143 *
6144 * \param S the string to convert.
6145 * \returns a new string, converted to the new encoding, or NULL on error.
6146 *
6147 * \threadsafety It is safe to call this macro from any thread.
6148 *
6149 * \since This macro is available since SDL 3.2.0.
6150 */
6151#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
6152
6153/**
6154 * Convert a UTF-8 string to UCS-2.
6155 *
6156 * This is a helper macro that might be more clear than calling
6157 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6158 * do not use an expression with side-effects here.
6159 *
6160 * \param S the string to convert.
6161 * \returns a new string, converted to the new encoding, or NULL on error.
6162 *
6163 * \threadsafety It is safe to call this macro from any thread.
6164 *
6165 * \since This macro is available since SDL 3.2.0.
6166 */
6167#define SDL_iconv_utf8_ucs2(S) SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
6168
6169/**
6170 * Convert a UTF-8 string to UCS-4.
6171 *
6172 * This is a helper macro that might be more clear than calling
6173 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6174 * do not use an expression with side-effects here.
6175 *
6176 * \param S the string to convert.
6177 * \returns a new string, converted to the new encoding, or NULL on error.
6178 *
6179 * \threadsafety It is safe to call this macro from any thread.
6180 *
6181 * \since This macro is available since SDL 3.2.0.
6182 */
6183#define SDL_iconv_utf8_ucs4(S) SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))
6184
6185/**
6186 * Convert a wchar_t string to UTF-8.
6187 *
6188 * This is a helper macro that might be more clear than calling
6189 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6190 * do not use an expression with side-effects here.
6191 *
6192 * \param S the string to convert.
6193 * \returns a new string, converted to the new encoding, or NULL on error.
6194 *
6195 * \threadsafety It is safe to call this macro from any thread.
6196 *
6197 * \since This macro is available since SDL 3.2.0.
6198 */
6199#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", SDL_reinterpret_cast(const char *, S), (SDL_wcslen(S)+1)*sizeof(wchar_t))
6200
6201
6202/* force builds using Clang's static analysis tools to use literal C runtime
6203 here, since there are possibly tests that are ineffective otherwise. */
6204#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
6205
6206/* The analyzer knows about strlcpy even when the system doesn't provide it */
6207#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
6208size_t strlcpy(char *dst, const char *src, size_t size);
6209#endif
6210
6211/* The analyzer knows about strlcat even when the system doesn't provide it */
6212#if !defined(HAVE_STRLCAT) && !defined(strlcat)
6213size_t strlcat(char *dst, const char *src, size_t size);
6214#endif
6215
6216#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
6217size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
6218#endif
6219
6220#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
6221size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
6222#endif
6223
6224#if !defined(HAVE_STRTOK_R) && !defined(strtok_r)
6225char *strtok_r(char *str, const char *delim, char **saveptr);
6226#endif
6227
6228#ifndef _WIN32
6229/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
6230/* not for windows: might conflict with string.h where strdup may have
6231 * dllimport attribute: https://github.com/libsdl-org/SDL/issues/12948 */
6232char *strdup(const char *str);
6233#endif
6234
6235/* Starting LLVM 16, the analyser errors out if these functions do not have
6236 their prototype defined (clang-diagnostic-implicit-function-declaration) */
6237#include <stdio.h>
6238#include <stdlib.h>
6239
6240#define SDL_malloc malloc
6241#define SDL_calloc calloc
6242#define SDL_realloc realloc
6243#define SDL_free free
6244#ifndef SDL_memcpy
6245#define SDL_memcpy memcpy
6246#endif
6247#ifndef SDL_memmove
6248#define SDL_memmove memmove
6249#endif
6250#ifndef SDL_memset
6251#define SDL_memset memset
6252#endif
6253#define SDL_memcmp memcmp
6254#define SDL_strlcpy strlcpy
6255#define SDL_strlcat strlcat
6256#define SDL_strlen strlen
6257#define SDL_wcslen wcslen
6258#define SDL_wcslcpy wcslcpy
6259#define SDL_wcslcat wcslcat
6260#define SDL_strdup strdup
6261#define SDL_wcsdup wcsdup
6262#define SDL_strchr strchr
6263#define SDL_strrchr strrchr
6264#define SDL_strstr strstr
6265#define SDL_wcsstr wcsstr
6266#define SDL_strtok_r strtok_r
6267#define SDL_strcmp strcmp
6268#define SDL_wcscmp wcscmp
6269#define SDL_strncmp strncmp
6270#define SDL_wcsncmp wcsncmp
6271#define SDL_strcasecmp strcasecmp
6272#define SDL_strncasecmp strncasecmp
6273#define SDL_strpbrk strpbrk
6274#define SDL_sscanf sscanf
6275#define SDL_vsscanf vsscanf
6276#define SDL_snprintf snprintf
6277#define SDL_vsnprintf vsnprintf
6278#endif
6279
6280/**
6281 * Multiply two integers, checking for overflow.
6282 *
6283 * If `a * b` would overflow, return false.
6284 *
6285 * Otherwise store `a * b` via ret and return true.
6286 *
6287 * \param a the multiplicand.
6288 * \param b the multiplier.
6289 * \param ret on non-overflow output, stores the multiplication result, may
6290 * not be NULL.
6291 * \returns false on overflow, true if result is multiplied without overflow.
6292 *
6293 * \threadsafety It is safe to call this function from any thread.
6294 *
6295 * \since This function is available since SDL 3.2.0.
6296 */
6297SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
6298{
6299 if (a != 0 && b > SDL_SIZE_MAX / a) {
6300 return false;
6301 }
6302 *ret = a * b;
6303 return true;
6304}
6305
6306#ifndef SDL_WIKI_DOCUMENTATION_SECTION
6307#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
6308/* This needs to be wrapped in an inline rather than being a direct #define,
6309 * because __builtin_mul_overflow() is type-generic, but we want to be
6310 * consistent about interpreting a and b as size_t. */
6311SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
6312{
6313 return (__builtin_mul_overflow(a, b, ret) == 0);
6314}
6315#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
6316#endif
6317#endif
6318
6319/**
6320 * Add two integers, checking for overflow.
6321 *
6322 * If `a + b` would overflow, return false.
6323 *
6324 * Otherwise store `a + b` via ret and return true.
6325 *
6326 * \param a the first addend.
6327 * \param b the second addend.
6328 * \param ret on non-overflow output, stores the addition result, may not be
6329 * NULL.
6330 * \returns false on overflow, true if result is added without overflow.
6331 *
6332 * \threadsafety It is safe to call this function from any thread.
6333 *
6334 * \since This function is available since SDL 3.2.0.
6335 */
6336SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
6337{
6338 if (b > SDL_SIZE_MAX - a) {
6339 return false;
6340 }
6341 *ret = a + b;
6342 return true;
6343}
6344
6345#ifndef SDL_WIKI_DOCUMENTATION_SECTION
6346#if SDL_HAS_BUILTIN(__builtin_add_overflow)
6347/* This needs to be wrapped in an inline rather than being a direct #define,
6348 * the same as the call to __builtin_mul_overflow() above. */
6349SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
6350{
6351 return (__builtin_add_overflow(a, b, ret) == 0);
6352}
6353#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
6354#endif
6355#endif
6356
6357/* This is a generic function pointer which should be cast to the type you expect */
6358#ifdef SDL_WIKI_DOCUMENTATION_SECTION
6359
6360/**
6361 * A generic function pointer.
6362 *
6363 * In theory, generic function pointers should use this, instead of `void *`,
6364 * since some platforms could treat code addresses differently than data
6365 * addresses. Although in current times no popular platforms make this
6366 * distinction, it is more correct and portable to use the correct type for a
6367 * generic pointer.
6368 *
6369 * If for some reason you need to force this typedef to be an actual `void *`,
6370 * perhaps to work around a compiler or existing code, you can define
6371 * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
6372 *
6373 * \since This datatype is available since SDL 3.2.0.
6374 */
6375typedef void (*SDL_FunctionPointer)(void);
6376#elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
6377typedef void *SDL_FunctionPointer;
6378#else
6379typedef void (*SDL_FunctionPointer)(void);
6380#endif
6381
6382/* Ends C function definitions when using C++ */
6383#ifdef __cplusplus
6384}
6385#endif
6386#include <SDL3/SDL_close_code.h>
6387
6388#endif /* SDL_stdinc_h_ */
#define SDL_ALLOC_SIZE(p)
#define SDL_ALLOC_SIZE2(p1, p2)
#define SDL_FORCE_INLINE
#define SDL_MALLOC
void SDL_DestroyEnvironment(SDL_Environment *env)
wchar_t * SDL_wcsdup(const wchar_t *wstr)
double SDL_sqrt(double x)
int SDL_atoi(const char *str)
#define SDL_memset
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
unsigned long long SDL_strtoull(const char *str, char **endp, int base)
float SDL_tanf(float x)
bool SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
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)
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
int SDL_tolower(int x)
float SDL_modff(float x, float *y)
double SDL_modf(double x, double *y)
Uint32 SDL_murmur3_32(const void *data, size_t len, Uint32 seed)
const char * SDL_getenv_unsafe(const char *name)
int SDL_abs(int x)
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3)
char * SDL_ulltoa(unsigned long long value, char *str, int radix)
size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Sint32 SDL_rand_r(Uint64 *state, Sint32 n)
double SDL_tan(double x)
uint8_t Uint8
Definition SDL_stdinc.h:459
char * SDL_ltoa(long value, char *str, int radix)
void SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
int SDL_isxdigit(int x)
Uint32 SDL_StepUTF8(const char **pstr, size_t *pslen)
float SDL_ceilf(float x)
int64_t Sint64
Definition SDL_stdinc.h:506
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)
int(* SDL_CompareCallback_r)(void *userdata, const void *a, const void *b)
#define SDL_OUT_BYTECAP(x)
char * SDL_strrchr(const char *str, int c)
#define SDL_SIZE_MAX
Definition SDL_stdinc.h:186
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
uint16_t Uint16
Definition SDL_stdinc.h:477
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
char ** SDL_GetEnvironmentVariables(SDL_Environment *env)
char * SDL_strtok_r(char *str, const char *delim, char **saveptr)
SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
float SDL_atanf(float x)
int SDL_isprint(int x)
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
int SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
void SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
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)
size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
long long SDL_wcstoll(const wchar_t *str, wchar_t **endp, int base)
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
struct SDL_Environment SDL_Environment
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)
int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
float SDL_randf(void)
bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite)
Sint32 SDL_rand(Sint32 n)
char * SDL_uitoa(unsigned int value, char *str, int radix)
void * alloca(size_t)
unsigned long long SDL_wcstoull(const wchar_t *str, wchar_t **endp, int base)
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)
int SDL_isinff(float x)
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:450
wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
char * SDL_lltoa(long long value, char *str, int radix)
int(* SDL_CompareCallback)(const void *a, const void *b)
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)
void SDL_srand(Uint64 seed)
Uint32 SDL_rand_bits_r(Uint64 *state)
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
char * SDL_strstr(const char *haystack, const char *needle)
int SDL_GetNumAllocations(void)
double SDL_exp(double x)
char * SDL_UCS4ToUTF8(Uint32 codepoint, char *dst)
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:358
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:486
size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
#define SDL_INOUT_Z_CAP(x)
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)
double SDL_fmod(double x, double y)
double SDL_fabs(double x)
int SDL_ispunct(int x)
float SDL_truncf(float x)
char * SDL_strpbrk(const char *str, const char *breakset)
double SDL_log10(double x)
SDL_MALLOC size_t size
float SDL_expf(float x)
#define SDL_WPRINTF_VARARG_FUNCV(fmtargnumber)
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)
SDL_Environment * SDL_CreateEnvironment(bool populated)
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_isnan(double x)
int SDL_isinf(double x)
float SDL_log10f(float x)
void(* SDL_free_func)(void *mem)
int SDL_memcmp(const void *s1, const void *s2, size_t len)
SDL_MALLOC void * SDL_aligned_alloc_zero(size_t alignment, size_t size)
const char * SDL_getenv(const char *name)
int16_t Sint16
Definition SDL_stdinc.h:468
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)
const char * SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name)
char * SDL_strnstr(const char *haystack, const char *needle, size_t maxlen)
Uint32 SDL_rand_bits(void)
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)
double SDL_cos(double x)
#define SDL_PRINTF_FORMAT_STRING
float SDL_fmodf(float x, float y)
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)
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:238
float SDL_atan2f(float y, float x)
int SDL_isupper(int x)
int SDL_unsetenv_unsafe(const char *name)
long SDL_wcstol(const wchar_t *str, wchar_t **endp, int base)
float SDL_fabsf(float x)
uint64_t Uint64
Definition SDL_stdinc.h:517
long long SDL_strtoll(const char *str, char **endp, int base)
Uint32 SDL_StepBackUTF8(const char *start, const char **pstr)
SDL_MALLOC char * SDL_strdup(const char *str)
int SDL_iscntrl(int x)
void * SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
#define SDL_memcpy
void SDL_free(void *mem)
void * SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
void *(* SDL_calloc_func)(size_t nmemb, size_t size)
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
double SDL_atan2(double y, double x)
double SDL_log(double x)
void(* SDL_FunctionPointer)(void)
int SDL_isnanf(float x)
int SDL_toupper(int x)
uint32_t Uint32
Definition SDL_stdinc.h:495
float SDL_powf(float x, float y)
unsigned long SDL_wcstoul(const wchar_t *str, wchar_t **endp, int base)
SDL_Environment * SDL_GetEnvironment(void)
size_t SDL_strlen(const char *str)
bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name)
#define SDL_memmove
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)
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:534
void *(* SDL_realloc_func)(void *mem, size_t size)
size_t SDL_utf8strlen(const char *str)
int SDL_isgraph(int x)
float SDL_randf_r(Uint64 *state)
int SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
#define SDL_OUT_Z_CAP(x)
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
double SDL_trunc(double x)
int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)