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