SDL 3.0
SDL_stdinc.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 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 * This is a general header that includes C language support. It implements a
26 * subset of the C runtime: these should all behave the same way as their C
27 * runtime equivalents, but with an SDL_ prefix.
28 */
29
30#ifndef SDL_stdinc_h_
31#define SDL_stdinc_h_
32
34
35#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
36#include <inttypes.h>
37#endif
38#include <stdarg.h>
39#include <stdint.h>
40#include <string.h>
41#include <wchar.h>
42
43#ifndef SDL_DISABLE_ALLOCA
44# ifndef alloca
45# ifdef HAVE_ALLOCA_H
46# include <alloca.h>
47# elif defined(SDL_PLATFORM_NETBSD)
48# if defined(__STRICT_ANSI__)
49# define SDL_DISABLE_ALLOCA
50# else
51# include <stdlib.h>
52# endif
53# elif defined(__GNUC__)
54# define alloca __builtin_alloca
55# elif defined(_MSC_VER)
56# include <malloc.h>
57# define alloca _alloca
58# elif defined(__WATCOMC__)
59# include <malloc.h>
60# elif defined(__BORLANDC__)
61# include <malloc.h>
62# elif defined(__DMC__)
63# include <stdlib.h>
64# elif defined(SDL_PLATFORM_AIX)
65# pragma alloca
66# elif defined(__MRC__)
67void *alloca(unsigned);
68# else
69void *alloca(size_t);
70# endif
71# endif
72#endif
73
74#ifdef SIZE_MAX
75# define SDL_SIZE_MAX SIZE_MAX
76#else
77# define SDL_SIZE_MAX ((size_t) -1)
78#endif
79
80/**
81 * Check if the compiler supports a given builtin.
82 * Supported by virtually all clang versions and recent gcc. Use this
83 * instead of checking the clang version if possible.
84 */
85#ifdef __has_builtin
86#define SDL_HAS_BUILTIN(x) __has_builtin(x)
87#else
88#define SDL_HAS_BUILTIN(x) 0
89#endif
90
91/**
92 * The number of elements in an array.
93 *
94 * This macro looks like it double-evaluates the argument, but it does so
95 * inside of `sizeof`, so there are no side-effects here, as expressions do
96 * not actually run any code in these cases.
97 *
98 * \since This macro is available since SDL 3.0.0.
99 */
100#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
101
102/**
103 * Macro useful for building other macros with strings in them.
104 *
105 * For example:
106 *
107 * ```c
108 * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
109 * ```
110 *
111 * \since This macro is available since SDL 3.0.0.
112 */
113#define SDL_STRINGIFY_ARG(arg) #arg
114
115/**
116 * \name Cast operators
117 *
118 * Use proper C++ casts when compiled as C++ to be compatible with the option
119 * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
120 */
121/* @{ */
122#ifdef __cplusplus
123#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
124#define SDL_static_cast(type, expression) static_cast<type>(expression)
125#define SDL_const_cast(type, expression) const_cast<type>(expression)
126#else
127#define SDL_reinterpret_cast(type, expression) ((type)(expression))
128#define SDL_static_cast(type, expression) ((type)(expression))
129#define SDL_const_cast(type, expression) ((type)(expression))
130#endif
131/* @} *//* Cast operators */
132
133/* Define a four character code as a Uint32 */
134#define SDL_FOURCC(A, B, C, D) \
135 ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
136 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
137 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
138 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
139
140#ifdef SDL_WIKI_DOCUMENTATION_SECTION
141
142/**
143 * Append the 64 bit integer suffix to a signed integer literal.
144 *
145 * This helps compilers that might believe a integer literal larger than
146 * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
147 * instead of `0xFFFFFFFF1` by itself.
148 *
149 * \since This macro is available since SDL 3.0.0.
150 *
151 * \sa SDL_UINT64_C
152 */
153#define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
154
155/**
156 * Append the 64 bit integer suffix to an unsigned integer literal.
157 *
158 * This helps compilers that might believe a integer literal larger than
159 * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
160 * instead of `0xFFFFFFFF1` by itself.
161 *
162 * \since This macro is available since SDL 3.0.0.
163 *
164 * \sa SDL_SINT64_C
165 */
166#define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
167
168#elif defined(INT64_C)
169#define SDL_SINT64_C(c) INT64_C(c)
170#define SDL_UINT64_C(c) UINT64_C(c)
171#elif defined(_MSC_VER)
172#define SDL_SINT64_C(c) c ## i64
173#define SDL_UINT64_C(c) c ## ui64
174#elif defined(__LP64__) || defined(_LP64)
175#define SDL_SINT64_C(c) c ## L
176#define SDL_UINT64_C(c) c ## UL
177#else
178#define SDL_SINT64_C(c) c ## LL
179#define SDL_UINT64_C(c) c ## ULL
180#endif
181
182/**
183 * \name Basic data types
184 */
185/* @{ */
186
187/**
188 * A boolean false.
189 *
190 * \since This macro is available since SDL 3.0.0.
191 *
192 * \sa SDL_bool
193 */
194#define SDL_FALSE 0
195
196/**
197 * A boolean true.
198 *
199 * \since This macro is available since SDL 3.0.0.
200 *
201 * \sa SDL_bool
202 */
203#define SDL_TRUE 1
204
205/**
206 * A boolean type: true or false.
207 *
208 * \since This datatype is available since SDL 3.0.0.
209 *
210 * \sa SDL_TRUE
211 * \sa SDL_FALSE
212 */
213typedef int SDL_bool;
214
215/**
216 * A signed 8-bit integer type.
217 *
218 * \since This macro is available since SDL 3.0.0.
219 */
220typedef int8_t Sint8;
221#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
222#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
223
224/**
225 * An unsigned 8-bit integer type.
226 *
227 * \since This macro is available since SDL 3.0.0.
228 */
229typedef uint8_t Uint8;
230#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
231#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
232
233/**
234 * A signed 16-bit integer type.
235 *
236 * \since This macro is available since SDL 3.0.0.
237 */
238typedef int16_t Sint16;
239#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
240#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
241
242/**
243 * An unsigned 16-bit integer type.
244 *
245 * \since This macro is available since SDL 3.0.0.
246 */
247typedef uint16_t Uint16;
248#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
249#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
250
251/**
252 * A signed 32-bit integer type.
253 *
254 * \since This macro is available since SDL 3.0.0.
255 */
256typedef int32_t Sint32;
257#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
258#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
259
260/**
261 * An unsigned 32-bit integer type.
262 *
263 * \since This macro is available since SDL 3.0.0.
264 */
265typedef uint32_t Uint32;
266#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
267#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
268
269/**
270 * A signed 64-bit integer type.
271 *
272 * \since This macro is available since SDL 3.0.0.
273 *
274 * \sa SDL_SINT64_C
275 */
276typedef int64_t Sint64;
277#define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
278#define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
279
280/**
281 * An unsigned 64-bit integer type.
282 *
283 * \since This macro is available since SDL 3.0.0.
284 *
285 * \sa SDL_UINT64_C
286 */
287typedef uint64_t Uint64;
288#define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
289#define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
290
291/**
292 * SDL times are signed, 64-bit integers representing nanoseconds since the
293 * Unix epoch (Jan 1, 1970).
294 *
295 * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
296 * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
297 * SDL_TimeToWindows() and SDL_TimeFromWindows().
298 *
299 * \since This macro is available since SDL 3.0.0.
300 *
301 * \sa SDL_MAX_SINT64
302 * \sa SDL_MIN_SINT64
303 */
305#define SDL_MAX_TIME SDL_MAX_SINT64
306#define SDL_MIN_TIME SDL_MIN_SINT64
307
308/* @} *//* Basic data types */
309
310/**
311 * \name Floating-point constants
312 */
313/* @{ */
314
315#ifdef FLT_EPSILON
316#define SDL_FLT_EPSILON FLT_EPSILON
317#else
318
319/**
320 * Epsilon constant, used for comparing floating-point numbers.
321 *
322 * Equals by default to platform-defined `FLT_EPSILON`, or
323 * `1.1920928955078125e-07F` if that's not available.
324 *
325 * \since This macro is available since SDL 3.0.0.
326 */
327#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
328#endif
329
330/* @} *//* Floating-point constants */
331
332/* Make sure we have macros for printing width-based integers.
333 * <stdint.h> should define these but this is not true all platforms.
334 * (for example win32) */
335#ifndef SDL_PRIs64
336#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
337#define SDL_PRIs64 "I64d"
338#elif defined(PRIs64)
339#define SDL_PRIs64 PRIs64
340#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
341#define SDL_PRIs64 "ld"
342#else
343#define SDL_PRIs64 "lld"
344#endif
345#endif
346#ifndef SDL_PRIu64
347#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
348#define SDL_PRIu64 "I64u"
349#elif defined(PRIu64)
350#define SDL_PRIu64 PRIu64
351#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
352#define SDL_PRIu64 "lu"
353#else
354#define SDL_PRIu64 "llu"
355#endif
356#endif
357#ifndef SDL_PRIx64
358#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
359#define SDL_PRIx64 "I64x"
360#elif defined(PRIx64)
361#define SDL_PRIx64 PRIx64
362#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
363#define SDL_PRIx64 "lx"
364#else
365#define SDL_PRIx64 "llx"
366#endif
367#endif
368#ifndef SDL_PRIX64
369#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
370#define SDL_PRIX64 "I64X"
371#elif defined(PRIX64)
372#define SDL_PRIX64 PRIX64
373#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
374#define SDL_PRIX64 "lX"
375#else
376#define SDL_PRIX64 "llX"
377#endif
378#endif
379#ifndef SDL_PRIs32
380#ifdef PRId32
381#define SDL_PRIs32 PRId32
382#else
383#define SDL_PRIs32 "d"
384#endif
385#endif
386#ifndef SDL_PRIu32
387#ifdef PRIu32
388#define SDL_PRIu32 PRIu32
389#else
390#define SDL_PRIu32 "u"
391#endif
392#endif
393#ifndef SDL_PRIx32
394#ifdef PRIx32
395#define SDL_PRIx32 PRIx32
396#else
397#define SDL_PRIx32 "x"
398#endif
399#endif
400#ifndef SDL_PRIX32
401#ifdef PRIX32
402#define SDL_PRIX32 PRIX32
403#else
404#define SDL_PRIX32 "X"
405#endif
406#endif
407
408/* Annotations to help code analysis tools */
409#ifdef SDL_DISABLE_ANALYZE_MACROS
410#define SDL_IN_BYTECAP(x)
411#define SDL_INOUT_Z_CAP(x)
412#define SDL_OUT_Z_CAP(x)
413#define SDL_OUT_CAP(x)
414#define SDL_OUT_BYTECAP(x)
415#define SDL_OUT_Z_BYTECAP(x)
416#define SDL_PRINTF_FORMAT_STRING
417#define SDL_SCANF_FORMAT_STRING
418#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
419#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
420#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
421#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
422#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
423#define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
424#else
425#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
426#include <sal.h>
427
428#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
429#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
430#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
431#define SDL_OUT_CAP(x) _Out_cap_(x)
432#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
433#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
434
435#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
436#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
437#else
438#define SDL_IN_BYTECAP(x)
439#define SDL_INOUT_Z_CAP(x)
440#define SDL_OUT_Z_CAP(x)
441#define SDL_OUT_CAP(x)
442#define SDL_OUT_BYTECAP(x)
443#define SDL_OUT_Z_BYTECAP(x)
444#define SDL_PRINTF_FORMAT_STRING
445#define SDL_SCANF_FORMAT_STRING
446#endif
447#ifdef __GNUC__
448#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
449#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
450#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
451#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
452#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
453#define SDL_WSCANF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wscanf__, fmtargnumber, fmtargnumber+1 ))) */
454#else
455#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
456#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
457#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
458#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
459#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
460#define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
461#endif
462#endif /* SDL_DISABLE_ANALYZE_MACROS */
463
464#ifndef SDL_COMPILE_TIME_ASSERT
465#if defined(__cplusplus)
466/* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
467#if (__cplusplus >= 201103L)
468#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
469#endif
470#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
471#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
472#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
473#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
474#endif
475#endif /* !SDL_COMPILE_TIME_ASSERT */
476
477#ifndef SDL_COMPILE_TIME_ASSERT
478/* universal, but may trigger -Wunused-local-typedefs */
479#define SDL_COMPILE_TIME_ASSERT(name, x) \
480 typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
481#endif
482
483/** \cond */
484#ifndef DOXYGEN_SHOULD_IGNORE_THIS
485SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
486SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
487SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
488SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
489SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
490SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
491SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
492SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
493#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
494/** \endcond */
495
496/* Check to make sure enums are the size of ints, for structure packing.
497 For both Watcom C/C++ and Borland C/C++ the compiler option that makes
498 enums having the size of an int must be enabled.
499 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
500*/
501
502/** \cond */
503#ifndef DOXYGEN_SHOULD_IGNORE_THIS
504#if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
505/* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
506typedef enum SDL_DUMMY_ENUM
507{
508 DUMMY_ENUM_VALUE
509} SDL_DUMMY_ENUM;
510
511SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
512#endif
513#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
514/** \endcond */
515
516#include <SDL3/SDL_begin_code.h>
517/* Set up for C function definitions, even when using C++ */
518#ifdef __cplusplus
519extern "C" {
520#endif
521
522#ifndef SDL_DISABLE_ALLOCA
523#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
524#define SDL_stack_free(data)
525#else
526#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
527#define SDL_stack_free(data) SDL_free(data)
528#endif
529
530extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
531extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
532extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
533extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
534
535typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
536typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
537typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
538typedef void (SDLCALL *SDL_free_func)(void *mem);
539
540/**
541 * Get the original set of SDL memory functions.
542 *
543 * This is what SDL_malloc and friends will use by default, if there has been
544 * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
545 * runtime's `malloc` functions behind the scenes! Different platforms and
546 * build configurations might do any number of unexpected things.
547 *
548 * \param malloc_func filled with malloc function.
549 * \param calloc_func filled with calloc function.
550 * \param realloc_func filled with realloc function.
551 * \param free_func filled with free function.
552 *
553 * \threadsafety It is safe to call this function from any thread.
554 *
555 * \since This function is available since SDL 3.0.0.
556 */
557extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
558 SDL_calloc_func *calloc_func,
559 SDL_realloc_func *realloc_func,
560 SDL_free_func *free_func);
561
562/**
563 * Get the current set of SDL memory functions.
564 *
565 * \param malloc_func filled with malloc function.
566 * \param calloc_func filled with calloc function.
567 * \param realloc_func filled with realloc function.
568 * \param free_func filled with free function.
569 *
570 * \threadsafety This does not hold a lock, so do not call this in the
571 * unlikely event of a background thread calling
572 * SDL_SetMemoryFunctions simultaneously.
573 *
574 * \since This function is available since SDL 3.0.0.
575 *
576 * \sa SDL_SetMemoryFunctions
577 * \sa SDL_GetOriginalMemoryFunctions
578 */
579extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
580 SDL_calloc_func *calloc_func,
581 SDL_realloc_func *realloc_func,
582 SDL_free_func *free_func);
583
584/**
585 * Replace SDL's memory allocation functions with a custom set.
586 *
587 * It is not safe to call this function once any allocations have been made,
588 * as future calls to SDL_free will use the new allocator, even if they came
589 * from an SDL_malloc made with the old one!
590 *
591 * If used, usually this needs to be the first call made into the SDL library,
592 * if not the very first thing done at program startup time.
593 *
594 * \param malloc_func custom malloc function.
595 * \param calloc_func custom calloc function.
596 * \param realloc_func custom realloc function.
597 * \param free_func custom free function.
598 * \returns 0 on success or a negative error code on failure; call
599 * SDL_GetError() for more information.
600 *
601 * \threadsafety It is safe to call this function from any thread, but one
602 * should not replace the memory functions once any allocations
603 * are made!
604 *
605 * \since This function is available since SDL 3.0.0.
606 *
607 * \sa SDL_GetMemoryFunctions
608 * \sa SDL_GetOriginalMemoryFunctions
609 */
610extern SDL_DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
611 SDL_calloc_func calloc_func,
612 SDL_realloc_func realloc_func,
613 SDL_free_func free_func);
614
615/**
616 * Allocate memory aligned to a specific value.
617 *
618 * If `alignment` is less than the size of `void *`, then it will be increased
619 * to match that.
620 *
621 * The returned memory address will be a multiple of the alignment value, and
622 * the amount of memory allocated will be a multiple of the alignment value.
623 *
624 * The memory returned by this function must be freed with SDL_aligned_free(),
625 * and _not_ SDL_free.
626 *
627 * \param alignment the alignment requested.
628 * \param size the size to allocate.
629 * \returns a pointer to the aligned memory.
630 *
631 * \threadsafety It is safe to call this function from any thread.
632 *
633 * \since This function is available since SDL 3.0.0.
634 *
635 * \sa SDL_aligned_free
636 */
637extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
638
639/**
640 * Free memory allocated by SDL_aligned_alloc().
641 *
642 * The pointer is no longer valid after this call and cannot be dereferenced
643 * anymore.
644 *
645 * \param mem a pointer previously returned by SDL_aligned_alloc.
646 *
647 * \threadsafety It is safe to call this function from any thread.
648 *
649 * \since This function is available since SDL 3.0.0.
650 *
651 * \sa SDL_aligned_alloc
652 */
653extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
654
655/**
656 * Get the number of outstanding (unfreed) allocations.
657 *
658 * \returns the number of allocations.
659 *
660 * \threadsafety It is safe to call this function from any thread.
661 *
662 * \since This function is available since SDL 3.0.0.
663 */
664extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
665
666extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
667extern SDL_DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
668extern SDL_DECLSPEC int SDLCALL SDL_unsetenv(const char *name);
669
670typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
671extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
672extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
673
674typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
675extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
676extern 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);
677
678extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
679
680/* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
681#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
682#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
683#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
684
685/**
686 * Query if a character is alphabetic (a letter).
687 *
688 * **WARNING**: Regardless of system locale, this will only treat ASCII values
689 * for English 'a-z' and 'A-Z' as true.
690 *
691 * \param x character value to check.
692 * \returns non-zero if x falls within the character class, zero otherwise.
693 *
694 * \threadsafety It is safe to call this function from any thread.
695 *
696 * \since This function is available since SDL 3.0.0.
697 */
698extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
699
700/**
701 * Query if a character is alphabetic (a letter) or a number.
702 *
703 * **WARNING**: Regardless of system locale, this will only treat ASCII values
704 * for English 'a-z', 'A-Z', and '0-9' as true.
705 *
706 * \param x character value to check.
707 * \returns non-zero if x falls within the character class, zero otherwise.
708 *
709 * \threadsafety It is safe to call this function from any thread.
710 *
711 * \since This function is available since SDL 3.0.0.
712 */
713extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
714
715/**
716 * Report if a character is blank (a space or tab).
717 *
718 * **WARNING**: Regardless of system locale, this will only treat ASCII values
719 * 0x20 (space) or 0x9 (tab) as true.
720 *
721 * \param x character value to check.
722 * \returns non-zero if x falls within the character class, zero otherwise.
723 *
724 * \threadsafety It is safe to call this function from any thread.
725 *
726 * \since This function is available since SDL 3.0.0.
727 */
728extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
729
730/**
731 * Report if a character is a control character.
732 *
733 * **WARNING**: Regardless of system locale, this will only treat ASCII values
734 * 0 through 0x1F, and 0x7F, as true.
735 *
736 * \param x character value to check.
737 * \returns non-zero if x falls within the character class, zero otherwise.
738 *
739 * \threadsafety It is safe to call this function from any thread.
740 *
741 * \since This function is available since SDL 3.0.0.
742 */
743extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
744
745/**
746 * Report if a character is a numeric digit.
747 *
748 * **WARNING**: Regardless of system locale, this will only treat ASCII values
749 * '0' (0x30) through '9' (0x39), as true.
750 *
751 * \param x character value to check.
752 * \returns non-zero if x falls within the character class, zero otherwise.
753 *
754 * \threadsafety It is safe to call this function from any thread.
755 *
756 * \since This function is available since SDL 3.0.0.
757 */
758extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
759
760/**
761 * Report if a character is a hexadecimal digit.
762 *
763 * **WARNING**: Regardless of system locale, this will only treat ASCII values
764 * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
765 *
766 * \param x character value to check.
767 * \returns non-zero if x falls within the character class, zero otherwise.
768 *
769 * \threadsafety It is safe to call this function from any thread.
770 *
771 * \since This function is available since SDL 3.0.0.
772 */
773extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
774
775/**
776 * Report if a character is a punctuation mark.
777 *
778 * **WARNING**: Regardless of system locale, this is equivalent to
779 * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
780 *
781 * \param x character value to check.
782 * \returns non-zero if x falls within the character class, zero otherwise.
783 *
784 * \threadsafety It is safe to call this function from any thread.
785 *
786 * \since This function is available since SDL 3.0.0.
787 *
788 * \sa SDL_isgraph
789 * \sa SDL_isalnum
790 */
791extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
792
793/**
794 * Report if a character is whitespace.
795 *
796 * **WARNING**: Regardless of system locale, this will only treat the
797 * following ASCII values as true:
798 *
799 * - space (0x20)
800 * - tab (0x09)
801 * - newline (0x0A)
802 * - vertical tab (0x0B)
803 * - form feed (0x0C)
804 * - return (0x0D)
805 *
806 * \param x character value to check.
807 * \returns non-zero if x falls within the character class, zero otherwise.
808 *
809 * \threadsafety It is safe to call this function from any thread.
810 *
811 * \since This function is available since SDL 3.0.0.
812 */
813extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
814
815/**
816 * Report if a character is upper case.
817 *
818 * **WARNING**: Regardless of system locale, this will only treat ASCII values
819 * 'A' through 'Z' as true.
820 *
821 * \param x character value to check.
822 * \returns non-zero if x falls within the character class, zero otherwise.
823 *
824 * \threadsafety It is safe to call this function from any thread.
825 *
826 * \since This function is available since SDL 3.0.0.
827 */
828extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
829
830/**
831 * Report if a character is lower case.
832 *
833 * **WARNING**: Regardless of system locale, this will only treat ASCII values
834 * 'a' through 'z' as true.
835 *
836 * \param x character value to check.
837 * \returns non-zero if x falls within the character class, zero otherwise.
838 *
839 * \threadsafety It is safe to call this function from any thread.
840 *
841 * \since This function is available since SDL 3.0.0.
842 */
843extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
844
845/**
846 * Report if a character is "printable".
847 *
848 * Be advised that "printable" has a definition that goes back to text
849 * terminals from the dawn of computing, making this a sort of special case
850 * function that is not suitable for Unicode (or most any) text management.
851 *
852 * **WARNING**: Regardless of system locale, this will only treat ASCII values
853 * ' ' (0x20) through '~' (0x7E) as true.
854 *
855 * \param x character value to check.
856 * \returns non-zero if x falls within the character class, zero otherwise.
857 *
858 * \threadsafety It is safe to call this function from any thread.
859 *
860 * \since This function is available since SDL 3.0.0.
861 */
862extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
863
864/**
865 * Report if a character is any "printable" except space.
866 *
867 * Be advised that "printable" has a definition that goes back to text
868 * terminals from the dawn of computing, making this a sort of special case
869 * function that is not suitable for Unicode (or most any) text management.
870 *
871 * **WARNING**: Regardless of system locale, this is equivalent to
872 * `(SDL_isprint(x)) && ((x) != ' ')`.
873 *
874 * \param x character value to check.
875 * \returns non-zero if x falls within the character class, zero otherwise.
876 *
877 * \threadsafety It is safe to call this function from any thread.
878 *
879 * \since This function is available since SDL 3.0.0.
880 *
881 * \sa SDL_isprint
882 */
883extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
884
885/**
886 * Convert low-ASCII English letters to uppercase.
887 *
888 * **WARNING**: Regardless of system locale, this will only convert ASCII
889 * values 'a' through 'z' to uppercase.
890 *
891 * This function returns the uppercase equivalent of `x`. If a character
892 * cannot be converted, or is already uppercase, this function returns `x`.
893 *
894 * \param x character value to check.
895 * \returns capitalized version of x, or x if no conversion available.
896 *
897 * \threadsafety It is safe to call this function from any thread.
898 *
899 * \since This function is available since SDL 3.0.0.
900 */
901extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
902
903/**
904 * Convert low-ASCII English letters to lowercase.
905 *
906 * **WARNING**: Regardless of system locale, this will only convert ASCII
907 * values 'A' through 'Z' to lowercase.
908 *
909 * This function returns the lowercase equivalent of `x`. If a character
910 * cannot be converted, or is already lowercase, this function returns `x`.
911 *
912 * \param x character value to check.
913 * \returns lowercase version of x, or x if no conversion available.
914 *
915 * \threadsafety It is safe to call this function from any thread.
916 *
917 * \since This function is available since SDL 3.0.0.
918 */
919extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
920
921extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
922extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
923
924extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
925
926/* Take advantage of compiler optimizations for memcpy */
927#ifndef SDL_SLOW_MEMCPY
928#ifdef SDL_memcpy
929#undef SDL_memcpy
930#endif
931#define SDL_memcpy memcpy
932#endif
933
934#define SDL_copyp(dst, src) \
935 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
936 SDL_memcpy((dst), (src), sizeof(*(src)))
937
938extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
939
940/* Take advantage of compiler optimizations for memmove */
941#ifndef SDL_SLOW_MEMMOVE
942#ifdef SDL_memmove
943#undef SDL_memmove
944#endif
945#define SDL_memmove memmove
946#endif
947
948extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
949extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
950
951/* Take advantage of compiler optimizations for memset */
952#ifndef SDL_SLOW_MEMSET
953#ifdef SDL_memset
954#undef SDL_memset
955#endif
956#define SDL_memset memset
957#endif
958
959#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
960#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
961#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
962
963extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
964
965extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
966extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
967extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
968extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
969extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
970extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
971extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
972
973/**
974 * Compare two null-terminated wide strings.
975 *
976 * This only compares wchar_t values until it hits a null-terminating
977 * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
978 * depending on your platform's wchar_t size), or uses valid Unicode values.
979 *
980 * \param str1 the first string to compare. NULL is not permitted!
981 * \param str2 the second string to compare. NULL is not permitted!
982 * \returns less than zero if str1 is "less than" str2, greater than zero if
983 * str1 is "greater than" str2, and zero if the strings match
984 * exactly.
985 *
986 * \threadsafety It is safe to call this function from any thread.
987 *
988 * \since This function is available since SDL 3.0.0.
989 */
990extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
991
992/**
993 * Compare two wide strings up to a number of wchar_t values.
994 *
995 * This only compares wchar_t values; it does not care if the string is
996 * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
997 * or uses valid Unicode values.
998 *
999 * Note that while this function is intended to be used with UTF-16 (or
1000 * UTF-32, depending on your platform's definition of wchar_t), it is
1001 * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
1002 * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
1003 * sequence, it will only compare a portion of the final character.
1004 *
1005 * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
1006 * match to this number of wide chars (or both have matched to a
1007 * null-terminator character before this count), they will be considered
1008 * equal.
1009 *
1010 * \param str1 the first string to compare. NULL is not permitted!
1011 * \param str2 the second string to compare. NULL is not permitted!
1012 * \param maxlen the maximum number of wchar_t to compare.
1013 * \returns less than zero if str1 is "less than" str2, greater than zero if
1014 * str1 is "greater than" str2, and zero if the strings match
1015 * exactly.
1016 *
1017 * \threadsafety It is safe to call this function from any thread.
1018 *
1019 * \since This function is available since SDL 3.0.0.
1020 */
1021extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
1022
1023/**
1024 * Compare two null-terminated wide strings, case-insensitively.
1025 *
1026 * This will work with Unicode strings, using a technique called
1027 * "case-folding" to handle the vast majority of case-sensitive human
1028 * languages regardless of system locale. It can deal with expanding values: a
1029 * German Eszett character can compare against two ASCII 's' chars and be
1030 * considered a match, for example. A notable exception: it does not handle
1031 * the Turkish 'i' character; human language is complicated!
1032 *
1033 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
1034 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
1035 * handles Unicode, it expects the string to be well-formed and not a
1036 * null-terminated string of arbitrary bytes. Characters that are not valid
1037 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
1038 * CHARACTER), which is to say two strings of random bits may turn out to
1039 * match if they convert to the same amount of replacement characters.
1040 *
1041 * \param str1 the first string to compare. NULL is not permitted!
1042 * \param str2 the second string to compare. NULL is not permitted!
1043 * \returns less than zero if str1 is "less than" str2, greater than zero if
1044 * str1 is "greater than" str2, and zero if the strings match
1045 * exactly.
1046 *
1047 * \threadsafety It is safe to call this function from any thread.
1048 *
1049 * \since This function is available since SDL 3.0.0.
1050 */
1051extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
1052
1053/**
1054 * Compare two wide strings, case-insensitively, up to a number of wchar_t.
1055 *
1056 * This will work with Unicode strings, using a technique called
1057 * "case-folding" to handle the vast majority of case-sensitive human
1058 * languages regardless of system locale. It can deal with expanding values: a
1059 * German Eszett character can compare against two ASCII 's' chars and be
1060 * considered a match, for example. A notable exception: it does not handle
1061 * the Turkish 'i' character; human language is complicated!
1062 *
1063 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
1064 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
1065 * handles Unicode, it expects the string to be well-formed and not a
1066 * null-terminated string of arbitrary bytes. Characters that are not valid
1067 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
1068 * CHARACTER), which is to say two strings of random bits may turn out to
1069 * match if they convert to the same amount of replacement characters.
1070 *
1071 * Note that while this function might deal with variable-sized characters,
1072 * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
1073 * multi-byte UTF-16 sequence, it may convert a portion of the final character
1074 * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
1075 * to overflow a buffer.
1076 *
1077 * `maxlen` specifies a maximum number of wchar_t values to compare; if the
1078 * strings match to this number of wchar_t (or both have matched to a
1079 * null-terminator character before this number of bytes), they will be
1080 * considered equal.
1081 *
1082 * \param str1 the first string to compare. NULL is not permitted!
1083 * \param str2 the second string to compare. NULL is not permitted!
1084 * \param maxlen the maximum number of wchar_t values to compare.
1085 * \returns less than zero if str1 is "less than" str2, greater than zero if
1086 * str1 is "greater than" str2, and zero if the strings match
1087 * exactly.
1088 *
1089 * \threadsafety It is safe to call this function from any thread.
1090 *
1091 * \since This function is available since SDL 3.0.0.
1092 */
1093extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
1094
1095extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
1096
1097extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
1098extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
1099extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
1100extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
1101extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
1102extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
1103extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
1104extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
1105
1106/**
1107 * Convert a string to uppercase.
1108 *
1109 * **WARNING**: Regardless of system locale, this will only convert ASCII
1110 * values 'A' through 'Z' to uppercase.
1111 *
1112 * This function operates on a null-terminated string of bytes--even if it is
1113 * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
1114 * uppercase equivalents in-place, returning the original `str` pointer.
1115 *
1116 * \param str the string to convert in-place. Can not be NULL.
1117 * \returns the `str` pointer passed into this function.
1118 *
1119 * \threadsafety It is safe to call this function from any thread.
1120 *
1121 * \since This function is available since SDL 3.0.0.
1122 *
1123 * \sa SDL_strlwr
1124 */
1125extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
1126
1127/**
1128 * Convert a string to lowercase.
1129 *
1130 * **WARNING**: Regardless of system locale, this will only convert ASCII
1131 * values 'A' through 'Z' to lowercase.
1132 *
1133 * This function operates on a null-terminated string of bytes--even if it is
1134 * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
1135 * lowercase equivalents in-place, returning the original `str` pointer.
1136 *
1137 * \param str the string to convert in-place. Can not be NULL.
1138 * \returns the `str` pointer passed into this function.
1139 *
1140 * \threadsafety It is safe to call this function from any thread.
1141 *
1142 * \since This function is available since SDL 3.0.0.
1143 *
1144 * \sa SDL_strupr
1145 */
1146extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
1147
1148extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
1149extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
1150extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
1151extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
1152extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
1153extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
1154extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
1155extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
1156
1157extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
1158extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
1159extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
1160extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
1161extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
1162extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
1163
1164extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
1165extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
1166extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
1167extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
1168extern SDL_DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
1169extern SDL_DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
1170extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
1171
1172/**
1173 * Compare two null-terminated UTF-8 strings.
1174 *
1175 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
1176 * since effectively this function just compares bytes until it hits a
1177 * null-terminating character. Also due to the nature of UTF-8, this can be
1178 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
1179 *
1180 * \param str1 the first string to compare. NULL is not permitted!
1181 * \param str2 the second string to compare. NULL is not permitted!
1182 * \returns less than zero if str1 is "less than" str2, greater than zero if
1183 * str1 is "greater than" str2, and zero if the strings match
1184 * exactly.
1185 *
1186 * \threadsafety It is safe to call this function from any thread.
1187 *
1188 * \since This function is available since SDL 3.0.0.
1189 */
1190extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
1191
1192/**
1193 * Compare two UTF-8 strings up to a number of bytes.
1194 *
1195 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
1196 * since effectively this function just compares bytes until it hits a
1197 * null-terminating character. Also due to the nature of UTF-8, this can be
1198 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
1199 *
1200 * Note that while this function is intended to be used with UTF-8, it is
1201 * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
1202 * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
1203 * compare a portion of the final character.
1204 *
1205 * `maxlen` specifies a maximum number of bytes to compare; if the strings
1206 * match to this number of bytes (or both have matched to a null-terminator
1207 * character before this number of bytes), they will be considered equal.
1208 *
1209 * \param str1 the first string to compare. NULL is not permitted!
1210 * \param str2 the second string to compare. NULL is not permitted!
1211 * \param maxlen the maximum number of _bytes_ to compare.
1212 * \returns less than zero if str1 is "less than" str2, greater than zero if
1213 * str1 is "greater than" str2, and zero if the strings match
1214 * exactly.
1215 *
1216 * \threadsafety It is safe to call this function from any thread.
1217 *
1218 * \since This function is available since SDL 3.0.0.
1219 */
1220extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
1221
1222/**
1223 * Compare two null-terminated UTF-8 strings, case-insensitively.
1224 *
1225 * This will work with Unicode strings, using a technique called
1226 * "case-folding" to handle the vast majority of case-sensitive human
1227 * languages regardless of system locale. It can deal with expanding values: a
1228 * German Eszett character can compare against two ASCII 's' chars and be
1229 * considered a match, for example. A notable exception: it does not handle
1230 * the Turkish 'i' character; human language is complicated!
1231 *
1232 * Since this handles Unicode, it expects the string to be well-formed UTF-8
1233 * and not a null-terminated string of arbitrary bytes. Bytes that are not
1234 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
1235 * CHARACTER), which is to say two strings of random bits may turn out to
1236 * match if they convert to the same amount of replacement characters.
1237 *
1238 * \param str1 the first string to compare. NULL is not permitted!
1239 * \param str2 the second string to compare. NULL is not permitted!
1240 * \returns less than zero if str1 is "less than" str2, greater than zero if
1241 * str1 is "greater than" str2, and zero if the strings match
1242 * exactly.
1243 *
1244 * \threadsafety It is safe to call this function from any thread.
1245 *
1246 * \since This function is available since SDL 3.0.0.
1247 */
1248extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
1249
1250
1251/**
1252 * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
1253 *
1254 * This will work with Unicode strings, using a technique called
1255 * "case-folding" to handle the vast majority of case-sensitive human
1256 * languages regardless of system locale. It can deal with expanding values: a
1257 * German Eszett character can compare against two ASCII 's' chars and be
1258 * considered a match, for example. A notable exception: it does not handle
1259 * the Turkish 'i' character; human language is complicated!
1260 *
1261 * Since this handles Unicode, it expects the string to be well-formed UTF-8
1262 * and not a null-terminated string of arbitrary bytes. Bytes that are not
1263 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
1264 * CHARACTER), which is to say two strings of random bits may turn out to
1265 * match if they convert to the same amount of replacement characters.
1266 *
1267 * Note that while this function is intended to be used with UTF-8, `maxlen`
1268 * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
1269 * UTF-8 sequence, it may convert a portion of the final character to one or
1270 * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
1271 * a buffer.
1272 *
1273 * `maxlen` specifies a maximum number of bytes to compare; if the strings
1274 * match to this number of bytes (or both have matched to a null-terminator
1275 * character before this number of bytes), they will be considered equal.
1276 *
1277 * \param str1 the first string to compare. NULL is not permitted!
1278 * \param str2 the second string to compare. NULL is not permitted!
1279 * \param maxlen the maximum number of bytes to compare.
1280 * \returns less than zero if str1 is "less than" str2, greater than zero if
1281 * str1 is "greater than" str2, and zero if the strings match
1282 * exactly.
1283 *
1284 * \threadsafety It is safe to call this function from any thread.
1285 *
1286 * \since This function is available since SDL 3.0.0.
1287 */
1288extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
1289
1290/**
1291 * The Unicode REPLACEMENT CHARACTER codepoint.
1292 *
1293 * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
1294 * with encoding errors.
1295 *
1296 * This tends to render as something like a question mark in most places.
1297 *
1298 * \since This macro is available since SDL 3.0.0.
1299 *
1300 * \sa SDL_StepUTF8
1301 */
1302#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
1303
1304/**
1305 * Decode a UTF-8 string, one Unicode codepoint at a time.
1306 *
1307 * This will return the first Unicode codepoint in the UTF-8 encoded string in
1308 * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
1309 *
1310 * It will not access more than `*pslen` bytes from the string. `*pslen` will
1311 * be adjusted, as well, subtracting the number of bytes consumed.
1312 *
1313 * `pslen` is allowed to be NULL, in which case the string _must_ be
1314 * NULL-terminated, as the function will blindly read until it sees the NULL
1315 * char.
1316 *
1317 * if `*pslen` is zero, it assumes the end of string is reached and returns a
1318 * zero codepoint regardless of the contents of the string buffer.
1319 *
1320 * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
1321 * zero, it will not advance `*pstr` or `*pslen` at all.
1322 *
1323 * Generally this function is called in a loop until it returns zero,
1324 * adjusting its parameters each iteration.
1325 *
1326 * If an invalid UTF-8 sequence is encountered, this function returns
1327 * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
1328 * (which is to say, a multibyte sequence might produce several
1329 * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
1330 * UTF-8 sequence).
1331 *
1332 * Several things can generate invalid UTF-8 sequences, including overlong
1333 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
1334 * refer to
1335 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
1336 * for details.
1337 *
1338 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
1339 * \param pslen a pointer to the number of bytes in the string, to be read and
1340 * adjusted. NULL is allowed.
1341 * \returns the first Unicode codepoint in the string.
1342 *
1343 * \threadsafety It is safe to call this function from any thread.
1344 *
1345 * \since This function is available since SDL 3.0.0.
1346 */
1347extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
1348
1349/**
1350 * Convert a single Unicode codepoint to UTF-8.
1351 *
1352 * The buffer pointed to by `dst` must be at least 4 bytes long, as this
1353 * function may generate between 1 and 4 bytes of output.
1354 *
1355 * This function returns the first byte _after_ the newly-written UTF-8
1356 * sequence, which is useful for encoding multiple codepoints in a loop, or
1357 * knowing where to write a NULL-terminator character to end the string (in
1358 * either case, plan to have a buffer of _more_ than 4 bytes!).
1359 *
1360 * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
1361 * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
1362 * codepoint instead, and not set an error.
1363 *
1364 * If `dst` is NULL, this returns NULL immediately without writing to the
1365 * pointer and without setting an error.
1366 *
1367 * \param codepoint a Unicode codepoint to convert to UTF-8.
1368 * \param dst the location to write the encoded UTF-8. Must point to at least
1369 * 4 bytes!
1370 * \returns the first byte past the newly-written UTF-8 sequence.
1371 *
1372 * \threadsafety It is safe to call this function from any thread.
1373 *
1374 * \since This function is available since SDL 3.0.0.
1375 */
1376extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
1377
1378
1379extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
1380extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
1381extern 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);
1382extern 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);
1383extern 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);
1384extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap);
1385extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
1386extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
1387
1388/**
1389 * Seeds the pseudo-random number generator.
1390 *
1391 * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
1392 * of 'random' numbers.
1393 *
1394 * \param seed the value to use as a random number seed, or 0 to use
1395 * SDL_GetPerformanceCounter().
1396 *
1397 * \threadsafety This should be called on the same thread that calls
1398 * SDL_rand*()
1399 *
1400 * \since This function is available since SDL 3.0.0.
1401 *
1402 * \sa SDL_rand
1403 * \sa SDL_rand_bits
1404 * \sa SDL_randf
1405 */
1406extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
1407
1408/**
1409 * Generate a pseudo-random number less than n for positive n
1410 *
1411 * The method used is faster and of better quality than `rand() % n`. Odds are
1412 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
1413 * much worse as n gets bigger.
1414 *
1415 * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
1416 * 1..6
1417 *
1418 * If you want to generate a pseudo-random number in the full range of Sint32,
1419 * you should use: (Sint32)SDL_rand_bits()
1420 *
1421 * If you want reproducible output, be sure to initialize with SDL_srand()
1422 * first.
1423 *
1424 * There are no guarantees as to the quality of the random sequence produced,
1425 * and this should not be used for security (cryptography, passwords) or where
1426 * money is on the line (loot-boxes, casinos). There are many random number
1427 * libraries available with different characteristics and you should pick one
1428 * of those to meet any serious needs.
1429 *
1430 * \param n the number of possible outcomes. n must be positive.
1431 * \returns a random value in the range of [0 .. n-1].
1432 *
1433 * \threadsafety All calls should be made from a single thread
1434 *
1435 * \since This function is available since SDL 3.0.0.
1436 *
1437 * \sa SDL_srand
1438 * \sa SDL_randf
1439 */
1440extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
1441
1442/**
1443 * Generate a uniform pseudo-random floating point number less than 1.0
1444 *
1445 * If you want reproducible output, be sure to initialize with SDL_srand()
1446 * first.
1447 *
1448 * There are no guarantees as to the quality of the random sequence produced,
1449 * and this should not be used for security (cryptography, passwords) or where
1450 * money is on the line (loot-boxes, casinos). There are many random number
1451 * libraries available with different characteristics and you should pick one
1452 * of those to meet any serious needs.
1453 *
1454 * \returns a random value in the range of [0.0, 1.0).
1455 *
1456 * \threadsafety All calls should be made from a single thread
1457 *
1458 * \since This function is available since SDL 3.0.0.
1459 *
1460 * \sa SDL_srand
1461 * \sa SDL_rand
1462 */
1463extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
1464
1465/**
1466 * Generate 32 pseudo-random bits.
1467 *
1468 * You likely want to use SDL_rand() to get a psuedo-random number instead.
1469 *
1470 * There are no guarantees as to the quality of the random sequence produced,
1471 * and this should not be used for security (cryptography, passwords) or where
1472 * money is on the line (loot-boxes, casinos). There are many random number
1473 * libraries available with different characteristics and you should pick one
1474 * of those to meet any serious needs.
1475 *
1476 * \returns a random value in the range of [0-SDL_MAX_UINT32].
1477 *
1478 * \threadsafety All calls should be made from a single thread
1479 *
1480 * \since This function is available since SDL 3.0.0.
1481 *
1482 * \sa SDL_rand
1483 * \sa SDL_randf
1484 * \sa SDL_srand
1485 */
1486extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
1487
1488/**
1489 * Generate a pseudo-random number less than n for positive n
1490 *
1491 * The method used is faster and of better quality than `rand() % n`. Odds are
1492 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
1493 * much worse as n gets bigger.
1494 *
1495 * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
1496 * 0..5 to 1..6
1497 *
1498 * If you want to generate a pseudo-random number in the full range of Sint32,
1499 * you should use: (Sint32)SDL_rand_bits_r(state)
1500 *
1501 * There are no guarantees as to the quality of the random sequence produced,
1502 * and this should not be used for security (cryptography, passwords) or where
1503 * money is on the line (loot-boxes, casinos). There are many random number
1504 * libraries available with different characteristics and you should pick one
1505 * of those to meet any serious needs.
1506 *
1507 * \param state a pointer to the current random number state, this may not be
1508 * NULL.
1509 * \param n the number of possible outcomes. n must be positive.
1510 * \returns a random value in the range of [0 .. n-1].
1511 *
1512 * \threadsafety This function is thread-safe, as long as the state pointer
1513 * isn't shared between threads.
1514 *
1515 * \since This function is available since SDL 3.0.0.
1516 *
1517 * \sa SDL_rand
1518 * \sa SDL_rand_bits_r
1519 * \sa SDL_randf_r
1520 */
1521extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
1522
1523/**
1524 * Generate a uniform pseudo-random floating point number less than 1.0
1525 *
1526 * If you want reproducible output, be sure to initialize with SDL_srand()
1527 * first.
1528 *
1529 * There are no guarantees as to the quality of the random sequence produced,
1530 * and this should not be used for security (cryptography, passwords) or where
1531 * money is on the line (loot-boxes, casinos). There are many random number
1532 * libraries available with different characteristics and you should pick one
1533 * of those to meet any serious needs.
1534 *
1535 * \param state a pointer to the current random number state, this may not be
1536 * NULL.
1537 * \returns a random value in the range of [0.0, 1.0).
1538 *
1539 * \threadsafety This function is thread-safe, as long as the state pointer
1540 * isn't shared between threads.
1541 *
1542 * \since This function is available since SDL 3.0.0.
1543 *
1544 * \sa SDL_rand_bits_r
1545 * \sa SDL_rand_r
1546 * \sa SDL_randf
1547 */
1548extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
1549
1550/**
1551 * Generate 32 pseudo-random bits.
1552 *
1553 * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
1554 *
1555 * There are no guarantees as to the quality of the random sequence produced,
1556 * and this should not be used for security (cryptography, passwords) or where
1557 * money is on the line (loot-boxes, casinos). There are many random number
1558 * libraries available with different characteristics and you should pick one
1559 * of those to meet any serious needs.
1560 *
1561 * \param state a pointer to the current random number state, this may not be
1562 * NULL.
1563 * \returns a random value in the range of [0-SDL_MAX_UINT32].
1564 *
1565 * \threadsafety This function is thread-safe, as long as the state pointer
1566 * isn't shared between threads.
1567 *
1568 * \since This function is available since SDL 3.0.0.
1569 *
1570 * \sa SDL_rand_r
1571 * \sa SDL_randf_r
1572 */
1573extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
1574
1575
1576#ifndef SDL_PI_D
1577#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
1578#endif
1579#ifndef SDL_PI_F
1580#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
1581#endif
1582
1583/**
1584 * Compute the arc cosine of `x`.
1585 *
1586 * The definition of `y = acos(x)` is `x = cos(y)`.
1587 *
1588 * Domain: `-1 <= x <= 1`
1589 *
1590 * Range: `0 <= y <= Pi`
1591 *
1592 * This function operates on double-precision floating point values, use
1593 * SDL_acosf for single-precision floats.
1594 *
1595 * This function may use a different approximation across different versions,
1596 * platforms and configurations. i.e, it can return a different value given
1597 * the same input on different machines or operating systems, or if SDL is
1598 * updated.
1599 *
1600 * \param x floating point value.
1601 * \returns arc cosine of `x`, in radians.
1602 *
1603 * \threadsafety It is safe to call this function from any thread.
1604 *
1605 * \since This function is available since SDL 3.0.0.
1606 *
1607 * \sa SDL_acosf
1608 * \sa SDL_asin
1609 * \sa SDL_cos
1610 */
1611extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
1612
1613/**
1614 * Compute the arc cosine of `x`.
1615 *
1616 * The definition of `y = acos(x)` is `x = cos(y)`.
1617 *
1618 * Domain: `-1 <= x <= 1`
1619 *
1620 * Range: `0 <= y <= Pi`
1621 *
1622 * This function operates on single-precision floating point values, use
1623 * SDL_acos for double-precision floats.
1624 *
1625 * This function may use a different approximation across different versions,
1626 * platforms and configurations. i.e, it can return a different value given
1627 * the same input on different machines or operating systems, or if SDL is
1628 * updated.
1629 *
1630 * \param x floating point value.
1631 * \returns arc cosine of `x`, in radians.
1632 *
1633 * \threadsafety It is safe to call this function from any thread.
1634 *
1635 * \since This function is available since SDL 3.0.0.
1636 *
1637 * \sa SDL_acos
1638 * \sa SDL_asinf
1639 * \sa SDL_cosf
1640 */
1641extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
1642
1643/**
1644 * Compute the arc sine of `x`.
1645 *
1646 * The definition of `y = asin(x)` is `x = sin(y)`.
1647 *
1648 * Domain: `-1 <= x <= 1`
1649 *
1650 * Range: `-Pi/2 <= y <= Pi/2`
1651 *
1652 * This function operates on double-precision floating point values, use
1653 * SDL_asinf for single-precision floats.
1654 *
1655 * This function may use a different approximation across different versions,
1656 * platforms and configurations. i.e, it can return a different value given
1657 * the same input on different machines or operating systems, or if SDL is
1658 * updated.
1659 *
1660 * \param x floating point value.
1661 * \returns arc sine of `x`, in radians.
1662 *
1663 * \threadsafety It is safe to call this function from any thread.
1664 *
1665 * \since This function is available since SDL 3.0.0.
1666 *
1667 * \sa SDL_asinf
1668 * \sa SDL_acos
1669 * \sa SDL_sin
1670 */
1671extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
1672
1673/**
1674 * Compute the arc sine of `x`.
1675 *
1676 * The definition of `y = asin(x)` is `x = sin(y)`.
1677 *
1678 * Domain: `-1 <= x <= 1`
1679 *
1680 * Range: `-Pi/2 <= y <= Pi/2`
1681 *
1682 * This function operates on single-precision floating point values, use
1683 * SDL_asin for double-precision floats.
1684 *
1685 * This function may use a different approximation across different versions,
1686 * platforms and configurations. i.e, it can return a different value given
1687 * the same input on different machines or operating systems, or if SDL is
1688 * updated.
1689 *
1690 * \param x floating point value.
1691 * \returns arc sine of `x`, in radians.
1692 *
1693 * \threadsafety It is safe to call this function from any thread.
1694 *
1695 * \since This function is available since SDL 3.0.0.
1696 *
1697 * \sa SDL_asin
1698 * \sa SDL_acosf
1699 * \sa SDL_sinf
1700 */
1701extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
1702
1703/**
1704 * Compute the arc tangent of `x`.
1705 *
1706 * The definition of `y = atan(x)` is `x = tan(y)`.
1707 *
1708 * Domain: `-INF <= x <= INF`
1709 *
1710 * Range: `-Pi/2 <= y <= Pi/2`
1711 *
1712 * This function operates on double-precision floating point values, use
1713 * SDL_atanf for single-precision floats.
1714 *
1715 * To calculate the arc tangent of y / x, use SDL_atan2.
1716 *
1717 * This function may use a different approximation across different versions,
1718 * platforms and configurations. i.e, it can return a different value given
1719 * the same input on different machines or operating systems, or if SDL is
1720 * updated.
1721 *
1722 * \param x floating point value.
1723 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
1724 *
1725 * \threadsafety It is safe to call this function from any thread.
1726 *
1727 * \since This function is available since SDL 3.0.0.
1728 *
1729 * \sa SDL_atanf
1730 * \sa SDL_atan2
1731 * \sa SDL_tan
1732 */
1733extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
1734
1735/**
1736 * Compute the arc tangent of `x`.
1737 *
1738 * The definition of `y = atan(x)` is `x = tan(y)`.
1739 *
1740 * Domain: `-INF <= x <= INF`
1741 *
1742 * Range: `-Pi/2 <= y <= Pi/2`
1743 *
1744 * This function operates on single-precision floating point values, use
1745 * SDL_atan for dboule-precision floats.
1746 *
1747 * To calculate the arc tangent of y / x, use SDL_atan2f.
1748 *
1749 * This function may use a different approximation across different versions,
1750 * platforms and configurations. i.e, it can return a different value given
1751 * the same input on different machines or operating systems, or if SDL is
1752 * updated.
1753 *
1754 * \param x floating point value.
1755 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
1756 *
1757 * \threadsafety It is safe to call this function from any thread.
1758 *
1759 * \since This function is available since SDL 3.0.0.
1760 *
1761 * \sa SDL_atan
1762 * \sa SDL_atan2f
1763 * \sa SDL_tanf
1764 */
1765extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
1766
1767/**
1768 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
1769 * the result's quadrant.
1770 *
1771 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
1772 * of z is determined based on the signs of x and y.
1773 *
1774 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
1775 *
1776 * Range: `-Pi/2 <= y <= Pi/2`
1777 *
1778 * This function operates on double-precision floating point values, use
1779 * SDL_atan2f for single-precision floats.
1780 *
1781 * To calculate the arc tangent of a single value, use SDL_atan.
1782 *
1783 * This function may use a different approximation across different versions,
1784 * platforms and configurations. i.e, it can return a different value given
1785 * the same input on different machines or operating systems, or if SDL is
1786 * updated.
1787 *
1788 * \param y floating point value of the numerator (y coordinate).
1789 * \param x floating point value of the denominator (x coordinate).
1790 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
1791 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
1792 *
1793 * \threadsafety It is safe to call this function from any thread.
1794 *
1795 * \since This function is available since SDL 3.0.0.
1796 *
1797 * \sa SDL_atan2f
1798 * \sa SDL_atan
1799 * \sa SDL_tan
1800 */
1801extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
1802
1803/**
1804 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
1805 * the result's quadrant.
1806 *
1807 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
1808 * of z is determined based on the signs of x and y.
1809 *
1810 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
1811 *
1812 * Range: `-Pi/2 <= y <= Pi/2`
1813 *
1814 * This function operates on single-precision floating point values, use
1815 * SDL_atan2 for double-precision floats.
1816 *
1817 * To calculate the arc tangent of a single value, use SDL_atanf.
1818 *
1819 * This function may use a different approximation across different versions,
1820 * platforms and configurations. i.e, it can return a different value given
1821 * the same input on different machines or operating systems, or if SDL is
1822 * updated.
1823 *
1824 * \param y floating point value of the numerator (y coordinate).
1825 * \param x floating point value of the denominator (x coordinate).
1826 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
1827 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
1828 *
1829 * \threadsafety It is safe to call this function from any thread.
1830 *
1831 * \since This function is available since SDL 3.0.0.
1832 *
1833 * \sa SDL_atan2f
1834 * \sa SDL_atan
1835 * \sa SDL_tan
1836 */
1837extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
1838
1839/**
1840 * Compute the ceiling of `x`.
1841 *
1842 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
1843 * rounded up to the nearest integer.
1844 *
1845 * Domain: `-INF <= x <= INF`
1846 *
1847 * Range: `-INF <= y <= INF`, y integer
1848 *
1849 * This function operates on double-precision floating point values, use
1850 * SDL_ceilf for single-precision floats.
1851 *
1852 * \param x floating point value.
1853 * \returns the ceiling of `x`.
1854 *
1855 * \threadsafety It is safe to call this function from any thread.
1856 *
1857 * \since This function is available since SDL 3.0.0.
1858 *
1859 * \sa SDL_ceilf
1860 * \sa SDL_floor
1861 * \sa SDL_trunc
1862 * \sa SDL_round
1863 * \sa SDL_lround
1864 */
1865extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
1866
1867/**
1868 * Compute the ceiling of `x`.
1869 *
1870 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
1871 * rounded up to the nearest integer.
1872 *
1873 * Domain: `-INF <= x <= INF`
1874 *
1875 * Range: `-INF <= y <= INF`, y integer
1876 *
1877 * This function operates on single-precision floating point values, use
1878 * SDL_ceil for double-precision floats.
1879 *
1880 * \param x floating point value.
1881 * \returns the ceiling of `x`.
1882 *
1883 * \threadsafety It is safe to call this function from any thread.
1884 *
1885 * \since This function is available since SDL 3.0.0.
1886 *
1887 * \sa SDL_ceil
1888 * \sa SDL_floorf
1889 * \sa SDL_truncf
1890 * \sa SDL_roundf
1891 * \sa SDL_lroundf
1892 */
1893extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
1894
1895/**
1896 * Copy the sign of one floating-point value to another.
1897 *
1898 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
1899 *
1900 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
1901 *
1902 * Range: `-INF <= z <= INF`
1903 *
1904 * This function operates on double-precision floating point values, use
1905 * SDL_copysignf for single-precision floats.
1906 *
1907 * \param x floating point value to use as the magnitude.
1908 * \param y floating point value to use as the sign.
1909 * \returns the floating point value with the sign of y and the magnitude of
1910 * x.
1911 *
1912 * \threadsafety It is safe to call this function from any thread.
1913 *
1914 * \since This function is available since SDL 3.0.0.
1915 *
1916 * \sa SDL_copysignf
1917 * \sa SDL_fabs
1918 */
1919extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
1920
1921/**
1922 * Copy the sign of one floating-point value to another.
1923 *
1924 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
1925 *
1926 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
1927 *
1928 * Range: `-INF <= z <= INF`
1929 *
1930 * This function operates on single-precision floating point values, use
1931 * SDL_copysign for double-precision floats.
1932 *
1933 * \param x floating point value to use as the magnitude.
1934 * \param y floating point value to use as the sign.
1935 * \returns the floating point value with the sign of y and the magnitude of
1936 * x.
1937 *
1938 * \threadsafety It is safe to call this function from any thread.
1939 *
1940 * \since This function is available since SDL 3.0.0.
1941 *
1942 * \sa SDL_copysignf
1943 * \sa SDL_fabsf
1944 */
1945extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
1946
1947/**
1948 * Compute the cosine of `x`.
1949 *
1950 * Domain: `-INF <= x <= INF`
1951 *
1952 * Range: `-1 <= y <= 1`
1953 *
1954 * This function operates on double-precision floating point values, use
1955 * SDL_cosf for single-precision floats.
1956 *
1957 * This function may use a different approximation across different versions,
1958 * platforms and configurations. i.e, it can return a different value given
1959 * the same input on different machines or operating systems, or if SDL is
1960 * updated.
1961 *
1962 * \param x floating point value, in radians.
1963 * \returns cosine of `x`.
1964 *
1965 * \threadsafety It is safe to call this function from any thread.
1966 *
1967 * \since This function is available since SDL 3.0.0.
1968 *
1969 * \sa SDL_cosf
1970 * \sa SDL_acos
1971 * \sa SDL_sin
1972 */
1973extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
1974
1975/**
1976 * Compute the cosine of `x`.
1977 *
1978 * Domain: `-INF <= x <= INF`
1979 *
1980 * Range: `-1 <= y <= 1`
1981 *
1982 * This function operates on single-precision floating point values, use
1983 * SDL_cos for double-precision floats.
1984 *
1985 * This function may use a different approximation across different versions,
1986 * platforms and configurations. i.e, it can return a different value given
1987 * the same input on different machines or operating systems, or if SDL is
1988 * updated.
1989 *
1990 * \param x floating point value, in radians.
1991 * \returns cosine of `x`.
1992 *
1993 * \threadsafety It is safe to call this function from any thread.
1994 *
1995 * \since This function is available since SDL 3.0.0.
1996 *
1997 * \sa SDL_cos
1998 * \sa SDL_acosf
1999 * \sa SDL_sinf
2000 */
2001extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
2002
2003/**
2004 * Compute the exponential of `x`.
2005 *
2006 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
2007 * natural logarithm. The inverse is the natural logarithm, SDL_log.
2008 *
2009 * Domain: `-INF <= x <= INF`
2010 *
2011 * Range: `0 <= y <= INF`
2012 *
2013 * The output will overflow if `exp(x)` is too large to be represented.
2014 *
2015 * This function operates on double-precision floating point values, use
2016 * SDL_expf for single-precision floats.
2017 *
2018 * This function may use a different approximation across different versions,
2019 * platforms and configurations. i.e, it can return a different value given
2020 * the same input on different machines or operating systems, or if SDL is
2021 * updated.
2022 *
2023 * \param x floating point value.
2024 * \returns value of `e^x`.
2025 *
2026 * \threadsafety It is safe to call this function from any thread.
2027 *
2028 * \since This function is available since SDL 3.0.0.
2029 *
2030 * \sa SDL_expf
2031 * \sa SDL_log
2032 */
2033extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
2034
2035/**
2036 * Compute the exponential of `x`.
2037 *
2038 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
2039 * natural logarithm. The inverse is the natural logarithm, SDL_logf.
2040 *
2041 * Domain: `-INF <= x <= INF`
2042 *
2043 * Range: `0 <= y <= INF`
2044 *
2045 * The output will overflow if `exp(x)` is too large to be represented.
2046 *
2047 * This function operates on single-precision floating point values, use
2048 * SDL_exp for double-precision floats.
2049 *
2050 * This function may use a different approximation across different versions,
2051 * platforms and configurations. i.e, it can return a different value given
2052 * the same input on different machines or operating systems, or if SDL is
2053 * updated.
2054 *
2055 * \param x floating point value.
2056 * \returns value of `e^x`.
2057 *
2058 * \threadsafety It is safe to call this function from any thread.
2059 *
2060 * \since This function is available since SDL 3.0.0.
2061 *
2062 * \sa SDL_exp
2063 * \sa SDL_logf
2064 */
2065extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
2066
2067/**
2068 * Compute the absolute value of `x`
2069 *
2070 * Domain: `-INF <= x <= INF`
2071 *
2072 * Range: `0 <= y <= INF`
2073 *
2074 * This function operates on double-precision floating point values, use
2075 * SDL_copysignf for single-precision floats.
2076 *
2077 * \param x floating point value to use as the magnitude.
2078 * \returns the absolute value of `x`.
2079 *
2080 * \threadsafety It is safe to call this function from any thread.
2081 *
2082 * \since This function is available since SDL 3.0.0.
2083 *
2084 * \sa SDL_fabsf
2085 */
2086extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
2087
2088/**
2089 * Compute the absolute value of `x`
2090 *
2091 * Domain: `-INF <= x <= INF`
2092 *
2093 * Range: `0 <= y <= INF`
2094 *
2095 * This function operates on single-precision floating point values, use
2096 * SDL_copysignf for double-precision floats.
2097 *
2098 * \param x floating point value to use as the magnitude.
2099 * \returns the absolute value of `x`.
2100 *
2101 * \threadsafety It is safe to call this function from any thread.
2102 *
2103 * \since This function is available since SDL 3.0.0.
2104 *
2105 * \sa SDL_fabs
2106 */
2107extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
2108
2109/**
2110 * Compute the floor of `x`.
2111 *
2112 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
2113 * rounded down to the nearest integer.
2114 *
2115 * Domain: `-INF <= x <= INF`
2116 *
2117 * Range: `-INF <= y <= INF`, y integer
2118 *
2119 * This function operates on double-precision floating point values, use
2120 * SDL_floorf for single-precision floats.
2121 *
2122 * \param x floating point value.
2123 * \returns the floor of `x`.
2124 *
2125 * \threadsafety It is safe to call this function from any thread.
2126 *
2127 * \since This function is available since SDL 3.0.0.
2128 *
2129 * \sa SDL_floorf
2130 * \sa SDL_ceil
2131 * \sa SDL_trunc
2132 * \sa SDL_round
2133 * \sa SDL_lround
2134 */
2135extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
2136
2137/**
2138 * Compute the floor of `x`.
2139 *
2140 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
2141 * rounded down to the nearest integer.
2142 *
2143 * Domain: `-INF <= x <= INF`
2144 *
2145 * Range: `-INF <= y <= INF`, y integer
2146 *
2147 * This function operates on single-precision floating point values, use
2148 * SDL_floorf for double-precision floats.
2149 *
2150 * \param x floating point value.
2151 * \returns the floor of `x`.
2152 *
2153 * \threadsafety It is safe to call this function from any thread.
2154 *
2155 * \since This function is available since SDL 3.0.0.
2156 *
2157 * \sa SDL_floor
2158 * \sa SDL_ceilf
2159 * \sa SDL_truncf
2160 * \sa SDL_roundf
2161 * \sa SDL_lroundf
2162 */
2163extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
2164
2165/**
2166 * Truncate `x` to an integer.
2167 *
2168 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
2169 * the fractional part of `x`, leaving only the integer part.
2170 *
2171 * Domain: `-INF <= x <= INF`
2172 *
2173 * Range: `-INF <= y <= INF`, y integer
2174 *
2175 * This function operates on double-precision floating point values, use
2176 * SDL_truncf for single-precision floats.
2177 *
2178 * \param x floating point value.
2179 * \returns `x` truncated to an integer.
2180 *
2181 * \threadsafety It is safe to call this function from any thread.
2182 *
2183 * \since This function is available since SDL 3.0.0.
2184 *
2185 * \sa SDL_truncf
2186 * \sa SDL_fmod
2187 * \sa SDL_ceil
2188 * \sa SDL_floor
2189 * \sa SDL_round
2190 * \sa SDL_lround
2191 */
2192extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
2193
2194/**
2195 * Truncate `x` to an integer.
2196 *
2197 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
2198 * the fractional part of `x`, leaving only the integer part.
2199 *
2200 * Domain: `-INF <= x <= INF`
2201 *
2202 * Range: `-INF <= y <= INF`, y integer
2203 *
2204 * This function operates on single-precision floating point values, use
2205 * SDL_truncf for double-precision floats.
2206 *
2207 * \param x floating point value.
2208 * \returns `x` truncated to an integer.
2209 *
2210 * \threadsafety It is safe to call this function from any thread.
2211 *
2212 * \since This function is available since SDL 3.0.0.
2213 *
2214 * \sa SDL_trunc
2215 * \sa SDL_fmodf
2216 * \sa SDL_ceilf
2217 * \sa SDL_floorf
2218 * \sa SDL_roundf
2219 * \sa SDL_lroundf
2220 */
2221extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
2222
2223/**
2224 * Return the floating-point remainder of `x / y`
2225 *
2226 * Divides `x` by `y`, and returns the remainder.
2227 *
2228 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
2229 *
2230 * Range: `-y <= z <= y`
2231 *
2232 * This function operates on double-precision floating point values, use
2233 * SDL_fmodf for single-precision floats.
2234 *
2235 * \param x the numerator.
2236 * \param y the denominator. Must not be 0.
2237 * \returns the remainder of `x / y`.
2238 *
2239 * \threadsafety It is safe to call this function from any thread.
2240 *
2241 * \since This function is available since SDL 3.0.0.
2242 *
2243 * \sa SDL_fmodf
2244 * \sa SDL_modf
2245 * \sa SDL_trunc
2246 * \sa SDL_ceil
2247 * \sa SDL_floor
2248 * \sa SDL_round
2249 * \sa SDL_lround
2250 */
2251extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
2252
2253/**
2254 * Return the floating-point remainder of `x / y`
2255 *
2256 * Divides `x` by `y`, and returns the remainder.
2257 *
2258 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
2259 *
2260 * Range: `-y <= z <= y`
2261 *
2262 * This function operates on single-precision floating point values, use
2263 * SDL_fmod for single-precision floats.
2264 *
2265 * \param x the numerator.
2266 * \param y the denominator. Must not be 0.
2267 * \returns the remainder of `x / y`.
2268 *
2269 * \threadsafety It is safe to call this function from any thread.
2270 *
2271 * \since This function is available since SDL 3.0.0.
2272 *
2273 * \sa SDL_fmod
2274 * \sa SDL_truncf
2275 * \sa SDL_modff
2276 * \sa SDL_ceilf
2277 * \sa SDL_floorf
2278 * \sa SDL_roundf
2279 * \sa SDL_lroundf
2280 */
2281extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
2282
2283/**
2284 * Return whether the value is infinity.
2285 *
2286 * \param x double-precision floating point value.
2287 * \returns non-zero if the value is infinity, 0 otherwise.
2288 *
2289 * \threadsafety It is safe to call this function from any thread.
2290 *
2291 * \since This function is available since SDL 3.0.0.
2292 *
2293 * \sa SDL_isinff
2294 */
2295extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
2296
2297/**
2298 * Return whether the value is infinity.
2299 *
2300 * \param x floating point value.
2301 * \returns non-zero if the value is infinity, 0 otherwise.
2302 *
2303 * \threadsafety It is safe to call this function from any thread.
2304 *
2305 * \since This function is available since SDL 3.0.0.
2306 *
2307 * \sa SDL_isinf
2308 */
2309extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
2310
2311/**
2312 * Return whether the value is NaN.
2313 *
2314 * \param x double-precision floating point value.
2315 * \returns non-zero if the value is NaN, 0 otherwise.
2316 *
2317 * \threadsafety It is safe to call this function from any thread.
2318 *
2319 * \since This function is available since SDL 3.0.0.
2320 *
2321 * \sa SDL_isnanf
2322 */
2323extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
2324
2325/**
2326 * Return whether the value is NaN.
2327 *
2328 * \param x floating point value.
2329 * \returns non-zero if the value is NaN, 0 otherwise.
2330 *
2331 * \threadsafety It is safe to call this function from any thread.
2332 *
2333 * \since This function is available since SDL 3.0.0.
2334 *
2335 * \sa SDL_isnan
2336 */
2337extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
2338
2339/**
2340 * Compute the natural logarithm of `x`.
2341 *
2342 * Domain: `0 < x <= INF`
2343 *
2344 * Range: `-INF <= y <= INF`
2345 *
2346 * It is an error for `x` to be less than or equal to 0.
2347 *
2348 * This function operates on double-precision floating point values, use
2349 * SDL_logf for single-precision floats.
2350 *
2351 * This function may use a different approximation across different versions,
2352 * platforms and configurations. i.e, it can return a different value given
2353 * the same input on different machines or operating systems, or if SDL is
2354 * updated.
2355 *
2356 * \param x floating point value. Must be greater than 0.
2357 * \returns the natural logarithm of `x`.
2358 *
2359 * \threadsafety It is safe to call this function from any thread.
2360 *
2361 * \since This function is available since SDL 3.0.0.
2362 *
2363 * \sa SDL_logf
2364 * \sa SDL_log10
2365 * \sa SDL_exp
2366 */
2367extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
2368
2369/**
2370 * Compute the natural logarithm of `x`.
2371 *
2372 * Domain: `0 < x <= INF`
2373 *
2374 * Range: `-INF <= y <= INF`
2375 *
2376 * It is an error for `x` to be less than or equal to 0.
2377 *
2378 * This function operates on single-precision floating point values, use
2379 * SDL_log for double-precision floats.
2380 *
2381 * This function may use a different approximation across different versions,
2382 * platforms and configurations. i.e, it can return a different value given
2383 * the same input on different machines or operating systems, or if SDL is
2384 * updated.
2385 *
2386 * \param x floating point value. Must be greater than 0.
2387 * \returns the natural logarithm of `x`.
2388 *
2389 * \threadsafety It is safe to call this function from any thread.
2390 *
2391 * \since This function is available since SDL 3.0.0.
2392 *
2393 * \sa SDL_log
2394 * \sa SDL_expf
2395 */
2396extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
2397
2398/**
2399 * Compute the base-10 logarithm of `x`.
2400 *
2401 * Domain: `0 < x <= INF`
2402 *
2403 * Range: `-INF <= y <= INF`
2404 *
2405 * It is an error for `x` to be less than or equal to 0.
2406 *
2407 * This function operates on double-precision floating point values, use
2408 * SDL_log10f for single-precision floats.
2409 *
2410 * This function may use a different approximation across different versions,
2411 * platforms and configurations. i.e, it can return a different value given
2412 * the same input on different machines or operating systems, or if SDL is
2413 * updated.
2414 *
2415 * \param x floating point value. Must be greater than 0.
2416 * \returns the logarithm of `x`.
2417 *
2418 * \threadsafety It is safe to call this function from any thread.
2419 *
2420 * \since This function is available since SDL 3.0.0.
2421 *
2422 * \sa SDL_log10f
2423 * \sa SDL_log
2424 * \sa SDL_pow
2425 */
2426extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
2427
2428/**
2429 * Compute the base-10 logarithm of `x`.
2430 *
2431 * Domain: `0 < x <= INF`
2432 *
2433 * Range: `-INF <= y <= INF`
2434 *
2435 * It is an error for `x` to be less than or equal to 0.
2436 *
2437 * This function operates on single-precision floating point values, use
2438 * SDL_log10 for double-precision floats.
2439 *
2440 * This function may use a different approximation across different versions,
2441 * platforms and configurations. i.e, it can return a different value given
2442 * the same input on different machines or operating systems, or if SDL is
2443 * updated.
2444 *
2445 * \param x floating point value. Must be greater than 0.
2446 * \returns the logarithm of `x`.
2447 *
2448 * \threadsafety It is safe to call this function from any thread.
2449 *
2450 * \since This function is available since SDL 3.0.0.
2451 *
2452 * \sa SDL_log10
2453 * \sa SDL_logf
2454 * \sa SDL_powf
2455 */
2456extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
2457
2458/**
2459 * Split `x` into integer and fractional parts
2460 *
2461 * This function operates on double-precision floating point values, use
2462 * SDL_modff for single-precision floats.
2463 *
2464 * \param x floating point value.
2465 * \param y output pointer to store the integer part of `x`.
2466 * \returns the fractional part of `x`.
2467 *
2468 * \threadsafety It is safe to call this function from any thread.
2469 *
2470 * \since This function is available since SDL 3.0.0.
2471 *
2472 * \sa SDL_modff
2473 * \sa SDL_trunc
2474 * \sa SDL_fmod
2475 */
2476extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
2477
2478/**
2479 * Split `x` into integer and fractional parts
2480 *
2481 * This function operates on single-precision floating point values, use
2482 * SDL_modf for double-precision floats.
2483 *
2484 * \param x floating point value.
2485 * \param y output pointer to store the integer part of `x`.
2486 * \returns the fractional part of `x`.
2487 *
2488 * \threadsafety It is safe to call this function from any thread.
2489 *
2490 * \since This function is available since SDL 3.0.0.
2491 *
2492 * \sa SDL_modf
2493 * \sa SDL_truncf
2494 * \sa SDL_fmodf
2495 */
2496extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
2497
2498/**
2499 * Raise `x` to the power `y`
2500 *
2501 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2502 *
2503 * Range: `-INF <= z <= INF`
2504 *
2505 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
2506 * instead.
2507 *
2508 * This function operates on double-precision floating point values, use
2509 * SDL_powf for single-precision floats.
2510 *
2511 * This function may use a different approximation across different versions,
2512 * platforms and configurations. i.e, it can return a different value given
2513 * the same input on different machines or operating systems, or if SDL is
2514 * updated.
2515 *
2516 * \param x the base.
2517 * \param y the exponent.
2518 * \returns `x` raised to the power `y`.
2519 *
2520 * \threadsafety It is safe to call this function from any thread.
2521 *
2522 * \since This function is available since SDL 3.0.0.
2523 *
2524 * \sa SDL_powf
2525 * \sa SDL_exp
2526 * \sa SDL_log
2527 */
2528extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
2529
2530/**
2531 * Raise `x` to the power `y`
2532 *
2533 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2534 *
2535 * Range: `-INF <= z <= INF`
2536 *
2537 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
2538 * instead.
2539 *
2540 * This function operates on single-precision floating point values, use
2541 * SDL_powf for double-precision floats.
2542 *
2543 * This function may use a different approximation across different versions,
2544 * platforms and configurations. i.e, it can return a different value given
2545 * the same input on different machines or operating systems, or if SDL is
2546 * updated.
2547 *
2548 * \param x the base.
2549 * \param y the exponent.
2550 * \returns `x` raised to the power `y`.
2551 *
2552 * \threadsafety It is safe to call this function from any thread.
2553 *
2554 * \since This function is available since SDL 3.0.0.
2555 *
2556 * \sa SDL_pow
2557 * \sa SDL_expf
2558 * \sa SDL_logf
2559 */
2560extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
2561
2562/**
2563 * Round `x` to the nearest integer.
2564 *
2565 * Rounds `x` to the nearest integer. Values halfway between integers will be
2566 * rounded away from zero.
2567 *
2568 * Domain: `-INF <= x <= INF`
2569 *
2570 * Range: `-INF <= y <= INF`, y integer
2571 *
2572 * This function operates on double-precision floating point values, use
2573 * SDL_roundf for single-precision floats. To get the result as an integer
2574 * type, use SDL_lround.
2575 *
2576 * \param x floating point value.
2577 * \returns the nearest integer to `x`.
2578 *
2579 * \threadsafety It is safe to call this function from any thread.
2580 *
2581 * \since This function is available since SDL 3.0.0.
2582 *
2583 * \sa SDL_roundf
2584 * \sa SDL_lround
2585 * \sa SDL_floor
2586 * \sa SDL_ceil
2587 * \sa SDL_trunc
2588 */
2589extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
2590
2591/**
2592 * Round `x` to the nearest integer.
2593 *
2594 * Rounds `x` to the nearest integer. Values halfway between integers will be
2595 * rounded away from zero.
2596 *
2597 * Domain: `-INF <= x <= INF`
2598 *
2599 * Range: `-INF <= y <= INF`, y integer
2600 *
2601 * This function operates on double-precision floating point values, use
2602 * SDL_roundf for single-precision floats. To get the result as an integer
2603 * type, use SDL_lroundf.
2604 *
2605 * \param x floating point value.
2606 * \returns the nearest integer to `x`.
2607 *
2608 * \threadsafety It is safe to call this function from any thread.
2609 *
2610 * \since This function is available since SDL 3.0.0.
2611 *
2612 * \sa SDL_round
2613 * \sa SDL_lroundf
2614 * \sa SDL_floorf
2615 * \sa SDL_ceilf
2616 * \sa SDL_truncf
2617 */
2618extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
2619
2620/**
2621 * Round `x` to the nearest integer representable as a long
2622 *
2623 * Rounds `x` to the nearest integer. Values halfway between integers will be
2624 * rounded away from zero.
2625 *
2626 * Domain: `-INF <= x <= INF`
2627 *
2628 * Range: `MIN_LONG <= y <= MAX_LONG`
2629 *
2630 * This function operates on double-precision floating point values, use
2631 * SDL_lround for single-precision floats. To get the result as a
2632 * floating-point type, use SDL_round.
2633 *
2634 * \param x floating point value.
2635 * \returns the nearest integer to `x`.
2636 *
2637 * \threadsafety It is safe to call this function from any thread.
2638 *
2639 * \since This function is available since SDL 3.0.0.
2640 *
2641 * \sa SDL_lroundf
2642 * \sa SDL_round
2643 * \sa SDL_floor
2644 * \sa SDL_ceil
2645 * \sa SDL_trunc
2646 */
2647extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
2648
2649/**
2650 * Round `x` to the nearest integer representable as a long
2651 *
2652 * Rounds `x` to the nearest integer. Values halfway between integers will be
2653 * rounded away from zero.
2654 *
2655 * Domain: `-INF <= x <= INF`
2656 *
2657 * Range: `MIN_LONG <= y <= MAX_LONG`
2658 *
2659 * This function operates on single-precision floating point values, use
2660 * SDL_lroundf for double-precision floats. To get the result as a
2661 * floating-point type, use SDL_roundf,
2662 *
2663 * \param x floating point value.
2664 * \returns the nearest integer to `x`.
2665 *
2666 * \threadsafety It is safe to call this function from any thread.
2667 *
2668 * \since This function is available since SDL 3.0.0.
2669 *
2670 * \sa SDL_lround
2671 * \sa SDL_roundf
2672 * \sa SDL_floorf
2673 * \sa SDL_ceilf
2674 * \sa SDL_truncf
2675 */
2676extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
2677
2678/**
2679 * Scale `x` by an integer power of two.
2680 *
2681 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
2682 *
2683 * Domain: `-INF <= x <= INF`, `n` integer
2684 *
2685 * Range: `-INF <= y <= INF`
2686 *
2687 * This function operates on double-precision floating point values, use
2688 * SDL_scalbnf for single-precision floats.
2689 *
2690 * \param x floating point value to be scaled.
2691 * \param n integer exponent.
2692 * \returns `x * 2^n`.
2693 *
2694 * \threadsafety It is safe to call this function from any thread.
2695 *
2696 * \since This function is available since SDL 3.0.0.
2697 *
2698 * \sa SDL_scalbnf
2699 * \sa SDL_pow
2700 */
2701extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
2702
2703/**
2704 * Scale `x` by an integer power of two.
2705 *
2706 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
2707 *
2708 * Domain: `-INF <= x <= INF`, `n` integer
2709 *
2710 * Range: `-INF <= y <= INF`
2711 *
2712 * This function operates on single-precision floating point values, use
2713 * SDL_scalbn for double-precision floats.
2714 *
2715 * \param x floating point value to be scaled.
2716 * \param n integer exponent.
2717 * \returns `x * 2^n`.
2718 *
2719 * \threadsafety It is safe to call this function from any thread.
2720 *
2721 * \since This function is available since SDL 3.0.0.
2722 *
2723 * \sa SDL_scalbn
2724 * \sa SDL_powf
2725 */
2726extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
2727
2728/**
2729 * Compute the sine of `x`.
2730 *
2731 * Domain: `-INF <= x <= INF`
2732 *
2733 * Range: `-1 <= y <= 1`
2734 *
2735 * This function operates on double-precision floating point values, use
2736 * SDL_sinf for single-precision floats.
2737 *
2738 * This function may use a different approximation across different versions,
2739 * platforms and configurations. i.e, it can return a different value given
2740 * the same input on different machines or operating systems, or if SDL is
2741 * updated.
2742 *
2743 * \param x floating point value, in radians.
2744 * \returns sine of `x`.
2745 *
2746 * \threadsafety It is safe to call this function from any thread.
2747 *
2748 * \since This function is available since SDL 3.0.0.
2749 *
2750 * \sa SDL_sinf
2751 * \sa SDL_asin
2752 * \sa SDL_cos
2753 */
2754extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
2755
2756/**
2757 * Compute the sine of `x`.
2758 *
2759 * Domain: `-INF <= x <= INF`
2760 *
2761 * Range: `-1 <= y <= 1`
2762 *
2763 * This function operates on single-precision floating point values, use
2764 * SDL_sinf for double-precision floats.
2765 *
2766 * This function may use a different approximation across different versions,
2767 * platforms and configurations. i.e, it can return a different value given
2768 * the same input on different machines or operating systems, or if SDL is
2769 * updated.
2770 *
2771 * \param x floating point value, in radians.
2772 * \returns sine of `x`.
2773 *
2774 * \threadsafety It is safe to call this function from any thread.
2775 *
2776 * \since This function is available since SDL 3.0.0.
2777 *
2778 * \sa SDL_sin
2779 * \sa SDL_asinf
2780 * \sa SDL_cosf
2781 */
2782extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
2783
2784/**
2785 * Compute the square root of `x`.
2786 *
2787 * Domain: `0 <= x <= INF`
2788 *
2789 * Range: `0 <= y <= INF`
2790 *
2791 * This function operates on double-precision floating point values, use
2792 * SDL_sqrtf for single-precision floats.
2793 *
2794 * This function may use a different approximation across different versions,
2795 * platforms and configurations. i.e, it can return a different value given
2796 * the same input on different machines or operating systems, or if SDL is
2797 * updated.
2798 *
2799 * \param x floating point value. Must be greater than or equal to 0.
2800 * \returns square root of `x`.
2801 *
2802 * \threadsafety It is safe to call this function from any thread.
2803 *
2804 * \since This function is available since SDL 3.0.0.
2805 *
2806 * \sa SDL_sqrtf
2807 */
2808extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
2809
2810/**
2811 * Compute the square root of `x`.
2812 *
2813 * Domain: `0 <= x <= INF`
2814 *
2815 * Range: `0 <= y <= INF`
2816 *
2817 * This function operates on single-precision floating point values, use
2818 * SDL_sqrt for double-precision floats.
2819 *
2820 * This function may use a different approximation across different versions,
2821 * platforms and configurations. i.e, it can return a different value given
2822 * the same input on different machines or operating systems, or if SDL is
2823 * updated.
2824 *
2825 * \param x floating point value. Must be greater than or equal to 0.
2826 * \returns square root of `x`.
2827 *
2828 * \threadsafety It is safe to call this function from any thread.
2829 *
2830 * \since This function is available since SDL 3.0.0.
2831 *
2832 * \sa SDL_sqrt
2833 */
2834extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
2835
2836/**
2837 * Compute the tangent of `x`.
2838 *
2839 * Domain: `-INF <= x <= INF`
2840 *
2841 * Range: `-INF <= y <= INF`
2842 *
2843 * This function operates on double-precision floating point values, use
2844 * SDL_tanf for single-precision floats.
2845 *
2846 * This function may use a different approximation across different versions,
2847 * platforms and configurations. i.e, it can return a different value given
2848 * the same input on different machines or operating systems, or if SDL is
2849 * updated.
2850 *
2851 * \param x floating point value, in radians.
2852 * \returns tangent of `x`.
2853 *
2854 * \threadsafety It is safe to call this function from any thread.
2855 *
2856 * \since This function is available since SDL 3.0.0.
2857 *
2858 * \sa SDL_tanf
2859 * \sa SDL_sin
2860 * \sa SDL_cos
2861 * \sa SDL_atan
2862 * \sa SDL_atan2
2863 */
2864extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
2865
2866/**
2867 * Compute the tangent of `x`.
2868 *
2869 * Domain: `-INF <= x <= INF`
2870 *
2871 * Range: `-INF <= y <= INF`
2872 *
2873 * This function operates on single-precision floating point values, use
2874 * SDL_tanf for double-precision floats.
2875 *
2876 * This function may use a different approximation across different versions,
2877 * platforms and configurations. i.e, it can return a different value given
2878 * the same input on different machines or operating systems, or if SDL is
2879 * updated.
2880 *
2881 * \param x floating point value, in radians.
2882 * \returns tangent of `x`.
2883 *
2884 * \threadsafety It is safe to call this function from any thread.
2885 *
2886 * \since This function is available since SDL 3.0.0.
2887 *
2888 * \sa SDL_tan
2889 * \sa SDL_sinf
2890 * \sa SDL_cosf
2891 * \sa SDL_atanf
2892 * \sa SDL_atan2f
2893 */
2894extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
2895
2896/* The SDL implementation of iconv() returns these error codes */
2897#define SDL_ICONV_ERROR (size_t)-1
2898#define SDL_ICONV_E2BIG (size_t)-2
2899#define SDL_ICONV_EILSEQ (size_t)-3
2900#define SDL_ICONV_EINVAL (size_t)-4
2901
2902/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
2903typedef struct SDL_iconv_data_t *SDL_iconv_t;
2904extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
2905 const char *fromcode);
2906extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
2907extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
2908 size_t * inbytesleft, char **outbuf,
2909 size_t * outbytesleft);
2910
2911/**
2912 * Helper function to convert a string's encoding in one call.
2913 *
2914 * This function converts a buffer or string between encodings in one pass.
2915 *
2916 * The string does not need to be NULL-terminated; this function operates on
2917 * the number of bytes specified in `inbytesleft` whether there is a NULL
2918 * character anywhere in the buffer.
2919 *
2920 * The returned string is owned by the caller, and should be passed to
2921 * SDL_free when no longer needed.
2922 *
2923 * \param tocode the character encoding of the output string. Examples are
2924 * "UTF-8", "UCS-4", etc.
2925 * \param fromcode the character encoding of data in `inbuf`.
2926 * \param inbuf the string to convert to a different encoding.
2927 * \param inbytesleft the size of the input string _in bytes_.
2928 * \returns a new string, converted to the new encoding, or NULL on error.
2929 *
2930 * \since This function is available since SDL 3.0.0.
2931 */
2932extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
2933 const char *fromcode,
2934 const char *inbuf,
2935 size_t inbytesleft);
2936
2937/* Some helper macros for common cases... */
2938#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
2939#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
2940#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
2941#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
2942
2943/* force builds using Clang's static analysis tools to use literal C runtime
2944 here, since there are possibly tests that are ineffective otherwise. */
2945#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
2946
2947/* The analyzer knows about strlcpy even when the system doesn't provide it */
2948#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
2949size_t strlcpy(char *dst, const char *src, size_t size);
2950#endif
2951
2952/* The analyzer knows about strlcat even when the system doesn't provide it */
2953#if !defined(HAVE_STRLCAT) && !defined(strlcat)
2954size_t strlcat(char *dst, const char *src, size_t size);
2955#endif
2956
2957#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
2958size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
2959#endif
2960
2961#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
2962size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
2963#endif
2964
2965/* Starting LLVM 16, the analyser errors out if these functions do not have
2966 their prototype defined (clang-diagnostic-implicit-function-declaration) */
2967#include <stdio.h>
2968#include <stdlib.h>
2969#include <strings.h>
2970
2971#define SDL_malloc malloc
2972#define SDL_calloc calloc
2973#define SDL_realloc realloc
2974#define SDL_free free
2975#ifndef SDL_memcpy
2976#define SDL_memcpy memcpy
2977#endif
2978#ifndef SDL_memmove
2979#define SDL_memmove memmove
2980#endif
2981#ifndef SDL_memset
2982#define SDL_memset memset
2983#endif
2984#define SDL_memcmp memcmp
2985#define SDL_strlcpy strlcpy
2986#define SDL_strlcat strlcat
2987#define SDL_strlen strlen
2988#define SDL_wcslen wcslen
2989#define SDL_wcslcpy wcslcpy
2990#define SDL_wcslcat wcslcat
2991#define SDL_strdup strdup
2992#define SDL_wcsdup wcsdup
2993#define SDL_strchr strchr
2994#define SDL_strrchr strrchr
2995#define SDL_strstr strstr
2996#define SDL_wcsstr wcsstr
2997#define SDL_strtok_r strtok_r
2998#define SDL_strcmp strcmp
2999#define SDL_wcscmp wcscmp
3000#define SDL_strncmp strncmp
3001#define SDL_wcsncmp wcsncmp
3002#define SDL_strcasecmp strcasecmp
3003#define SDL_strncasecmp strncasecmp
3004#define SDL_sscanf sscanf
3005#define SDL_vsscanf vsscanf
3006#define SDL_snprintf snprintf
3007#define SDL_vsnprintf vsnprintf
3008#endif
3009
3010/**
3011 * Multiply two integers, checking for overflow.
3012 *
3013 * If `a * b` would overflow, return -1.
3014 *
3015 * Otherwise store `a * b` via ret and return 0.
3016 *
3017 * \param a the multiplicand.
3018 * \param b the multiplier.
3019 * \param ret on non-overflow output, stores the multiplication result. May
3020 * not be NULL.
3021 * \returns -1 on overflow, 0 if result doesn't overflow.
3022 *
3023 * \threadsafety It is safe to call this function from any thread.
3024 *
3025 * \since This function is available since SDL 3.0.0.
3026 */
3028 size_t b,
3029 size_t *ret)
3030{
3031 if (a != 0 && b > SDL_SIZE_MAX / a) {
3032 return -1;
3033 }
3034 *ret = a * b;
3035 return 0;
3036}
3037
3038#ifndef SDL_WIKI_DOCUMENTATION_SECTION
3039#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
3040/* This needs to be wrapped in an inline rather than being a direct #define,
3041 * because __builtin_mul_overflow() is type-generic, but we want to be
3042 * consistent about interpreting a and b as size_t. */
3043SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a,
3044 size_t b,
3045 size_t *ret)
3046{
3047 return __builtin_mul_overflow(a, b, ret) == 0 ? 0 : -1;
3048}
3049#define SDL_size_mul_overflow(a, b, ret) (SDL_size_mul_overflow_builtin(a, b, ret))
3050#endif
3051#endif
3052
3053/**
3054 * Add two integers, checking for overflow.
3055 *
3056 * If `a + b` would overflow, return -1.
3057 *
3058 * Otherwise store `a + b` via ret and return 0.
3059 *
3060 * \param a the first addend.
3061 * \param b the second addend.
3062 * \param ret on non-overflow output, stores the addition result. May not be
3063 * NULL.
3064 * \returns -1 on overflow, 0 if result doesn't overflow.
3065 *
3066 * \threadsafety It is safe to call this function from any thread.
3067 *
3068 * \since This function is available since SDL 3.0.0.
3069 */
3071 size_t b,
3072 size_t *ret)
3073{
3074 if (b > SDL_SIZE_MAX - a) {
3075 return -1;
3076 }
3077 *ret = a + b;
3078 return 0;
3079}
3080
3081#ifndef SDL_WIKI_DOCUMENTATION_SECTION
3082#if SDL_HAS_BUILTIN(__builtin_add_overflow)
3083/* This needs to be wrapped in an inline rather than being a direct #define,
3084 * the same as the call to __builtin_mul_overflow() above. */
3085SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a,
3086 size_t b,
3087 size_t *ret)
3088{
3089 return __builtin_add_overflow(a, b, ret) == 0 ? 0 : -1;
3090}
3091#define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret))
3092#endif
3093#endif
3094
3095/* This is a generic function pointer which should be cast to the type you expect */
3096#ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
3097typedef void *SDL_FunctionPointer;
3098#else
3099typedef void (*SDL_FunctionPointer)(void);
3100#endif
3101
3102/* Ends C function definitions when using C++ */
3103#ifdef __cplusplus
3104}
3105#endif
3106#include <SDL3/SDL_close_code.h>
3107
3108#endif /* SDL_stdinc_h_ */
#define SDL_ALLOC_SIZE(p)
#define SDL_ALLOC_SIZE2(p1, p2)
#define SDL_FORCE_INLINE
#define SDL_MALLOC
wchar_t * SDL_wcsdup(const wchar_t *wstr)
double SDL_sqrt(double x)
int SDL_atoi(const char *str)
#define SDL_memset
Definition SDL_stdinc.h:956
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
float SDL_tanf(float x)
char * SDL_strtok_r(char *s1, const char *s2, char **saveptr)
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)
int SDL_tolower(int x)
float SDL_modff(float x, float *y)
double SDL_modf(double x, double *y)
int SDL_abs(int x)
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:229
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:276
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)
Definition SDL_stdinc.h:535
int(* SDL_CompareCallback_r)(void *userdata, const void *a, const void *b)
Definition SDL_stdinc.h:674
#define SDL_OUT_BYTECAP(x)
Definition SDL_stdinc.h:442
char * SDL_strrchr(const char *str, int c)
#define SDL_SIZE_MAX
Definition SDL_stdinc.h:77
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
uint16_t Uint16
Definition SDL_stdinc.h:247
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
float SDL_atanf(float x)
int SDL_isprint(int x)
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:456
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)
int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
SDL_FORCE_INLINE int SDL_size_mul_overflow(size_t a, size_t b, size_t *ret)
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
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)
Definition SDL_stdinc.h:438
int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
float SDL_randf(void)
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:220
wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
int(* SDL_CompareCallback)(const void *a, const void *b)
Definition SDL_stdinc.h:670
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)
Definition SDL_stdinc.h:458
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
Definition SDL_stdinc.h:445
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:256
int SDL_setenv(const char *name, const char *value, int overwrite)
size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
#define SDL_INOUT_Z_CAP(x)
Definition SDL_stdinc.h:439
double SDL_scalbn(double x, int n)
int SDL_unsetenv(const char *name)
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)
char * SDL_lltoa(Sint64 value, char *str, int radix)
double SDL_fabs(double x)
Sint64 SDL_strtoll(const char *str, char **endp, int base)
int SDL_ispunct(int x)
float SDL_truncf(float x)
double SDL_log10(double x)
SDL_MALLOC size_t size
Definition SDL_stdinc.h:531
float SDL_expf(float x)
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)
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_bool
Definition SDL_stdinc.h:213
int SDL_isinf(double x)
float SDL_log10f(float x)
void(* SDL_free_func)(void *mem)
Definition SDL_stdinc.h:538
int SDL_memcmp(const void *s1, const void *s2, size_t len)
char * SDL_ulltoa(Uint64 value, char *str, int radix)
const char * SDL_getenv(const char *name)
int16_t Sint16
Definition SDL_stdinc.h:238
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)
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)
SDL_FORCE_INLINE int SDL_size_add_overflow(size_t a, size_t b, size_t *ret)
double SDL_cos(double x)
#define SDL_PRINTF_FORMAT_STRING
Definition SDL_stdinc.h:444
float SDL_fmodf(float x, float y)
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap)
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)
Definition SDL_stdinc.h:455
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:479
float SDL_atan2f(float y, float x)
int SDL_isupper(int x)
long SDL_wcstol(const wchar_t *str, wchar_t **endp, int base)
float SDL_fabsf(float x)
uint64_t Uint64
Definition SDL_stdinc.h:287
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
Definition SDL_stdinc.h:931
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)
Definition SDL_stdinc.h:536
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:457
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:265
float SDL_powf(float x, float y)
size_t SDL_strlen(const char *str)
#define SDL_memmove
Definition SDL_stdinc.h:945
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:304
void *(* SDL_realloc_func)(void *mem, size_t size)
Definition SDL_stdinc.h:537
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)
Definition SDL_stdinc.h:440
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:459
Uint64 SDL_strtoull(const char *str, char **endp, int base)
double SDL_trunc(double x)