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