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