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 * Note that on Windows, the variable names pulled in from the system at
1780 * startup have their ASCII values uppercased, to match what most platforms
1781 * expect even though the Windows system environment table is
1782 * case-insensitive. Once those uppercased variable names are in an
1783 * SDL_Environment, SDL treats them as case-sensitive.
1784 *
1785 * \returns a pointer to the environment for the process or NULL on failure;
1786 * call SDL_GetError() for more information.
1787 *
1788 * \threadsafety It is safe to call this function from any thread.
1789 *
1790 * \since This function is available since SDL 3.2.0.
1791 *
1792 * \sa SDL_GetEnvironmentVariable
1793 * \sa SDL_GetEnvironmentVariables
1794 * \sa SDL_SetEnvironmentVariable
1795 * \sa SDL_UnsetEnvironmentVariable
1796 */
1797extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
1798
1799/**
1800 * Create a set of environment variables.
1801 *
1802 * Note that on Windows, the variable names pulled in from the system, if
1803 * `populated` is true, have their ASCII values uppercased, to match what most
1804 * platforms expect even though the Windows system environment table is
1805 * case-insensitive. Once those uppercased variable names are in an
1806 * SDL_Environment, SDL treats them as case-sensitive.
1807 *
1808 * \param populated true to initialize it from the C runtime environment,
1809 * false to create an empty environment.
1810 * \returns a pointer to the new environment or NULL on failure; call
1811 * SDL_GetError() for more information.
1812 *
1813 * \threadsafety If `populated` is false, it is safe to call this function
1814 * from any thread, otherwise it is safe if no other threads are
1815 * calling setenv() or unsetenv()
1816 *
1817 * \since This function is available since SDL 3.2.0.
1818 *
1819 * \sa SDL_GetEnvironmentVariable
1820 * \sa SDL_GetEnvironmentVariables
1821 * \sa SDL_SetEnvironmentVariable
1822 * \sa SDL_UnsetEnvironmentVariable
1823 * \sa SDL_DestroyEnvironment
1824 */
1825extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
1826
1827/**
1828 * Get the value of a variable in the environment.
1829 *
1830 * \param env the environment to query.
1831 * \param name the name of the variable to get.
1832 * \returns a pointer to the value of the variable or NULL if it can't be
1833 * found.
1834 *
1835 * \threadsafety It is safe to call this function from any thread.
1836 *
1837 * \since This function is available since SDL 3.2.0.
1838 *
1839 * \sa SDL_GetEnvironment
1840 * \sa SDL_CreateEnvironment
1841 * \sa SDL_GetEnvironmentVariables
1842 * \sa SDL_SetEnvironmentVariable
1843 * \sa SDL_UnsetEnvironmentVariable
1844 */
1845extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
1846
1847/**
1848 * Get all variables in the environment.
1849 *
1850 * \param env the environment to query.
1851 * \returns a NULL terminated array of pointers to environment variables in
1852 * the form "variable=value" or NULL on failure; call SDL_GetError()
1853 * for more information. This is a single allocation that should be
1854 * freed with SDL_free() when it is no longer needed.
1855 *
1856 * \threadsafety It is safe to call this function from any thread.
1857 *
1858 * \since This function is available since SDL 3.2.0.
1859 *
1860 * \sa SDL_GetEnvironment
1861 * \sa SDL_CreateEnvironment
1862 * \sa SDL_GetEnvironmentVariable
1863 * \sa SDL_SetEnvironmentVariable
1864 * \sa SDL_UnsetEnvironmentVariable
1865 */
1866extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
1867
1868/**
1869 * Set the value of a variable in the environment.
1870 *
1871 * \param env the environment to modify.
1872 * \param name the name of the variable to set.
1873 * \param value the value of the variable to set.
1874 * \param overwrite true to overwrite the variable if it exists, false to
1875 * return success without setting the variable if it already
1876 * exists.
1877 * \returns true on success or false on failure; call SDL_GetError() for more
1878 * information.
1879 *
1880 * \threadsafety It is safe to call this function from any thread.
1881 *
1882 * \since This function is available since SDL 3.2.0.
1883 *
1884 * \sa SDL_GetEnvironment
1885 * \sa SDL_CreateEnvironment
1886 * \sa SDL_GetEnvironmentVariable
1887 * \sa SDL_GetEnvironmentVariables
1888 * \sa SDL_UnsetEnvironmentVariable
1889 */
1890extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
1891
1892/**
1893 * Clear a variable from the environment.
1894 *
1895 * \param env the environment to modify.
1896 * \param name the name of the variable to unset.
1897 * \returns true on success or false on failure; call SDL_GetError() for more
1898 * information.
1899 *
1900 * \threadsafety It is safe to call this function from any thread.
1901 *
1902 * \since This function is available since SDL 3.2.0.
1903 *
1904 * \sa SDL_GetEnvironment
1905 * \sa SDL_CreateEnvironment
1906 * \sa SDL_GetEnvironmentVariable
1907 * \sa SDL_GetEnvironmentVariables
1908 * \sa SDL_SetEnvironmentVariable
1909 * \sa SDL_UnsetEnvironmentVariable
1910 */
1911extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
1912
1913/**
1914 * Destroy a set of environment variables.
1915 *
1916 * \param env the environment to destroy.
1917 *
1918 * \threadsafety It is safe to call this function from any thread, as long as
1919 * the environment is no longer in use.
1920 *
1921 * \since This function is available since SDL 3.2.0.
1922 *
1923 * \sa SDL_CreateEnvironment
1924 */
1925extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
1926
1927/**
1928 * Get the value of a variable in the environment.
1929 *
1930 * The name of the variable is case sensitive on all platforms.
1931 *
1932 * This function uses SDL's cached copy of the environment and is thread-safe.
1933 *
1934 * \param name the name of the variable to get.
1935 * \returns a pointer to the value of the variable or NULL if it can't be
1936 * found.
1937 *
1938 * \threadsafety It is safe to call this function from any thread.
1939 *
1940 * \since This function is available since SDL 3.2.0.
1941 */
1942extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
1943
1944/**
1945 * Get the value of a variable in the environment.
1946 *
1947 * This function bypasses SDL's cached copy of the environment and is not
1948 * thread-safe.
1949 *
1950 * On some platforms, this may make case-insensitive matches, while other
1951 * platforms are case-sensitive. It is best to be precise with strings used
1952 * for queries through this interface. SDL_getenv is always case-sensitive,
1953 * however.
1954 *
1955 * \param name the name of the variable to get.
1956 * \returns a pointer to the value of the variable or NULL if it can't be
1957 * found.
1958 *
1959 * \threadsafety This function is not thread safe, consider using SDL_getenv()
1960 * instead.
1961 *
1962 * \since This function is available since SDL 3.2.0.
1963 *
1964 * \sa SDL_getenv
1965 */
1966extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
1967
1968/**
1969 * Set the value of a variable in the environment.
1970 *
1971 * \param name the name of the variable to set.
1972 * \param value the value of the variable to set.
1973 * \param overwrite 1 to overwrite the variable if it exists, 0 to return
1974 * success without setting the variable if it already exists.
1975 * \returns 0 on success, -1 on error.
1976 *
1977 * \threadsafety This function is not thread safe, consider using
1978 * SDL_SetEnvironmentVariable() instead.
1979 *
1980 * \since This function is available since SDL 3.2.0.
1981 *
1982 * \sa SDL_SetEnvironmentVariable
1983 */
1984extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
1985
1986/**
1987 * Clear a variable from the environment.
1988 *
1989 * \param name the name of the variable to unset.
1990 * \returns 0 on success, -1 on error.
1991 *
1992 * \threadsafety This function is not thread safe, consider using
1993 * SDL_UnsetEnvironmentVariable() instead.
1994 *
1995 * \since This function is available since SDL 3.2.0.
1996 *
1997 * \sa SDL_UnsetEnvironmentVariable
1998 */
1999extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
2000
2001/**
2002 * A callback used with SDL sorting and binary search functions.
2003 *
2004 * \param a a pointer to the first element being compared.
2005 * \param b a pointer to the second element being compared.
2006 * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
2007 * before `a`, 0 if they are equal. If two elements are equal, their
2008 * order in the sorted array is undefined.
2009 *
2010 * \since This callback is available since SDL 3.2.0.
2011 *
2012 * \sa SDL_bsearch
2013 * \sa SDL_qsort
2014 */
2015typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
2016
2017/**
2018 * Sort an array.
2019 *
2020 * For example:
2021 *
2022 * ```c
2023 * typedef struct {
2024 * int key;
2025 * const char *string;
2026 * } data;
2027 *
2028 * int SDLCALL compare(const void *a, const void *b)
2029 * {
2030 * const data *A = (const data *)a;
2031 * const data *B = (const data *)b;
2032 *
2033 * if (A->n < B->n) {
2034 * return -1;
2035 * } else if (B->n < A->n) {
2036 * return 1;
2037 * } else {
2038 * return 0;
2039 * }
2040 * }
2041 *
2042 * data values[] = {
2043 * { 3, "third" }, { 1, "first" }, { 2, "second" }
2044 * };
2045 *
2046 * SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
2047 * ```
2048 *
2049 * \param base a pointer to the start of the array.
2050 * \param nmemb the number of elements in the array.
2051 * \param size the size of the elements in the array.
2052 * \param compare a function used to compare elements in the array.
2053 *
2054 * \threadsafety It is safe to call this function from any thread.
2055 *
2056 * \since This function is available since SDL 3.2.0.
2057 *
2058 * \sa SDL_bsearch
2059 * \sa SDL_qsort_r
2060 */
2061extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
2062
2063/**
2064 * Perform a binary search on a previously sorted array.
2065 *
2066 * For example:
2067 *
2068 * ```c
2069 * typedef struct {
2070 * int key;
2071 * const char *string;
2072 * } data;
2073 *
2074 * int SDLCALL compare(const void *a, const void *b)
2075 * {
2076 * const data *A = (const data *)a;
2077 * const data *B = (const data *)b;
2078 *
2079 * if (A->n < B->n) {
2080 * return -1;
2081 * } else if (B->n < A->n) {
2082 * return 1;
2083 * } else {
2084 * return 0;
2085 * }
2086 * }
2087 *
2088 * data values[] = {
2089 * { 1, "first" }, { 2, "second" }, { 3, "third" }
2090 * };
2091 * data key = { 2, NULL };
2092 *
2093 * data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
2094 * ```
2095 *
2096 * \param key a pointer to a key equal to the element being searched for.
2097 * \param base a pointer to the start of the array.
2098 * \param nmemb the number of elements in the array.
2099 * \param size the size of the elements in the array.
2100 * \param compare a function used to compare elements in the array.
2101 * \returns a pointer to the matching element in the array, or NULL if not
2102 * found.
2103 *
2104 * \threadsafety It is safe to call this function from any thread.
2105 *
2106 * \since This function is available since SDL 3.2.0.
2107 *
2108 * \sa SDL_bsearch_r
2109 * \sa SDL_qsort
2110 */
2111extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
2112
2113/**
2114 * A callback used with SDL sorting and binary search functions.
2115 *
2116 * \param userdata the `userdata` pointer passed to the sort function.
2117 * \param a a pointer to the first element being compared.
2118 * \param b a pointer to the second element being compared.
2119 * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
2120 * before `a`, 0 if they are equal. If two elements are equal, their
2121 * order in the sorted array is undefined.
2122 *
2123 * \since This callback is available since SDL 3.2.0.
2124 *
2125 * \sa SDL_qsort_r
2126 * \sa SDL_bsearch_r
2127 */
2128typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
2129
2130/**
2131 * Sort an array, passing a userdata pointer to the compare function.
2132 *
2133 * For example:
2134 *
2135 * ```c
2136 * typedef enum {
2137 * sort_increasing,
2138 * sort_decreasing,
2139 * } sort_method;
2140 *
2141 * typedef struct {
2142 * int key;
2143 * const char *string;
2144 * } data;
2145 *
2146 * int SDLCALL compare(const void *userdata, const void *a, const void *b)
2147 * {
2148 * sort_method method = (sort_method)(uintptr_t)userdata;
2149 * const data *A = (const data *)a;
2150 * const data *B = (const data *)b;
2151 *
2152 * if (A->key < B->key) {
2153 * return (method == sort_increasing) ? -1 : 1;
2154 * } else if (B->key < A->key) {
2155 * return (method == sort_increasing) ? 1 : -1;
2156 * } else {
2157 * return 0;
2158 * }
2159 * }
2160 *
2161 * data values[] = {
2162 * { 3, "third" }, { 1, "first" }, { 2, "second" }
2163 * };
2164 *
2165 * SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
2166 * ```
2167 *
2168 * \param base a pointer to the start of the array.
2169 * \param nmemb the number of elements in the array.
2170 * \param size the size of the elements in the array.
2171 * \param compare a function used to compare elements in the array.
2172 * \param userdata a pointer to pass to the compare function.
2173 *
2174 * \threadsafety It is safe to call this function from any thread.
2175 *
2176 * \since This function is available since SDL 3.2.0.
2177 *
2178 * \sa SDL_bsearch_r
2179 * \sa SDL_qsort
2180 */
2181extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
2182
2183/**
2184 * Perform a binary search on a previously sorted array, passing a userdata
2185 * pointer to the compare function.
2186 *
2187 * For example:
2188 *
2189 * ```c
2190 * typedef enum {
2191 * sort_increasing,
2192 * sort_decreasing,
2193 * } sort_method;
2194 *
2195 * typedef struct {
2196 * int key;
2197 * const char *string;
2198 * } data;
2199 *
2200 * int SDLCALL compare(const void *userdata, const void *a, const void *b)
2201 * {
2202 * sort_method method = (sort_method)(uintptr_t)userdata;
2203 * const data *A = (const data *)a;
2204 * const data *B = (const data *)b;
2205 *
2206 * if (A->key < B->key) {
2207 * return (method == sort_increasing) ? -1 : 1;
2208 * } else if (B->key < A->key) {
2209 * return (method == sort_increasing) ? 1 : -1;
2210 * } else {
2211 * return 0;
2212 * }
2213 * }
2214 *
2215 * data values[] = {
2216 * { 1, "first" }, { 2, "second" }, { 3, "third" }
2217 * };
2218 * data key = { 2, NULL };
2219 *
2220 * data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
2221 * ```
2222 *
2223 * \param key a pointer to a key equal to the element being searched for.
2224 * \param base a pointer to the start of the array.
2225 * \param nmemb the number of elements in the array.
2226 * \param size the size of the elements in the array.
2227 * \param compare a function used to compare elements in the array.
2228 * \param userdata a pointer to pass to the compare function.
2229 * \returns a pointer to the matching element in the array, or NULL if not
2230 * found.
2231 *
2232 * \threadsafety It is safe to call this function from any thread.
2233 *
2234 * \since This function is available since SDL 3.2.0.
2235 *
2236 * \sa SDL_bsearch
2237 * \sa SDL_qsort_r
2238 */
2239extern 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);
2240
2241/**
2242 * Compute the absolute value of `x`.
2243 *
2244 * \param x an integer value.
2245 * \returns the absolute value of x.
2246 *
2247 * \threadsafety It is safe to call this function from any thread.
2248 *
2249 * \since This function is available since SDL 3.2.0.
2250 */
2251extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
2252
2253/**
2254 * Return the lesser of two values.
2255 *
2256 * This is a helper macro that might be more clear than writing out the
2257 * comparisons directly, and works with any type that can be compared with the
2258 * `<` operator. However, it double-evaluates both its parameters, so do not
2259 * use expressions with side-effects here.
2260 *
2261 * \param x the first value to compare.
2262 * \param y the second value to compare.
2263 * \returns the lesser of `x` and `y`.
2264 *
2265 * \threadsafety It is safe to call this macro from any thread.
2266 *
2267 * \since This macro is available since SDL 3.2.0.
2268 */
2269#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
2270
2271/**
2272 * Return the greater of two values.
2273 *
2274 * This is a helper macro that might be more clear than writing out the
2275 * comparisons directly, and works with any type that can be compared with the
2276 * `>` operator. However, it double-evaluates both its parameters, so do not
2277 * use expressions with side-effects here.
2278 *
2279 * \param x the first value to compare.
2280 * \param y the second value to compare.
2281 * \returns the greater of `x` and `y`.
2282 *
2283 * \threadsafety It is safe to call this macro from any thread.
2284 *
2285 * \since This macro is available since SDL 3.2.0.
2286 */
2287#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
2288
2289/**
2290 * Return a value clamped to a range.
2291 *
2292 * If `x` is outside the range a values between `a` and `b`, the returned
2293 * value will be `a` or `b` as appropriate. Otherwise, `x` is returned.
2294 *
2295 * This macro will produce incorrect results if `b` is less than `a`.
2296 *
2297 * This is a helper macro that might be more clear than writing out the
2298 * comparisons directly, and works with any type that can be compared with the
2299 * `<` and `>` operators. However, it double-evaluates all its parameters, so
2300 * do not use expressions with side-effects here.
2301 *
2302 * \param x the value to compare.
2303 * \param a the low end value.
2304 * \param b the high end value.
2305 * \returns x, clamped between a and b.
2306 *
2307 * \threadsafety It is safe to call this macro from any thread.
2308 *
2309 * \since This macro is available since SDL 3.2.0.
2310 */
2311#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
2312
2313/**
2314 * Query if a character is alphabetic (a letter).
2315 *
2316 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2317 * for English 'a-z' and 'A-Z' as true.
2318 *
2319 * \param x character value to check.
2320 * \returns non-zero if x falls within the character class, zero otherwise.
2321 *
2322 * \threadsafety It is safe to call this function from any thread.
2323 *
2324 * \since This function is available since SDL 3.2.0.
2325 */
2326extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
2327
2328/**
2329 * Query if a character is alphabetic (a letter) or a number.
2330 *
2331 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2332 * for English 'a-z', 'A-Z', and '0-9' as true.
2333 *
2334 * \param x character value to check.
2335 * \returns non-zero if x falls within the character class, zero otherwise.
2336 *
2337 * \threadsafety It is safe to call this function from any thread.
2338 *
2339 * \since This function is available since SDL 3.2.0.
2340 */
2341extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
2342
2343/**
2344 * Report if a character is blank (a space or tab).
2345 *
2346 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2347 * 0x20 (space) or 0x9 (tab) as true.
2348 *
2349 * \param x character value to check.
2350 * \returns non-zero if x falls within the character class, zero otherwise.
2351 *
2352 * \threadsafety It is safe to call this function from any thread.
2353 *
2354 * \since This function is available since SDL 3.2.0.
2355 */
2356extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
2357
2358/**
2359 * Report if a character is a control character.
2360 *
2361 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2362 * 0 through 0x1F, and 0x7F, as true.
2363 *
2364 * \param x character value to check.
2365 * \returns non-zero if x falls within the character class, zero otherwise.
2366 *
2367 * \threadsafety It is safe to call this function from any thread.
2368 *
2369 * \since This function is available since SDL 3.2.0.
2370 */
2371extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
2372
2373/**
2374 * Report if a character is a numeric digit.
2375 *
2376 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2377 * '0' (0x30) through '9' (0x39), as true.
2378 *
2379 * \param x character value to check.
2380 * \returns non-zero if x falls within the character class, zero otherwise.
2381 *
2382 * \threadsafety It is safe to call this function from any thread.
2383 *
2384 * \since This function is available since SDL 3.2.0.
2385 */
2386extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
2387
2388/**
2389 * Report if a character is a hexadecimal digit.
2390 *
2391 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2392 * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
2393 *
2394 * \param x character value to check.
2395 * \returns non-zero if x falls within the character class, zero otherwise.
2396 *
2397 * \threadsafety It is safe to call this function from any thread.
2398 *
2399 * \since This function is available since SDL 3.2.0.
2400 */
2401extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
2402
2403/**
2404 * Report if a character is a punctuation mark.
2405 *
2406 * **WARNING**: Regardless of system locale, this is equivalent to
2407 * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
2408 *
2409 * \param x character value to check.
2410 * \returns non-zero if x falls within the character class, zero otherwise.
2411 *
2412 * \threadsafety It is safe to call this function from any thread.
2413 *
2414 * \since This function is available since SDL 3.2.0.
2415 *
2416 * \sa SDL_isgraph
2417 * \sa SDL_isalnum
2418 */
2419extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
2420
2421/**
2422 * Report if a character is whitespace.
2423 *
2424 * **WARNING**: Regardless of system locale, this will only treat the
2425 * following ASCII values as true:
2426 *
2427 * - space (0x20)
2428 * - tab (0x09)
2429 * - newline (0x0A)
2430 * - vertical tab (0x0B)
2431 * - form feed (0x0C)
2432 * - return (0x0D)
2433 *
2434 * \param x character value to check.
2435 * \returns non-zero if x falls within the character class, zero otherwise.
2436 *
2437 * \threadsafety It is safe to call this function from any thread.
2438 *
2439 * \since This function is available since SDL 3.2.0.
2440 */
2441extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
2442
2443/**
2444 * Report if a character is upper case.
2445 *
2446 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2447 * 'A' through 'Z' as true.
2448 *
2449 * \param x character value to check.
2450 * \returns non-zero if x falls within the character class, zero otherwise.
2451 *
2452 * \threadsafety It is safe to call this function from any thread.
2453 *
2454 * \since This function is available since SDL 3.2.0.
2455 */
2456extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
2457
2458/**
2459 * Report if a character is lower case.
2460 *
2461 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2462 * 'a' through 'z' as true.
2463 *
2464 * \param x character value to check.
2465 * \returns non-zero if x falls within the character class, zero otherwise.
2466 *
2467 * \threadsafety It is safe to call this function from any thread.
2468 *
2469 * \since This function is available since SDL 3.2.0.
2470 */
2471extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
2472
2473/**
2474 * Report if a character is "printable".
2475 *
2476 * Be advised that "printable" has a definition that goes back to text
2477 * terminals from the dawn of computing, making this a sort of special case
2478 * function that is not suitable for Unicode (or most any) text management.
2479 *
2480 * **WARNING**: Regardless of system locale, this will only treat ASCII values
2481 * ' ' (0x20) through '~' (0x7E) as true.
2482 *
2483 * \param x character value to check.
2484 * \returns non-zero if x falls within the character class, zero otherwise.
2485 *
2486 * \threadsafety It is safe to call this function from any thread.
2487 *
2488 * \since This function is available since SDL 3.2.0.
2489 */
2490extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
2491
2492/**
2493 * Report if a character is any "printable" except space.
2494 *
2495 * Be advised that "printable" has a definition that goes back to text
2496 * terminals from the dawn of computing, making this a sort of special case
2497 * function that is not suitable for Unicode (or most any) text management.
2498 *
2499 * **WARNING**: Regardless of system locale, this is equivalent to
2500 * `(SDL_isprint(x)) && ((x) != ' ')`.
2501 *
2502 * \param x character value to check.
2503 * \returns non-zero if x falls within the character class, zero otherwise.
2504 *
2505 * \threadsafety It is safe to call this function from any thread.
2506 *
2507 * \since This function is available since SDL 3.2.0.
2508 *
2509 * \sa SDL_isprint
2510 */
2511extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
2512
2513/**
2514 * Convert low-ASCII English letters to uppercase.
2515 *
2516 * **WARNING**: Regardless of system locale, this will only convert ASCII
2517 * values 'a' through 'z' to uppercase.
2518 *
2519 * This function returns the uppercase equivalent of `x`. If a character
2520 * cannot be converted, or is already uppercase, this function returns `x`.
2521 *
2522 * \param x character value to check.
2523 * \returns capitalized version of x, or x if no conversion available.
2524 *
2525 * \threadsafety It is safe to call this function from any thread.
2526 *
2527 * \since This function is available since SDL 3.2.0.
2528 */
2529extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
2530
2531/**
2532 * Convert low-ASCII English letters to lowercase.
2533 *
2534 * **WARNING**: Regardless of system locale, this will only convert ASCII
2535 * values 'A' through 'Z' to lowercase.
2536 *
2537 * This function returns the lowercase equivalent of `x`. If a character
2538 * cannot be converted, or is already lowercase, this function returns `x`.
2539 *
2540 * \param x character value to check.
2541 * \returns lowercase version of x, or x if no conversion available.
2542 *
2543 * \threadsafety It is safe to call this function from any thread.
2544 *
2545 * \since This function is available since SDL 3.2.0.
2546 */
2547extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
2548
2549/**
2550 * Calculate a CRC-16 value.
2551 *
2552 * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
2553 *
2554 * This function can be called multiple times, to stream data to be
2555 * checksummed in blocks. Each call must provide the previous CRC-16 return
2556 * value to be updated with the next block. The first call to this function
2557 * for a set of blocks should pass in a zero CRC value.
2558 *
2559 * \param crc the current checksum for this data set, or 0 for a new data set.
2560 * \param data a new block of data to add to the checksum.
2561 * \param len the size, in bytes, of the new block of data.
2562 * \returns a CRC-16 checksum value of all blocks in the data set.
2563 *
2564 * \threadsafety It is safe to call this function from any thread.
2565 *
2566 * \since This function is available since SDL 3.2.0.
2567 */
2568extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
2569
2570/**
2571 * Calculate a CRC-32 value.
2572 *
2573 * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
2574 *
2575 * This function can be called multiple times, to stream data to be
2576 * checksummed in blocks. Each call must provide the previous CRC-32 return
2577 * value to be updated with the next block. The first call to this function
2578 * for a set of blocks should pass in a zero CRC value.
2579 *
2580 * \param crc the current checksum for this data set, or 0 for a new data set.
2581 * \param data a new block of data to add to the checksum.
2582 * \param len the size, in bytes, of the new block of data.
2583 * \returns a CRC-32 checksum value of all blocks in the data set.
2584 *
2585 * \threadsafety It is safe to call this function from any thread.
2586 *
2587 * \since This function is available since SDL 3.2.0.
2588 */
2589extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
2590
2591/**
2592 * Calculate a 32-bit MurmurHash3 value for a block of data.
2593 *
2594 * https://en.wikipedia.org/wiki/MurmurHash
2595 *
2596 * A seed may be specified, which changes the final results consistently, but
2597 * this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous
2598 * result from this function back into itself as the next seed value to
2599 * calculate a hash in chunks; it won't produce the same hash as it would if
2600 * the same data was provided in a single call.
2601 *
2602 * If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not
2603 * cryptographically secure, so it shouldn't be used for hashing top-secret
2604 * data.
2605 *
2606 * \param data the data to be hashed.
2607 * \param len the size of data, in bytes.
2608 * \param seed a value that alters the final hash value.
2609 * \returns a Murmur3 32-bit hash value.
2610 *
2611 * \threadsafety It is safe to call this function from any thread.
2612 *
2613 * \since This function is available since SDL 3.2.0.
2614 */
2615extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed);
2616
2617/**
2618 * Copy non-overlapping memory.
2619 *
2620 * The memory regions must not overlap. If they do, use SDL_memmove() instead.
2621 *
2622 * \param dst The destination memory region. Must not be NULL, and must not
2623 * overlap with `src`.
2624 * \param src The source memory region. Must not be NULL, and must not overlap
2625 * with `dst`.
2626 * \param len The length in bytes of both `dst` and `src`.
2627 * \returns `dst`.
2628 *
2629 * \threadsafety It is safe to call this function from any thread.
2630 *
2631 * \since This function is available since SDL 3.2.0.
2632 *
2633 * \sa SDL_memmove
2634 */
2635extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
2636
2637/* Take advantage of compiler optimizations for memcpy */
2638#ifndef SDL_SLOW_MEMCPY
2639#ifdef SDL_memcpy
2640#undef SDL_memcpy
2641#endif
2642#define SDL_memcpy memcpy
2643#endif
2644
2645
2646/**
2647 * A macro to copy memory between objects, with basic type checking.
2648 *
2649 * SDL_memcpy and SDL_memmove do not care where you copy memory to and from,
2650 * which can lead to bugs. This macro aims to avoid most of those bugs by
2651 * making sure that the source and destination are both pointers to objects
2652 * that are the same size. It does not check that the objects are the same
2653 * _type_, just that the copy will not overflow either object.
2654 *
2655 * The size check happens at compile time, and the compiler will throw an
2656 * error if the objects are different sizes.
2657 *
2658 * Generally this is intended to copy a single object, not an array.
2659 *
2660 * This macro looks like it double-evaluates its parameters, but the extras
2661 * them are in `sizeof` sections, which generate no code nor side-effects.
2662 *
2663 * \param dst a pointer to the destination object. Must not be NULL.
2664 * \param src a pointer to the source object. Must not be NULL.
2665 *
2666 * \threadsafety It is safe to call this function from any thread.
2667 *
2668 * \since This function is available since SDL 3.2.0.
2669 */
2670#define SDL_copyp(dst, src) \
2671 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
2672 SDL_memcpy((dst), (src), sizeof(*(src)))
2673
2674/**
2675 * Copy memory ranges that might overlap.
2676 *
2677 * It is okay for the memory regions to overlap. If you are confident that the
2678 * regions never overlap, using SDL_memcpy() may improve performance.
2679 *
2680 * \param dst The destination memory region. Must not be NULL.
2681 * \param src The source memory region. Must not be NULL.
2682 * \param len The length in bytes of both `dst` and `src`.
2683 * \returns `dst`.
2684 *
2685 * \threadsafety It is safe to call this function from any thread.
2686 *
2687 * \since This function is available since SDL 3.2.0.
2688 *
2689 * \sa SDL_memcpy
2690 */
2691extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
2692
2693/* Take advantage of compiler optimizations for memmove */
2694#ifndef SDL_SLOW_MEMMOVE
2695#ifdef SDL_memmove
2696#undef SDL_memmove
2697#endif
2698#define SDL_memmove memmove
2699#endif
2700
2701/**
2702 * Initialize all bytes of buffer of memory to a specific value.
2703 *
2704 * This function will set `len` bytes, pointed to by `dst`, to the value
2705 * specified in `c`.
2706 *
2707 * Despite `c` being an `int` instead of a `char`, this only operates on
2708 * bytes; `c` must be a value between 0 and 255, inclusive.
2709 *
2710 * \param dst the destination memory region. Must not be NULL.
2711 * \param c the byte value to set.
2712 * \param len the length, in bytes, to set in `dst`.
2713 * \returns `dst`.
2714 *
2715 * \threadsafety It is safe to call this function from any thread.
2716 *
2717 * \since This function is available since SDL 3.2.0.
2718 */
2719extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
2720
2721/**
2722 * Initialize all 32-bit words of buffer of memory to a specific value.
2723 *
2724 * This function will set a buffer of `dwords` Uint32 values, pointed to by
2725 * `dst`, to the value specified in `val`.
2726 *
2727 * Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited
2728 * to a range of 0-255.
2729 *
2730 * \param dst the destination memory region. Must not be NULL.
2731 * \param val the Uint32 value to set.
2732 * \param dwords the number of Uint32 values to set in `dst`.
2733 * \returns `dst`.
2734 *
2735 * \threadsafety It is safe to call this function from any thread.
2736 *
2737 * \since This function is available since SDL 3.2.0.
2738 */
2739extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
2740
2741/* Take advantage of compiler optimizations for memset */
2742#ifndef SDL_SLOW_MEMSET
2743#ifdef SDL_memset
2744#undef SDL_memset
2745#endif
2746#define SDL_memset memset
2747#endif
2748
2749/**
2750 * Clear an object's memory to zero.
2751 *
2752 * This is wrapper over SDL_memset that handles calculating the object size,
2753 * so there's no chance of copy/paste errors, and the code is cleaner.
2754 *
2755 * This requires an object, not a pointer to an object, nor an array.
2756 *
2757 * \param x the object to clear.
2758 *
2759 * \threadsafety It is safe to call this macro from any thread.
2760 *
2761 * \since This macro is available since SDL 3.2.0.
2762 *
2763 * \sa SDL_zerop
2764 * \sa SDL_zeroa
2765 */
2766#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
2767
2768/**
2769 * Clear an object's memory to zero, using a pointer.
2770 *
2771 * This is wrapper over SDL_memset that handles calculating the object size,
2772 * so there's no chance of copy/paste errors, and the code is cleaner.
2773 *
2774 * This requires a pointer to an object, not an object itself, nor an array.
2775 *
2776 * \param x a pointer to the object to clear.
2777 *
2778 * \threadsafety It is safe to call this macro from any thread.
2779 *
2780 * \since This macro is available since SDL 3.2.0.
2781 *
2782 * \sa SDL_zero
2783 * \sa SDL_zeroa
2784 */
2785#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
2786
2787/**
2788 * Clear an array's memory to zero.
2789 *
2790 * This is wrapper over SDL_memset that handles calculating the array size, so
2791 * there's no chance of copy/paste errors, and the code is cleaner.
2792 *
2793 * This requires an array, not an object, nor a pointer to an object.
2794 *
2795 * \param x an array to clear.
2796 *
2797 * \threadsafety It is safe to call this macro from any thread.
2798 *
2799 * \since This macro is available since SDL 3.2.0.
2800 *
2801 * \sa SDL_zero
2802 * \sa SDL_zerop
2803 */
2804#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
2805
2806
2807/**
2808 * Compare two buffers of memory.
2809 *
2810 * \param s1 the first buffer to compare. NULL is not permitted!
2811 * \param s2 the second buffer to compare. NULL is not permitted!
2812 * \param len the number of bytes to compare between the buffers.
2813 * \returns less than zero if s1 is "less than" s2, greater than zero if s1 is
2814 * "greater than" s2, and zero if the buffers match exactly for `len`
2815 * bytes.
2816 *
2817 * \threadsafety It is safe to call this function from any thread.
2818 *
2819 * \since This function is available since SDL 3.2.0.
2820 */
2821extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
2822
2823/**
2824 * This works exactly like wcslen() but doesn't require access to a C runtime.
2825 *
2826 * Counts the number of wchar_t values in `wstr`, excluding the null
2827 * terminator.
2828 *
2829 * Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
2830 * this counts wchar_t values in a string, even if the string's encoding is of
2831 * variable width, like UTF-16.
2832 *
2833 * Also be aware that wchar_t is different sizes on different platforms (4
2834 * bytes on Linux, 2 on Windows, etc).
2835 *
2836 * \param wstr The null-terminated wide string to read. Must not be NULL.
2837 * \returns the length (in wchar_t values, excluding the null terminator) of
2838 * `wstr`.
2839 *
2840 * \threadsafety It is safe to call this function from any thread.
2841 *
2842 * \since This function is available since SDL 3.2.0.
2843 *
2844 * \sa SDL_wcsnlen
2845 * \sa SDL_utf8strlen
2846 * \sa SDL_utf8strnlen
2847 */
2848extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
2849
2850/**
2851 * This works exactly like wcsnlen() but doesn't require access to a C
2852 * runtime.
2853 *
2854 * Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
2855 * null terminator.
2856 *
2857 * Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
2858 * this counts wchar_t values in a string, even if the string's encoding is of
2859 * variable width, like UTF-16.
2860 *
2861 * Also be aware that wchar_t is different sizes on different platforms (4
2862 * bytes on Linux, 2 on Windows, etc).
2863 *
2864 * Also, `maxlen` is a count of wide characters, not bytes!
2865 *
2866 * \param wstr The null-terminated wide string to read. Must not be NULL.
2867 * \param maxlen The maximum amount of wide characters to count.
2868 * \returns the length (in wide characters, excluding the null terminator) of
2869 * `wstr` but never more than `maxlen`.
2870 *
2871 * \threadsafety It is safe to call this function from any thread.
2872 *
2873 * \since This function is available since SDL 3.2.0.
2874 *
2875 * \sa SDL_wcslen
2876 * \sa SDL_utf8strlen
2877 * \sa SDL_utf8strnlen
2878 */
2879extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
2880
2881/**
2882 * Copy a wide string.
2883 *
2884 * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
2885 * appends a null terminator.
2886 *
2887 * `src` and `dst` must not overlap.
2888 *
2889 * If `maxlen` is 0, no wide characters are copied and no null terminator is
2890 * written.
2891 *
2892 * \param dst The destination buffer. Must not be NULL, and must not overlap
2893 * with `src`.
2894 * \param src The null-terminated wide string to copy. Must not be NULL, and
2895 * must not overlap with `dst`.
2896 * \param maxlen The length (in wide characters) of the destination buffer.
2897 * \returns the length (in wide characters, excluding the null terminator) of
2898 * `src`.
2899 *
2900 * \threadsafety It is safe to call this function from any thread.
2901 *
2902 * \since This function is available since SDL 3.2.0.
2903 *
2904 * \sa SDL_wcslcat
2905 */
2906extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
2907
2908/**
2909 * Concatenate wide strings.
2910 *
2911 * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
2912 * from `src` to the end of the wide string in `dst`, then appends a null
2913 * terminator.
2914 *
2915 * `src` and `dst` must not overlap.
2916 *
2917 * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
2918 * unmodified.
2919 *
2920 * \param dst The destination buffer already containing the first
2921 * null-terminated wide string. Must not be NULL and must not
2922 * overlap with `src`.
2923 * \param src The second null-terminated wide string. Must not be NULL, and
2924 * must not overlap with `dst`.
2925 * \param maxlen The length (in wide characters) of the destination buffer.
2926 * \returns the length (in wide characters, excluding the null terminator) of
2927 * the string in `dst` plus the length of `src`.
2928 *
2929 * \threadsafety It is safe to call this function from any thread.
2930 *
2931 * \since This function is available since SDL 3.2.0.
2932 *
2933 * \sa SDL_wcslcpy
2934 */
2935extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
2936
2937/**
2938 * Allocate a copy of a wide string.
2939 *
2940 * This allocates enough space for a null-terminated copy of `wstr`, using
2941 * SDL_malloc, and then makes a copy of the string into this space.
2942 *
2943 * The returned string is owned by the caller, and should be passed to
2944 * SDL_free when no longer needed.
2945 *
2946 * \param wstr the string to copy.
2947 * \returns a pointer to the newly-allocated wide string.
2948 *
2949 * \threadsafety It is safe to call this function from any thread.
2950 *
2951 * \since This function is available since SDL 3.2.0.
2952 */
2953extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
2954
2955/**
2956 * Search a wide string for the first instance of a specific substring.
2957 *
2958 * The search ends once it finds the requested substring, or a null terminator
2959 * byte to end the string.
2960 *
2961 * Note that this looks for strings of _wide characters_, not _codepoints_, so
2962 * it's legal to search for malformed and incomplete UTF-16 sequences.
2963 *
2964 * \param haystack the wide string to search. Must not be NULL.
2965 * \param needle the wide string to search for. Must not be NULL.
2966 * \returns a pointer to the first instance of `needle` in the string, or NULL
2967 * if not found.
2968 *
2969 * \threadsafety It is safe to call this function from any thread.
2970 *
2971 * \since This function is available since SDL 3.2.0.
2972 */
2973extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
2974
2975/**
2976 * Search a wide string, up to n wide chars, for the first instance of a
2977 * specific substring.
2978 *
2979 * The search ends once it finds the requested substring, or a null terminator
2980 * value to end the string, or `maxlen` wide character have been examined. It
2981 * is possible to use this function on a wide string without a null
2982 * terminator.
2983 *
2984 * Note that this looks for strings of _wide characters_, not _codepoints_, so
2985 * it's legal to search for malformed and incomplete UTF-16 sequences.
2986 *
2987 * \param haystack the wide string to search. Must not be NULL.
2988 * \param needle the wide string to search for. Must not be NULL.
2989 * \param maxlen the maximum number of wide characters to search in
2990 * `haystack`.
2991 * \returns a pointer to the first instance of `needle` in the string, or NULL
2992 * if not found.
2993 *
2994 * \threadsafety It is safe to call this function from any thread.
2995 *
2996 * \since This function is available since SDL 3.2.0.
2997 */
2998extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
2999
3000/**
3001 * Compare two null-terminated wide strings.
3002 *
3003 * This only compares wchar_t values until it hits a null-terminating
3004 * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
3005 * depending on your platform's wchar_t size), or uses valid Unicode values.
3006 *
3007 * \param str1 the first string to compare. NULL is not permitted!
3008 * \param str2 the second string to compare. NULL is not permitted!
3009 * \returns less than zero if str1 is "less than" str2, greater than zero if
3010 * str1 is "greater than" str2, and zero if the strings match
3011 * exactly.
3012 *
3013 * \threadsafety It is safe to call this function from any thread.
3014 *
3015 * \since This function is available since SDL 3.2.0.
3016 */
3017extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
3018
3019/**
3020 * Compare two wide strings up to a number of wchar_t values.
3021 *
3022 * This only compares wchar_t values; it does not care if the string is
3023 * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
3024 * or uses valid Unicode values.
3025 *
3026 * Note that while this function is intended to be used with UTF-16 (or
3027 * UTF-32, depending on your platform's definition of wchar_t), it is
3028 * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
3029 * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
3030 * sequence, it will only compare a portion of the final character.
3031 *
3032 * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
3033 * match to this number of wide chars (or both have matched to a
3034 * null-terminator character before this count), they will be considered
3035 * equal.
3036 *
3037 * \param str1 the first string to compare. NULL is not permitted!
3038 * \param str2 the second string to compare. NULL is not permitted!
3039 * \param maxlen the maximum number of wchar_t to compare.
3040 * \returns less than zero if str1 is "less than" str2, greater than zero if
3041 * str1 is "greater than" str2, and zero if the strings match
3042 * exactly.
3043 *
3044 * \threadsafety It is safe to call this function from any thread.
3045 *
3046 * \since This function is available since SDL 3.2.0.
3047 */
3048extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
3049
3050/**
3051 * Compare two null-terminated wide strings, case-insensitively.
3052 *
3053 * This will work with Unicode strings, using a technique called
3054 * "case-folding" to handle the vast majority of case-sensitive human
3055 * languages regardless of system locale. It can deal with expanding values: a
3056 * German Eszett character can compare against two ASCII 's' chars and be
3057 * considered a match, for example. A notable exception: it does not handle
3058 * the Turkish 'i' character; human language is complicated!
3059 *
3060 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
3061 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
3062 * handles Unicode, it expects the string to be well-formed and not a
3063 * null-terminated string of arbitrary bytes. Characters that are not valid
3064 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
3065 * CHARACTER), which is to say two strings of random bits may turn out to
3066 * match if they convert to the same amount of replacement characters.
3067 *
3068 * \param str1 the first string to compare. NULL is not permitted!
3069 * \param str2 the second string to compare. NULL is not permitted!
3070 * \returns less than zero if str1 is "less than" str2, greater than zero if
3071 * str1 is "greater than" str2, and zero if the strings match
3072 * exactly.
3073 *
3074 * \threadsafety It is safe to call this function from any thread.
3075 *
3076 * \since This function is available since SDL 3.2.0.
3077 */
3078extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
3079
3080/**
3081 * Compare two wide strings, case-insensitively, up to a number of wchar_t.
3082 *
3083 * This will work with Unicode strings, using a technique called
3084 * "case-folding" to handle the vast majority of case-sensitive human
3085 * languages regardless of system locale. It can deal with expanding values: a
3086 * German Eszett character can compare against two ASCII 's' chars and be
3087 * considered a match, for example. A notable exception: it does not handle
3088 * the Turkish 'i' character; human language is complicated!
3089 *
3090 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
3091 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
3092 * handles Unicode, it expects the string to be well-formed and not a
3093 * null-terminated string of arbitrary bytes. Characters that are not valid
3094 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
3095 * CHARACTER), which is to say two strings of random bits may turn out to
3096 * match if they convert to the same amount of replacement characters.
3097 *
3098 * Note that while this function might deal with variable-sized characters,
3099 * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
3100 * multi-byte UTF-16 sequence, it may convert a portion of the final character
3101 * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
3102 * to overflow a buffer.
3103 *
3104 * `maxlen` specifies a maximum number of wchar_t values to compare; if the
3105 * strings match to this number of wchar_t (or both have matched to a
3106 * null-terminator character before this number of bytes), they will be
3107 * considered equal.
3108 *
3109 * \param str1 the first string to compare. NULL is not permitted!
3110 * \param str2 the second string to compare. NULL is not permitted!
3111 * \param maxlen the maximum number of wchar_t values to compare.
3112 * \returns less than zero if str1 is "less than" str2, greater than zero if
3113 * str1 is "greater than" str2, and zero if the strings match
3114 * exactly.
3115 *
3116 * \threadsafety It is safe to call this function from any thread.
3117 *
3118 * \since This function is available since SDL 3.2.0.
3119 */
3120extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
3121
3122/**
3123 * Parse a `long` from a wide string.
3124 *
3125 * If `str` starts with whitespace, then those whitespace characters are
3126 * skipped before attempting to parse the number.
3127 *
3128 * If the parsed number does not fit inside a `long`, the result is clamped to
3129 * the minimum and maximum representable `long` values.
3130 *
3131 * \param str The null-terminated wide string to read. Must not be NULL.
3132 * \param endp If not NULL, the address of the first invalid wide character
3133 * (i.e. the next character after the parsed number) will be
3134 * written to this pointer.
3135 * \param base The base of the integer to read. Supported values are 0 and 2
3136 * to 36 inclusive. If 0, the base will be inferred from the
3137 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3138 * otherwise).
3139 * \returns the parsed `long`, or 0 if no number could be parsed.
3140 *
3141 * \threadsafety It is safe to call this function from any thread.
3142 *
3143 * \since This function is available since SDL 3.2.0.
3144 *
3145 * \sa SDL_strtol
3146 */
3147extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
3148
3149/**
3150 * Parse an `unsigned long` from a wide string.
3151 *
3152 * If `str` starts with whitespace, then those whitespace characters are
3153 * skipped before attempting to parse the number.
3154 *
3155 * If the parsed number does not fit inside an `unsigned long`, the result is
3156 * clamped to the minimum and maximum representable `unsigned long` values.
3157 *
3158 * \param str The null-terminated wide string to read. Must not be NULL.
3159 * \param endp If not NULL, the address of the first invalid wide character
3160 * (i.e. the next character after the parsed number) will be
3161 * written to this pointer.
3162 * \param base The base of the integer to read. Supported values are 0 and 2
3163 * to 36 inclusive. If 0, the base will be inferred from the
3164 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3165 * otherwise).
3166 * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
3167 *
3168 * \threadsafety It is safe to call this function from any thread.
3169 *
3170 * \since This function is available since SDL 3.6.0.
3171 *
3172 * \sa SDL_strtoul
3173 */
3174extern SDL_DECLSPEC unsigned long SDLCALL SDL_wcstoul(const wchar_t *str, wchar_t **endp, int base);
3175
3176#ifndef SDL_NOLONGLONG
3177
3178/**
3179 * Parse a `long long` from a wide string.
3180 *
3181 * If `str` starts with whitespace, then those whitespace characters are
3182 * skipped before attempting to parse the number.
3183 *
3184 * If the parsed number does not fit inside a `long long`, the result is
3185 * clamped to the minimum and maximum representable `long long` values.
3186 *
3187 * \param str The null-terminated wide string to read. Must not be NULL.
3188 * \param endp If not NULL, the address of the first invalid wide character
3189 * (i.e. the next character after the parsed number) will be
3190 * written to this pointer.
3191 * \param base The base of the integer to read. Supported values are 0 and 2
3192 * to 36 inclusive. If 0, the base will be inferred from the
3193 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3194 * otherwise).
3195 * \returns the parsed `long long`, or 0 if no number could be parsed.
3196 *
3197 * \threadsafety It is safe to call this function from any thread.
3198 *
3199 * \since This function is available since SDL 3.6.0.
3200 *
3201 * \sa SDL_strtoll
3202 */
3203extern SDL_DECLSPEC long long SDLCALL SDL_wcstoll(const wchar_t *str, wchar_t **endp, int base);
3204
3205/**
3206 * Parse an `unsigned long long` from a wide string.
3207 *
3208 * If `str` starts with whitespace, then those whitespace characters are
3209 * skipped before attempting to parse the number.
3210 *
3211 * If the parsed number does not fit inside an `unsigned long long`, the
3212 * result is clamped to the minimum and maximum representable `unsigned long
3213 * long` values.
3214 *
3215 * \param str The null-terminated wide string to read. Must not be NULL.
3216 * \param endp If not NULL, the address of the first invalid wide character
3217 * (i.e. the next character after the parsed number) will be
3218 * written to this pointer.
3219 * \param base The base of the integer to read. Supported values are 0 and 2
3220 * to 36 inclusive. If 0, the base will be inferred from the
3221 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3222 * otherwise).
3223 * \returns the parsed `unsigned long long`, or 0 if no number could be
3224 * parsed.
3225 *
3226 * \threadsafety It is safe to call this function from any thread.
3227 *
3228 * \since This function is available since SDL 3.6.0.
3229 *
3230 * \sa SDL_strtoull
3231 */
3232extern SDL_DECLSPEC unsigned long long SDLCALL SDL_wcstoull(const wchar_t *str, wchar_t **endp, int base);
3233
3234#endif /* !SDL_NOLONGLONG */
3235
3236/**
3237 * This works exactly like strlen() but doesn't require access to a C runtime.
3238 *
3239 * Counts the bytes in `str`, excluding the null terminator.
3240 *
3241 * If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
3242 *
3243 * \param str The null-terminated string to read. Must not be NULL.
3244 * \returns the length (in bytes, excluding the null terminator) of `str`.
3245 *
3246 * \threadsafety It is safe to call this function from any thread.
3247 *
3248 * \since This function is available since SDL 3.2.0.
3249 *
3250 * \sa SDL_strnlen
3251 * \sa SDL_utf8strlen
3252 * \sa SDL_utf8strnlen
3253 */
3254extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
3255
3256/**
3257 * This works exactly like strnlen() but doesn't require access to a C
3258 * runtime.
3259 *
3260 * Counts up to a maximum of `maxlen` bytes in `str`, excluding the null
3261 * terminator.
3262 *
3263 * If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().
3264 *
3265 * \param str The null-terminated string to read. Must not be NULL.
3266 * \param maxlen The maximum amount of bytes to count.
3267 * \returns the length (in bytes, excluding the null terminator) of `src` but
3268 * never more than `maxlen`.
3269 *
3270 * \threadsafety It is safe to call this function from any thread.
3271 *
3272 * \since This function is available since SDL 3.2.0.
3273 *
3274 * \sa SDL_strlen
3275 * \sa SDL_utf8strlen
3276 * \sa SDL_utf8strnlen
3277 */
3278extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
3279
3280/**
3281 * Copy a string.
3282 *
3283 * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
3284 * then appends a null terminator.
3285 *
3286 * If `maxlen` is 0, no characters are copied and no null terminator is
3287 * written.
3288 *
3289 * If you want to copy an UTF-8 string but need to ensure that multi-byte
3290 * sequences are not truncated, consider using SDL_utf8strlcpy().
3291 *
3292 * \param dst The destination buffer. Must not be NULL, and must not overlap
3293 * with `src`.
3294 * \param src The null-terminated string to copy. Must not be NULL, and must
3295 * not overlap with `dst`.
3296 * \param maxlen The length (in characters) of the destination buffer.
3297 * \returns the length (in characters, excluding the null terminator) of
3298 * `src`.
3299 *
3300 * \threadsafety It is safe to call this function from any thread.
3301 *
3302 * \since This function is available since SDL 3.2.0.
3303 *
3304 * \sa SDL_strlcat
3305 * \sa SDL_utf8strlcpy
3306 */
3307extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
3308
3309/**
3310 * Copy an UTF-8 string.
3311 *
3312 * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
3313 * also ensuring that the string written to `dst` does not end in a truncated
3314 * multi-byte sequence. Finally, it appends a null terminator.
3315 *
3316 * `src` and `dst` must not overlap.
3317 *
3318 * Note that unlike SDL_strlcpy(), this function returns the number of bytes
3319 * written, not the length of `src`.
3320 *
3321 * \param dst The destination buffer. Must not be NULL, and must not overlap
3322 * with `src`.
3323 * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
3324 * must not overlap with `dst`.
3325 * \param dst_bytes The length (in bytes) of the destination buffer. Must not
3326 * be 0.
3327 * \returns the number of bytes written, excluding the null terminator.
3328 *
3329 * \threadsafety It is safe to call this function from any thread.
3330 *
3331 * \since This function is available since SDL 3.2.0.
3332 *
3333 * \sa SDL_strlcpy
3334 */
3335extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
3336
3337/**
3338 * Concatenate strings.
3339 *
3340 * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
3341 * `src` to the end of the string in `dst`, then appends a null terminator.
3342 *
3343 * `src` and `dst` must not overlap.
3344 *
3345 * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
3346 * unmodified.
3347 *
3348 * \param dst The destination buffer already containing the first
3349 * null-terminated string. Must not be NULL and must not overlap
3350 * with `src`.
3351 * \param src The second null-terminated string. Must not be NULL, and must
3352 * not overlap with `dst`.
3353 * \param maxlen The length (in characters) of the destination buffer.
3354 * \returns the length (in characters, excluding the null terminator) of the
3355 * string in `dst` plus the length of `src`.
3356 *
3357 * \threadsafety It is safe to call this function from any thread.
3358 *
3359 * \since This function is available since SDL 3.2.0.
3360 *
3361 * \sa SDL_strlcpy
3362 */
3363extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
3364
3365/**
3366 * Allocate a copy of a string.
3367 *
3368 * This allocates enough space for a null-terminated copy of `str`, using
3369 * SDL_malloc, and then makes a copy of the string into this space.
3370 *
3371 * The returned string is owned by the caller, and should be passed to
3372 * SDL_free when no longer needed.
3373 *
3374 * \param str the string to copy.
3375 * \returns a pointer to the newly-allocated string.
3376 *
3377 * \threadsafety It is safe to call this function from any thread.
3378 *
3379 * \since This function is available since SDL 3.2.0.
3380 */
3381extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
3382
3383/**
3384 * Allocate a copy of a string, up to n characters.
3385 *
3386 * This allocates enough space for a null-terminated copy of `str`, up to
3387 * `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into
3388 * this space.
3389 *
3390 * If the string is longer than `maxlen` bytes, the returned string will be
3391 * `maxlen` bytes long, plus a null-terminator character that isn't included
3392 * in the count.
3393 *
3394 * The returned string is owned by the caller, and should be passed to
3395 * SDL_free when no longer needed.
3396 *
3397 * \param str the string to copy.
3398 * \param maxlen the maximum length of the copied string, not counting the
3399 * null-terminator character.
3400 * \returns a pointer to the newly-allocated string.
3401 *
3402 * \threadsafety It is safe to call this function from any thread.
3403 *
3404 * \since This function is available since SDL 3.2.0.
3405 */
3406extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
3407
3408/**
3409 * Reverse a string's contents.
3410 *
3411 * This reverses a null-terminated string in-place. Only the content of the
3412 * string is reversed; the null-terminator character remains at the end of the
3413 * reversed string.
3414 *
3415 * **WARNING**: This function reverses the _bytes_ of the string, not the
3416 * codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
3417 * will ruin the string data. You should only use this function on strings
3418 * that are completely comprised of low ASCII characters.
3419 *
3420 * \param str the string to reverse.
3421 * \returns `str`.
3422 *
3423 * \threadsafety It is safe to call this function from any thread.
3424 *
3425 * \since This function is available since SDL 3.2.0.
3426 */
3427extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
3428
3429/**
3430 * Convert a string to uppercase.
3431 *
3432 * **WARNING**: Regardless of system locale, this will only convert ASCII
3433 * values 'a' through 'z' to uppercase.
3434 *
3435 * This function operates on a null-terminated string of bytes--even if it is
3436 * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
3437 * uppercase equivalents in-place, returning the original `str` pointer.
3438 *
3439 * \param str the string to convert in-place. Can not be NULL.
3440 * \returns the `str` pointer passed into this function.
3441 *
3442 * \threadsafety It is safe to call this function from any thread.
3443 *
3444 * \since This function is available since SDL 3.2.0.
3445 *
3446 * \sa SDL_strlwr
3447 */
3448extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
3449
3450/**
3451 * Convert a string to lowercase.
3452 *
3453 * **WARNING**: Regardless of system locale, this will only convert ASCII
3454 * values 'A' through 'Z' to lowercase.
3455 *
3456 * This function operates on a null-terminated string of bytes--even if it is
3457 * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
3458 * lowercase equivalents in-place, returning the original `str` pointer.
3459 *
3460 * \param str the string to convert in-place. Can not be NULL.
3461 * \returns the `str` pointer passed into this function.
3462 *
3463 * \threadsafety It is safe to call this function from any thread.
3464 *
3465 * \since This function is available since SDL 3.2.0.
3466 *
3467 * \sa SDL_strupr
3468 */
3469extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
3470
3471/**
3472 * Search a string for the first instance of a specific byte.
3473 *
3474 * The search ends once it finds the requested byte value, or a null
3475 * terminator byte to end the string.
3476 *
3477 * Note that this looks for _bytes_, not _characters_, so you cannot match
3478 * against a Unicode codepoint > 255, regardless of character encoding.
3479 *
3480 * \param str the string to search. Must not be NULL.
3481 * \param c the byte value to search for.
3482 * \returns a pointer to the first instance of `c` in the string, or NULL if
3483 * not found.
3484 *
3485 * \threadsafety It is safe to call this function from any thread.
3486 *
3487 * \since This function is available since SDL 3.2.0.
3488 */
3489extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
3490
3491/**
3492 * Search a string for the last instance of a specific byte.
3493 *
3494 * The search must go until it finds a null terminator byte to end the string.
3495 *
3496 * Note that this looks for _bytes_, not _characters_, so you cannot match
3497 * against a Unicode codepoint > 255, regardless of character encoding.
3498 *
3499 * \param str the string to search. Must not be NULL.
3500 * \param c the byte value to search for.
3501 * \returns a pointer to the last instance of `c` in the string, or NULL if
3502 * not found.
3503 *
3504 * \threadsafety It is safe to call this function from any thread.
3505 *
3506 * \since This function is available since SDL 3.2.0.
3507 */
3508extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
3509
3510/**
3511 * Search a string for the first instance of a specific substring.
3512 *
3513 * The search ends once it finds the requested substring, or a null terminator
3514 * byte to end the string.
3515 *
3516 * Note that this looks for strings of _bytes_, not _characters_, so it's
3517 * legal to search for malformed and incomplete UTF-8 sequences.
3518 *
3519 * \param haystack the string to search. Must not be NULL.
3520 * \param needle the string to search for. Must not be NULL.
3521 * \returns a pointer to the first instance of `needle` in the string, or NULL
3522 * if not found.
3523 *
3524 * \threadsafety It is safe to call this function from any thread.
3525 *
3526 * \since This function is available since SDL 3.2.0.
3527 */
3528extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
3529
3530/**
3531 * Search a string, up to n bytes, for the first instance of a specific
3532 * substring.
3533 *
3534 * The search ends once it finds the requested substring, or a null terminator
3535 * byte to end the string, or `maxlen` bytes have been examined. It is
3536 * possible to use this function on a string without a null terminator.
3537 *
3538 * Note that this looks for strings of _bytes_, not _characters_, so it's
3539 * legal to search for malformed and incomplete UTF-8 sequences.
3540 *
3541 * \param haystack the string to search. Must not be NULL.
3542 * \param needle the string to search for. Must not be NULL.
3543 * \param maxlen the maximum number of bytes to search in `haystack`.
3544 * \returns a pointer to the first instance of `needle` in the string, or NULL
3545 * if not found.
3546 *
3547 * \threadsafety It is safe to call this function from any thread.
3548 *
3549 * \since This function is available since SDL 3.2.0.
3550 */
3551extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
3552
3553/**
3554 * Search a UTF-8 string for the first instance of a specific substring,
3555 * case-insensitively.
3556 *
3557 * This will work with Unicode strings, using a technique called
3558 * "case-folding" to handle the vast majority of case-sensitive human
3559 * languages regardless of system locale. It can deal with expanding values: a
3560 * German Eszett character can compare against two ASCII 's' chars and be
3561 * considered a match, for example. A notable exception: it does not handle
3562 * the Turkish 'i' character; human language is complicated!
3563 *
3564 * Since this handles Unicode, it expects the strings to be well-formed UTF-8
3565 * and not a null-terminated string of arbitrary bytes. Bytes that are not
3566 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
3567 * CHARACTER), which is to say two strings of random bits may turn out to
3568 * match if they convert to the same amount of replacement characters.
3569 *
3570 * \param haystack the string to search. Must not be NULL.
3571 * \param needle the string to search for. Must not be NULL.
3572 * \returns a pointer to the first instance of `needle` in the string, or NULL
3573 * if not found.
3574 *
3575 * \threadsafety It is safe to call this function from any thread.
3576 *
3577 * \since This function is available since SDL 3.2.0.
3578 */
3579extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
3580
3581/**
3582 * This works exactly like strtok_r() but doesn't require access to a C
3583 * runtime.
3584 *
3585 * Break a string up into a series of tokens.
3586 *
3587 * To start tokenizing a new string, `str` should be the non-NULL address of
3588 * the string to start tokenizing. Future calls to get the next token from the
3589 * same string should specify a NULL.
3590 *
3591 * Note that this function will overwrite pieces of `str` with null chars to
3592 * split it into tokens. This function cannot be used with const/read-only
3593 * strings!
3594 *
3595 * `saveptr` just needs to point to a `char *` that can be overwritten; SDL
3596 * will use this to save tokenizing state between calls. It is initialized if
3597 * `str` is non-NULL, and used to resume tokenizing when `str` is NULL.
3598 *
3599 * \param str the string to tokenize, or NULL to continue tokenizing.
3600 * \param delim the delimiter string that separates tokens.
3601 * \param saveptr pointer to a char *, used for ongoing state.
3602 * \returns A pointer to the next token, or NULL if no tokens remain.
3603 *
3604 * \threadsafety It is safe to call this function from any thread.
3605 *
3606 * \since This function is available since SDL 3.2.0.
3607 */
3608extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr);
3609
3610/**
3611 * Count the number of codepoints in a UTF-8 string.
3612 *
3613 * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
3614 * terminator.
3615 *
3616 * If you need to count the bytes in a string instead, consider using
3617 * SDL_strlen().
3618 *
3619 * Since this handles Unicode, it expects the strings to be well-formed UTF-8
3620 * and not a null-terminated string of arbitrary bytes. Bytes that are not
3621 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
3622 * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
3623 * count by several replacement characters.
3624 *
3625 * \param str The null-terminated UTF-8 string to read. Must not be NULL.
3626 * \returns The length (in codepoints, excluding the null terminator) of
3627 * `src`.
3628 *
3629 * \threadsafety It is safe to call this function from any thread.
3630 *
3631 * \since This function is available since SDL 3.2.0.
3632 *
3633 * \sa SDL_utf8strnlen
3634 * \sa SDL_strlen
3635 */
3636extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
3637
3638/**
3639 * Count the number of codepoints in a UTF-8 string, up to n bytes.
3640 *
3641 * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
3642 * terminator.
3643 *
3644 * If you need to count the bytes in a string instead, consider using
3645 * SDL_strnlen().
3646 *
3647 * The counting stops at `bytes` bytes (not codepoints!). This seems
3648 * counterintuitive, but makes it easy to express the total size of the
3649 * string's buffer.
3650 *
3651 * Since this handles Unicode, it expects the strings to be well-formed UTF-8
3652 * and not a null-terminated string of arbitrary bytes. Bytes that are not
3653 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
3654 * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
3655 * count by several replacement characters.
3656 *
3657 * \param str The null-terminated UTF-8 string to read. Must not be NULL.
3658 * \param bytes The maximum amount of bytes to count.
3659 * \returns The length (in codepoints, excluding the null terminator) of `src`
3660 * but never more than `maxlen`.
3661 *
3662 * \threadsafety It is safe to call this function from any thread.
3663 *
3664 * \since This function is available since SDL 3.2.0.
3665 *
3666 * \sa SDL_utf8strlen
3667 * \sa SDL_strnlen
3668 */
3669extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
3670
3671/**
3672 * Convert an integer into a string.
3673 *
3674 * This requires a radix to specified for string format. Specifying 10
3675 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3676 * to 36.
3677 *
3678 * Note that this function will overflow a buffer if `str` is not large enough
3679 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3680 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3681 * much more space than you expect to use (and don't forget possible negative
3682 * signs, null terminator bytes, etc).
3683 *
3684 * \param value the integer to convert.
3685 * \param str the buffer to write the string into.
3686 * \param radix the radix to use for string generation.
3687 * \returns `str`.
3688 *
3689 * \threadsafety It is safe to call this function from any thread.
3690 *
3691 * \since This function is available since SDL 3.2.0.
3692 *
3693 * \sa SDL_uitoa
3694 * \sa SDL_ltoa
3695 * \sa SDL_lltoa
3696 */
3697extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
3698
3699/**
3700 * Convert an unsigned integer into a string.
3701 *
3702 * This requires a radix to specified for string format. Specifying 10
3703 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3704 * to 36.
3705 *
3706 * Note that this function will overflow a buffer if `str` is not large enough
3707 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3708 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3709 * much more space than you expect to use (and don't forget null terminator
3710 * bytes, etc).
3711 *
3712 * \param value the unsigned integer to convert.
3713 * \param str the buffer to write the string into.
3714 * \param radix the radix to use for string generation.
3715 * \returns `str`.
3716 *
3717 * \threadsafety It is safe to call this function from any thread.
3718 *
3719 * \since This function is available since SDL 3.2.0.
3720 *
3721 * \sa SDL_itoa
3722 * \sa SDL_ultoa
3723 * \sa SDL_ulltoa
3724 */
3725extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
3726
3727/**
3728 * Convert a long integer into a string.
3729 *
3730 * This requires a radix to specified for string format. Specifying 10
3731 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3732 * to 36.
3733 *
3734 * Note that this function will overflow a buffer if `str` is not large enough
3735 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3736 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3737 * much more space than you expect to use (and don't forget possible negative
3738 * signs, null terminator bytes, etc).
3739 *
3740 * \param value the long integer to convert.
3741 * \param str the buffer to write the string into.
3742 * \param radix the radix to use for string generation.
3743 * \returns `str`.
3744 *
3745 * \threadsafety It is safe to call this function from any thread.
3746 *
3747 * \since This function is available since SDL 3.2.0.
3748 *
3749 * \sa SDL_ultoa
3750 * \sa SDL_itoa
3751 * \sa SDL_lltoa
3752 */
3753extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
3754
3755/**
3756 * Convert an unsigned long integer into a string.
3757 *
3758 * This requires a radix to specified for string format. Specifying 10
3759 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3760 * to 36.
3761 *
3762 * Note that this function will overflow a buffer if `str` is not large enough
3763 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3764 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3765 * much more space than you expect to use (and don't forget null terminator
3766 * bytes, etc).
3767 *
3768 * \param value the unsigned long integer to convert.
3769 * \param str the buffer to write the string into.
3770 * \param radix the radix to use for string generation.
3771 * \returns `str`.
3772 *
3773 * \threadsafety It is safe to call this function from any thread.
3774 *
3775 * \since This function is available since SDL 3.2.0.
3776 *
3777 * \sa SDL_ltoa
3778 * \sa SDL_uitoa
3779 * \sa SDL_ulltoa
3780 */
3781extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
3782
3783#ifndef SDL_NOLONGLONG
3784
3785/**
3786 * Convert a long long integer into a string.
3787 *
3788 * This requires a radix to specified for string format. Specifying 10
3789 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3790 * to 36.
3791 *
3792 * Note that this function will overflow a buffer if `str` is not large enough
3793 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3794 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3795 * much more space than you expect to use (and don't forget possible negative
3796 * signs, null terminator bytes, etc).
3797 *
3798 * \param value the long long integer to convert.
3799 * \param str the buffer to write the string into.
3800 * \param radix the radix to use for string generation.
3801 * \returns `str`.
3802 *
3803 * \threadsafety It is safe to call this function from any thread.
3804 *
3805 * \since This function is available since SDL 3.2.0.
3806 *
3807 * \sa SDL_ulltoa
3808 * \sa SDL_itoa
3809 * \sa SDL_ltoa
3810 */
3811extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
3812
3813/**
3814 * Convert an unsigned long long integer into a string.
3815 *
3816 * This requires a radix to specified for string format. Specifying 10
3817 * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
3818 * to 36.
3819 *
3820 * Note that this function will overflow a buffer if `str` is not large enough
3821 * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
3822 * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
3823 * much more space than you expect to use (and don't forget null terminator
3824 * bytes, etc).
3825 *
3826 * \param value the unsigned long long integer to convert.
3827 * \param str the buffer to write the string into.
3828 * \param radix the radix to use for string generation.
3829 * \returns `str`.
3830 *
3831 * \threadsafety It is safe to call this function from any thread.
3832 *
3833 * \since This function is available since SDL 3.2.0.
3834 *
3835 * \sa SDL_lltoa
3836 * \sa SDL_uitoa
3837 * \sa SDL_ultoa
3838 */
3839extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
3840#endif
3841
3842/**
3843 * Parse an `int` from a string.
3844 *
3845 * The result of calling `SDL_atoi(str)` is equivalent to
3846 * `(int)SDL_strtol(str, NULL, 10)`.
3847 *
3848 * \param str The null-terminated string to read. Must not be NULL.
3849 * \returns the parsed `int`.
3850 *
3851 * \threadsafety It is safe to call this function from any thread.
3852 *
3853 * \since This function is available since SDL 3.2.0.
3854 *
3855 * \sa SDL_atof
3856 * \sa SDL_strtol
3857 * \sa SDL_strtoul
3858 * \sa SDL_strtoll
3859 * \sa SDL_strtoull
3860 * \sa SDL_strtod
3861 * \sa SDL_itoa
3862 */
3863extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
3864
3865/**
3866 * Parse a `double` from a string.
3867 *
3868 * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
3869 * NULL)`.
3870 *
3871 * \param str The null-terminated string to read. Must not be NULL.
3872 * \returns the parsed `double`.
3873 *
3874 * \threadsafety It is safe to call this function from any thread.
3875 *
3876 * \since This function is available since SDL 3.2.0.
3877 *
3878 * \sa SDL_atoi
3879 * \sa SDL_strtol
3880 * \sa SDL_strtoul
3881 * \sa SDL_strtoll
3882 * \sa SDL_strtoull
3883 * \sa SDL_strtod
3884 */
3885extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
3886
3887/**
3888 * Parse a `long` from a string.
3889 *
3890 * If `str` starts with whitespace, then those whitespace characters are
3891 * skipped before attempting to parse the number.
3892 *
3893 * If the parsed number does not fit inside a `long`, the result is clamped to
3894 * the minimum and maximum representable `long` values.
3895 *
3896 * \param str The null-terminated string to read. Must not be NULL.
3897 * \param endp If not NULL, the address of the first invalid character (i.e.
3898 * the next character after the parsed number) will be written to
3899 * this pointer.
3900 * \param base The base of the integer to read. Supported values are 0 and 2
3901 * to 36 inclusive. If 0, the base will be inferred from the
3902 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3903 * otherwise).
3904 * \returns the parsed `long`, or 0 if no number could be parsed.
3905 *
3906 * \threadsafety It is safe to call this function from any thread.
3907 *
3908 * \since This function is available since SDL 3.2.0.
3909 *
3910 * \sa SDL_atoi
3911 * \sa SDL_atof
3912 * \sa SDL_strtoul
3913 * \sa SDL_strtoll
3914 * \sa SDL_strtoull
3915 * \sa SDL_strtod
3916 * \sa SDL_ltoa
3917 * \sa SDL_wcstol
3918 */
3919extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
3920
3921/**
3922 * Parse an `unsigned long` from a string.
3923 *
3924 * If `str` starts with whitespace, then those whitespace characters are
3925 * skipped before attempting to parse the number.
3926 *
3927 * If the parsed number does not fit inside an `unsigned long`, the result is
3928 * clamped to the maximum representable `unsigned long` value.
3929 *
3930 * \param str The null-terminated string to read. Must not be NULL.
3931 * \param endp If not NULL, the address of the first invalid character (i.e.
3932 * the next character after the parsed number) will be written to
3933 * this pointer.
3934 * \param base The base of the integer to read. Supported values are 0 and 2
3935 * to 36 inclusive. If 0, the base will be inferred from the
3936 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3937 * otherwise).
3938 * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
3939 *
3940 * \threadsafety It is safe to call this function from any thread.
3941 *
3942 * \since This function is available since SDL 3.2.0.
3943 *
3944 * \sa SDL_atoi
3945 * \sa SDL_atof
3946 * \sa SDL_strtol
3947 * \sa SDL_strtoll
3948 * \sa SDL_strtoull
3949 * \sa SDL_strtod
3950 * \sa SDL_ultoa
3951 */
3952extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
3953
3954#ifndef SDL_NOLONGLONG
3955
3956/**
3957 * Parse a `long long` from a string.
3958 *
3959 * If `str` starts with whitespace, then those whitespace characters are
3960 * skipped before attempting to parse the number.
3961 *
3962 * If the parsed number does not fit inside a `long long`, the result is
3963 * clamped to the minimum and maximum representable `long long` values.
3964 *
3965 * \param str The null-terminated string to read. Must not be NULL.
3966 * \param endp If not NULL, the address of the first invalid character (i.e.
3967 * the next character after the parsed number) will be written to
3968 * this pointer.
3969 * \param base The base of the integer to read. Supported values are 0 and 2
3970 * to 36 inclusive. If 0, the base will be inferred from the
3971 * number's prefix (0x for hexadecimal, 0 for octal, decimal
3972 * otherwise).
3973 * \returns the parsed `long long`, or 0 if no number could be parsed.
3974 *
3975 * \threadsafety It is safe to call this function from any thread.
3976 *
3977 * \since This function is available since SDL 3.2.0.
3978 *
3979 * \sa SDL_atoi
3980 * \sa SDL_atof
3981 * \sa SDL_strtol
3982 * \sa SDL_strtoul
3983 * \sa SDL_strtoull
3984 * \sa SDL_strtod
3985 * \sa SDL_lltoa
3986 */
3987extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
3988
3989/**
3990 * Parse an `unsigned long long` from a string.
3991 *
3992 * If `str` starts with whitespace, then those whitespace characters are
3993 * skipped before attempting to parse the number.
3994 *
3995 * If the parsed number does not fit inside an `unsigned long long`, the
3996 * result is clamped to the maximum representable `unsigned long long` value.
3997 *
3998 * \param str The null-terminated string to read. Must not be NULL.
3999 * \param endp If not NULL, the address of the first invalid character (i.e.
4000 * the next character after the parsed number) will be written to
4001 * this pointer.
4002 * \param base The base of the integer to read. Supported values are 0 and 2
4003 * to 36 inclusive. If 0, the base will be inferred from the
4004 * number's prefix (0x for hexadecimal, 0 for octal, decimal
4005 * otherwise).
4006 * \returns the parsed `unsigned long long`, or 0 if no number could be
4007 * parsed.
4008 *
4009 * \threadsafety It is safe to call this function from any thread.
4010 *
4011 * \since This function is available since SDL 3.2.0.
4012 *
4013 * \sa SDL_atoi
4014 * \sa SDL_atof
4015 * \sa SDL_strtol
4016 * \sa SDL_strtoll
4017 * \sa SDL_strtoul
4018 * \sa SDL_strtod
4019 * \sa SDL_ulltoa
4020 */
4021extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
4022#endif
4023
4024/**
4025 * Parse a `double` from a string.
4026 *
4027 * This function makes fewer guarantees than the C runtime `strtod`:
4028 *
4029 * - Only decimal notation is guaranteed to be supported. The handling of
4030 * scientific and hexadecimal notation is unspecified.
4031 * - Whether or not INF and NAN can be parsed is unspecified.
4032 * - The precision of the result is unspecified.
4033 *
4034 * \param str the null-terminated string to read. Must not be NULL.
4035 * \param endp if not NULL, the address of the first invalid character (i.e.
4036 * the next character after the parsed number) will be written to
4037 * this pointer.
4038 * \returns the parsed `double`, or 0 if no number could be parsed.
4039 *
4040 * \threadsafety It is safe to call this function from any thread.
4041 *
4042 * \since This function is available since SDL 3.2.0.
4043 *
4044 * \sa SDL_atoi
4045 * \sa SDL_atof
4046 * \sa SDL_strtol
4047 * \sa SDL_strtoll
4048 * \sa SDL_strtoul
4049 * \sa SDL_strtoull
4050 */
4051extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
4052
4053/**
4054 * Compare two null-terminated UTF-8 strings.
4055 *
4056 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
4057 * since effectively this function just compares bytes until it hits a
4058 * null-terminating character. Also due to the nature of UTF-8, this can be
4059 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
4060 *
4061 * \param str1 the first string to compare. NULL is not permitted!
4062 * \param str2 the second string to compare. NULL is not permitted!
4063 * \returns less than zero if str1 is "less than" str2, greater than zero if
4064 * str1 is "greater than" str2, and zero if the strings match
4065 * exactly.
4066 *
4067 * \threadsafety It is safe to call this function from any thread.
4068 *
4069 * \since This function is available since SDL 3.2.0.
4070 */
4071extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
4072
4073/**
4074 * Compare two UTF-8 strings up to a number of bytes.
4075 *
4076 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
4077 * since effectively this function just compares bytes until it hits a
4078 * null-terminating character. Also due to the nature of UTF-8, this can be
4079 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
4080 *
4081 * Note that while this function is intended to be used with UTF-8, it is
4082 * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
4083 * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
4084 * compare a portion of the final character.
4085 *
4086 * `maxlen` specifies a maximum number of bytes to compare; if the strings
4087 * match to this number of bytes (or both have matched to a null-terminator
4088 * character before this number of bytes), they will be considered equal.
4089 *
4090 * \param str1 the first string to compare. NULL is not permitted!
4091 * \param str2 the second string to compare. NULL is not permitted!
4092 * \param maxlen the maximum number of _bytes_ to compare.
4093 * \returns less than zero if str1 is "less than" str2, greater than zero if
4094 * str1 is "greater than" str2, and zero if the strings match
4095 * exactly.
4096 *
4097 * \threadsafety It is safe to call this function from any thread.
4098 *
4099 * \since This function is available since SDL 3.2.0.
4100 */
4101extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
4102
4103/**
4104 * Compare two null-terminated UTF-8 strings, case-insensitively.
4105 *
4106 * This will work with Unicode strings, using a technique called
4107 * "case-folding" to handle the vast majority of case-sensitive human
4108 * languages regardless of system locale. It can deal with expanding values: a
4109 * German Eszett character can compare against two ASCII 's' chars and be
4110 * considered a match, for example. A notable exception: it does not handle
4111 * the Turkish 'i' character; human language is complicated!
4112 *
4113 * Since this handles Unicode, it expects the string to be well-formed UTF-8
4114 * and not a null-terminated string of arbitrary bytes. Bytes that are not
4115 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
4116 * CHARACTER), which is to say two strings of random bits may turn out to
4117 * match if they convert to the same amount of replacement characters.
4118 *
4119 * \param str1 the first string to compare. NULL is not permitted!
4120 * \param str2 the second string to compare. NULL is not permitted!
4121 * \returns less than zero if str1 is "less than" str2, greater than zero if
4122 * str1 is "greater than" str2, and zero if the strings match
4123 * exactly.
4124 *
4125 * \threadsafety It is safe to call this function from any thread.
4126 *
4127 * \since This function is available since SDL 3.2.0.
4128 */
4129extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
4130
4131
4132/**
4133 * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
4134 *
4135 * This will work with Unicode strings, using a technique called
4136 * "case-folding" to handle the vast majority of case-sensitive human
4137 * languages regardless of system locale. It can deal with expanding values: a
4138 * German Eszett character can compare against two ASCII 's' chars and be
4139 * considered a match, for example. A notable exception: it does not handle
4140 * the Turkish 'i' character; human language is complicated!
4141 *
4142 * Since this handles Unicode, it expects the string to be well-formed UTF-8
4143 * and not a null-terminated string of arbitrary bytes. Bytes that are not
4144 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
4145 * CHARACTER), which is to say two strings of random bits may turn out to
4146 * match if they convert to the same amount of replacement characters.
4147 *
4148 * Note that while this function is intended to be used with UTF-8, `maxlen`
4149 * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
4150 * UTF-8 sequence, it may convert a portion of the final character to one or
4151 * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
4152 * a buffer.
4153 *
4154 * `maxlen` specifies a maximum number of bytes to compare; if the strings
4155 * match to this number of bytes (or both have matched to a null-terminator
4156 * character before this number of bytes), they will be considered equal.
4157 *
4158 * \param str1 the first string to compare. NULL is not permitted!
4159 * \param str2 the second string to compare. NULL is not permitted!
4160 * \param maxlen the maximum number of bytes to compare.
4161 * \returns less than zero if str1 is "less than" str2, greater than zero if
4162 * str1 is "greater than" str2, and zero if the strings match
4163 * exactly.
4164 *
4165 * \threadsafety It is safe to call this function from any thread.
4166 *
4167 * \since This function is available since SDL 3.2.0.
4168 */
4169extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
4170
4171/**
4172 * Searches a string for the first occurrence of any character contained in a
4173 * breakset, and returns a pointer from the string to that character.
4174 *
4175 * \param str The null-terminated string to be searched. Must not be NULL, and
4176 * must not overlap with `breakset`.
4177 * \param breakset A null-terminated string containing the list of characters
4178 * to look for. Must not be NULL, and must not overlap with
4179 * `str`.
4180 * \returns A pointer to the location, in str, of the first occurrence of a
4181 * character present in the breakset, or NULL if none is found.
4182 *
4183 * \threadsafety It is safe to call this function from any thread.
4184 *
4185 * \since This function is available since SDL 3.2.0.
4186 */
4187extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
4188
4189/**
4190 * The Unicode REPLACEMENT CHARACTER codepoint.
4191 *
4192 * SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they
4193 * encounter a UTF-8 string with encoding errors.
4194 *
4195 * This tends to render as something like a question mark in most places.
4196 *
4197 * \since This macro is available since SDL 3.2.0.
4198 *
4199 * \sa SDL_StepBackUTF8
4200 * \sa SDL_StepUTF8
4201 */
4202#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
4203
4204/**
4205 * Decode a UTF-8 string, one Unicode codepoint at a time.
4206 *
4207 * This will return the first Unicode codepoint in the UTF-8 encoded string in
4208 * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
4209 *
4210 * It will not access more than `*pslen` bytes from the string. `*pslen` will
4211 * be adjusted, as well, subtracting the number of bytes consumed.
4212 *
4213 * `pslen` is allowed to be NULL, in which case the string _must_ be
4214 * NULL-terminated, as the function will blindly read until it sees the NULL
4215 * char.
4216 *
4217 * If `*pslen` is zero, it assumes the end of string is reached and returns a
4218 * zero codepoint regardless of the contents of the string buffer.
4219 *
4220 * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
4221 * zero, it will not advance `*pstr` or `*pslen` at all.
4222 *
4223 * Generally this function is called in a loop until it returns zero,
4224 * adjusting its parameters each iteration.
4225 *
4226 * If an invalid UTF-8 sequence is encountered, this function returns
4227 * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
4228 * (which is to say, a multibyte sequence might produce several
4229 * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
4230 * UTF-8 sequence).
4231 *
4232 * Several things can generate invalid UTF-8 sequences, including overlong
4233 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
4234 * refer to
4235 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
4236 * for details.
4237 *
4238 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
4239 * \param pslen a pointer to the number of bytes in the string, to be read and
4240 * adjusted. NULL is allowed.
4241 * \returns the first Unicode codepoint in the string.
4242 *
4243 * \threadsafety It is safe to call this function from any thread.
4244 *
4245 * \since This function is available since SDL 3.2.0.
4246 */
4247extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
4248
4249/**
4250 * Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
4251 *
4252 * This will go to the start of the previous Unicode codepoint in the string,
4253 * move `*pstr` to that location and return that codepoint.
4254 *
4255 * If `*pstr` is already at the start of the string), it will not advance
4256 * `*pstr` at all.
4257 *
4258 * Generally this function is called in a loop until it returns zero,
4259 * adjusting its parameter each iteration.
4260 *
4261 * If an invalid UTF-8 sequence is encountered, this function returns
4262 * SDL_INVALID_UNICODE_CODEPOINT.
4263 *
4264 * Several things can generate invalid UTF-8 sequences, including overlong
4265 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
4266 * refer to
4267 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
4268 * for details.
4269 *
4270 * \param start a pointer to the beginning of the UTF-8 string.
4271 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
4272 * \returns the previous Unicode codepoint in the string.
4273 *
4274 * \threadsafety It is safe to call this function from any thread.
4275 *
4276 * \since This function is available since SDL 3.2.0.
4277 */
4278extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr);
4279
4280/**
4281 * Convert a single Unicode codepoint to UTF-8.
4282 *
4283 * The buffer pointed to by `dst` must be at least 4 bytes long, as this
4284 * function may generate between 1 and 4 bytes of output.
4285 *
4286 * This function returns the first byte _after_ the newly-written UTF-8
4287 * sequence, which is useful for encoding multiple codepoints in a loop, or
4288 * knowing where to write a NULL-terminator character to end the string (in
4289 * either case, plan to have a buffer of _more_ than 4 bytes!).
4290 *
4291 * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
4292 * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
4293 * codepoint instead, and not set an error.
4294 *
4295 * If `dst` is NULL, this returns NULL immediately without writing to the
4296 * pointer and without setting an error.
4297 *
4298 * \param codepoint a Unicode codepoint to convert to UTF-8.
4299 * \param dst the location to write the encoded UTF-8. Must point to at least
4300 * 4 bytes!
4301 * \returns the first byte past the newly-written UTF-8 sequence.
4302 *
4303 * \threadsafety It is safe to call this function from any thread.
4304 *
4305 * \since This function is available since SDL 3.2.0.
4306 */
4307extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
4308
4309/**
4310 * This works exactly like sscanf() but doesn't require access to a C runtime.
4311 *
4312 * Scan a string, matching a format string, converting each '%' item and
4313 * storing it to pointers provided through variable arguments.
4314 *
4315 * \param text the string to scan. Must not be NULL.
4316 * \param fmt a printf-style format string. Must not be NULL.
4317 * \param ... a list of pointers to values to be filled in with scanned items.
4318 * \returns the number of items that matched the format string.
4319 *
4320 * \threadsafety It is safe to call this function from any thread.
4321 *
4322 * \since This function is available since SDL 3.2.0.
4323 */
4324extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
4325
4326/**
4327 * This works exactly like vsscanf() but doesn't require access to a C
4328 * runtime.
4329 *
4330 * Functions identically to SDL_sscanf(), except it takes a `va_list` instead
4331 * of using `...` variable arguments.
4332 *
4333 * \param text the string to scan. Must not be NULL.
4334 * \param fmt a printf-style format string. Must not be NULL.
4335 * \param ap a `va_list` of pointers to values to be filled in with scanned
4336 * items.
4337 * \returns the number of items that matched the format string.
4338 *
4339 * \threadsafety It is safe to call this function from any thread.
4340 *
4341 * \since This function is available since SDL 3.2.0.
4342 */
4343extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
4344
4345/**
4346 * This works exactly like snprintf() but doesn't require access to a C
4347 * runtime.
4348 *
4349 * Format a string of up to `maxlen`-1 bytes, converting each '%' item with
4350 * values provided through variable arguments.
4351 *
4352 * While some C runtimes differ on how to deal with too-large strings, this
4353 * function null-terminates the output, by treating the null-terminator as
4354 * part of the `maxlen` count. Note that if `maxlen` is zero, however, no
4355 * bytes will be written at all.
4356 *
4357 * This function returns the number of _bytes_ (not _characters_) that should
4358 * be written, excluding the null-terminator character. If this returns a
4359 * number >= `maxlen`, it means the output string was truncated. A negative
4360 * return value means an error occurred.
4361 *
4362 * Referencing the output string's pointer with a format item is undefined
4363 * behavior.
4364 *
4365 * \param text the buffer to write the string into. Must not be NULL.
4366 * \param maxlen the maximum bytes to write, including the null-terminator.
4367 * \param fmt a printf-style format string. Must not be NULL.
4368 * \param ... a list of values to be used with the format string.
4369 * \returns the number of bytes that should be written, not counting the
4370 * null-terminator char, or a negative value on error.
4371 *
4372 * \threadsafety It is safe to call this function from any thread.
4373 *
4374 * \since This function is available since SDL 3.2.0.
4375 */
4376extern 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);
4377
4378/**
4379 * This works exactly like swprintf() but doesn't require access to a C
4380 * runtime.
4381 *
4382 * Format a wide string of up to `maxlen`-1 wchar_t values, converting each
4383 * '%' item with values provided through variable arguments.
4384 *
4385 * While some C runtimes differ on how to deal with too-large strings, this
4386 * function null-terminates the output, by treating the null-terminator as
4387 * part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide
4388 * characters will be written at all.
4389 *
4390 * This function returns the number of _wide characters_ (not _codepoints_)
4391 * that should be written, excluding the null-terminator character. If this
4392 * returns a number >= `maxlen`, it means the output string was truncated. A
4393 * negative return value means an error occurred.
4394 *
4395 * Referencing the output string's pointer with a format item is undefined
4396 * behavior.
4397 *
4398 * \param text the buffer to write the wide string into. Must not be NULL.
4399 * \param maxlen the maximum wchar_t values to write, including the
4400 * null-terminator.
4401 * \param fmt a printf-style format string. Must not be NULL.
4402 * \param ... a list of values to be used with the format string.
4403 * \returns the number of wide characters that should be written, not counting
4404 * the null-terminator char, or a negative value on error.
4405 *
4406 * \threadsafety It is safe to call this function from any thread.
4407 *
4408 * \since This function is available since SDL 3.2.0.
4409 */
4410extern 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);
4411
4412/**
4413 * This works exactly like vsnprintf() but doesn't require access to a C
4414 * runtime.
4415 *
4416 * Functions identically to SDL_snprintf(), except it takes a `va_list`
4417 * instead of using `...` variable arguments.
4418 *
4419 * \param text the buffer to write the string into. Must not be NULL.
4420 * \param maxlen the maximum bytes to write, including the null-terminator.
4421 * \param fmt a printf-style format string. Must not be NULL.
4422 * \param ap a `va_list` values to be used with the format string.
4423 * \returns the number of bytes that should be written, not counting the
4424 * null-terminator char, or a negative value on error.
4425 *
4426 * \threadsafety It is safe to call this function from any thread.
4427 *
4428 * \since This function is available since SDL 3.2.0.
4429 */
4430extern 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);
4431
4432/**
4433 * This works exactly like vswprintf() but doesn't require access to a C
4434 * runtime.
4435 *
4436 * Functions identically to SDL_swprintf(), except it takes a `va_list`
4437 * instead of using `...` variable arguments.
4438 *
4439 * \param text the buffer to write the string into. Must not be NULL.
4440 * \param maxlen the maximum wide characters to write, including the
4441 * null-terminator.
4442 * \param fmt a printf-style format wide string. Must not be NULL.
4443 * \param ap a `va_list` values to be used with the format string.
4444 * \returns the number of wide characters that should be written, not counting
4445 * the null-terminator char, or a negative value on error.
4446 *
4447 * \threadsafety It is safe to call this function from any thread.
4448 *
4449 * \since This function is available since SDL 3.2.0.
4450 */
4451extern 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);
4452
4453/**
4454 * This works exactly like asprintf() but doesn't require access to a C
4455 * runtime.
4456 *
4457 * Functions identically to SDL_snprintf(), except it allocates a buffer large
4458 * enough to hold the output string on behalf of the caller.
4459 *
4460 * On success, this function returns the number of bytes (not characters)
4461 * comprising the output string, not counting the null-terminator character,
4462 * and sets `*strp` to the newly-allocated string.
4463 *
4464 * On error, this function returns a negative number, and the value of `*strp`
4465 * is undefined.
4466 *
4467 * The returned string is owned by the caller, and should be passed to
4468 * SDL_free when no longer needed.
4469 *
4470 * \param strp on output, is set to the new string. Must not be NULL.
4471 * \param fmt a printf-style format string. Must not be NULL.
4472 * \param ... a list of values to be used with the format string.
4473 * \returns the number of bytes in the newly-allocated string, not counting
4474 * the null-terminator char, or a negative value on error.
4475 *
4476 * \threadsafety It is safe to call this function from any thread.
4477 *
4478 * \since This function is available since SDL 3.2.0.
4479 */
4480extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
4481
4482/**
4483 * This works exactly like vasprintf() but doesn't require access to a C
4484 * runtime.
4485 *
4486 * Functions identically to SDL_asprintf(), except it takes a `va_list`
4487 * instead of using `...` variable arguments.
4488 *
4489 * \param strp on output, is set to the new string. Must not be NULL.
4490 * \param fmt a printf-style format string. Must not be NULL.
4491 * \param ap a `va_list` values to be used with the format string.
4492 * \returns the number of bytes in the newly-allocated string, not counting
4493 * the null-terminator char, or a negative value on error.
4494 *
4495 * \threadsafety It is safe to call this function from any thread.
4496 *
4497 * \since This function is available since SDL 3.2.0.
4498 */
4499extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
4500
4501/**
4502 * Seeds the pseudo-random number generator.
4503 *
4504 * Reusing the seed number will cause SDL_rand() to repeat the same stream of
4505 * 'random' numbers.
4506 *
4507 * \param seed the value to use as a random number seed, or 0 to use
4508 * SDL_GetPerformanceCounter().
4509 *
4510 * \threadsafety This should be called on the same thread that calls
4511 * SDL_rand()
4512 *
4513 * \since This function is available since SDL 3.2.0.
4514 *
4515 * \sa SDL_rand
4516 * \sa SDL_rand_bits
4517 * \sa SDL_randf
4518 */
4519extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
4520
4521/**
4522 * Generate a pseudo-random number less than n for positive n
4523 *
4524 * The method used is faster and of better quality than `rand() % n`. Odds are
4525 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
4526 * much worse as n gets bigger.
4527 *
4528 * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
4529 * 1..6
4530 *
4531 * If you want to generate a pseudo-random number in the full range of Sint32,
4532 * you should use: (Sint32)SDL_rand_bits()
4533 *
4534 * If you want reproducible output, be sure to initialize with SDL_srand()
4535 * first.
4536 *
4537 * There are no guarantees as to the quality of the random sequence produced,
4538 * and this should not be used for security (cryptography, passwords) or where
4539 * money is on the line (loot-boxes, casinos). There are many random number
4540 * libraries available with different characteristics and you should pick one
4541 * of those to meet any serious needs.
4542 *
4543 * \param n the number of possible outcomes. n must be positive.
4544 * \returns a random value in the range of [0 .. n-1].
4545 *
4546 * \threadsafety All calls should be made from a single thread
4547 *
4548 * \since This function is available since SDL 3.2.0.
4549 *
4550 * \sa SDL_srand
4551 * \sa SDL_randf
4552 */
4553extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
4554
4555/**
4556 * Generate a uniform pseudo-random floating point number less than 1.0
4557 *
4558 * If you want reproducible output, be sure to initialize with SDL_srand()
4559 * first.
4560 *
4561 * There are no guarantees as to the quality of the random sequence produced,
4562 * and this should not be used for security (cryptography, passwords) or where
4563 * money is on the line (loot-boxes, casinos). There are many random number
4564 * libraries available with different characteristics and you should pick one
4565 * of those to meet any serious needs.
4566 *
4567 * \returns a random value in the range of [0.0, 1.0).
4568 *
4569 * \threadsafety All calls should be made from a single thread
4570 *
4571 * \since This function is available since SDL 3.2.0.
4572 *
4573 * \sa SDL_srand
4574 * \sa SDL_rand
4575 */
4576extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
4577
4578/**
4579 * Generate 32 pseudo-random bits.
4580 *
4581 * You likely want to use SDL_rand() to get a pseudo-random number instead.
4582 *
4583 * There are no guarantees as to the quality of the random sequence produced,
4584 * and this should not be used for security (cryptography, passwords) or where
4585 * money is on the line (loot-boxes, casinos). There are many random number
4586 * libraries available with different characteristics and you should pick one
4587 * of those to meet any serious needs.
4588 *
4589 * \returns a random value in the range of [0-SDL_MAX_UINT32].
4590 *
4591 * \threadsafety All calls should be made from a single thread
4592 *
4593 * \since This function is available since SDL 3.2.0.
4594 *
4595 * \sa SDL_rand
4596 * \sa SDL_randf
4597 * \sa SDL_srand
4598 */
4599extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
4600
4601/**
4602 * Generate a pseudo-random number less than n for positive n
4603 *
4604 * The method used is faster and of better quality than `rand() % n`. Odds are
4605 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
4606 * much worse as n gets bigger.
4607 *
4608 * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
4609 * 0..5 to 1..6
4610 *
4611 * If you want to generate a pseudo-random number in the full range of Sint32,
4612 * you should use: (Sint32)SDL_rand_bits_r(state)
4613 *
4614 * There are no guarantees as to the quality of the random sequence produced,
4615 * and this should not be used for security (cryptography, passwords) or where
4616 * money is on the line (loot-boxes, casinos). There are many random number
4617 * libraries available with different characteristics and you should pick one
4618 * of those to meet any serious needs.
4619 *
4620 * \param state a pointer to the current random number state, this may not be
4621 * NULL.
4622 * \param n the number of possible outcomes. n must be positive.
4623 * \returns a random value in the range of [0 .. n-1].
4624 *
4625 * \threadsafety This function is thread-safe, as long as the state pointer
4626 * isn't shared between threads.
4627 *
4628 * \since This function is available since SDL 3.2.0.
4629 *
4630 * \sa SDL_rand
4631 * \sa SDL_rand_bits_r
4632 * \sa SDL_randf_r
4633 */
4634extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
4635
4636/**
4637 * Generate a uniform pseudo-random floating point number less than 1.0
4638 *
4639 * There are no guarantees as to the quality of the random sequence produced,
4640 * and this should not be used for security (cryptography, passwords) or where
4641 * money is on the line (loot-boxes, casinos). There are many random number
4642 * libraries available with different characteristics and you should pick one
4643 * of those to meet any serious needs.
4644 *
4645 * \param state a pointer to the current random number state, this may not be
4646 * NULL.
4647 * \returns a random value in the range of [0.0, 1.0).
4648 *
4649 * \threadsafety This function is thread-safe, as long as the state pointer
4650 * isn't shared between threads.
4651 *
4652 * \since This function is available since SDL 3.2.0.
4653 *
4654 * \sa SDL_rand_bits_r
4655 * \sa SDL_rand_r
4656 * \sa SDL_randf
4657 */
4658extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
4659
4660/**
4661 * Generate 32 pseudo-random bits.
4662 *
4663 * You likely want to use SDL_rand_r() to get a pseudo-random number instead.
4664 *
4665 * There are no guarantees as to the quality of the random sequence produced,
4666 * and this should not be used for security (cryptography, passwords) or where
4667 * money is on the line (loot-boxes, casinos). There are many random number
4668 * libraries available with different characteristics and you should pick one
4669 * of those to meet any serious needs.
4670 *
4671 * \param state a pointer to the current random number state, this may not be
4672 * NULL.
4673 * \returns a random value in the range of [0-SDL_MAX_UINT32].
4674 *
4675 * \threadsafety This function is thread-safe, as long as the state pointer
4676 * isn't shared between threads.
4677 *
4678 * \since This function is available since SDL 3.2.0.
4679 *
4680 * \sa SDL_rand_r
4681 * \sa SDL_randf_r
4682 */
4683extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
4684
4685#ifndef SDL_PI_D
4686
4687/**
4688 * The value of Pi, as a double-precision floating point literal.
4689 *
4690 * \since This macro is available since SDL 3.2.0.
4691 *
4692 * \sa SDL_PI_F
4693 */
4694#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
4695#endif
4696
4697#ifndef SDL_PI_F
4698
4699/**
4700 * The value of Pi, as a single-precision floating point literal.
4701 *
4702 * \since This macro is available since SDL 3.2.0.
4703 *
4704 * \sa SDL_PI_D
4705 */
4706#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
4707#endif
4708
4709/**
4710 * Compute the arc cosine of `x`.
4711 *
4712 * The definition of `y = acos(x)` is `x = cos(y)`.
4713 *
4714 * Domain: `-1 <= x <= 1`
4715 *
4716 * Range: `0 <= y <= Pi`
4717 *
4718 * This function operates on double-precision floating point values, use
4719 * SDL_acosf for single-precision floats.
4720 *
4721 * This function may use a different approximation across different versions,
4722 * platforms and configurations. i.e, it can return a different value given
4723 * the same input on different machines or operating systems, or if SDL is
4724 * updated.
4725 *
4726 * \param x floating point value.
4727 * \returns arc cosine of `x`, in radians.
4728 *
4729 * \threadsafety It is safe to call this function from any thread.
4730 *
4731 * \since This function is available since SDL 3.2.0.
4732 *
4733 * \sa SDL_acosf
4734 * \sa SDL_asin
4735 * \sa SDL_cos
4736 */
4737extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
4738
4739/**
4740 * Compute the arc cosine of `x`.
4741 *
4742 * The definition of `y = acos(x)` is `x = cos(y)`.
4743 *
4744 * Domain: `-1 <= x <= 1`
4745 *
4746 * Range: `0 <= y <= Pi`
4747 *
4748 * This function operates on single-precision floating point values, use
4749 * SDL_acos for double-precision floats.
4750 *
4751 * This function may use a different approximation across different versions,
4752 * platforms and configurations. i.e, it can return a different value given
4753 * the same input on different machines or operating systems, or if SDL is
4754 * updated.
4755 *
4756 * \param x floating point value.
4757 * \returns arc cosine of `x`, in radians.
4758 *
4759 * \threadsafety It is safe to call this function from any thread.
4760 *
4761 * \since This function is available since SDL 3.2.0.
4762 *
4763 * \sa SDL_acos
4764 * \sa SDL_asinf
4765 * \sa SDL_cosf
4766 */
4767extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
4768
4769/**
4770 * Compute the arc sine of `x`.
4771 *
4772 * The definition of `y = asin(x)` is `x = sin(y)`.
4773 *
4774 * Domain: `-1 <= x <= 1`
4775 *
4776 * Range: `-Pi/2 <= y <= Pi/2`
4777 *
4778 * This function operates on double-precision floating point values, use
4779 * SDL_asinf for single-precision floats.
4780 *
4781 * This function may use a different approximation across different versions,
4782 * platforms and configurations. i.e, it can return a different value given
4783 * the same input on different machines or operating systems, or if SDL is
4784 * updated.
4785 *
4786 * \param x floating point value.
4787 * \returns arc sine of `x`, in radians.
4788 *
4789 * \threadsafety It is safe to call this function from any thread.
4790 *
4791 * \since This function is available since SDL 3.2.0.
4792 *
4793 * \sa SDL_asinf
4794 * \sa SDL_acos
4795 * \sa SDL_sin
4796 */
4797extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
4798
4799/**
4800 * Compute the arc sine of `x`.
4801 *
4802 * The definition of `y = asin(x)` is `x = sin(y)`.
4803 *
4804 * Domain: `-1 <= x <= 1`
4805 *
4806 * Range: `-Pi/2 <= y <= Pi/2`
4807 *
4808 * This function operates on single-precision floating point values, use
4809 * SDL_asin for double-precision floats.
4810 *
4811 * This function may use a different approximation across different versions,
4812 * platforms and configurations. i.e, it can return a different value given
4813 * the same input on different machines or operating systems, or if SDL is
4814 * updated.
4815 *
4816 * \param x floating point value.
4817 * \returns arc sine of `x`, in radians.
4818 *
4819 * \threadsafety It is safe to call this function from any thread.
4820 *
4821 * \since This function is available since SDL 3.2.0.
4822 *
4823 * \sa SDL_asin
4824 * \sa SDL_acosf
4825 * \sa SDL_sinf
4826 */
4827extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
4828
4829/**
4830 * Compute the arc tangent of `x`.
4831 *
4832 * The definition of `y = atan(x)` is `x = tan(y)`.
4833 *
4834 * Domain: `-INF <= x <= INF`
4835 *
4836 * Range: `-Pi/2 <= y <= Pi/2`
4837 *
4838 * This function operates on double-precision floating point values, use
4839 * SDL_atanf for single-precision floats.
4840 *
4841 * To calculate the arc tangent of y / x, use SDL_atan2.
4842 *
4843 * This function may use a different approximation across different versions,
4844 * platforms and configurations. i.e, it can return a different value given
4845 * the same input on different machines or operating systems, or if SDL is
4846 * updated.
4847 *
4848 * \param x floating point value.
4849 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
4850 *
4851 * \threadsafety It is safe to call this function from any thread.
4852 *
4853 * \since This function is available since SDL 3.2.0.
4854 *
4855 * \sa SDL_atanf
4856 * \sa SDL_atan2
4857 * \sa SDL_tan
4858 */
4859extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
4860
4861/**
4862 * Compute the arc tangent of `x`.
4863 *
4864 * The definition of `y = atan(x)` is `x = tan(y)`.
4865 *
4866 * Domain: `-INF <= x <= INF`
4867 *
4868 * Range: `-Pi/2 <= y <= Pi/2`
4869 *
4870 * This function operates on single-precision floating point values, use
4871 * SDL_atan for dboule-precision floats.
4872 *
4873 * To calculate the arc tangent of y / x, use SDL_atan2f.
4874 *
4875 * This function may use a different approximation across different versions,
4876 * platforms and configurations. i.e, it can return a different value given
4877 * the same input on different machines or operating systems, or if SDL is
4878 * updated.
4879 *
4880 * \param x floating point value.
4881 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
4882 *
4883 * \threadsafety It is safe to call this function from any thread.
4884 *
4885 * \since This function is available since SDL 3.2.0.
4886 *
4887 * \sa SDL_atan
4888 * \sa SDL_atan2f
4889 * \sa SDL_tanf
4890 */
4891extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
4892
4893/**
4894 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
4895 * the result's quadrant.
4896 *
4897 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
4898 * of z is determined based on the signs of x and y.
4899 *
4900 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
4901 *
4902 * Range: `-Pi <= z <= Pi`
4903 *
4904 * This function operates on double-precision floating point values, use
4905 * SDL_atan2f for single-precision floats.
4906 *
4907 * To calculate the arc tangent of a single value, use SDL_atan.
4908 *
4909 * This function may use a different approximation across different versions,
4910 * platforms and configurations. i.e, it can return a different value given
4911 * the same input on different machines or operating systems, or if SDL is
4912 * updated.
4913 *
4914 * \param y floating point value of the numerator (y coordinate).
4915 * \param x floating point value of the denominator (x coordinate).
4916 * \returns arc tangent of `y / x` in radians, or, if `x = 0`, either `-Pi/2`,
4917 * `0`, or `Pi/2`, depending on the value of `y`.
4918 *
4919 * \threadsafety It is safe to call this function from any thread.
4920 *
4921 * \since This function is available since SDL 3.2.0.
4922 *
4923 * \sa SDL_atan2f
4924 * \sa SDL_atan
4925 * \sa SDL_tan
4926 */
4927extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
4928
4929/**
4930 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
4931 * the result's quadrant.
4932 *
4933 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
4934 * of z is determined based on the signs of x and y.
4935 *
4936 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
4937 *
4938 * Range: `-Pi <= y <= Pi`
4939 *
4940 * This function operates on single-precision floating point values, use
4941 * SDL_atan2 for double-precision floats.
4942 *
4943 * To calculate the arc tangent of a single value, use SDL_atanf.
4944 *
4945 * This function may use a different approximation across different versions,
4946 * platforms and configurations. i.e, it can return a different value given
4947 * the same input on different machines or operating systems, or if SDL is
4948 * updated.
4949 *
4950 * \param y floating point value of the numerator (y coordinate).
4951 * \param x floating point value of the denominator (x coordinate).
4952 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
4953 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
4954 *
4955 * \threadsafety It is safe to call this function from any thread.
4956 *
4957 * \since This function is available since SDL 3.2.0.
4958 *
4959 * \sa SDL_atan2
4960 * \sa SDL_atan
4961 * \sa SDL_tan
4962 */
4963extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
4964
4965/**
4966 * Compute the ceiling of `x`.
4967 *
4968 * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
4969 * rounded up to the nearest integer.
4970 *
4971 * Domain: `-INF <= x <= INF`
4972 *
4973 * Range: `-INF <= y <= INF`, y integer
4974 *
4975 * This function operates on double-precision floating point values, use
4976 * SDL_ceilf for single-precision floats.
4977 *
4978 * \param x floating point value.
4979 * \returns the ceiling of `x`.
4980 *
4981 * \threadsafety It is safe to call this function from any thread.
4982 *
4983 * \since This function is available since SDL 3.2.0.
4984 *
4985 * \sa SDL_ceilf
4986 * \sa SDL_floor
4987 * \sa SDL_trunc
4988 * \sa SDL_round
4989 * \sa SDL_lround
4990 */
4991extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
4992
4993/**
4994 * Compute the ceiling of `x`.
4995 *
4996 * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
4997 * rounded up to the nearest integer.
4998 *
4999 * Domain: `-INF <= x <= INF`
5000 *
5001 * Range: `-INF <= y <= INF`, y integer
5002 *
5003 * This function operates on single-precision floating point values, use
5004 * SDL_ceil for double-precision floats.
5005 *
5006 * \param x floating point value.
5007 * \returns the ceiling of `x`.
5008 *
5009 * \threadsafety It is safe to call this function from any thread.
5010 *
5011 * \since This function is available since SDL 3.2.0.
5012 *
5013 * \sa SDL_ceil
5014 * \sa SDL_floorf
5015 * \sa SDL_truncf
5016 * \sa SDL_roundf
5017 * \sa SDL_lroundf
5018 */
5019extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
5020
5021/**
5022 * Copy the sign of one floating-point value to another.
5023 *
5024 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
5025 *
5026 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
5027 *
5028 * Range: `-INF <= z <= INF`
5029 *
5030 * This function operates on double-precision floating point values, use
5031 * SDL_copysignf for single-precision floats.
5032 *
5033 * \param x floating point value to use as the magnitude.
5034 * \param y floating point value to use as the sign.
5035 * \returns the floating point value with the sign of y and the magnitude of
5036 * x.
5037 *
5038 * \threadsafety It is safe to call this function from any thread.
5039 *
5040 * \since This function is available since SDL 3.2.0.
5041 *
5042 * \sa SDL_copysignf
5043 * \sa SDL_fabs
5044 */
5045extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
5046
5047/**
5048 * Copy the sign of one floating-point value to another.
5049 *
5050 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
5051 *
5052 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
5053 *
5054 * Range: `-INF <= z <= INF`
5055 *
5056 * This function operates on single-precision floating point values, use
5057 * SDL_copysign for double-precision floats.
5058 *
5059 * \param x floating point value to use as the magnitude.
5060 * \param y floating point value to use as the sign.
5061 * \returns the floating point value with the sign of y and the magnitude of
5062 * x.
5063 *
5064 * \threadsafety It is safe to call this function from any thread.
5065 *
5066 * \since This function is available since SDL 3.2.0.
5067 *
5068 * \sa SDL_copysign
5069 * \sa SDL_fabsf
5070 */
5071extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
5072
5073/**
5074 * Compute the cosine of `x`.
5075 *
5076 * Domain: `-INF <= x <= INF`
5077 *
5078 * Range: `-1 <= y <= 1`
5079 *
5080 * This function operates on double-precision floating point values, use
5081 * SDL_cosf for single-precision floats.
5082 *
5083 * This function may use a different approximation across different versions,
5084 * platforms and configurations. i.e, it can return a different value given
5085 * the same input on different machines or operating systems, or if SDL is
5086 * updated.
5087 *
5088 * \param x floating point value, in radians.
5089 * \returns cosine of `x`.
5090 *
5091 * \threadsafety It is safe to call this function from any thread.
5092 *
5093 * \since This function is available since SDL 3.2.0.
5094 *
5095 * \sa SDL_cosf
5096 * \sa SDL_acos
5097 * \sa SDL_sin
5098 */
5099extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
5100
5101/**
5102 * Compute the cosine of `x`.
5103 *
5104 * Domain: `-INF <= x <= INF`
5105 *
5106 * Range: `-1 <= y <= 1`
5107 *
5108 * This function operates on single-precision floating point values, use
5109 * SDL_cos for double-precision floats.
5110 *
5111 * This function may use a different approximation across different versions,
5112 * platforms and configurations. i.e, it can return a different value given
5113 * the same input on different machines or operating systems, or if SDL is
5114 * updated.
5115 *
5116 * \param x floating point value, in radians.
5117 * \returns cosine of `x`.
5118 *
5119 * \threadsafety It is safe to call this function from any thread.
5120 *
5121 * \since This function is available since SDL 3.2.0.
5122 *
5123 * \sa SDL_cos
5124 * \sa SDL_acosf
5125 * \sa SDL_sinf
5126 */
5127extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
5128
5129/**
5130 * Compute the exponential of `x`.
5131 *
5132 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
5133 * natural logarithm. The inverse is the natural logarithm, SDL_log.
5134 *
5135 * Domain: `-INF <= x <= INF`
5136 *
5137 * Range: `0 <= y <= INF`
5138 *
5139 * The output will overflow if `exp(x)` is too large to be represented.
5140 *
5141 * This function operates on double-precision floating point values, use
5142 * SDL_expf for single-precision floats.
5143 *
5144 * This function may use a different approximation across different versions,
5145 * platforms and configurations. i.e, it can return a different value given
5146 * the same input on different machines or operating systems, or if SDL is
5147 * updated.
5148 *
5149 * \param x floating point value.
5150 * \returns value of `e^x`.
5151 *
5152 * \threadsafety It is safe to call this function from any thread.
5153 *
5154 * \since This function is available since SDL 3.2.0.
5155 *
5156 * \sa SDL_expf
5157 * \sa SDL_log
5158 */
5159extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
5160
5161/**
5162 * Compute the exponential of `x`.
5163 *
5164 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
5165 * natural logarithm. The inverse is the natural logarithm, SDL_logf.
5166 *
5167 * Domain: `-INF <= x <= INF`
5168 *
5169 * Range: `0 <= y <= INF`
5170 *
5171 * The output will overflow if `exp(x)` is too large to be represented.
5172 *
5173 * This function operates on single-precision floating point values, use
5174 * SDL_exp for double-precision floats.
5175 *
5176 * This function may use a different approximation across different versions,
5177 * platforms and configurations. i.e, it can return a different value given
5178 * the same input on different machines or operating systems, or if SDL is
5179 * updated.
5180 *
5181 * \param x floating point value.
5182 * \returns value of `e^x`.
5183 *
5184 * \threadsafety It is safe to call this function from any thread.
5185 *
5186 * \since This function is available since SDL 3.2.0.
5187 *
5188 * \sa SDL_exp
5189 * \sa SDL_logf
5190 */
5191extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
5192
5193/**
5194 * Compute the absolute value of `x`
5195 *
5196 * Domain: `-INF <= x <= INF`
5197 *
5198 * Range: `0 <= y <= INF`
5199 *
5200 * This function operates on double-precision floating point values, use
5201 * SDL_fabsf for single-precision floats.
5202 *
5203 * \param x floating point value to use as the magnitude.
5204 * \returns the absolute value of `x`.
5205 *
5206 * \threadsafety It is safe to call this function from any thread.
5207 *
5208 * \since This function is available since SDL 3.2.0.
5209 *
5210 * \sa SDL_fabsf
5211 */
5212extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
5213
5214/**
5215 * Compute the absolute value of `x`
5216 *
5217 * Domain: `-INF <= x <= INF`
5218 *
5219 * Range: `0 <= y <= INF`
5220 *
5221 * This function operates on single-precision floating point values, use
5222 * SDL_fabs for double-precision floats.
5223 *
5224 * \param x floating point value to use as the magnitude.
5225 * \returns the absolute value of `x`.
5226 *
5227 * \threadsafety It is safe to call this function from any thread.
5228 *
5229 * \since This function is available since SDL 3.2.0.
5230 *
5231 * \sa SDL_fabs
5232 */
5233extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
5234
5235/**
5236 * Compute the floor of `x`.
5237 *
5238 * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
5239 * rounded down to the nearest integer.
5240 *
5241 * Domain: `-INF <= x <= INF`
5242 *
5243 * Range: `-INF <= y <= INF`, y integer
5244 *
5245 * This function operates on double-precision floating point values, use
5246 * SDL_floorf for single-precision floats.
5247 *
5248 * \param x floating point value.
5249 * \returns the floor of `x`.
5250 *
5251 * \threadsafety It is safe to call this function from any thread.
5252 *
5253 * \since This function is available since SDL 3.2.0.
5254 *
5255 * \sa SDL_floorf
5256 * \sa SDL_ceil
5257 * \sa SDL_trunc
5258 * \sa SDL_round
5259 * \sa SDL_lround
5260 */
5261extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
5262
5263/**
5264 * Compute the floor of `x`.
5265 *
5266 * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
5267 * rounded down to the nearest integer.
5268 *
5269 * Domain: `-INF <= x <= INF`
5270 *
5271 * Range: `-INF <= y <= INF`, y integer
5272 *
5273 * This function operates on single-precision floating point values, use
5274 * SDL_floor for double-precision floats.
5275 *
5276 * \param x floating point value.
5277 * \returns the floor of `x`.
5278 *
5279 * \threadsafety It is safe to call this function from any thread.
5280 *
5281 * \since This function is available since SDL 3.2.0.
5282 *
5283 * \sa SDL_floor
5284 * \sa SDL_ceilf
5285 * \sa SDL_truncf
5286 * \sa SDL_roundf
5287 * \sa SDL_lroundf
5288 */
5289extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
5290
5291/**
5292 * Truncate `x` to an integer.
5293 *
5294 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
5295 * the fractional part of `x`, leaving only the integer part.
5296 *
5297 * Domain: `-INF <= x <= INF`
5298 *
5299 * Range: `-INF <= y <= INF`, y integer
5300 *
5301 * This function operates on double-precision floating point values, use
5302 * SDL_truncf for single-precision floats.
5303 *
5304 * \param x floating point value.
5305 * \returns `x` truncated to an integer.
5306 *
5307 * \threadsafety It is safe to call this function from any thread.
5308 *
5309 * \since This function is available since SDL 3.2.0.
5310 *
5311 * \sa SDL_truncf
5312 * \sa SDL_fmod
5313 * \sa SDL_ceil
5314 * \sa SDL_floor
5315 * \sa SDL_round
5316 * \sa SDL_lround
5317 */
5318extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
5319
5320/**
5321 * Truncate `x` to an integer.
5322 *
5323 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
5324 * the fractional part of `x`, leaving only the integer part.
5325 *
5326 * Domain: `-INF <= x <= INF`
5327 *
5328 * Range: `-INF <= y <= INF`, y integer
5329 *
5330 * This function operates on single-precision floating point values, use
5331 * SDL_trunc for double-precision floats.
5332 *
5333 * \param x floating point value.
5334 * \returns `x` truncated to an integer.
5335 *
5336 * \threadsafety It is safe to call this function from any thread.
5337 *
5338 * \since This function is available since SDL 3.2.0.
5339 *
5340 * \sa SDL_trunc
5341 * \sa SDL_fmodf
5342 * \sa SDL_ceilf
5343 * \sa SDL_floorf
5344 * \sa SDL_roundf
5345 * \sa SDL_lroundf
5346 */
5347extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
5348
5349/**
5350 * Return the floating-point remainder of `x / y`
5351 *
5352 * Divides `x` by `y`, and returns the remainder.
5353 *
5354 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
5355 *
5356 * Range: `-y <= z <= y`
5357 *
5358 * This function operates on double-precision floating point values, use
5359 * SDL_fmodf for single-precision floats.
5360 *
5361 * \param x the numerator.
5362 * \param y the denominator. Must not be 0.
5363 * \returns the remainder of `x / y`.
5364 *
5365 * \threadsafety It is safe to call this function from any thread.
5366 *
5367 * \since This function is available since SDL 3.2.0.
5368 *
5369 * \sa SDL_fmodf
5370 * \sa SDL_modf
5371 * \sa SDL_trunc
5372 * \sa SDL_ceil
5373 * \sa SDL_floor
5374 * \sa SDL_round
5375 * \sa SDL_lround
5376 */
5377extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
5378
5379/**
5380 * Return the floating-point remainder of `x / y`
5381 *
5382 * Divides `x` by `y`, and returns the remainder.
5383 *
5384 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
5385 *
5386 * Range: `-y <= z <= y`
5387 *
5388 * This function operates on single-precision floating point values, use
5389 * SDL_fmod for double-precision floats.
5390 *
5391 * \param x the numerator.
5392 * \param y the denominator. Must not be 0.
5393 * \returns the remainder of `x / y`.
5394 *
5395 * \threadsafety It is safe to call this function from any thread.
5396 *
5397 * \since This function is available since SDL 3.2.0.
5398 *
5399 * \sa SDL_fmod
5400 * \sa SDL_truncf
5401 * \sa SDL_modff
5402 * \sa SDL_ceilf
5403 * \sa SDL_floorf
5404 * \sa SDL_roundf
5405 * \sa SDL_lroundf
5406 */
5407extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
5408
5409/**
5410 * Return whether the value is infinity.
5411 *
5412 * \param x double-precision floating point value.
5413 * \returns non-zero if the value is infinity, 0 otherwise.
5414 *
5415 * \threadsafety It is safe to call this function from any thread.
5416 *
5417 * \since This function is available since SDL 3.2.0.
5418 *
5419 * \sa SDL_isinff
5420 */
5421extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
5422
5423/**
5424 * Return whether the value is infinity.
5425 *
5426 * \param x floating point value.
5427 * \returns non-zero if the value is infinity, 0 otherwise.
5428 *
5429 * \threadsafety It is safe to call this function from any thread.
5430 *
5431 * \since This function is available since SDL 3.2.0.
5432 *
5433 * \sa SDL_isinf
5434 */
5435extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
5436
5437/**
5438 * Return whether the value is NaN.
5439 *
5440 * \param x double-precision floating point value.
5441 * \returns non-zero if the value is NaN, 0 otherwise.
5442 *
5443 * \threadsafety It is safe to call this function from any thread.
5444 *
5445 * \since This function is available since SDL 3.2.0.
5446 *
5447 * \sa SDL_isnanf
5448 */
5449extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
5450
5451/**
5452 * Return whether the value is NaN.
5453 *
5454 * \param x floating point value.
5455 * \returns non-zero if the value is NaN, 0 otherwise.
5456 *
5457 * \threadsafety It is safe to call this function from any thread.
5458 *
5459 * \since This function is available since SDL 3.2.0.
5460 *
5461 * \sa SDL_isnan
5462 */
5463extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
5464
5465/**
5466 * Compute the natural logarithm of `x`.
5467 *
5468 * Domain: `0 < x <= INF`
5469 *
5470 * Range: `-INF <= y <= INF`
5471 *
5472 * It is an error for `x` to be less than or equal to 0.
5473 *
5474 * This function operates on double-precision floating point values, use
5475 * SDL_logf for single-precision floats.
5476 *
5477 * This function may use a different approximation across different versions,
5478 * platforms and configurations. i.e, it can return a different value given
5479 * the same input on different machines or operating systems, or if SDL is
5480 * updated.
5481 *
5482 * \param x floating point value. Must be greater than 0.
5483 * \returns the natural logarithm of `x`.
5484 *
5485 * \threadsafety It is safe to call this function from any thread.
5486 *
5487 * \since This function is available since SDL 3.2.0.
5488 *
5489 * \sa SDL_logf
5490 * \sa SDL_log10
5491 * \sa SDL_exp
5492 */
5493extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
5494
5495/**
5496 * Compute the natural logarithm of `x`.
5497 *
5498 * Domain: `0 < x <= INF`
5499 *
5500 * Range: `-INF <= y <= INF`
5501 *
5502 * It is an error for `x` to be less than or equal to 0.
5503 *
5504 * This function operates on single-precision floating point values, use
5505 * SDL_log for double-precision floats.
5506 *
5507 * This function may use a different approximation across different versions,
5508 * platforms and configurations. i.e, it can return a different value given
5509 * the same input on different machines or operating systems, or if SDL is
5510 * updated.
5511 *
5512 * \param x floating point value. Must be greater than 0.
5513 * \returns the natural logarithm of `x`.
5514 *
5515 * \threadsafety It is safe to call this function from any thread.
5516 *
5517 * \since This function is available since SDL 3.2.0.
5518 *
5519 * \sa SDL_log
5520 * \sa SDL_expf
5521 */
5522extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
5523
5524/**
5525 * Compute the base-10 logarithm of `x`.
5526 *
5527 * Domain: `0 < x <= INF`
5528 *
5529 * Range: `-INF <= y <= INF`
5530 *
5531 * It is an error for `x` to be less than or equal to 0.
5532 *
5533 * This function operates on double-precision floating point values, use
5534 * SDL_log10f for single-precision floats.
5535 *
5536 * This function may use a different approximation across different versions,
5537 * platforms and configurations. i.e, it can return a different value given
5538 * the same input on different machines or operating systems, or if SDL is
5539 * updated.
5540 *
5541 * \param x floating point value. Must be greater than 0.
5542 * \returns the logarithm of `x`.
5543 *
5544 * \threadsafety It is safe to call this function from any thread.
5545 *
5546 * \since This function is available since SDL 3.2.0.
5547 *
5548 * \sa SDL_log10f
5549 * \sa SDL_log
5550 * \sa SDL_pow
5551 */
5552extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
5553
5554/**
5555 * Compute the base-10 logarithm of `x`.
5556 *
5557 * Domain: `0 < x <= INF`
5558 *
5559 * Range: `-INF <= y <= INF`
5560 *
5561 * It is an error for `x` to be less than or equal to 0.
5562 *
5563 * This function operates on single-precision floating point values, use
5564 * SDL_log10 for double-precision floats.
5565 *
5566 * This function may use a different approximation across different versions,
5567 * platforms and configurations. i.e, it can return a different value given
5568 * the same input on different machines or operating systems, or if SDL is
5569 * updated.
5570 *
5571 * \param x floating point value. Must be greater than 0.
5572 * \returns the logarithm of `x`.
5573 *
5574 * \threadsafety It is safe to call this function from any thread.
5575 *
5576 * \since This function is available since SDL 3.2.0.
5577 *
5578 * \sa SDL_log10
5579 * \sa SDL_logf
5580 * \sa SDL_powf
5581 */
5582extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
5583
5584/**
5585 * Split `x` into integer and fractional parts
5586 *
5587 * This function operates on double-precision floating point values, use
5588 * SDL_modff for single-precision floats.
5589 *
5590 * \param x floating point value.
5591 * \param y output pointer to store the integer part of `x`.
5592 * \returns the fractional part of `x`.
5593 *
5594 * \threadsafety It is safe to call this function from any thread.
5595 *
5596 * \since This function is available since SDL 3.2.0.
5597 *
5598 * \sa SDL_modff
5599 * \sa SDL_trunc
5600 * \sa SDL_fmod
5601 */
5602extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
5603
5604/**
5605 * Split `x` into integer and fractional parts
5606 *
5607 * This function operates on single-precision floating point values, use
5608 * SDL_modf for double-precision floats.
5609 *
5610 * \param x floating point value.
5611 * \param y output pointer to store the integer part of `x`.
5612 * \returns the fractional part of `x`.
5613 *
5614 * \threadsafety It is safe to call this function from any thread.
5615 *
5616 * \since This function is available since SDL 3.2.0.
5617 *
5618 * \sa SDL_modf
5619 * \sa SDL_truncf
5620 * \sa SDL_fmodf
5621 */
5622extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
5623
5624/**
5625 * Raise `x` to the power `y`
5626 *
5627 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
5628 *
5629 * Range: `-INF <= z <= INF`
5630 *
5631 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
5632 * instead.
5633 *
5634 * This function operates on double-precision floating point values, use
5635 * SDL_powf for single-precision floats.
5636 *
5637 * This function may use a different approximation across different versions,
5638 * platforms and configurations. i.e, it can return a different value given
5639 * the same input on different machines or operating systems, or if SDL is
5640 * updated.
5641 *
5642 * \param x the base.
5643 * \param y the exponent.
5644 * \returns `x` raised to the power `y`.
5645 *
5646 * \threadsafety It is safe to call this function from any thread.
5647 *
5648 * \since This function is available since SDL 3.2.0.
5649 *
5650 * \sa SDL_powf
5651 * \sa SDL_exp
5652 * \sa SDL_log
5653 */
5654extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
5655
5656/**
5657 * Raise `x` to the power `y`
5658 *
5659 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
5660 *
5661 * Range: `-INF <= z <= INF`
5662 *
5663 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
5664 * instead.
5665 *
5666 * This function operates on single-precision floating point values, use
5667 * SDL_pow for double-precision floats.
5668 *
5669 * This function may use a different approximation across different versions,
5670 * platforms and configurations. i.e, it can return a different value given
5671 * the same input on different machines or operating systems, or if SDL is
5672 * updated.
5673 *
5674 * \param x the base.
5675 * \param y the exponent.
5676 * \returns `x` raised to the power `y`.
5677 *
5678 * \threadsafety It is safe to call this function from any thread.
5679 *
5680 * \since This function is available since SDL 3.2.0.
5681 *
5682 * \sa SDL_pow
5683 * \sa SDL_expf
5684 * \sa SDL_logf
5685 */
5686extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
5687
5688/**
5689 * Round `x` to the nearest integer.
5690 *
5691 * Rounds `x` to the nearest integer. Values halfway between integers will be
5692 * rounded away from zero.
5693 *
5694 * Domain: `-INF <= x <= INF`
5695 *
5696 * Range: `-INF <= y <= INF`, y integer
5697 *
5698 * This function operates on double-precision floating point values, use
5699 * SDL_roundf for single-precision floats. To get the result as an integer
5700 * type, use SDL_lround.
5701 *
5702 * \param x floating point value.
5703 * \returns the nearest integer to `x`.
5704 *
5705 * \threadsafety It is safe to call this function from any thread.
5706 *
5707 * \since This function is available since SDL 3.2.0.
5708 *
5709 * \sa SDL_roundf
5710 * \sa SDL_lround
5711 * \sa SDL_floor
5712 * \sa SDL_ceil
5713 * \sa SDL_trunc
5714 */
5715extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
5716
5717/**
5718 * Round `x` to the nearest integer.
5719 *
5720 * Rounds `x` to the nearest integer. Values halfway between integers will be
5721 * rounded away from zero.
5722 *
5723 * Domain: `-INF <= x <= INF`
5724 *
5725 * Range: `-INF <= y <= INF`, y integer
5726 *
5727 * This function operates on single-precision floating point values, use
5728 * SDL_round for double-precision floats. To get the result as an integer
5729 * type, use SDL_lroundf.
5730 *
5731 * \param x floating point value.
5732 * \returns the nearest integer to `x`.
5733 *
5734 * \threadsafety It is safe to call this function from any thread.
5735 *
5736 * \since This function is available since SDL 3.2.0.
5737 *
5738 * \sa SDL_round
5739 * \sa SDL_lroundf
5740 * \sa SDL_floorf
5741 * \sa SDL_ceilf
5742 * \sa SDL_truncf
5743 */
5744extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
5745
5746/**
5747 * Round `x` to the nearest integer representable as a long
5748 *
5749 * Rounds `x` to the nearest integer. Values halfway between integers will be
5750 * rounded away from zero.
5751 *
5752 * Domain: `-INF <= x <= INF`
5753 *
5754 * Range: `MIN_LONG <= y <= MAX_LONG`
5755 *
5756 * This function operates on double-precision floating point values, use
5757 * SDL_lroundf for single-precision floats. To get the result as a
5758 * floating-point type, use SDL_round.
5759 *
5760 * \param x floating point value.
5761 * \returns the nearest integer to `x`.
5762 *
5763 * \threadsafety It is safe to call this function from any thread.
5764 *
5765 * \since This function is available since SDL 3.2.0.
5766 *
5767 * \sa SDL_lroundf
5768 * \sa SDL_round
5769 * \sa SDL_floor
5770 * \sa SDL_ceil
5771 * \sa SDL_trunc
5772 */
5773extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
5774
5775/**
5776 * Round `x` to the nearest integer representable as a long
5777 *
5778 * Rounds `x` to the nearest integer. Values halfway between integers will be
5779 * rounded away from zero.
5780 *
5781 * Domain: `-INF <= x <= INF`
5782 *
5783 * Range: `MIN_LONG <= y <= MAX_LONG`
5784 *
5785 * This function operates on single-precision floating point values, use
5786 * SDL_lround for double-precision floats. To get the result as a
5787 * floating-point type, use SDL_roundf.
5788 *
5789 * \param x floating point value.
5790 * \returns the nearest integer to `x`.
5791 *
5792 * \threadsafety It is safe to call this function from any thread.
5793 *
5794 * \since This function is available since SDL 3.2.0.
5795 *
5796 * \sa SDL_lround
5797 * \sa SDL_roundf
5798 * \sa SDL_floorf
5799 * \sa SDL_ceilf
5800 * \sa SDL_truncf
5801 */
5802extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
5803
5804/**
5805 * Scale `x` by an integer power of two.
5806 *
5807 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
5808 *
5809 * Domain: `-INF <= x <= INF`, `n` integer
5810 *
5811 * Range: `-INF <= y <= INF`
5812 *
5813 * This function operates on double-precision floating point values, use
5814 * SDL_scalbnf for single-precision floats.
5815 *
5816 * \param x floating point value to be scaled.
5817 * \param n integer exponent.
5818 * \returns `x * 2^n`.
5819 *
5820 * \threadsafety It is safe to call this function from any thread.
5821 *
5822 * \since This function is available since SDL 3.2.0.
5823 *
5824 * \sa SDL_scalbnf
5825 * \sa SDL_pow
5826 */
5827extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
5828
5829/**
5830 * Scale `x` by an integer power of two.
5831 *
5832 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
5833 *
5834 * Domain: `-INF <= x <= INF`, `n` integer
5835 *
5836 * Range: `-INF <= y <= INF`
5837 *
5838 * This function operates on single-precision floating point values, use
5839 * SDL_scalbn for double-precision floats.
5840 *
5841 * \param x floating point value to be scaled.
5842 * \param n integer exponent.
5843 * \returns `x * 2^n`.
5844 *
5845 * \threadsafety It is safe to call this function from any thread.
5846 *
5847 * \since This function is available since SDL 3.2.0.
5848 *
5849 * \sa SDL_scalbn
5850 * \sa SDL_powf
5851 */
5852extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
5853
5854/**
5855 * Compute the sine of `x`.
5856 *
5857 * Domain: `-INF <= x <= INF`
5858 *
5859 * Range: `-1 <= y <= 1`
5860 *
5861 * This function operates on double-precision floating point values, use
5862 * SDL_sinf for single-precision floats.
5863 *
5864 * This function may use a different approximation across different versions,
5865 * platforms and configurations. i.e, it can return a different value given
5866 * the same input on different machines or operating systems, or if SDL is
5867 * updated.
5868 *
5869 * \param x floating point value, in radians.
5870 * \returns sine of `x`.
5871 *
5872 * \threadsafety It is safe to call this function from any thread.
5873 *
5874 * \since This function is available since SDL 3.2.0.
5875 *
5876 * \sa SDL_sinf
5877 * \sa SDL_asin
5878 * \sa SDL_cos
5879 */
5880extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
5881
5882/**
5883 * Compute the sine of `x`.
5884 *
5885 * Domain: `-INF <= x <= INF`
5886 *
5887 * Range: `-1 <= y <= 1`
5888 *
5889 * This function operates on single-precision floating point values, use
5890 * SDL_sin for double-precision floats.
5891 *
5892 * This function may use a different approximation across different versions,
5893 * platforms and configurations. i.e, it can return a different value given
5894 * the same input on different machines or operating systems, or if SDL is
5895 * updated.
5896 *
5897 * \param x floating point value, in radians.
5898 * \returns sine of `x`.
5899 *
5900 * \threadsafety It is safe to call this function from any thread.
5901 *
5902 * \since This function is available since SDL 3.2.0.
5903 *
5904 * \sa SDL_sin
5905 * \sa SDL_asinf
5906 * \sa SDL_cosf
5907 */
5908extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
5909
5910/**
5911 * Compute the square root of `x`.
5912 *
5913 * Domain: `0 <= x <= INF`
5914 *
5915 * Range: `0 <= y <= INF`
5916 *
5917 * This function operates on double-precision floating point values, use
5918 * SDL_sqrtf for single-precision floats.
5919 *
5920 * This function may use a different approximation across different versions,
5921 * platforms and configurations. i.e, it can return a different value given
5922 * the same input on different machines or operating systems, or if SDL is
5923 * updated.
5924 *
5925 * \param x floating point value. Must be greater than or equal to 0.
5926 * \returns square root of `x`.
5927 *
5928 * \threadsafety It is safe to call this function from any thread.
5929 *
5930 * \since This function is available since SDL 3.2.0.
5931 *
5932 * \sa SDL_sqrtf
5933 */
5934extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
5935
5936/**
5937 * Compute the square root of `x`.
5938 *
5939 * Domain: `0 <= x <= INF`
5940 *
5941 * Range: `0 <= y <= INF`
5942 *
5943 * This function operates on single-precision floating point values, use
5944 * SDL_sqrt for double-precision floats.
5945 *
5946 * This function may use a different approximation across different versions,
5947 * platforms and configurations. i.e, it can return a different value given
5948 * the same input on different machines or operating systems, or if SDL is
5949 * updated.
5950 *
5951 * \param x floating point value. Must be greater than or equal to 0.
5952 * \returns square root of `x`.
5953 *
5954 * \threadsafety It is safe to call this function from any thread.
5955 *
5956 * \since This function is available since SDL 3.2.0.
5957 *
5958 * \sa SDL_sqrt
5959 */
5960extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
5961
5962/**
5963 * Compute the tangent of `x`.
5964 *
5965 * Domain: `-INF <= x <= INF`
5966 *
5967 * Range: `-INF <= y <= INF`
5968 *
5969 * This function operates on double-precision floating point values, use
5970 * SDL_tanf for single-precision floats.
5971 *
5972 * This function may use a different approximation across different versions,
5973 * platforms and configurations. i.e, it can return a different value given
5974 * the same input on different machines or operating systems, or if SDL is
5975 * updated.
5976 *
5977 * \param x floating point value, in radians.
5978 * \returns tangent of `x`.
5979 *
5980 * \threadsafety It is safe to call this function from any thread.
5981 *
5982 * \since This function is available since SDL 3.2.0.
5983 *
5984 * \sa SDL_tanf
5985 * \sa SDL_sin
5986 * \sa SDL_cos
5987 * \sa SDL_atan
5988 * \sa SDL_atan2
5989 */
5990extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
5991
5992/**
5993 * Compute the tangent of `x`.
5994 *
5995 * Domain: `-INF <= x <= INF`
5996 *
5997 * Range: `-INF <= y <= INF`
5998 *
5999 * This function operates on single-precision floating point values, use
6000 * SDL_tan for double-precision floats.
6001 *
6002 * This function may use a different approximation across different versions,
6003 * platforms and configurations. i.e, it can return a different value given
6004 * the same input on different machines or operating systems, or if SDL is
6005 * updated.
6006 *
6007 * \param x floating point value, in radians.
6008 * \returns tangent of `x`.
6009 *
6010 * \threadsafety It is safe to call this function from any thread.
6011 *
6012 * \since This function is available since SDL 3.2.0.
6013 *
6014 * \sa SDL_tan
6015 * \sa SDL_sinf
6016 * \sa SDL_cosf
6017 * \sa SDL_atanf
6018 * \sa SDL_atan2f
6019 */
6020extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
6021
6022/**
6023 * An opaque handle representing string encoding conversion state.
6024 *
6025 * \since This datatype is available since SDL 3.2.0.
6026 *
6027 * \sa SDL_iconv_open
6028 */
6029typedef struct SDL_iconv_data_t *SDL_iconv_t;
6030
6031/**
6032 * This function allocates a context for the specified character set
6033 * conversion.
6034 *
6035 * \param tocode The target character encoding, must not be NULL.
6036 * \param fromcode The source character encoding, must not be NULL.
6037 * \returns a handle that must be freed with SDL_iconv_close, or
6038 * SDL_ICONV_ERROR on failure.
6039 *
6040 * \threadsafety It is safe to call this function from any thread.
6041 *
6042 * \since This function is available since SDL 3.2.0.
6043 *
6044 * \sa SDL_iconv
6045 * \sa SDL_iconv_close
6046 * \sa SDL_iconv_string
6047 */
6048extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
6049 const char *fromcode);
6050
6051/**
6052 * This function frees a context used for character set conversion.
6053 *
6054 * \param cd The character set conversion handle.
6055 * \returns 0 on success, or -1 on failure.
6056 *
6057 * \threadsafety It is safe to call this function from any thread.
6058 *
6059 * \since This function is available since SDL 3.2.0.
6060 *
6061 * \sa SDL_iconv
6062 * \sa SDL_iconv_open
6063 * \sa SDL_iconv_string
6064 */
6065extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
6066
6067/**
6068 * This function converts text between encodings, reading from and writing to
6069 * a buffer.
6070 *
6071 * It returns the number of successful conversions on success. On error,
6072 * SDL_ICONV_E2BIG is returned when the output buffer is too small, or
6073 * SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered,
6074 * or SDL_ICONV_EINVAL is returned when an incomplete input sequence is
6075 * encountered.
6076 *
6077 * On exit:
6078 *
6079 * - inbuf will point to the beginning of the next multibyte sequence. On
6080 * error, this is the location of the problematic input sequence. On
6081 * success, this is the end of the input sequence.
6082 * - inbytesleft will be set to the number of bytes left to convert, which
6083 * will be 0 on success.
6084 * - outbuf will point to the location where to store the next output byte.
6085 * - outbytesleft will be set to the number of bytes left in the output
6086 * buffer.
6087 *
6088 * \param cd The character set conversion context, created in
6089 * SDL_iconv_open().
6090 * \param inbuf Address of variable that points to the first character of the
6091 * input sequence.
6092 * \param inbytesleft The number of bytes in the input buffer.
6093 * \param outbuf Address of variable that points to the output buffer.
6094 * \param outbytesleft The number of bytes in the output buffer.
6095 * \returns the number of conversions on success, or a negative error code.
6096 *
6097 * \threadsafety Do not use the same SDL_iconv_t from two threads at once.
6098 *
6099 * \since This function is available since SDL 3.2.0.
6100 *
6101 * \sa SDL_iconv_open
6102 * \sa SDL_iconv_close
6103 * \sa SDL_iconv_string
6104 */
6105extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
6106 size_t *inbytesleft, char **outbuf,
6107 size_t *outbytesleft);
6108
6109#define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
6110#define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
6111#define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
6112#define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
6113
6114
6115/**
6116 * Helper function to convert a string's encoding in one call.
6117 *
6118 * This function converts a buffer or string between encodings in one pass.
6119 *
6120 * The string does not need to be NULL-terminated; this function operates on
6121 * the number of bytes specified in `inbytesleft` whether there is a NULL
6122 * character anywhere in the buffer.
6123 *
6124 * The returned string is owned by the caller, and should be passed to
6125 * SDL_free when no longer needed.
6126 *
6127 * \param tocode the character encoding of the output string. Examples are
6128 * "UTF-8", "UCS-4", etc.
6129 * \param fromcode the character encoding of data in `inbuf`.
6130 * \param inbuf the string to convert to a different encoding.
6131 * \param inbytesleft the size of the input string _in bytes_.
6132 * \returns a new string, converted to the new encoding, or NULL on error.
6133 *
6134 * \threadsafety It is safe to call this function from any thread.
6135 *
6136 * \since This function is available since SDL 3.2.0.
6137 *
6138 * \sa SDL_iconv_open
6139 * \sa SDL_iconv_close
6140 * \sa SDL_iconv
6141 */
6142extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
6143 const char *fromcode,
6144 const char *inbuf,
6145 size_t inbytesleft);
6146
6147/* Some helper macros for common SDL_iconv_string cases... */
6148
6149/**
6150 * Convert a UTF-8 string to the current locale's character encoding.
6151 *
6152 * This is a helper macro that might be more clear than calling
6153 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6154 * do not use an expression with side-effects here.
6155 *
6156 * \param S the string to convert.
6157 * \returns a new string, converted to the new encoding, or NULL on error.
6158 *
6159 * \threadsafety It is safe to call this macro from any thread.
6160 *
6161 * \since This macro is available since SDL 3.2.0.
6162 */
6163#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
6164
6165/**
6166 * Convert a UTF-8 string to UCS-2.
6167 *
6168 * This is a helper macro that might be more clear than calling
6169 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6170 * do not use an expression with side-effects here.
6171 *
6172 * \param S the string to convert.
6173 * \returns a new string, converted to the new encoding, or NULL on error.
6174 *
6175 * \threadsafety It is safe to call this macro from any thread.
6176 *
6177 * \since This macro is available since SDL 3.2.0.
6178 */
6179#define SDL_iconv_utf8_ucs2(S) SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
6180
6181/**
6182 * Convert a UTF-8 string to UCS-4.
6183 *
6184 * This is a helper macro that might be more clear than calling
6185 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6186 * do not use an expression with side-effects here.
6187 *
6188 * \param S the string to convert.
6189 * \returns a new string, converted to the new encoding, or NULL on error.
6190 *
6191 * \threadsafety It is safe to call this macro from any thread.
6192 *
6193 * \since This macro is available since SDL 3.2.0.
6194 */
6195#define SDL_iconv_utf8_ucs4(S) SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))
6196
6197/**
6198 * Convert a wchar_t string to UTF-8.
6199 *
6200 * This is a helper macro that might be more clear than calling
6201 * SDL_iconv_string directly. However, it double-evaluates its parameter, so
6202 * do not use an expression with side-effects here.
6203 *
6204 * \param S the string to convert.
6205 * \returns a new string, converted to the new encoding, or NULL on error.
6206 *
6207 * \threadsafety It is safe to call this macro from any thread.
6208 *
6209 * \since This macro is available since SDL 3.2.0.
6210 */
6211#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))
6212
6213
6214/* force builds using Clang's static analysis tools to use literal C runtime
6215 here, since there are possibly tests that are ineffective otherwise. */
6216#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
6217
6218/* The analyzer knows about strlcpy even when the system doesn't provide it */
6219#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
6220size_t strlcpy(char *dst, const char *src, size_t size);
6221#endif
6222
6223/* The analyzer knows about strlcat even when the system doesn't provide it */
6224#if !defined(HAVE_STRLCAT) && !defined(strlcat)
6225size_t strlcat(char *dst, const char *src, size_t size);
6226#endif
6227
6228#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
6229size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
6230#endif
6231
6232#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
6233size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
6234#endif
6235
6236#if !defined(HAVE_STRTOK_R) && !defined(strtok_r)
6237char *strtok_r(char *str, const char *delim, char **saveptr);
6238#endif
6239
6240#ifndef _WIN32
6241/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
6242/* not for windows: might conflict with string.h where strdup may have
6243 * dllimport attribute: https://github.com/libsdl-org/SDL/issues/12948 */
6244char *strdup(const char *str);
6245#endif
6246
6247/* Starting LLVM 16, the analyser errors out if these functions do not have
6248 their prototype defined (clang-diagnostic-implicit-function-declaration) */
6249#include <stdio.h>
6250#include <stdlib.h>
6251
6252#define SDL_malloc malloc
6253#define SDL_calloc calloc
6254#define SDL_realloc realloc
6255#define SDL_free free
6256#ifndef SDL_memcpy
6257#define SDL_memcpy memcpy
6258#endif
6259#ifndef SDL_memmove
6260#define SDL_memmove memmove
6261#endif
6262#ifndef SDL_memset
6263#define SDL_memset memset
6264#endif
6265#define SDL_memcmp memcmp
6266#define SDL_strlcpy strlcpy
6267#define SDL_strlcat strlcat
6268#define SDL_strlen strlen
6269#define SDL_wcslen wcslen
6270#define SDL_wcslcpy wcslcpy
6271#define SDL_wcslcat wcslcat
6272#define SDL_strdup strdup
6273#define SDL_wcsdup wcsdup
6274#define SDL_strchr strchr
6275#define SDL_strrchr strrchr
6276#define SDL_strstr strstr
6277#define SDL_wcsstr wcsstr
6278#define SDL_strtok_r strtok_r
6279#define SDL_strcmp strcmp
6280#define SDL_wcscmp wcscmp
6281#define SDL_strncmp strncmp
6282#define SDL_wcsncmp wcsncmp
6283#define SDL_strcasecmp strcasecmp
6284#define SDL_strncasecmp strncasecmp
6285#define SDL_strpbrk strpbrk
6286#define SDL_sscanf sscanf
6287#define SDL_vsscanf vsscanf
6288#define SDL_snprintf snprintf
6289#define SDL_vsnprintf vsnprintf
6290#endif
6291
6292/**
6293 * Multiply two integers, checking for overflow.
6294 *
6295 * If `a * b` would overflow, return false.
6296 *
6297 * Otherwise store `a * b` via ret and return true.
6298 *
6299 * \param a the multiplicand.
6300 * \param b the multiplier.
6301 * \param ret on non-overflow output, stores the multiplication result, may
6302 * not be NULL.
6303 * \returns false on overflow, true if result is multiplied without overflow.
6304 *
6305 * \threadsafety It is safe to call this function from any thread.
6306 *
6307 * \since This function is available since SDL 3.2.0.
6308 */
6309SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
6310{
6311 if (a != 0 && b > SDL_SIZE_MAX / a) {
6312 return false;
6313 }
6314 *ret = a * b;
6315 return true;
6316}
6317
6318#ifndef SDL_WIKI_DOCUMENTATION_SECTION
6319#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
6320/* This needs to be wrapped in an inline rather than being a direct #define,
6321 * because __builtin_mul_overflow() is type-generic, but we want to be
6322 * consistent about interpreting a and b as size_t. */
6323SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
6324{
6325 return (__builtin_mul_overflow(a, b, ret) == 0);
6326}
6327#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
6328#endif
6329#endif
6330
6331/**
6332 * Add two integers, checking for overflow.
6333 *
6334 * If `a + b` would overflow, return false.
6335 *
6336 * Otherwise store `a + b` via ret and return true.
6337 *
6338 * \param a the first addend.
6339 * \param b the second addend.
6340 * \param ret on non-overflow output, stores the addition result, may not be
6341 * NULL.
6342 * \returns false on overflow, true if result is added without overflow.
6343 *
6344 * \threadsafety It is safe to call this function from any thread.
6345 *
6346 * \since This function is available since SDL 3.2.0.
6347 */
6348SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
6349{
6350 if (b > SDL_SIZE_MAX - a) {
6351 return false;
6352 }
6353 *ret = a + b;
6354 return true;
6355}
6356
6357#ifndef SDL_WIKI_DOCUMENTATION_SECTION
6358#if SDL_HAS_BUILTIN(__builtin_add_overflow)
6359/* This needs to be wrapped in an inline rather than being a direct #define,
6360 * the same as the call to __builtin_mul_overflow() above. */
6361SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
6362{
6363 return (__builtin_add_overflow(a, b, ret) == 0);
6364}
6365#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
6366#endif
6367#endif
6368
6369/* This is a generic function pointer which should be cast to the type you expect */
6370#ifdef SDL_WIKI_DOCUMENTATION_SECTION
6371
6372/**
6373 * A generic function pointer.
6374 *
6375 * In theory, generic function pointers should use this, instead of `void *`,
6376 * since some platforms could treat code addresses differently than data
6377 * addresses. Although in current times no popular platforms make this
6378 * distinction, it is more correct and portable to use the correct type for a
6379 * generic pointer.
6380 *
6381 * If for some reason you need to force this typedef to be an actual `void *`,
6382 * perhaps to work around a compiler or existing code, you can define
6383 * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
6384 *
6385 * \since This datatype is available since SDL 3.2.0.
6386 */
6387typedef void (*SDL_FunctionPointer)(void);
6388#elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
6389typedef void *SDL_FunctionPointer;
6390#else
6391typedef void (*SDL_FunctionPointer)(void);
6392#endif
6393
6394/* Ends C function definitions when using C++ */
6395#ifdef __cplusplus
6396}
6397#endif
6398#include <SDL3/SDL_close_code.h>
6399
6400#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)