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