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