SDL 3.0
SDL_stdinc.h File Reference
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
+ Include dependency graph for SDL_stdinc.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SDL_SIZE_MAX   ((size_t) -1)
 
#define SDL_HAS_BUILTIN(x)   0
 
#define SDL_arraysize(array)   (sizeof(array)/sizeof(array[0]))
 
#define SDL_STRINGIFY_ARG(arg)   #arg
 
Cast operators

Use proper C++ casts when compiled as C++ to be compatible with the option -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).

#define SDL_reinterpret_cast(type, expression)   ((type)(expression))
 
#define SDL_static_cast(type, expression)   ((type)(expression))
 
#define SDL_const_cast(type, expression)   ((type)(expression))
 
#define SDL_FOURCC(A, B, C, D)
 
#define SDL_SINT64_C(c)   c ## LL
 
#define SDL_UINT64_C(c)   c ## ULL
 

Functions

void * alloca (size_t)
 

Basic data types

#define SDL_FALSE   false
 
#define SDL_TRUE   true
 
#define SDL_MAX_SINT8   ((Sint8)0x7F) /* 127 */
 
#define SDL_MIN_SINT8   ((Sint8)(~0x7F)) /* -128 */
 
#define SDL_MAX_UINT8   ((Uint8)0xFF) /* 255 */
 
#define SDL_MIN_UINT8   ((Uint8)0x00) /* 0 */
 
#define SDL_MAX_SINT16   ((Sint16)0x7FFF) /* 32767 */
 
#define SDL_MIN_SINT16   ((Sint16)(~0x7FFF)) /* -32768 */
 
#define SDL_MAX_UINT16   ((Uint16)0xFFFF) /* 65535 */
 
#define SDL_MIN_UINT16   ((Uint16)0x0000) /* 0 */
 
#define SDL_MAX_SINT32   ((Sint32)0x7FFFFFFF) /* 2147483647 */
 
#define SDL_MIN_SINT32   ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
 
#define SDL_MAX_UINT32   ((Uint32)0xFFFFFFFFu) /* 4294967295 */
 
#define SDL_MIN_UINT32   ((Uint32)0x00000000) /* 0 */
 
#define SDL_MAX_SINT64   SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
 
#define SDL_MIN_SINT64   ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
 
#define SDL_MAX_UINT64   SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
 
#define SDL_MIN_UINT64   SDL_UINT64_C(0x0000000000000000) /* 0 */
 
#define SDL_MAX_TIME   SDL_MAX_SINT64
 
#define SDL_MIN_TIME   SDL_MIN_SINT64
 
typedef bool SDL_bool
 
typedef int8_t Sint8
 
typedef uint8_t Uint8
 
typedef int16_t Sint16
 
typedef uint16_t Uint16
 
typedef int32_t Sint32
 
typedef uint32_t Uint32
 
typedef int64_t Sint64
 
typedef uint64_t Uint64
 
typedef Sint64 SDL_Time
 

Floating-point constants

#define SDL_FLT_EPSILON   1.1920928955078125e-07F /* 0x0.000002p0 */
 
#define SDL_PRIs64   "lld"
 
#define SDL_PRIu64   "llu"
 
#define SDL_PRIx64   "llx"
 
#define SDL_PRIX64   "llX"
 
#define SDL_PRIs32   "d"
 
#define SDL_PRIu32   "u"
 
#define SDL_PRIx32   "x"
 
#define SDL_PRIX32   "X"
 
#define SDL_IN_BYTECAP(x)
 
#define SDL_INOUT_Z_CAP(x)
 
#define SDL_OUT_Z_CAP(x)
 
#define SDL_OUT_CAP(x)
 
#define SDL_OUT_BYTECAP(x)
 
#define SDL_OUT_Z_BYTECAP(x)
 
#define SDL_PRINTF_FORMAT_STRING
 
#define SDL_SCANF_FORMAT_STRING
 
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
 
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
 
#define SDL_SCANF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
 
#define SDL_WPRINTF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_COMPILE_TIME_ASSERT(name, x)    typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
 
#define SDL_INIT_INTERFACE(iface)
 
#define SDL_stack_alloc(type, count)   (type*)alloca(sizeof(type)*(count))
 
#define SDL_stack_free(data)
 
#define SDL_min(x, y)   (((x) < (y)) ? (x) : (y))
 
#define SDL_max(x, y)   (((x) > (y)) ? (x) : (y))
 
#define SDL_clamp(x, a, b)   (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
 
#define SDL_memcpy   memcpy
 
#define SDL_copyp(dst, src)
 
#define SDL_memmove   memmove
 
#define SDL_memset   memset
 
#define SDL_zero(x)   SDL_memset(&(x), 0, sizeof((x)))
 
#define SDL_zerop(x)   SDL_memset((x), 0, sizeof(*(x)))
 
#define SDL_zeroa(x)   SDL_memset((x), 0, sizeof((x)))
 
#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD
 
#define SDL_PI_D   3.141592653589793238462643383279502884
 
#define SDL_PI_F   3.141592653589793238462643383279502884F
 
#define SDL_ICONV_ERROR   (size_t)-1
 
#define SDL_ICONV_E2BIG   (size_t)-2
 
#define SDL_ICONV_EILSEQ   (size_t)-3
 
#define SDL_ICONV_EINVAL   (size_t)-4
 
#define SDL_iconv_utf8_locale(S)   SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_utf8_ucs2(S)   (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_utf8_ucs4(S)   (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_wchar_utf8(S)   SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
 
typedef void *(* SDL_malloc_func) (size_t size)
 
typedef void *(* SDL_calloc_func) (size_t nmemb, size_t size)
 
typedef void *(* SDL_realloc_func) (void *mem, size_t size)
 
typedef void(* SDL_free_func) (void *mem)
 
typedef struct SDL_Environment SDL_Environment
 
typedef int(* SDL_CompareCallback) (const void *a, const void *b)
 
typedef int(* SDL_CompareCallback_r) (void *userdata, const void *a, const void *b)
 
typedef struct SDL_iconv_data_t * SDL_iconv_t
 
typedef void(* SDL_FunctionPointer) (void)
 
SDL_MALLOC size_t size
 
SDL_MALLOC void * SDL_malloc (size_t size)
 
SDL_MALLOC SDL_ALLOC_SIZE2 (1, 2) void *SDL_calloc(size_t nmemb
 
 SDL_ALLOC_SIZE (2) void *SDL_realloc(void *mem
 
void SDL_free (void *mem)
 
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_GetMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
 
SDL_bool SDL_SetMemoryFunctions (SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
 
SDL_MALLOC void * SDL_aligned_alloc (size_t alignment, size_t size)
 
void SDL_aligned_free (void *mem)
 
int SDL_GetNumAllocations (void)
 
SDL_EnvironmentSDL_GetEnvironment (void)
 
SDL_EnvironmentSDL_CreateEnvironment (SDL_bool populated)
 
const char * SDL_GetEnvironmentVariable (SDL_Environment *env, const char *name)
 
char ** SDL_GetEnvironmentVariables (SDL_Environment *env)
 
SDL_bool SDL_SetEnvironmentVariable (SDL_Environment *env, const char *name, const char *value, SDL_bool overwrite)
 
SDL_bool SDL_UnsetEnvironmentVariable (SDL_Environment *env, const char *name)
 
void SDL_DestroyEnvironment (SDL_Environment *env)
 
const char * SDL_getenv (const char *name)
 
const char * SDL_getenv_unsafe (const char *name)
 
int SDL_setenv_unsafe (const char *name, const char *value, int overwrite)
 
int SDL_unsetenv_unsafe (const char *name)
 
void SDL_qsort (void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void * SDL_bsearch (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void SDL_qsort_r (void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
void * SDL_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
int SDL_abs (int x)
 
int SDL_isalpha (int x)
 
int SDL_isalnum (int x)
 
int SDL_isblank (int x)
 
int SDL_iscntrl (int x)
 
int SDL_isdigit (int x)
 
int SDL_isxdigit (int x)
 
int SDL_ispunct (int x)
 
int SDL_isspace (int x)
 
int SDL_isupper (int x)
 
int SDL_islower (int x)
 
int SDL_isprint (int x)
 
int SDL_isgraph (int x)
 
int SDL_toupper (int x)
 
int SDL_tolower (int x)
 
Uint16 SDL_crc16 (Uint16 crc, const void *data, size_t len)
 
Uint32 SDL_crc32 (Uint32 crc, const void *data, size_t len)
 
void * SDL_memcpy (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memmove (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memset (SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
 
void * SDL_memset4 (void *dst, Uint32 val, size_t dwords)
 
int SDL_memcmp (const void *s1, const void *s2, size_t len)
 
size_t SDL_wcslen (const wchar_t *wstr)
 
size_t SDL_wcsnlen (const wchar_t *wstr, size_t maxlen)
 
size_t SDL_wcslcpy (SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
size_t SDL_wcslcat (SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
wchar_t * SDL_wcsdup (const wchar_t *wstr)
 
wchar_t * SDL_wcsstr (const wchar_t *haystack, const wchar_t *needle)
 
wchar_t * SDL_wcsnstr (const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
 
int SDL_wcscmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
int SDL_wcscasecmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncasecmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
long SDL_wcstol (const wchar_t *str, wchar_t **endp, int base)
 
size_t SDL_strlen (const char *str)
 
size_t SDL_strnlen (const char *str, size_t maxlen)
 
size_t SDL_strlcpy (SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
size_t SDL_utf8strlcpy (SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
 
size_t SDL_strlcat (SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
SDL_MALLOC char * SDL_strdup (const char *str)
 
SDL_MALLOC char * SDL_strndup (const char *str, size_t maxlen)
 
char * SDL_strrev (char *str)
 
char * SDL_strupr (char *str)
 
char * SDL_strlwr (char *str)
 
char * SDL_strchr (const char *str, int c)
 
char * SDL_strrchr (const char *str, int c)
 
char * SDL_strstr (const char *haystack, const char *needle)
 
char * SDL_strnstr (const char *haystack, const char *needle, size_t maxlen)
 
char * SDL_strcasestr (const char *haystack, const char *needle)
 
char * SDL_strtok_r (char *s1, const char *s2, char **saveptr)
 
size_t SDL_utf8strlen (const char *str)
 
size_t SDL_utf8strnlen (const char *str, size_t bytes)
 
char * SDL_itoa (int value, char *str, int radix)
 
char * SDL_uitoa (unsigned int value, char *str, int radix)
 
char * SDL_ltoa (long value, char *str, int radix)
 
char * SDL_ultoa (unsigned long value, char *str, int radix)
 
char * SDL_lltoa (long long value, char *str, int radix)
 
char * SDL_ulltoa (unsigned long long value, char *str, int radix)
 
int SDL_atoi (const char *str)
 
double SDL_atof (const char *str)
 
long SDL_strtol (const char *str, char **endp, int base)
 
unsigned long SDL_strtoul (const char *str, char **endp, int base)
 
long long SDL_strtoll (const char *str, char **endp, int base)
 
unsigned long long SDL_strtoull (const char *str, char **endp, int base)
 
double SDL_strtod (const char *str, char **endp)
 
int SDL_strcmp (const char *str1, const char *str2)
 
int SDL_strncmp (const char *str1, const char *str2, size_t maxlen)
 
int SDL_strcasecmp (const char *str1, const char *str2)
 
int SDL_strncasecmp (const char *str1, const char *str2, size_t maxlen)
 
char * SDL_strpbrk (const char *str, const char *breakset)
 
Uint32 SDL_StepUTF8 (const char **pstr, size_t *pslen)
 
char * SDL_UCS4ToUTF8 (Uint32 codepoint, char *dst)
 
int SDL_sscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
 
int SDL_vsscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2)
 
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)
 
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)
 
int SDL_vswprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3)
 
int SDL_asprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
 
int SDL_vasprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
 
void SDL_srand (Uint64 seed)
 
Sint32 SDL_rand (Sint32 n)
 
float SDL_randf (void)
 
Uint32 SDL_rand_bits (void)
 
Sint32 SDL_rand_r (Uint64 *state, Sint32 n)
 
float SDL_randf_r (Uint64 *state)
 
Uint32 SDL_rand_bits_r (Uint64 *state)
 
double SDL_acos (double x)
 
float SDL_acosf (float x)
 
double SDL_asin (double x)
 
float SDL_asinf (float x)
 
double SDL_atan (double x)
 
float SDL_atanf (float x)
 
double SDL_atan2 (double y, double x)
 
float SDL_atan2f (float y, float x)
 
double SDL_ceil (double x)
 
float SDL_ceilf (float x)
 
double SDL_copysign (double x, double y)
 
float SDL_copysignf (float x, float y)
 
double SDL_cos (double x)
 
float SDL_cosf (float x)
 
double SDL_exp (double x)
 
float SDL_expf (float x)
 
double SDL_fabs (double x)
 
float SDL_fabsf (float x)
 
double SDL_floor (double x)
 
float SDL_floorf (float x)
 
double SDL_trunc (double x)
 
float SDL_truncf (float x)
 
double SDL_fmod (double x, double y)
 
float SDL_fmodf (float x, float y)
 
int SDL_isinf (double x)
 
int SDL_isinff (float x)
 
int SDL_isnan (double x)
 
int SDL_isnanf (float x)
 
double SDL_log (double x)
 
float SDL_logf (float x)
 
double SDL_log10 (double x)
 
float SDL_log10f (float x)
 
double SDL_modf (double x, double *y)
 
float SDL_modff (float x, float *y)
 
double SDL_pow (double x, double y)
 
float SDL_powf (float x, float y)
 
double SDL_round (double x)
 
float SDL_roundf (float x)
 
long SDL_lround (double x)
 
long SDL_lroundf (float x)
 
double SDL_scalbn (double x, int n)
 
float SDL_scalbnf (float x, int n)
 
double SDL_sin (double x)
 
float SDL_sinf (float x)
 
double SDL_sqrt (double x)
 
float SDL_sqrtf (float x)
 
double SDL_tan (double x)
 
float SDL_tanf (float x)
 
SDL_iconv_t SDL_iconv_open (const char *tocode, const char *fromcode)
 
int SDL_iconv_close (SDL_iconv_t cd)
 
size_t SDL_iconv (SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
 
char * SDL_iconv_string (const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
 
SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow (size_t a, size_t b, size_t *ret)
 
SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow (size_t a, size_t b, size_t *ret)
 

Macro Definition Documentation

◆ SDL_arraysize

#define SDL_arraysize (   array)    (sizeof(array)/sizeof(array[0]))

The number of elements in an array.

This macro looks like it double-evaluates the argument, but it does so inside of sizeof, so there are no side-effects here, as expressions do not actually run any code in these cases.

Since
This macro is available since SDL 3.0.0.

Definition at line 105 of file SDL_stdinc.h.

◆ SDL_clamp

#define SDL_clamp (   x,
  a,
 
)    (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))

Definition at line 1221 of file SDL_stdinc.h.

◆ SDL_COMPILE_TIME_ASSERT

#define SDL_COMPILE_TIME_ASSERT (   name,
 
)     typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]

Definition at line 567 of file SDL_stdinc.h.

585{
586 Uint8 a;
587 void *b;
588} SDL_alignment_test;
589SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
590SDL_COMPILE_TIME_ASSERT(two_s_complement, (int)~(int)0 == (int)(-1));
591#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
592/** \endcond */
593
594/* Check to make sure enums are the size of ints, for structure packing.
595 For both Watcom C/C++ and Borland C/C++ the compiler option that makes
596 enums having the size of an int must be enabled.
597 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
598*/
599
600/** \cond */
601#ifndef DOXYGEN_SHOULD_IGNORE_THIS
602#if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
603/* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
604typedef enum SDL_DUMMY_ENUM
605{
606 DUMMY_ENUM_VALUE
607} SDL_DUMMY_ENUM;
608
609SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
610#endif
611#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
612/** \endcond */
613
614#include <SDL3/SDL_begin_code.h>
615/* Set up for C function definitions, even when using C++ */
616#ifdef __cplusplus
617extern "C" {
618#endif
619
620/**
621 * A macro to initialize an SDL interface.
622 *
623 * This macro will initialize an SDL interface structure and should be called
624 * before you fill out the fields with your implementation.
625 *
626 * You can use it like this:
627 *
628 * ```c
629 * SDL_IOStreamInterface iface;
630 *
631 * SDL_INIT_INTERFACE(&iface);
632 *
633 * // Fill in the interface function pointers with your implementation
634 * iface.seek = ...
635 *
636 * stream = SDL_OpenIO(&iface, NULL);
637 * ```
638 *
639 * If you are using designated initializers, you can use the size of the
640 * interface as the version, e.g.
641 *
642 * ```c
643 * SDL_IOStreamInterface iface = {
644 * .version = sizeof(iface),
645 * .seek = ...
646 * };
647 * stream = SDL_OpenIO(&iface, NULL);
648 * ```
649 *
650 * \threadsafety It is safe to call this macro from any thread.
651 *
652 * \since This macro is available since SDL 3.0.0.
653 *
654 * \sa SDL_IOStreamInterface
655 * \sa SDL_StorageInterface
656 * \sa SDL_VirtualJoystickDesc
657 */
658#define SDL_INIT_INTERFACE(iface) \
659 do { \
660 SDL_zerop(iface); \
661 (iface)->version = sizeof(*(iface)); \
662 } while (0)
663
664
665#ifndef SDL_DISABLE_ALLOCA
666#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
667#define SDL_stack_free(data)
668#else
669#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
670#define SDL_stack_free(data) SDL_free(data)
671#endif
672
673/**
674 * Allocate uninitialized memory.
675 *
676 * The allocated memory returned by this function must be freed with
677 * SDL_free().
678 *
679 * If `size` is 0, it will be set to 1.
680 *
681 * If you want to allocate memory aligned to a specific alignment, consider
682 * using SDL_aligned_alloc().
683 *
684 * \param size the size to allocate.
685 * \returns a pointer to the allocated memory, or NULL if allocation failed.
686 *
687 * \threadsafety It is safe to call this function from any thread.
688 *
689 * \since This function is available since SDL 3.0.0.
690 *
691 * \sa SDL_free
692 * \sa SDL_calloc
693 * \sa SDL_realloc
694 * \sa SDL_aligned_alloc
695 */
696extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
697
698/**
699 * Allocate a zero-initialized array.
700 *
701 * The memory returned by this function must be freed with SDL_free().
702 *
703 * If either of `nmemb` or `size` is 0, they will both be set to 1.
704 *
705 * \param nmemb the number of elements in the array.
706 * \param size the size of each element of the array.
707 * \returns a pointer to the allocated array, or NULL if allocation failed.
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 *
713 * \sa SDL_free
714 * \sa SDL_malloc
715 * \sa SDL_realloc
716 */
717extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
718
719/**
720 * Change the size of allocated memory.
721 *
722 * The memory returned by this function must be freed with SDL_free().
723 *
724 * If `size` is 0, it will be set to 1. Note that this is unlike some other C
725 * runtime `realloc` implementations, which may treat `realloc(mem, 0)` the
726 * same way as `free(mem)`.
727 *
728 * If `mem` is NULL, the behavior of this function is equivalent to
729 * SDL_malloc(). Otherwise, the function can have one of three possible
730 * outcomes:
731 *
732 * - If it returns the same pointer as `mem`, it means that `mem` was resized
733 * in place without freeing.
734 * - If it returns a different non-NULL pointer, it means that `mem` was freed
735 * and cannot be dereferenced anymore.
736 * - If it returns NULL (indicating failure), then `mem` will remain valid and
737 * must still be freed with SDL_free().
738 *
739 * \param mem a pointer to allocated memory to reallocate, or NULL.
740 * \param size the new size of the memory.
741 * \returns a pointer to the newly allocated memory, or NULL if allocation
742 * failed.
743 *
744 * \threadsafety It is safe to call this function from any thread.
745 *
746 * \since This function is available since SDL 3.0.0.
747 *
748 * \sa SDL_free
749 * \sa SDL_malloc
750 * \sa SDL_calloc
751 */
752extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
753
754/**
755 * Free allocated memory.
756 *
757 * The pointer is no longer valid after this call and cannot be dereferenced
758 * anymore.
759 *
760 * If `mem` is NULL, this function does nothing.
761 *
762 * \param mem a pointer to allocated memory, or NULL.
763 *
764 * \threadsafety It is safe to call this function from any thread.
765 *
766 * \since This function is available since SDL 3.0.0.
767 *
768 * \sa SDL_malloc
769 * \sa SDL_calloc
770 * \sa SDL_realloc
771 */
772extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
773
774/**
775 * A callback used to implement SDL_malloc().
776 *
777 * SDL will always ensure that the passed `size` is greater than 0.
778 *
779 * \param size the size to allocate.
780 * \returns a pointer to the allocated memory, or NULL if allocation failed.
781 *
782 * \threadsafety It should be safe to call this callback from any thread.
783 *
784 * \since This datatype is available since SDL 3.0.0.
785 *
786 * \sa SDL_malloc
787 * \sa SDL_GetOriginalMemoryFunctions
788 * \sa SDL_GetMemoryFunctions
789 * \sa SDL_SetMemoryFunctions
790 */
791typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
792
793/**
794 * A callback used to implement SDL_calloc().
795 *
796 * SDL will always ensure that the passed `nmemb` and `size` are both greater
797 * than 0.
798 *
799 * \param nmemb the number of elements in the array.
800 * \param size the size of each element of the array.
801 * \returns a pointer to the allocated array, or NULL if allocation failed.
802 *
803 * \threadsafety It should be safe to call this callback from any thread.
804 *
805 * \since This datatype is available since SDL 3.0.0.
806 *
807 * \sa SDL_calloc
808 * \sa SDL_GetOriginalMemoryFunctions
809 * \sa SDL_GetMemoryFunctions
810 * \sa SDL_SetMemoryFunctions
811 */
812typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
813
814/**
815 * A callback used to implement SDL_realloc().
816 *
817 * SDL will always ensure that the passed `size` is greater than 0.
818 *
819 * \param mem a pointer to allocated memory to reallocate, or NULL.
820 * \param size the new size of the memory.
821 * \returns a pointer to the newly allocated memory, or NULL if allocation
822 * failed.
823 *
824 * \threadsafety It should be safe to call this callback from any thread.
825 *
826 * \since This datatype is available since SDL 3.0.0.
827 *
828 * \sa SDL_realloc
829 * \sa SDL_GetOriginalMemoryFunctions
830 * \sa SDL_GetMemoryFunctions
831 * \sa SDL_SetMemoryFunctions
832 */
833typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
834
835/**
836 * A callback used to implement SDL_free().
837 *
838 * SDL will always ensure that the passed `mem` is a non-NULL pointer.
839 *
840 * \param mem a pointer to allocated memory.
841 *
842 * \threadsafety It should be safe to call this callback from any thread.
843 *
844 * \since This datatype is available since SDL 3.0.0.
845 *
846 * \sa SDL_free
847 * \sa SDL_GetOriginalMemoryFunctions
848 * \sa SDL_GetMemoryFunctions
849 * \sa SDL_SetMemoryFunctions
850 */
851typedef void (SDLCALL *SDL_free_func)(void *mem);
852
853/**
854 * Get the original set of SDL memory functions.
855 *
856 * This is what SDL_malloc and friends will use by default, if there has been
857 * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
858 * runtime's `malloc` functions behind the scenes! Different platforms and
859 * build configurations might do any number of unexpected things.
860 *
861 * \param malloc_func filled with malloc function.
862 * \param calloc_func filled with calloc function.
863 * \param realloc_func filled with realloc function.
864 * \param free_func filled with free function.
865 *
866 * \threadsafety It is safe to call this function from any thread.
867 *
868 * \since This function is available since SDL 3.0.0.
869 */
870extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
871 SDL_calloc_func *calloc_func,
872 SDL_realloc_func *realloc_func,
873 SDL_free_func *free_func);
874
875/**
876 * Get the current set of SDL memory functions.
877 *
878 * \param malloc_func filled with malloc function.
879 * \param calloc_func filled with calloc function.
880 * \param realloc_func filled with realloc function.
881 * \param free_func filled with free function.
882 *
883 * \threadsafety This does not hold a lock, so do not call this in the
884 * unlikely event of a background thread calling
885 * SDL_SetMemoryFunctions simultaneously.
886 *
887 * \since This function is available since SDL 3.0.0.
888 *
889 * \sa SDL_SetMemoryFunctions
890 * \sa SDL_GetOriginalMemoryFunctions
891 */
892extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
893 SDL_calloc_func *calloc_func,
894 SDL_realloc_func *realloc_func,
895 SDL_free_func *free_func);
896
897/**
898 * Replace SDL's memory allocation functions with a custom set.
899 *
900 * It is not safe to call this function once any allocations have been made,
901 * as future calls to SDL_free will use the new allocator, even if they came
902 * from an SDL_malloc made with the old one!
903 *
904 * If used, usually this needs to be the first call made into the SDL library,
905 * if not the very first thing done at program startup time.
906 *
907 * \param malloc_func custom malloc function.
908 * \param calloc_func custom calloc function.
909 * \param realloc_func custom realloc function.
910 * \param free_func custom free function.
911 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
912 * for more information.
913 *
914 * \threadsafety It is safe to call this function from any thread, but one
915 * should not replace the memory functions once any allocations
916 * are made!
917 *
918 * \since This function is available since SDL 3.0.0.
919 *
920 * \sa SDL_GetMemoryFunctions
921 * \sa SDL_GetOriginalMemoryFunctions
922 */
923extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
924 SDL_calloc_func calloc_func,
925 SDL_realloc_func realloc_func,
926 SDL_free_func free_func);
927
928/**
929 * Allocate memory aligned to a specific alignment.
930 *
931 * The memory returned by this function must be freed with SDL_aligned_free(),
932 * _not_ SDL_free().
933 *
934 * If `alignment` is less than the size of `void *`, it will be increased to
935 * match that.
936 *
937 * The returned memory address will be a multiple of the alignment value, and
938 * the size of the memory allocated will be a multiple of the alignment value.
939 *
940 * \param alignment the alignment of the memory.
941 * \param size the size to allocate.
942 * \returns a pointer to the aligned memory, or NULL if allocation failed.
943 *
944 * \threadsafety It is safe to call this function from any thread.
945 *
946 * \since This function is available since SDL 3.0.0.
947 *
948 * \sa SDL_aligned_free
949 */
950extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
951
952/**
953 * Free memory allocated by SDL_aligned_alloc().
954 *
955 * The pointer is no longer valid after this call and cannot be dereferenced
956 * anymore.
957 *
958 * If `mem` is NULL, this function does nothing.
959 *
960 * \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
961 *
962 * \threadsafety It is safe to call this function from any thread.
963 *
964 * \since This function is available since SDL 3.0.0.
965 *
966 * \sa SDL_aligned_alloc
967 */
968extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
969
970/**
971 * Get the number of outstanding (unfreed) allocations.
972 *
973 * \returns the number of allocations.
974 *
975 * \threadsafety It is safe to call this function from any thread.
976 *
977 * \since This function is available since SDL 3.0.0.
978 */
979extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
980
981/**
982 * A thread-safe set of environment variables
983 *
984 * \since This struct is available since SDL 3.0.0.
985 *
986 * \sa SDL_GetEnvironment
987 * \sa SDL_CreateEnvironment
988 * \sa SDL_GetEnvironmentVariable
989 * \sa SDL_GetEnvironmentVariables
990 * \sa SDL_SetEnvironmentVariable
991 * \sa SDL_UnsetEnvironmentVariable
992 * \sa SDL_DestroyEnvironment
993 */
994typedef struct SDL_Environment SDL_Environment;
995
996/**
997 * Get the process environment.
998 *
999 * This is initialized at application start and is not affected by setenv()
1000 * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
1001 * SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
1002 * SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
1003 * in the C runtime environment after SDL_Quit().
1004 *
1005 * \returns a pointer to the environment for the process or NULL on failure;
1006 * call SDL_GetError() for more information.
1007 *
1008 * \threadsafety It is safe to call this function from any thread.
1009 *
1010 * \since This function is available since SDL 3.0.0.
1011 *
1012 * \sa SDL_GetEnvironmentVariable
1013 * \sa SDL_GetEnvironmentVariables
1014 * \sa SDL_SetEnvironmentVariable
1015 * \sa SDL_UnsetEnvironmentVariable
1016 */
1017extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
1018
1019/**
1020 * Create a set of environment variables
1021 *
1022 * \param populated SDL_TRUE to initialize it from the C runtime environment,
1023 * SDL_FALSE to create an empty environment.
1024 * \returns a pointer to the new environment or NULL on failure; call
1025 * SDL_GetError() for more information.
1026 *
1027 * \threadsafety If `populated` is SDL_FALSE, it is safe to call this function
1028 * from any thread, otherwise it is safe if no other threads are
1029 * calling setenv() or unsetenv()
1030 *
1031 * \since This function is available since SDL 3.0.0.
1032 *
1033 * \sa SDL_GetEnvironmentVariable
1034 * \sa SDL_GetEnvironmentVariables
1035 * \sa SDL_SetEnvironmentVariable
1036 * \sa SDL_UnsetEnvironmentVariable
1037 * \sa SDL_DestroyEnvironment
1038 */
1039extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(SDL_bool populated);
1040
1041/**
1042 * Get the value of a variable in the environment.
1043 *
1044 * \param env the environment to query.
1045 * \param name the name of the variable to get.
1046 * \returns a pointer to the value of the variable or NULL if it can't be
1047 * found.
1048 *
1049 * \threadsafety It is safe to call this function from any thread.
1050 *
1051 * \since This function is available since SDL 3.0.0.
1052 *
1053 * \sa SDL_GetEnvironment
1054 * \sa SDL_CreateEnvironment
1055 * \sa SDL_GetEnvironmentVariables
1056 * \sa SDL_SetEnvironmentVariable
1057 * \sa SDL_UnsetEnvironmentVariable
1058 */
1059extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
1060
1061/**
1062 * Get all variables in the environment.
1063 *
1064 * \param env the environment to query.
1065 * \returns a NULL terminated array of pointers to environment variables in
1066 * the form "variable=value" or NULL on failure; call SDL_GetError()
1067 * for more information. This is a single allocation that should be
1068 * freed with SDL_free() when it is no longer needed.
1069 *
1070 * \threadsafety It is safe to call this function from any thread.
1071 *
1072 * \since This function is available since SDL 3.0.0.
1073 *
1074 * \sa SDL_GetEnvironment
1075 * \sa SDL_CreateEnvironment
1076 * \sa SDL_GetEnvironmentVariables
1077 * \sa SDL_SetEnvironmentVariable
1078 * \sa SDL_UnsetEnvironmentVariable
1079 */
1080extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
1081
1082/**
1083 * Set the value of a variable in the environment.
1084 *
1085 * \param env the environment to modify.
1086 * \param name the name of the variable to set.
1087 * \param value the value of the variable to set.
1088 * \param overwrite SDL_TRUE to overwrite the variable if it exists, SDL_FALSE
1089 * to return success without setting the variable if it
1090 * already exists.
1091 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1092 * for more information.
1093 *
1094 * \threadsafety It is safe to call this function from any thread.
1095 *
1096 * \since This function is available since SDL 3.0.0.
1097 *
1098 * \sa SDL_GetEnvironment
1099 * \sa SDL_CreateEnvironment
1100 * \sa SDL_GetEnvironmentVariable
1101 * \sa SDL_GetEnvironmentVariables
1102 * \sa SDL_UnsetEnvironmentVariable
1103 */
1104extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, SDL_bool overwrite);
1105
1106/**
1107 * Clear a variable from the environment.
1108 *
1109 * \param env the environment to modify.
1110 * \param name the name of the variable to unset.
1111 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1112 * for more information.
1113 *
1114 * \threadsafety It is safe to call this function from any thread.
1115 *
1116 * \since This function is available since SDL 3.0.0.
1117 *
1118 * \sa SDL_GetEnvironment
1119 * \sa SDL_CreateEnvironment
1120 * \sa SDL_GetEnvironmentVariable
1121 * \sa SDL_GetEnvironmentVariables
1122 * \sa SDL_SetEnvironmentVariable
1123 * \sa SDL_UnsetEnvironmentVariable
1124 */
1125extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
1126
1127/**
1128 * Destroy a set of environment variables.
1129 *
1130 * \param env the environment to destroy.
1131 *
1132 * \threadsafety It is safe to call this function from any thread, as long as
1133 * the environment is no longer in use.
1134 *
1135 * \since This function is available since SDL 3.0.0.
1136 *
1137 * \sa SDL_CreateEnvironment
1138 */
1139extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
1140
1141/**
1142 * Get the value of a variable in the environment.
1143 *
1144 * This function uses SDL's cached copy of the environment and is thread-safe.
1145 *
1146 * \param name the name of the variable to get.
1147 * \returns a pointer to the value of the variable or NULL if it can't be
1148 * found.
1149 *
1150 * \threadsafety It is safe to call this function from any thread.
1151 *
1152 * \since This function is available since SDL 3.0.0.
1153 */
1154extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
1155
1156/**
1157 * Get the value of a variable in the environment.
1158 *
1159 * This function bypasses SDL's cached copy of the environment and is not
1160 * thread-safe.
1161 *
1162 * \param name the name of the variable to get.
1163 * \returns a pointer to the value of the variable or NULL if it can't be
1164 * found.
1165 *
1166 * \threadsafety This function is not thread safe, consider using SDL_getenv()
1167 * instead.
1168 *
1169 * \since This function is available since SDL 3.0.0.
1170 *
1171 * \sa SDL_getenv
1172 */
1173extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
1174
1175/**
1176 * Set the value of a variable in the environment.
1177 *
1178 * \param name the name of the variable to set.
1179 * \param value the value of the variable to set.
1180 * \param overwrite 1 to overwrite the variable if it exists, 0 to return
1181 * success without setting the variable if it already exists.
1182 * \returns 0 on success, -1 on error.
1183 *
1184 * \threadsafety This function is not thread safe, consider using
1185 * SDL_SetEnvironmentVariable() instead.
1186 *
1187 * \since This function is available since SDL 3.0.0.
1188 *
1189 * \sa SDL_SetEnvironmentVariable
1190 */
1191extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
1192
1193/**
1194 * Clear a variable from the environment.
1195 *
1196 * \param name the name of the variable to unset.
1197 * \returns 0 on success, -1 on error.
1198 *
1199 * \threadsafety This function is not thread safe, consider using
1200 * SDL_UnsetEnvironmentVariable() instead.
1201 *
1202 * \since This function is available since SDL 3.0.0.
1203 *
1204 * \sa SDL_UnsetEnvironmentVariable
1205 */
1206extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
1207
1208typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
1209extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
1210extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
1211
1212typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
1213extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
1214extern 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);
1215
1216extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
1217
1218/* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
1219#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
1220#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
1221#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
1222
1223/**
1224 * Query if a character is alphabetic (a letter).
1225 *
1226 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1227 * for English 'a-z' and 'A-Z' as true.
1228 *
1229 * \param x character value to check.
1230 * \returns non-zero if x falls within the character class, zero otherwise.
1231 *
1232 * \threadsafety It is safe to call this function from any thread.
1233 *
1234 * \since This function is available since SDL 3.0.0.
1235 */
1236extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
1237
1238/**
1239 * Query if a character is alphabetic (a letter) or a number.
1240 *
1241 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1242 * for English 'a-z', 'A-Z', and '0-9' as true.
1243 *
1244 * \param x character value to check.
1245 * \returns non-zero if x falls within the character class, zero otherwise.
1246 *
1247 * \threadsafety It is safe to call this function from any thread.
1248 *
1249 * \since This function is available since SDL 3.0.0.
1250 */
1251extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
1252
1253/**
1254 * Report if a character is blank (a space or tab).
1255 *
1256 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1257 * 0x20 (space) or 0x9 (tab) as true.
1258 *
1259 * \param x character value to check.
1260 * \returns non-zero if x falls within the character class, zero otherwise.
1261 *
1262 * \threadsafety It is safe to call this function from any thread.
1263 *
1264 * \since This function is available since SDL 3.0.0.
1265 */
1266extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
1267
1268/**
1269 * Report if a character is a control character.
1270 *
1271 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1272 * 0 through 0x1F, and 0x7F, as true.
1273 *
1274 * \param x character value to check.
1275 * \returns non-zero if x falls within the character class, zero otherwise.
1276 *
1277 * \threadsafety It is safe to call this function from any thread.
1278 *
1279 * \since This function is available since SDL 3.0.0.
1280 */
1281extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
1282
1283/**
1284 * Report if a character is a numeric digit.
1285 *
1286 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1287 * '0' (0x30) through '9' (0x39), as true.
1288 *
1289 * \param x character value to check.
1290 * \returns non-zero if x falls within the character class, zero otherwise.
1291 *
1292 * \threadsafety It is safe to call this function from any thread.
1293 *
1294 * \since This function is available since SDL 3.0.0.
1295 */
1296extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
1297
1298/**
1299 * Report if a character is a hexadecimal digit.
1300 *
1301 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1302 * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
1303 *
1304 * \param x character value to check.
1305 * \returns non-zero if x falls within the character class, zero otherwise.
1306 *
1307 * \threadsafety It is safe to call this function from any thread.
1308 *
1309 * \since This function is available since SDL 3.0.0.
1310 */
1311extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
1312
1313/**
1314 * Report if a character is a punctuation mark.
1315 *
1316 * **WARNING**: Regardless of system locale, this is equivalent to
1317 * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
1318 *
1319 * \param x character value to check.
1320 * \returns non-zero if x falls within the character class, zero otherwise.
1321 *
1322 * \threadsafety It is safe to call this function from any thread.
1323 *
1324 * \since This function is available since SDL 3.0.0.
1325 *
1326 * \sa SDL_isgraph
1327 * \sa SDL_isalnum
1328 */
1329extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
1330
1331/**
1332 * Report if a character is whitespace.
1333 *
1334 * **WARNING**: Regardless of system locale, this will only treat the
1335 * following ASCII values as true:
1336 *
1337 * - space (0x20)
1338 * - tab (0x09)
1339 * - newline (0x0A)
1340 * - vertical tab (0x0B)
1341 * - form feed (0x0C)
1342 * - return (0x0D)
1343 *
1344 * \param x character value to check.
1345 * \returns non-zero if x falls within the character class, zero otherwise.
1346 *
1347 * \threadsafety It is safe to call this function from any thread.
1348 *
1349 * \since This function is available since SDL 3.0.0.
1350 */
1351extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
1352
1353/**
1354 * Report if a character is upper case.
1355 *
1356 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1357 * 'A' through 'Z' as true.
1358 *
1359 * \param x character value to check.
1360 * \returns non-zero if x falls within the character class, zero otherwise.
1361 *
1362 * \threadsafety It is safe to call this function from any thread.
1363 *
1364 * \since This function is available since SDL 3.0.0.
1365 */
1366extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
1367
1368/**
1369 * Report if a character is lower case.
1370 *
1371 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1372 * 'a' through 'z' as true.
1373 *
1374 * \param x character value to check.
1375 * \returns non-zero if x falls within the character class, zero otherwise.
1376 *
1377 * \threadsafety It is safe to call this function from any thread.
1378 *
1379 * \since This function is available since SDL 3.0.0.
1380 */
1381extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
1382
1383/**
1384 * Report if a character is "printable".
1385 *
1386 * Be advised that "printable" has a definition that goes back to text
1387 * terminals from the dawn of computing, making this a sort of special case
1388 * function that is not suitable for Unicode (or most any) text management.
1389 *
1390 * **WARNING**: Regardless of system locale, this will only treat ASCII values
1391 * ' ' (0x20) through '~' (0x7E) as true.
1392 *
1393 * \param x character value to check.
1394 * \returns non-zero if x falls within the character class, zero otherwise.
1395 *
1396 * \threadsafety It is safe to call this function from any thread.
1397 *
1398 * \since This function is available since SDL 3.0.0.
1399 */
1400extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
1401
1402/**
1403 * Report if a character is any "printable" except space.
1404 *
1405 * Be advised that "printable" has a definition that goes back to text
1406 * terminals from the dawn of computing, making this a sort of special case
1407 * function that is not suitable for Unicode (or most any) text management.
1408 *
1409 * **WARNING**: Regardless of system locale, this is equivalent to
1410 * `(SDL_isprint(x)) && ((x) != ' ')`.
1411 *
1412 * \param x character value to check.
1413 * \returns non-zero if x falls within the character class, zero otherwise.
1414 *
1415 * \threadsafety It is safe to call this function from any thread.
1416 *
1417 * \since This function is available since SDL 3.0.0.
1418 *
1419 * \sa SDL_isprint
1420 */
1421extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
1422
1423/**
1424 * Convert low-ASCII English letters to uppercase.
1425 *
1426 * **WARNING**: Regardless of system locale, this will only convert ASCII
1427 * values 'a' through 'z' to uppercase.
1428 *
1429 * This function returns the uppercase equivalent of `x`. If a character
1430 * cannot be converted, or is already uppercase, this function returns `x`.
1431 *
1432 * \param x character value to check.
1433 * \returns capitalized version of x, or x if no conversion available.
1434 *
1435 * \threadsafety It is safe to call this function from any thread.
1436 *
1437 * \since This function is available since SDL 3.0.0.
1438 */
1439extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
1440
1441/**
1442 * Convert low-ASCII English letters to lowercase.
1443 *
1444 * **WARNING**: Regardless of system locale, this will only convert ASCII
1445 * values 'A' through 'Z' to lowercase.
1446 *
1447 * This function returns the lowercase equivalent of `x`. If a character
1448 * cannot be converted, or is already lowercase, this function returns `x`.
1449 *
1450 * \param x character value to check.
1451 * \returns lowercase version of x, or x if no conversion available.
1452 *
1453 * \threadsafety It is safe to call this function from any thread.
1454 *
1455 * \since This function is available since SDL 3.0.0.
1456 */
1457extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
1458
1459extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
1460extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
1461
1462/**
1463 * Copy non-overlapping memory.
1464 *
1465 * The memory regions must not overlap. If they do, use SDL_memmove() instead.
1466 *
1467 * \param dst The destination memory region. Must not be NULL, and must not
1468 * overlap with `src`.
1469 * \param src The source memory region. Must not be NULL, and must not overlap
1470 * with `dst`.
1471 * \param len The length in bytes of both `dst` and `src`.
1472 * \returns `dst`.
1473 *
1474 * \threadsafety It is safe to call this function from any thread.
1475 *
1476 * \since This function is available since SDL 3.0.0.
1477 *
1478 * \sa SDL_memmove
1479 */
1480extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
1481
1482/* Take advantage of compiler optimizations for memcpy */
1483#ifndef SDL_SLOW_MEMCPY
1484#ifdef SDL_memcpy
1485#undef SDL_memcpy
1486#endif
1487#define SDL_memcpy memcpy
1488#endif
1489
1490#define SDL_copyp(dst, src) \
1491 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
1492 SDL_memcpy((dst), (src), sizeof(*(src)))
1493
1494/**
1495 * Copy memory.
1496 *
1497 * It is okay for the memory regions to overlap. If you are confident that the
1498 * regions never overlap, using SDL_memcpy() may improve performance.
1499 *
1500 * \param dst The destination memory region. Must not be NULL.
1501 * \param src The source memory region. Must not be NULL.
1502 * \param len The length in bytes of both `dst` and `src`.
1503 * \returns `dst`.
1504 *
1505 * \threadsafety It is safe to call this function from any thread.
1506 *
1507 * \since This function is available since SDL 3.0.0.
1508 *
1509 * \sa SDL_memcpy
1510 */
1511extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
1512
1513/* Take advantage of compiler optimizations for memmove */
1514#ifndef SDL_SLOW_MEMMOVE
1515#ifdef SDL_memmove
1516#undef SDL_memmove
1517#endif
1518#define SDL_memmove memmove
1519#endif
1520
1521extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
1522extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
1523
1524/* Take advantage of compiler optimizations for memset */
1525#ifndef SDL_SLOW_MEMSET
1526#ifdef SDL_memset
1527#undef SDL_memset
1528#endif
1529#define SDL_memset memset
1530#endif
1531
1532#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
1533#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
1534#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
1535
1536extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
1537
1538extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
1539extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
1540
1541/**
1542 * Copy a wide string.
1543 *
1544 * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
1545 * appends a null terminator.
1546 *
1547 * `src` and `dst` must not overlap.
1548 *
1549 * If `maxlen` is 0, no wide characters are copied and no null terminator is
1550 * written.
1551 *
1552 * \param dst The destination buffer. Must not be NULL, and must not overlap
1553 * with `src`.
1554 * \param src The null-terminated wide string to copy. Must not be NULL, and
1555 * must not overlap with `dst`.
1556 * \param maxlen The length (in wide characters) of the destination buffer.
1557 * \returns The length (in wide characters, excluding the null terminator) of
1558 * `src`.
1559 *
1560 * \threadsafety It is safe to call this function from any thread.
1561 *
1562 * \since This function is available since SDL 3.0.0.
1563 *
1564 * \sa SDL_wcslcat
1565 */
1566extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
1567
1568/**
1569 * Concatenate wide strings.
1570 *
1571 * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
1572 * from `src` to the end of the wide string in `dst`, then appends a null
1573 * terminator.
1574 *
1575 * `src` and `dst` must not overlap.
1576 *
1577 * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
1578 * unmodified.
1579 *
1580 * \param dst The destination buffer already containing the first
1581 * null-terminated wide string. Must not be NULL and must not
1582 * overlap with `src`.
1583 * \param src The second null-terminated wide string. Must not be NULL, and
1584 * must not overlap with `dst`.
1585 * \param maxlen The length (in wide characters) of the destination buffer.
1586 * \returns The length (in wide characters, excluding the null terminator) of
1587 * the string in `dst` plus the length of `src`.
1588 *
1589 * \threadsafety It is safe to call this function from any thread.
1590 *
1591 * \since This function is available since SDL 3.0.0.
1592 *
1593 * \sa SDL_wcslcpy
1594 */
1595extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
1596
1597extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
1598extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
1599extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
1600
1601/**
1602 * Compare two null-terminated wide strings.
1603 *
1604 * This only compares wchar_t values until it hits a null-terminating
1605 * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
1606 * depending on your platform's wchar_t size), or uses valid Unicode values.
1607 *
1608 * \param str1 the first string to compare. NULL is not permitted!
1609 * \param str2 the second string to compare. NULL is not permitted!
1610 * \returns less than zero if str1 is "less than" str2, greater than zero if
1611 * str1 is "greater than" str2, and zero if the strings match
1612 * exactly.
1613 *
1614 * \threadsafety It is safe to call this function from any thread.
1615 *
1616 * \since This function is available since SDL 3.0.0.
1617 */
1618extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
1619
1620/**
1621 * Compare two wide strings up to a number of wchar_t values.
1622 *
1623 * This only compares wchar_t values; it does not care if the string is
1624 * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
1625 * or uses valid Unicode values.
1626 *
1627 * Note that while this function is intended to be used with UTF-16 (or
1628 * UTF-32, depending on your platform's definition of wchar_t), it is
1629 * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
1630 * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
1631 * sequence, it will only compare a portion of the final character.
1632 *
1633 * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
1634 * match to this number of wide chars (or both have matched to a
1635 * null-terminator character before this count), they will be considered
1636 * equal.
1637 *
1638 * \param str1 the first string to compare. NULL is not permitted!
1639 * \param str2 the second string to compare. NULL is not permitted!
1640 * \param maxlen the maximum number of wchar_t to compare.
1641 * \returns less than zero if str1 is "less than" str2, greater than zero if
1642 * str1 is "greater than" str2, and zero if the strings match
1643 * exactly.
1644 *
1645 * \threadsafety It is safe to call this function from any thread.
1646 *
1647 * \since This function is available since SDL 3.0.0.
1648 */
1649extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
1650
1651/**
1652 * Compare two null-terminated wide strings, case-insensitively.
1653 *
1654 * This will work with Unicode strings, using a technique called
1655 * "case-folding" to handle the vast majority of case-sensitive human
1656 * languages regardless of system locale. It can deal with expanding values: a
1657 * German Eszett character can compare against two ASCII 's' chars and be
1658 * considered a match, for example. A notable exception: it does not handle
1659 * the Turkish 'i' character; human language is complicated!
1660 *
1661 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
1662 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
1663 * handles Unicode, it expects the string to be well-formed and not a
1664 * null-terminated string of arbitrary bytes. Characters that are not valid
1665 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
1666 * CHARACTER), which is to say two strings of random bits may turn out to
1667 * match if they convert to the same amount of replacement characters.
1668 *
1669 * \param str1 the first string to compare. NULL is not permitted!
1670 * \param str2 the second string to compare. NULL is not permitted!
1671 * \returns less than zero if str1 is "less than" str2, greater than zero if
1672 * str1 is "greater than" str2, and zero if the strings match
1673 * exactly.
1674 *
1675 * \threadsafety It is safe to call this function from any thread.
1676 *
1677 * \since This function is available since SDL 3.0.0.
1678 */
1679extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
1680
1681/**
1682 * Compare two wide strings, case-insensitively, up to a number of wchar_t.
1683 *
1684 * This will work with Unicode strings, using a technique called
1685 * "case-folding" to handle the vast majority of case-sensitive human
1686 * languages regardless of system locale. It can deal with expanding values: a
1687 * German Eszett character can compare against two ASCII 's' chars and be
1688 * considered a match, for example. A notable exception: it does not handle
1689 * the Turkish 'i' character; human language is complicated!
1690 *
1691 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
1692 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
1693 * handles Unicode, it expects the string to be well-formed and not a
1694 * null-terminated string of arbitrary bytes. Characters that are not valid
1695 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
1696 * CHARACTER), which is to say two strings of random bits may turn out to
1697 * match if they convert to the same amount of replacement characters.
1698 *
1699 * Note that while this function might deal with variable-sized characters,
1700 * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
1701 * multi-byte UTF-16 sequence, it may convert a portion of the final character
1702 * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
1703 * to overflow a buffer.
1704 *
1705 * `maxlen` specifies a maximum number of wchar_t values to compare; if the
1706 * strings match to this number of wchar_t (or both have matched to a
1707 * null-terminator character before this number of bytes), they will be
1708 * considered equal.
1709 *
1710 * \param str1 the first string to compare. NULL is not permitted!
1711 * \param str2 the second string to compare. NULL is not permitted!
1712 * \param maxlen the maximum number of wchar_t values to compare.
1713 * \returns less than zero if str1 is "less than" str2, greater than zero if
1714 * str1 is "greater than" str2, and zero if the strings match
1715 * exactly.
1716 *
1717 * \threadsafety It is safe to call this function from any thread.
1718 *
1719 * \since This function is available since SDL 3.0.0.
1720 */
1721extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
1722
1723/**
1724 * Parse a `long` from a wide string.
1725 *
1726 * If `str` starts with whitespace, then those whitespace characters are
1727 * skipped before attempting to parse the number.
1728 *
1729 * If the parsed number does not fit inside a `long`, the result is clamped to
1730 * the minimum and maximum representable `long` values.
1731 *
1732 * \param str The null-terminated wide string to read. Must not be NULL.
1733 * \param endp If not NULL, the address of the first invalid wide character
1734 * (i.e. the next character after the parsed number) will be
1735 * written to this pointer.
1736 * \param base The base of the integer to read. Supported values are 0 and 2
1737 * to 36 inclusive. If 0, the base will be inferred from the
1738 * number's prefix (0x for hexadecimal, 0 for octal, decimal
1739 * otherwise).
1740 * \returns The parsed `long`, or 0 if no number could be parsed.
1741 *
1742 * \threadsafety It is safe to call this function from any thread.
1743 *
1744 * \since This function is available since SDL 3.0.0.
1745 *
1746 * \sa SDL_strtol
1747 */
1748extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
1749
1750extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
1751extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
1752
1753/**
1754 * Copy a string.
1755 *
1756 * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
1757 * then appends a null terminator.
1758 *
1759 * If `maxlen` is 0, no characters are copied and no null terminator is
1760 * written.
1761 *
1762 * If you want to copy an UTF-8 string but need to ensure that multi-byte
1763 * sequences are not truncated, consider using SDL_utf8strlcpy().
1764 *
1765 * \param dst The destination buffer. Must not be NULL, and must not overlap
1766 * with `src`.
1767 * \param src The null-terminated string to copy. Must not be NULL, and must
1768 * not overlap with `dst`.
1769 * \param maxlen The length (in characters) of the destination buffer.
1770 * \returns The length (in characters, excluding the null terminator) of
1771 * `src`.
1772 *
1773 * \threadsafety It is safe to call this function from any thread.
1774 *
1775 * \since This function is available since SDL 3.0.0.
1776 *
1777 * \sa SDL_strlcat
1778 * \sa SDL_utf8strlcpy
1779 */
1780extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
1781
1782/**
1783 * Copy an UTF-8 string.
1784 *
1785 * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
1786 * also ensuring that the string written to `dst` does not end in a truncated
1787 * multi-byte sequence. Finally, it appends a null terminator.
1788 *
1789 * `src` and `dst` must not overlap.
1790 *
1791 * Note that unlike SDL_strlcpy(), this function returns the number of bytes
1792 * written, not the length of `src`.
1793 *
1794 * \param dst The destination buffer. Must not be NULL, and must not overlap
1795 * with `src`.
1796 * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
1797 * must not overlap with `dst`.
1798 * \param dst_bytes The length (in bytes) of the destination buffer. Must not
1799 * be 0.
1800 * \returns The number of bytes written, excluding the null terminator.
1801 *
1802 * \threadsafety It is safe to call this function from any thread.
1803 *
1804 * \since This function is available since SDL 3.0.0.
1805 *
1806 * \sa SDL_strlcpy
1807 */
1808extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
1809
1810/**
1811 * Concatenate strings.
1812 *
1813 * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
1814 * `src` to the end of the string in `dst`, then appends a null terminator.
1815 *
1816 * `src` and `dst` must not overlap.
1817 *
1818 * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
1819 * unmodified.
1820 *
1821 * \param dst The destination buffer already containing the first
1822 * null-terminated string. Must not be NULL and must not overlap
1823 * with `src`.
1824 * \param src The second null-terminated string. Must not be NULL, and must
1825 * not overlap with `dst`.
1826 * \param maxlen The length (in characters) of the destination buffer.
1827 * \returns The length (in characters, excluding the null terminator) of the
1828 * string in `dst` plus the length of `src`.
1829 *
1830 * \threadsafety It is safe to call this function from any thread.
1831 *
1832 * \since This function is available since SDL 3.0.0.
1833 *
1834 * \sa SDL_strlcpy
1835 */
1836extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
1837
1838extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
1839extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
1840extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
1841
1842/**
1843 * Convert a string to uppercase.
1844 *
1845 * **WARNING**: Regardless of system locale, this will only convert ASCII
1846 * values 'A' through 'Z' to uppercase.
1847 *
1848 * This function operates on a null-terminated string of bytes--even if it is
1849 * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
1850 * uppercase equivalents in-place, returning the original `str` pointer.
1851 *
1852 * \param str the string to convert in-place. Can not be NULL.
1853 * \returns the `str` pointer passed into this function.
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_strlwr
1860 */
1861extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
1862
1863/**
1864 * Convert a string to lowercase.
1865 *
1866 * **WARNING**: Regardless of system locale, this will only convert ASCII
1867 * values 'A' through 'Z' to lowercase.
1868 *
1869 * This function operates on a null-terminated string of bytes--even if it is
1870 * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
1871 * lowercase equivalents in-place, returning the original `str` pointer.
1872 *
1873 * \param str the string to convert in-place. Can not be NULL.
1874 * \returns the `str` pointer passed into this function.
1875 *
1876 * \threadsafety It is safe to call this function from any thread.
1877 *
1878 * \since This function is available since SDL 3.0.0.
1879 *
1880 * \sa SDL_strupr
1881 */
1882extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
1883
1884extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
1885extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
1886extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
1887extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
1888extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
1889extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
1890extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
1891extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
1892
1893extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
1894extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
1895extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
1896extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
1897extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
1898extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
1899
1900/**
1901 * Parse an `int` from a string.
1902 *
1903 * The result of calling `SDL_atoi(str)` is equivalent to
1904 * `(int)SDL_strtol(str, NULL, 10)`.
1905 *
1906 * \param str The null-terminated string to read. Must not be NULL.
1907 * \returns The parsed `int`.
1908 *
1909 * \threadsafety It is safe to call this function from any thread.
1910 *
1911 * \since This function is available since SDL 3.0.0.
1912 *
1913 * \sa SDL_atof
1914 * \sa SDL_strtol
1915 * \sa SDL_strtoul
1916 * \sa SDL_strtoll
1917 * \sa SDL_strtoull
1918 * \sa SDL_strtod
1919 * \sa SDL_itoa
1920 */
1921extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
1922
1923/**
1924 * Parse a `double` from a string.
1925 *
1926 * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
1927 * NULL)`.
1928 *
1929 * \param str The null-terminated string to read. Must not be NULL.
1930 * \returns The parsed `double`.
1931 *
1932 * \threadsafety It is safe to call this function from any thread.
1933 *
1934 * \since This function is available since SDL 3.0.0.
1935 *
1936 * \sa SDL_atoi
1937 * \sa SDL_strtol
1938 * \sa SDL_strtoul
1939 * \sa SDL_strtoll
1940 * \sa SDL_strtoull
1941 * \sa SDL_strtod
1942 */
1943extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
1944
1945/**
1946 * Parse a `long` from a string.
1947 *
1948 * If `str` starts with whitespace, then those whitespace characters are
1949 * skipped before attempting to parse the number.
1950 *
1951 * If the parsed number does not fit inside a `long`, the result is clamped to
1952 * the minimum and maximum representable `long` values.
1953 *
1954 * \param str The null-terminated string to read. Must not be NULL.
1955 * \param endp If not NULL, the address of the first invalid character (i.e.
1956 * the next character after the parsed number) will be written to
1957 * this pointer.
1958 * \param base The base of the integer to read. Supported values are 0 and 2
1959 * to 36 inclusive. If 0, the base will be inferred from the
1960 * number's prefix (0x for hexadecimal, 0 for octal, decimal
1961 * otherwise).
1962 * \returns The parsed `long`, or 0 if no number could be parsed.
1963 *
1964 * \threadsafety It is safe to call this function from any thread.
1965 *
1966 * \since This function is available since SDL 3.0.0.
1967 *
1968 * \sa SDL_atoi
1969 * \sa SDL_atof
1970 * \sa SDL_strtoul
1971 * \sa SDL_strtoll
1972 * \sa SDL_strtoull
1973 * \sa SDL_strtod
1974 * \sa SDL_ltoa
1975 * \sa SDL_wcstol
1976 */
1977extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
1978
1979/**
1980 * Parse an `unsigned long` from a string.
1981 *
1982 * If `str` starts with whitespace, then those whitespace characters are
1983 * skipped before attempting to parse the number.
1984 *
1985 * If the parsed number does not fit inside an `unsigned long`, the result is
1986 * clamped to the maximum representable `unsigned long` value.
1987 *
1988 * \param str The null-terminated string to read. Must not be NULL.
1989 * \param endp If not NULL, the address of the first invalid character (i.e.
1990 * the next character after the parsed number) will be written to
1991 * this pointer.
1992 * \param base The base of the integer to read. Supported values are 0 and 2
1993 * to 36 inclusive. If 0, the base will be inferred from the
1994 * number's prefix (0x for hexadecimal, 0 for octal, decimal
1995 * otherwise).
1996 * \returns The parsed `unsigned long`, or 0 if no number could be parsed.
1997 *
1998 * \threadsafety It is safe to call this function from any thread.
1999 *
2000 * \since This function is available since SDL 3.0.0.
2001 *
2002 * \sa SDL_atoi
2003 * \sa SDL_atof
2004 * \sa SDL_strtol
2005 * \sa SDL_strtoll
2006 * \sa SDL_strtoull
2007 * \sa SDL_strtod
2008 * \sa SDL_ultoa
2009 */
2010extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
2011
2012/**
2013 * Parse a `long long` from a string.
2014 *
2015 * If `str` starts with whitespace, then those whitespace characters are
2016 * skipped before attempting to parse the number.
2017 *
2018 * If the parsed number does not fit inside a `long long`, the result is
2019 * clamped to the minimum and maximum representable `long long` values.
2020 *
2021 * \param str The null-terminated string to read. Must not be NULL.
2022 * \param endp If not NULL, the address of the first invalid character (i.e.
2023 * the next character after the parsed number) will be written to
2024 * this pointer.
2025 * \param base The base of the integer to read. Supported values are 0 and 2
2026 * to 36 inclusive. If 0, the base will be inferred from the
2027 * number's prefix (0x for hexadecimal, 0 for octal, decimal
2028 * otherwise).
2029 * \returns The parsed `long long`, or 0 if no number could be parsed.
2030 *
2031 * \threadsafety It is safe to call this function from any thread.
2032 *
2033 * \since This function is available since SDL 3.0.0.
2034 *
2035 * \sa SDL_atoi
2036 * \sa SDL_atof
2037 * \sa SDL_strtol
2038 * \sa SDL_strtoul
2039 * \sa SDL_strtoull
2040 * \sa SDL_strtod
2041 * \sa SDL_lltoa
2042 */
2043extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
2044
2045/**
2046 * Parse an `unsigned long long` from a string.
2047 *
2048 * If `str` starts with whitespace, then those whitespace characters are
2049 * skipped before attempting to parse the number.
2050 *
2051 * If the parsed number does not fit inside an `unsigned long long`, the
2052 * result is clamped to the maximum representable `unsigned long long` value.
2053 *
2054 * \param str The null-terminated string to read. Must not be NULL.
2055 * \param endp If not NULL, the address of the first invalid character (i.e.
2056 * the next character after the parsed number) will be written to
2057 * this pointer.
2058 * \param base The base of the integer to read. Supported values are 0 and 2
2059 * to 36 inclusive. If 0, the base will be inferred from the
2060 * number's prefix (0x for hexadecimal, 0 for octal, decimal
2061 * otherwise).
2062 * \returns The parsed `unsigned long long`, or 0 if no number could be
2063 * parsed.
2064 *
2065 * \threadsafety It is safe to call this function from any thread.
2066 *
2067 * \since This function is available since SDL 3.0.0.
2068 *
2069 * \sa SDL_atoi
2070 * \sa SDL_atof
2071 * \sa SDL_strtol
2072 * \sa SDL_strtoll
2073 * \sa SDL_strtoul
2074 * \sa SDL_strtod
2075 * \sa SDL_ulltoa
2076 */
2077extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
2078
2079/**
2080 * Parse a `double` from a string.
2081 *
2082 * This function makes fewer guarantees than the C runtime `strtod`:
2083 *
2084 * - Only decimal notation is guaranteed to be supported. The handling of
2085 * scientific and hexadecimal notation is unspecified.
2086 * - Whether or not INF and NAN can be parsed is unspecified.
2087 * - The precision of the result is unspecified.
2088 *
2089 * \param str The null-terminated string to read. Must not be NULL.
2090 * \param endp If not NULL, the address of the first invalid character (i.e.
2091 * the next character after the parsed number) will be written to
2092 * this pointer.
2093 * \returns The parsed `double`, or 0 if no number could be parsed.
2094 *
2095 * \threadsafety It is safe to call this function from any thread.
2096 *
2097 * \since This function is available since SDL 3.0.0.
2098 *
2099 * \sa SDL_atoi
2100 * \sa SDL_atof
2101 * \sa SDL_strtol
2102 * \sa SDL_strtoll
2103 * \sa SDL_strtoul
2104 * \sa SDL_strtoull
2105 */
2106extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
2107
2108/**
2109 * Compare two null-terminated UTF-8 strings.
2110 *
2111 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
2112 * since effectively this function just compares bytes until it hits a
2113 * null-terminating character. Also due to the nature of UTF-8, this can be
2114 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
2115 *
2116 * \param str1 the first string to compare. NULL is not permitted!
2117 * \param str2 the second string to compare. NULL is not permitted!
2118 * \returns less than zero if str1 is "less than" str2, greater than zero if
2119 * str1 is "greater than" str2, and zero if the strings match
2120 * exactly.
2121 *
2122 * \threadsafety It is safe to call this function from any thread.
2123 *
2124 * \since This function is available since SDL 3.0.0.
2125 */
2126extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
2127
2128/**
2129 * Compare two UTF-8 strings up to a number of bytes.
2130 *
2131 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
2132 * since effectively this function just compares bytes until it hits a
2133 * null-terminating character. Also due to the nature of UTF-8, this can be
2134 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
2135 *
2136 * Note that while this function is intended to be used with UTF-8, it is
2137 * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
2138 * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
2139 * compare a portion of the final character.
2140 *
2141 * `maxlen` specifies a maximum number of bytes to compare; if the strings
2142 * match to this number of bytes (or both have matched to a null-terminator
2143 * character before this number of bytes), they will be considered equal.
2144 *
2145 * \param str1 the first string to compare. NULL is not permitted!
2146 * \param str2 the second string to compare. NULL is not permitted!
2147 * \param maxlen the maximum number of _bytes_ to compare.
2148 * \returns less than zero if str1 is "less than" str2, greater than zero if
2149 * str1 is "greater than" str2, and zero if the strings match
2150 * exactly.
2151 *
2152 * \threadsafety It is safe to call this function from any thread.
2153 *
2154 * \since This function is available since SDL 3.0.0.
2155 */
2156extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
2157
2158/**
2159 * Compare two null-terminated UTF-8 strings, case-insensitively.
2160 *
2161 * This will work with Unicode strings, using a technique called
2162 * "case-folding" to handle the vast majority of case-sensitive human
2163 * languages regardless of system locale. It can deal with expanding values: a
2164 * German Eszett character can compare against two ASCII 's' chars and be
2165 * considered a match, for example. A notable exception: it does not handle
2166 * the Turkish 'i' character; human language is complicated!
2167 *
2168 * Since this handles Unicode, it expects the string to be well-formed UTF-8
2169 * and not a null-terminated string of arbitrary bytes. Bytes that are not
2170 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
2171 * CHARACTER), which is to say two strings of random bits may turn out to
2172 * match if they convert to the same amount of replacement characters.
2173 *
2174 * \param str1 the first string to compare. NULL is not permitted!
2175 * \param str2 the second string to compare. NULL is not permitted!
2176 * \returns less than zero if str1 is "less than" str2, greater than zero if
2177 * str1 is "greater than" str2, and zero if the strings match
2178 * exactly.
2179 *
2180 * \threadsafety It is safe to call this function from any thread.
2181 *
2182 * \since This function is available since SDL 3.0.0.
2183 */
2184extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
2185
2186
2187/**
2188 * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
2189 *
2190 * This will work with Unicode strings, using a technique called
2191 * "case-folding" to handle the vast majority of case-sensitive human
2192 * languages regardless of system locale. It can deal with expanding values: a
2193 * German Eszett character can compare against two ASCII 's' chars and be
2194 * considered a match, for example. A notable exception: it does not handle
2195 * the Turkish 'i' character; human language is complicated!
2196 *
2197 * Since this handles Unicode, it expects the string to be well-formed UTF-8
2198 * and not a null-terminated string of arbitrary bytes. Bytes that are not
2199 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
2200 * CHARACTER), which is to say two strings of random bits may turn out to
2201 * match if they convert to the same amount of replacement characters.
2202 *
2203 * Note that while this function is intended to be used with UTF-8, `maxlen`
2204 * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
2205 * UTF-8 sequence, it may convert a portion of the final character to one or
2206 * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
2207 * a buffer.
2208 *
2209 * `maxlen` specifies a maximum number of bytes to compare; if the strings
2210 * match to this number of bytes (or both have matched to a null-terminator
2211 * character before this number of bytes), they will be considered equal.
2212 *
2213 * \param str1 the first string to compare. NULL is not permitted!
2214 * \param str2 the second string to compare. NULL is not permitted!
2215 * \param maxlen the maximum number of bytes to compare.
2216 * \returns less than zero if str1 is "less than" str2, greater than zero if
2217 * str1 is "greater than" str2, and zero if the strings match
2218 * exactly.
2219 *
2220 * \threadsafety It is safe to call this function from any thread.
2221 *
2222 * \since This function is available since SDL 3.0.0.
2223 */
2224extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
2225
2226/**
2227 * Searches a string for the first occurence of any character contained in a
2228 * breakset, and returns a pointer from the string to that character.
2229 *
2230 * \param str The null-terminated string to be searched. Must not be NULL, and
2231 * must not overlap with `breakset`.
2232 * \param breakset A null-terminated string containing the list of characters
2233 * to look for. Must not be NULL, and must not overlap with
2234 * `str`.
2235 * \returns A pointer to the location, in str, of the first occurence of a
2236 * character present in the breakset, or NULL if none is found.
2237 *
2238 * \threadsafety It is safe to call this function from any thread.
2239 *
2240 * \since This function is available since SDL 3.0.0.
2241 */
2242extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
2243
2244/**
2245 * The Unicode REPLACEMENT CHARACTER codepoint.
2246 *
2247 * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
2248 * with encoding errors.
2249 *
2250 * This tends to render as something like a question mark in most places.
2251 *
2252 * \since This macro is available since SDL 3.0.0.
2253 *
2254 * \sa SDL_StepUTF8
2255 */
2256#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
2257
2258/**
2259 * Decode a UTF-8 string, one Unicode codepoint at a time.
2260 *
2261 * This will return the first Unicode codepoint in the UTF-8 encoded string in
2262 * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
2263 *
2264 * It will not access more than `*pslen` bytes from the string. `*pslen` will
2265 * be adjusted, as well, subtracting the number of bytes consumed.
2266 *
2267 * `pslen` is allowed to be NULL, in which case the string _must_ be
2268 * NULL-terminated, as the function will blindly read until it sees the NULL
2269 * char.
2270 *
2271 * if `*pslen` is zero, it assumes the end of string is reached and returns a
2272 * zero codepoint regardless of the contents of the string buffer.
2273 *
2274 * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
2275 * zero, it will not advance `*pstr` or `*pslen` at all.
2276 *
2277 * Generally this function is called in a loop until it returns zero,
2278 * adjusting its parameters each iteration.
2279 *
2280 * If an invalid UTF-8 sequence is encountered, this function returns
2281 * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
2282 * (which is to say, a multibyte sequence might produce several
2283 * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
2284 * UTF-8 sequence).
2285 *
2286 * Several things can generate invalid UTF-8 sequences, including overlong
2287 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
2288 * refer to
2289 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
2290 * for details.
2291 *
2292 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
2293 * \param pslen a pointer to the number of bytes in the string, to be read and
2294 * adjusted. NULL is allowed.
2295 * \returns the first Unicode codepoint in the string.
2296 *
2297 * \threadsafety It is safe to call this function from any thread.
2298 *
2299 * \since This function is available since SDL 3.0.0.
2300 */
2301extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
2302
2303/**
2304 * Convert a single Unicode codepoint to UTF-8.
2305 *
2306 * The buffer pointed to by `dst` must be at least 4 bytes long, as this
2307 * function may generate between 1 and 4 bytes of output.
2308 *
2309 * This function returns the first byte _after_ the newly-written UTF-8
2310 * sequence, which is useful for encoding multiple codepoints in a loop, or
2311 * knowing where to write a NULL-terminator character to end the string (in
2312 * either case, plan to have a buffer of _more_ than 4 bytes!).
2313 *
2314 * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
2315 * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
2316 * codepoint instead, and not set an error.
2317 *
2318 * If `dst` is NULL, this returns NULL immediately without writing to the
2319 * pointer and without setting an error.
2320 *
2321 * \param codepoint a Unicode codepoint to convert to UTF-8.
2322 * \param dst the location to write the encoded UTF-8. Must point to at least
2323 * 4 bytes!
2324 * \returns the first byte past the newly-written UTF-8 sequence.
2325 *
2326 * \threadsafety It is safe to call this function from any thread.
2327 *
2328 * \since This function is available since SDL 3.0.0.
2329 */
2330extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
2331
2332
2333extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
2334extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
2335extern 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);
2336extern 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);
2337extern 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);
2338extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3);
2339extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
2340extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
2341
2342/**
2343 * Seeds the pseudo-random number generator.
2344 *
2345 * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
2346 * of 'random' numbers.
2347 *
2348 * \param seed the value to use as a random number seed, or 0 to use
2349 * SDL_GetPerformanceCounter().
2350 *
2351 * \threadsafety This should be called on the same thread that calls
2352 * SDL_rand*()
2353 *
2354 * \since This function is available since SDL 3.0.0.
2355 *
2356 * \sa SDL_rand
2357 * \sa SDL_rand_bits
2358 * \sa SDL_randf
2359 */
2360extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
2361
2362/**
2363 * Generate a pseudo-random number less than n for positive n
2364 *
2365 * The method used is faster and of better quality than `rand() % n`. Odds are
2366 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
2367 * much worse as n gets bigger.
2368 *
2369 * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
2370 * 1..6
2371 *
2372 * If you want to generate a pseudo-random number in the full range of Sint32,
2373 * you should use: (Sint32)SDL_rand_bits()
2374 *
2375 * If you want reproducible output, be sure to initialize with SDL_srand()
2376 * first.
2377 *
2378 * There are no guarantees as to the quality of the random sequence produced,
2379 * and this should not be used for security (cryptography, passwords) or where
2380 * money is on the line (loot-boxes, casinos). There are many random number
2381 * libraries available with different characteristics and you should pick one
2382 * of those to meet any serious needs.
2383 *
2384 * \param n the number of possible outcomes. n must be positive.
2385 * \returns a random value in the range of [0 .. n-1].
2386 *
2387 * \threadsafety All calls should be made from a single thread
2388 *
2389 * \since This function is available since SDL 3.0.0.
2390 *
2391 * \sa SDL_srand
2392 * \sa SDL_randf
2393 */
2394extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
2395
2396/**
2397 * Generate a uniform pseudo-random floating point number less than 1.0
2398 *
2399 * If you want reproducible output, be sure to initialize with SDL_srand()
2400 * first.
2401 *
2402 * There are no guarantees as to the quality of the random sequence produced,
2403 * and this should not be used for security (cryptography, passwords) or where
2404 * money is on the line (loot-boxes, casinos). There are many random number
2405 * libraries available with different characteristics and you should pick one
2406 * of those to meet any serious needs.
2407 *
2408 * \returns a random value in the range of [0.0, 1.0).
2409 *
2410 * \threadsafety All calls should be made from a single thread
2411 *
2412 * \since This function is available since SDL 3.0.0.
2413 *
2414 * \sa SDL_srand
2415 * \sa SDL_rand
2416 */
2417extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
2418
2419/**
2420 * Generate 32 pseudo-random bits.
2421 *
2422 * You likely want to use SDL_rand() to get a psuedo-random number instead.
2423 *
2424 * There are no guarantees as to the quality of the random sequence produced,
2425 * and this should not be used for security (cryptography, passwords) or where
2426 * money is on the line (loot-boxes, casinos). There are many random number
2427 * libraries available with different characteristics and you should pick one
2428 * of those to meet any serious needs.
2429 *
2430 * \returns a random value in the range of [0-SDL_MAX_UINT32].
2431 *
2432 * \threadsafety All calls should be made from a single thread
2433 *
2434 * \since This function is available since SDL 3.0.0.
2435 *
2436 * \sa SDL_rand
2437 * \sa SDL_randf
2438 * \sa SDL_srand
2439 */
2440extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
2441
2442/**
2443 * Generate a pseudo-random number less than n for positive n
2444 *
2445 * The method used is faster and of better quality than `rand() % n`. Odds are
2446 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
2447 * much worse as n gets bigger.
2448 *
2449 * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
2450 * 0..5 to 1..6
2451 *
2452 * If you want to generate a pseudo-random number in the full range of Sint32,
2453 * you should use: (Sint32)SDL_rand_bits_r(state)
2454 *
2455 * There are no guarantees as to the quality of the random sequence produced,
2456 * and this should not be used for security (cryptography, passwords) or where
2457 * money is on the line (loot-boxes, casinos). There are many random number
2458 * libraries available with different characteristics and you should pick one
2459 * of those to meet any serious needs.
2460 *
2461 * \param state a pointer to the current random number state, this may not be
2462 * NULL.
2463 * \param n the number of possible outcomes. n must be positive.
2464 * \returns a random value in the range of [0 .. n-1].
2465 *
2466 * \threadsafety This function is thread-safe, as long as the state pointer
2467 * isn't shared between threads.
2468 *
2469 * \since This function is available since SDL 3.0.0.
2470 *
2471 * \sa SDL_rand
2472 * \sa SDL_rand_bits_r
2473 * \sa SDL_randf_r
2474 */
2475extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
2476
2477/**
2478 * Generate a uniform pseudo-random floating point number less than 1.0
2479 *
2480 * If you want reproducible output, be sure to initialize with SDL_srand()
2481 * first.
2482 *
2483 * There are no guarantees as to the quality of the random sequence produced,
2484 * and this should not be used for security (cryptography, passwords) or where
2485 * money is on the line (loot-boxes, casinos). There are many random number
2486 * libraries available with different characteristics and you should pick one
2487 * of those to meet any serious needs.
2488 *
2489 * \param state a pointer to the current random number state, this may not be
2490 * NULL.
2491 * \returns a random value in the range of [0.0, 1.0).
2492 *
2493 * \threadsafety This function is thread-safe, as long as the state pointer
2494 * isn't shared between threads.
2495 *
2496 * \since This function is available since SDL 3.0.0.
2497 *
2498 * \sa SDL_rand_bits_r
2499 * \sa SDL_rand_r
2500 * \sa SDL_randf
2501 */
2502extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
2503
2504/**
2505 * Generate 32 pseudo-random bits.
2506 *
2507 * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
2508 *
2509 * There are no guarantees as to the quality of the random sequence produced,
2510 * and this should not be used for security (cryptography, passwords) or where
2511 * money is on the line (loot-boxes, casinos). There are many random number
2512 * libraries available with different characteristics and you should pick one
2513 * of those to meet any serious needs.
2514 *
2515 * \param state a pointer to the current random number state, this may not be
2516 * NULL.
2517 * \returns a random value in the range of [0-SDL_MAX_UINT32].
2518 *
2519 * \threadsafety This function is thread-safe, as long as the state pointer
2520 * isn't shared between threads.
2521 *
2522 * \since This function is available since SDL 3.0.0.
2523 *
2524 * \sa SDL_rand_r
2525 * \sa SDL_randf_r
2526 */
2527extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
2528
2529
2530#ifndef SDL_PI_D
2531#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
2532#endif
2533#ifndef SDL_PI_F
2534#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
2535#endif
2536
2537/**
2538 * Compute the arc cosine of `x`.
2539 *
2540 * The definition of `y = acos(x)` is `x = cos(y)`.
2541 *
2542 * Domain: `-1 <= x <= 1`
2543 *
2544 * Range: `0 <= y <= Pi`
2545 *
2546 * This function operates on double-precision floating point values, use
2547 * SDL_acosf for single-precision floats.
2548 *
2549 * This function may use a different approximation across different versions,
2550 * platforms and configurations. i.e, it can return a different value given
2551 * the same input on different machines or operating systems, or if SDL is
2552 * updated.
2553 *
2554 * \param x floating point value.
2555 * \returns arc cosine of `x`, in radians.
2556 *
2557 * \threadsafety It is safe to call this function from any thread.
2558 *
2559 * \since This function is available since SDL 3.0.0.
2560 *
2561 * \sa SDL_acosf
2562 * \sa SDL_asin
2563 * \sa SDL_cos
2564 */
2565extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
2566
2567/**
2568 * Compute the arc cosine of `x`.
2569 *
2570 * The definition of `y = acos(x)` is `x = cos(y)`.
2571 *
2572 * Domain: `-1 <= x <= 1`
2573 *
2574 * Range: `0 <= y <= Pi`
2575 *
2576 * This function operates on single-precision floating point values, use
2577 * SDL_acos for double-precision floats.
2578 *
2579 * This function may use a different approximation across different versions,
2580 * platforms and configurations. i.e, it can return a different value given
2581 * the same input on different machines or operating systems, or if SDL is
2582 * updated.
2583 *
2584 * \param x floating point value.
2585 * \returns arc cosine of `x`, in radians.
2586 *
2587 * \threadsafety It is safe to call this function from any thread.
2588 *
2589 * \since This function is available since SDL 3.0.0.
2590 *
2591 * \sa SDL_acos
2592 * \sa SDL_asinf
2593 * \sa SDL_cosf
2594 */
2595extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
2596
2597/**
2598 * Compute the arc sine of `x`.
2599 *
2600 * The definition of `y = asin(x)` is `x = sin(y)`.
2601 *
2602 * Domain: `-1 <= x <= 1`
2603 *
2604 * Range: `-Pi/2 <= y <= Pi/2`
2605 *
2606 * This function operates on double-precision floating point values, use
2607 * SDL_asinf for single-precision floats.
2608 *
2609 * This function may use a different approximation across different versions,
2610 * platforms and configurations. i.e, it can return a different value given
2611 * the same input on different machines or operating systems, or if SDL is
2612 * updated.
2613 *
2614 * \param x floating point value.
2615 * \returns arc sine of `x`, in radians.
2616 *
2617 * \threadsafety It is safe to call this function from any thread.
2618 *
2619 * \since This function is available since SDL 3.0.0.
2620 *
2621 * \sa SDL_asinf
2622 * \sa SDL_acos
2623 * \sa SDL_sin
2624 */
2625extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
2626
2627/**
2628 * Compute the arc sine of `x`.
2629 *
2630 * The definition of `y = asin(x)` is `x = sin(y)`.
2631 *
2632 * Domain: `-1 <= x <= 1`
2633 *
2634 * Range: `-Pi/2 <= y <= Pi/2`
2635 *
2636 * This function operates on single-precision floating point values, use
2637 * SDL_asin for double-precision floats.
2638 *
2639 * This function may use a different approximation across different versions,
2640 * platforms and configurations. i.e, it can return a different value given
2641 * the same input on different machines or operating systems, or if SDL is
2642 * updated.
2643 *
2644 * \param x floating point value.
2645 * \returns arc sine of `x`, in radians.
2646 *
2647 * \threadsafety It is safe to call this function from any thread.
2648 *
2649 * \since This function is available since SDL 3.0.0.
2650 *
2651 * \sa SDL_asin
2652 * \sa SDL_acosf
2653 * \sa SDL_sinf
2654 */
2655extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
2656
2657/**
2658 * Compute the arc tangent of `x`.
2659 *
2660 * The definition of `y = atan(x)` is `x = tan(y)`.
2661 *
2662 * Domain: `-INF <= x <= INF`
2663 *
2664 * Range: `-Pi/2 <= y <= Pi/2`
2665 *
2666 * This function operates on double-precision floating point values, use
2667 * SDL_atanf for single-precision floats.
2668 *
2669 * To calculate the arc tangent of y / x, use SDL_atan2.
2670 *
2671 * This function may use a different approximation across different versions,
2672 * platforms and configurations. i.e, it can return a different value given
2673 * the same input on different machines or operating systems, or if SDL is
2674 * updated.
2675 *
2676 * \param x floating point value.
2677 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
2678 *
2679 * \threadsafety It is safe to call this function from any thread.
2680 *
2681 * \since This function is available since SDL 3.0.0.
2682 *
2683 * \sa SDL_atanf
2684 * \sa SDL_atan2
2685 * \sa SDL_tan
2686 */
2687extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
2688
2689/**
2690 * Compute the arc tangent of `x`.
2691 *
2692 * The definition of `y = atan(x)` is `x = tan(y)`.
2693 *
2694 * Domain: `-INF <= x <= INF`
2695 *
2696 * Range: `-Pi/2 <= y <= Pi/2`
2697 *
2698 * This function operates on single-precision floating point values, use
2699 * SDL_atan for dboule-precision floats.
2700 *
2701 * To calculate the arc tangent of y / x, use SDL_atan2f.
2702 *
2703 * This function may use a different approximation across different versions,
2704 * platforms and configurations. i.e, it can return a different value given
2705 * the same input on different machines or operating systems, or if SDL is
2706 * updated.
2707 *
2708 * \param x floating point value.
2709 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
2710 *
2711 * \threadsafety It is safe to call this function from any thread.
2712 *
2713 * \since This function is available since SDL 3.0.0.
2714 *
2715 * \sa SDL_atan
2716 * \sa SDL_atan2f
2717 * \sa SDL_tanf
2718 */
2719extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
2720
2721/**
2722 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
2723 * the result's quadrant.
2724 *
2725 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
2726 * of z is determined based on the signs of x and y.
2727 *
2728 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2729 *
2730 * Range: `-Pi/2 <= y <= Pi/2`
2731 *
2732 * This function operates on double-precision floating point values, use
2733 * SDL_atan2f for single-precision floats.
2734 *
2735 * To calculate the arc tangent of a single value, use SDL_atan.
2736 *
2737 * This function may use a different approximation across different versions,
2738 * platforms and configurations. i.e, it can return a different value given
2739 * the same input on different machines or operating systems, or if SDL is
2740 * updated.
2741 *
2742 * \param y floating point value of the numerator (y coordinate).
2743 * \param x floating point value of the denominator (x coordinate).
2744 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
2745 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
2746 *
2747 * \threadsafety It is safe to call this function from any thread.
2748 *
2749 * \since This function is available since SDL 3.0.0.
2750 *
2751 * \sa SDL_atan2f
2752 * \sa SDL_atan
2753 * \sa SDL_tan
2754 */
2755extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
2756
2757/**
2758 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
2759 * the result's quadrant.
2760 *
2761 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
2762 * of z is determined based on the signs of x and y.
2763 *
2764 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2765 *
2766 * Range: `-Pi/2 <= y <= Pi/2`
2767 *
2768 * This function operates on single-precision floating point values, use
2769 * SDL_atan2 for double-precision floats.
2770 *
2771 * To calculate the arc tangent of a single value, use SDL_atanf.
2772 *
2773 * This function may use a different approximation across different versions,
2774 * platforms and configurations. i.e, it can return a different value given
2775 * the same input on different machines or operating systems, or if SDL is
2776 * updated.
2777 *
2778 * \param y floating point value of the numerator (y coordinate).
2779 * \param x floating point value of the denominator (x coordinate).
2780 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
2781 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
2782 *
2783 * \threadsafety It is safe to call this function from any thread.
2784 *
2785 * \since This function is available since SDL 3.0.0.
2786 *
2787 * \sa SDL_atan2f
2788 * \sa SDL_atan
2789 * \sa SDL_tan
2790 */
2791extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
2792
2793/**
2794 * Compute the ceiling of `x`.
2795 *
2796 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
2797 * rounded up to the nearest integer.
2798 *
2799 * Domain: `-INF <= x <= INF`
2800 *
2801 * Range: `-INF <= y <= INF`, y integer
2802 *
2803 * This function operates on double-precision floating point values, use
2804 * SDL_ceilf for single-precision floats.
2805 *
2806 * \param x floating point value.
2807 * \returns the ceiling of `x`.
2808 *
2809 * \threadsafety It is safe to call this function from any thread.
2810 *
2811 * \since This function is available since SDL 3.0.0.
2812 *
2813 * \sa SDL_ceilf
2814 * \sa SDL_floor
2815 * \sa SDL_trunc
2816 * \sa SDL_round
2817 * \sa SDL_lround
2818 */
2819extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
2820
2821/**
2822 * Compute the ceiling of `x`.
2823 *
2824 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
2825 * rounded up to the nearest integer.
2826 *
2827 * Domain: `-INF <= x <= INF`
2828 *
2829 * Range: `-INF <= y <= INF`, y integer
2830 *
2831 * This function operates on single-precision floating point values, use
2832 * SDL_ceil for double-precision floats.
2833 *
2834 * \param x floating point value.
2835 * \returns the ceiling of `x`.
2836 *
2837 * \threadsafety It is safe to call this function from any thread.
2838 *
2839 * \since This function is available since SDL 3.0.0.
2840 *
2841 * \sa SDL_ceil
2842 * \sa SDL_floorf
2843 * \sa SDL_truncf
2844 * \sa SDL_roundf
2845 * \sa SDL_lroundf
2846 */
2847extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
2848
2849/**
2850 * Copy the sign of one floating-point value to another.
2851 *
2852 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
2853 *
2854 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
2855 *
2856 * Range: `-INF <= z <= INF`
2857 *
2858 * This function operates on double-precision floating point values, use
2859 * SDL_copysignf for single-precision floats.
2860 *
2861 * \param x floating point value to use as the magnitude.
2862 * \param y floating point value to use as the sign.
2863 * \returns the floating point value with the sign of y and the magnitude of
2864 * x.
2865 *
2866 * \threadsafety It is safe to call this function from any thread.
2867 *
2868 * \since This function is available since SDL 3.0.0.
2869 *
2870 * \sa SDL_copysignf
2871 * \sa SDL_fabs
2872 */
2873extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
2874
2875/**
2876 * Copy the sign of one floating-point value to another.
2877 *
2878 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
2879 *
2880 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
2881 *
2882 * Range: `-INF <= z <= INF`
2883 *
2884 * This function operates on single-precision floating point values, use
2885 * SDL_copysign for double-precision floats.
2886 *
2887 * \param x floating point value to use as the magnitude.
2888 * \param y floating point value to use as the sign.
2889 * \returns the floating point value with the sign of y and the magnitude of
2890 * x.
2891 *
2892 * \threadsafety It is safe to call this function from any thread.
2893 *
2894 * \since This function is available since SDL 3.0.0.
2895 *
2896 * \sa SDL_copysignf
2897 * \sa SDL_fabsf
2898 */
2899extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
2900
2901/**
2902 * Compute the cosine of `x`.
2903 *
2904 * Domain: `-INF <= x <= INF`
2905 *
2906 * Range: `-1 <= y <= 1`
2907 *
2908 * This function operates on double-precision floating point values, use
2909 * SDL_cosf for single-precision floats.
2910 *
2911 * This function may use a different approximation across different versions,
2912 * platforms and configurations. i.e, it can return a different value given
2913 * the same input on different machines or operating systems, or if SDL is
2914 * updated.
2915 *
2916 * \param x floating point value, in radians.
2917 * \returns cosine of `x`.
2918 *
2919 * \threadsafety It is safe to call this function from any thread.
2920 *
2921 * \since This function is available since SDL 3.0.0.
2922 *
2923 * \sa SDL_cosf
2924 * \sa SDL_acos
2925 * \sa SDL_sin
2926 */
2927extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
2928
2929/**
2930 * Compute the cosine of `x`.
2931 *
2932 * Domain: `-INF <= x <= INF`
2933 *
2934 * Range: `-1 <= y <= 1`
2935 *
2936 * This function operates on single-precision floating point values, use
2937 * SDL_cos for double-precision floats.
2938 *
2939 * This function may use a different approximation across different versions,
2940 * platforms and configurations. i.e, it can return a different value given
2941 * the same input on different machines or operating systems, or if SDL is
2942 * updated.
2943 *
2944 * \param x floating point value, in radians.
2945 * \returns cosine of `x`.
2946 *
2947 * \threadsafety It is safe to call this function from any thread.
2948 *
2949 * \since This function is available since SDL 3.0.0.
2950 *
2951 * \sa SDL_cos
2952 * \sa SDL_acosf
2953 * \sa SDL_sinf
2954 */
2955extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
2956
2957/**
2958 * Compute the exponential of `x`.
2959 *
2960 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
2961 * natural logarithm. The inverse is the natural logarithm, SDL_log.
2962 *
2963 * Domain: `-INF <= x <= INF`
2964 *
2965 * Range: `0 <= y <= INF`
2966 *
2967 * The output will overflow if `exp(x)` is too large to be represented.
2968 *
2969 * This function operates on double-precision floating point values, use
2970 * SDL_expf for single-precision floats.
2971 *
2972 * This function may use a different approximation across different versions,
2973 * platforms and configurations. i.e, it can return a different value given
2974 * the same input on different machines or operating systems, or if SDL is
2975 * updated.
2976 *
2977 * \param x floating point value.
2978 * \returns value of `e^x`.
2979 *
2980 * \threadsafety It is safe to call this function from any thread.
2981 *
2982 * \since This function is available since SDL 3.0.0.
2983 *
2984 * \sa SDL_expf
2985 * \sa SDL_log
2986 */
2987extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
2988
2989/**
2990 * Compute the exponential of `x`.
2991 *
2992 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
2993 * natural logarithm. The inverse is the natural logarithm, SDL_logf.
2994 *
2995 * Domain: `-INF <= x <= INF`
2996 *
2997 * Range: `0 <= y <= INF`
2998 *
2999 * The output will overflow if `exp(x)` is too large to be represented.
3000 *
3001 * This function operates on single-precision floating point values, use
3002 * SDL_exp for double-precision floats.
3003 *
3004 * This function may use a different approximation across different versions,
3005 * platforms and configurations. i.e, it can return a different value given
3006 * the same input on different machines or operating systems, or if SDL is
3007 * updated.
3008 *
3009 * \param x floating point value.
3010 * \returns value of `e^x`.
3011 *
3012 * \threadsafety It is safe to call this function from any thread.
3013 *
3014 * \since This function is available since SDL 3.0.0.
3015 *
3016 * \sa SDL_exp
3017 * \sa SDL_logf
3018 */
3019extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
3020
3021/**
3022 * Compute the absolute value of `x`
3023 *
3024 * Domain: `-INF <= x <= INF`
3025 *
3026 * Range: `0 <= y <= INF`
3027 *
3028 * This function operates on double-precision floating point values, use
3029 * SDL_copysignf for single-precision floats.
3030 *
3031 * \param x floating point value to use as the magnitude.
3032 * \returns the absolute value of `x`.
3033 *
3034 * \threadsafety It is safe to call this function from any thread.
3035 *
3036 * \since This function is available since SDL 3.0.0.
3037 *
3038 * \sa SDL_fabsf
3039 */
3040extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
3041
3042/**
3043 * Compute the absolute value of `x`
3044 *
3045 * Domain: `-INF <= x <= INF`
3046 *
3047 * Range: `0 <= y <= INF`
3048 *
3049 * This function operates on single-precision floating point values, use
3050 * SDL_copysignf for double-precision floats.
3051 *
3052 * \param x floating point value to use as the magnitude.
3053 * \returns the absolute value of `x`.
3054 *
3055 * \threadsafety It is safe to call this function from any thread.
3056 *
3057 * \since This function is available since SDL 3.0.0.
3058 *
3059 * \sa SDL_fabs
3060 */
3061extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
3062
3063/**
3064 * Compute the floor of `x`.
3065 *
3066 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
3067 * rounded down to the nearest integer.
3068 *
3069 * Domain: `-INF <= x <= INF`
3070 *
3071 * Range: `-INF <= y <= INF`, y integer
3072 *
3073 * This function operates on double-precision floating point values, use
3074 * SDL_floorf for single-precision floats.
3075 *
3076 * \param x floating point value.
3077 * \returns the floor of `x`.
3078 *
3079 * \threadsafety It is safe to call this function from any thread.
3080 *
3081 * \since This function is available since SDL 3.0.0.
3082 *
3083 * \sa SDL_floorf
3084 * \sa SDL_ceil
3085 * \sa SDL_trunc
3086 * \sa SDL_round
3087 * \sa SDL_lround
3088 */
3089extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
3090
3091/**
3092 * Compute the floor of `x`.
3093 *
3094 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
3095 * rounded down to the nearest integer.
3096 *
3097 * Domain: `-INF <= x <= INF`
3098 *
3099 * Range: `-INF <= y <= INF`, y integer
3100 *
3101 * This function operates on single-precision floating point values, use
3102 * SDL_floorf for double-precision floats.
3103 *
3104 * \param x floating point value.
3105 * \returns the floor of `x`.
3106 *
3107 * \threadsafety It is safe to call this function from any thread.
3108 *
3109 * \since This function is available since SDL 3.0.0.
3110 *
3111 * \sa SDL_floor
3112 * \sa SDL_ceilf
3113 * \sa SDL_truncf
3114 * \sa SDL_roundf
3115 * \sa SDL_lroundf
3116 */
3117extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
3118
3119/**
3120 * Truncate `x` to an integer.
3121 *
3122 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
3123 * the fractional part of `x`, leaving only the integer part.
3124 *
3125 * Domain: `-INF <= x <= INF`
3126 *
3127 * Range: `-INF <= y <= INF`, y integer
3128 *
3129 * This function operates on double-precision floating point values, use
3130 * SDL_truncf for single-precision floats.
3131 *
3132 * \param x floating point value.
3133 * \returns `x` truncated to an integer.
3134 *
3135 * \threadsafety It is safe to call this function from any thread.
3136 *
3137 * \since This function is available since SDL 3.0.0.
3138 *
3139 * \sa SDL_truncf
3140 * \sa SDL_fmod
3141 * \sa SDL_ceil
3142 * \sa SDL_floor
3143 * \sa SDL_round
3144 * \sa SDL_lround
3145 */
3146extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
3147
3148/**
3149 * Truncate `x` to an integer.
3150 *
3151 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
3152 * the fractional part of `x`, leaving only the integer part.
3153 *
3154 * Domain: `-INF <= x <= INF`
3155 *
3156 * Range: `-INF <= y <= INF`, y integer
3157 *
3158 * This function operates on single-precision floating point values, use
3159 * SDL_truncf for double-precision floats.
3160 *
3161 * \param x floating point value.
3162 * \returns `x` truncated to an integer.
3163 *
3164 * \threadsafety It is safe to call this function from any thread.
3165 *
3166 * \since This function is available since SDL 3.0.0.
3167 *
3168 * \sa SDL_trunc
3169 * \sa SDL_fmodf
3170 * \sa SDL_ceilf
3171 * \sa SDL_floorf
3172 * \sa SDL_roundf
3173 * \sa SDL_lroundf
3174 */
3175extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
3176
3177/**
3178 * Return the floating-point remainder of `x / y`
3179 *
3180 * Divides `x` by `y`, and returns the remainder.
3181 *
3182 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
3183 *
3184 * Range: `-y <= z <= y`
3185 *
3186 * This function operates on double-precision floating point values, use
3187 * SDL_fmodf for single-precision floats.
3188 *
3189 * \param x the numerator.
3190 * \param y the denominator. Must not be 0.
3191 * \returns the remainder of `x / y`.
3192 *
3193 * \threadsafety It is safe to call this function from any thread.
3194 *
3195 * \since This function is available since SDL 3.0.0.
3196 *
3197 * \sa SDL_fmodf
3198 * \sa SDL_modf
3199 * \sa SDL_trunc
3200 * \sa SDL_ceil
3201 * \sa SDL_floor
3202 * \sa SDL_round
3203 * \sa SDL_lround
3204 */
3205extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
3206
3207/**
3208 * Return the floating-point remainder of `x / y`
3209 *
3210 * Divides `x` by `y`, and returns the remainder.
3211 *
3212 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
3213 *
3214 * Range: `-y <= z <= y`
3215 *
3216 * This function operates on single-precision floating point values, use
3217 * SDL_fmod for single-precision floats.
3218 *
3219 * \param x the numerator.
3220 * \param y the denominator. Must not be 0.
3221 * \returns the remainder of `x / y`.
3222 *
3223 * \threadsafety It is safe to call this function from any thread.
3224 *
3225 * \since This function is available since SDL 3.0.0.
3226 *
3227 * \sa SDL_fmod
3228 * \sa SDL_truncf
3229 * \sa SDL_modff
3230 * \sa SDL_ceilf
3231 * \sa SDL_floorf
3232 * \sa SDL_roundf
3233 * \sa SDL_lroundf
3234 */
3235extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
3236
3237/**
3238 * Return whether the value is infinity.
3239 *
3240 * \param x double-precision floating point value.
3241 * \returns non-zero if the value is infinity, 0 otherwise.
3242 *
3243 * \threadsafety It is safe to call this function from any thread.
3244 *
3245 * \since This function is available since SDL 3.0.0.
3246 *
3247 * \sa SDL_isinff
3248 */
3249extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
3250
3251/**
3252 * Return whether the value is infinity.
3253 *
3254 * \param x floating point value.
3255 * \returns non-zero if the value is infinity, 0 otherwise.
3256 *
3257 * \threadsafety It is safe to call this function from any thread.
3258 *
3259 * \since This function is available since SDL 3.0.0.
3260 *
3261 * \sa SDL_isinf
3262 */
3263extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
3264
3265/**
3266 * Return whether the value is NaN.
3267 *
3268 * \param x double-precision floating point value.
3269 * \returns non-zero if the value is NaN, 0 otherwise.
3270 *
3271 * \threadsafety It is safe to call this function from any thread.
3272 *
3273 * \since This function is available since SDL 3.0.0.
3274 *
3275 * \sa SDL_isnanf
3276 */
3277extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
3278
3279/**
3280 * Return whether the value is NaN.
3281 *
3282 * \param x floating point value.
3283 * \returns non-zero if the value is NaN, 0 otherwise.
3284 *
3285 * \threadsafety It is safe to call this function from any thread.
3286 *
3287 * \since This function is available since SDL 3.0.0.
3288 *
3289 * \sa SDL_isnan
3290 */
3291extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
3292
3293/**
3294 * Compute the natural logarithm of `x`.
3295 *
3296 * Domain: `0 < x <= INF`
3297 *
3298 * Range: `-INF <= y <= INF`
3299 *
3300 * It is an error for `x` to be less than or equal to 0.
3301 *
3302 * This function operates on double-precision floating point values, use
3303 * SDL_logf for single-precision floats.
3304 *
3305 * This function may use a different approximation across different versions,
3306 * platforms and configurations. i.e, it can return a different value given
3307 * the same input on different machines or operating systems, or if SDL is
3308 * updated.
3309 *
3310 * \param x floating point value. Must be greater than 0.
3311 * \returns the natural logarithm of `x`.
3312 *
3313 * \threadsafety It is safe to call this function from any thread.
3314 *
3315 * \since This function is available since SDL 3.0.0.
3316 *
3317 * \sa SDL_logf
3318 * \sa SDL_log10
3319 * \sa SDL_exp
3320 */
3321extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
3322
3323/**
3324 * Compute the natural logarithm of `x`.
3325 *
3326 * Domain: `0 < x <= INF`
3327 *
3328 * Range: `-INF <= y <= INF`
3329 *
3330 * It is an error for `x` to be less than or equal to 0.
3331 *
3332 * This function operates on single-precision floating point values, use
3333 * SDL_log for double-precision floats.
3334 *
3335 * This function may use a different approximation across different versions,
3336 * platforms and configurations. i.e, it can return a different value given
3337 * the same input on different machines or operating systems, or if SDL is
3338 * updated.
3339 *
3340 * \param x floating point value. Must be greater than 0.
3341 * \returns the natural logarithm of `x`.
3342 *
3343 * \threadsafety It is safe to call this function from any thread.
3344 *
3345 * \since This function is available since SDL 3.0.0.
3346 *
3347 * \sa SDL_log
3348 * \sa SDL_expf
3349 */
3350extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
3351
3352/**
3353 * Compute the base-10 logarithm of `x`.
3354 *
3355 * Domain: `0 < x <= INF`
3356 *
3357 * Range: `-INF <= y <= INF`
3358 *
3359 * It is an error for `x` to be less than or equal to 0.
3360 *
3361 * This function operates on double-precision floating point values, use
3362 * SDL_log10f for single-precision floats.
3363 *
3364 * This function may use a different approximation across different versions,
3365 * platforms and configurations. i.e, it can return a different value given
3366 * the same input on different machines or operating systems, or if SDL is
3367 * updated.
3368 *
3369 * \param x floating point value. Must be greater than 0.
3370 * \returns the logarithm of `x`.
3371 *
3372 * \threadsafety It is safe to call this function from any thread.
3373 *
3374 * \since This function is available since SDL 3.0.0.
3375 *
3376 * \sa SDL_log10f
3377 * \sa SDL_log
3378 * \sa SDL_pow
3379 */
3380extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
3381
3382/**
3383 * Compute the base-10 logarithm of `x`.
3384 *
3385 * Domain: `0 < x <= INF`
3386 *
3387 * Range: `-INF <= y <= INF`
3388 *
3389 * It is an error for `x` to be less than or equal to 0.
3390 *
3391 * This function operates on single-precision floating point values, use
3392 * SDL_log10 for double-precision floats.
3393 *
3394 * This function may use a different approximation across different versions,
3395 * platforms and configurations. i.e, it can return a different value given
3396 * the same input on different machines or operating systems, or if SDL is
3397 * updated.
3398 *
3399 * \param x floating point value. Must be greater than 0.
3400 * \returns the logarithm of `x`.
3401 *
3402 * \threadsafety It is safe to call this function from any thread.
3403 *
3404 * \since This function is available since SDL 3.0.0.
3405 *
3406 * \sa SDL_log10
3407 * \sa SDL_logf
3408 * \sa SDL_powf
3409 */
3410extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
3411
3412/**
3413 * Split `x` into integer and fractional parts
3414 *
3415 * This function operates on double-precision floating point values, use
3416 * SDL_modff for single-precision floats.
3417 *
3418 * \param x floating point value.
3419 * \param y output pointer to store the integer part of `x`.
3420 * \returns the fractional part of `x`.
3421 *
3422 * \threadsafety It is safe to call this function from any thread.
3423 *
3424 * \since This function is available since SDL 3.0.0.
3425 *
3426 * \sa SDL_modff
3427 * \sa SDL_trunc
3428 * \sa SDL_fmod
3429 */
3430extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
3431
3432/**
3433 * Split `x` into integer and fractional parts
3434 *
3435 * This function operates on single-precision floating point values, use
3436 * SDL_modf for double-precision floats.
3437 *
3438 * \param x floating point value.
3439 * \param y output pointer to store the integer part of `x`.
3440 * \returns the fractional part of `x`.
3441 *
3442 * \threadsafety It is safe to call this function from any thread.
3443 *
3444 * \since This function is available since SDL 3.0.0.
3445 *
3446 * \sa SDL_modf
3447 * \sa SDL_truncf
3448 * \sa SDL_fmodf
3449 */
3450extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
3451
3452/**
3453 * Raise `x` to the power `y`
3454 *
3455 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
3456 *
3457 * Range: `-INF <= z <= INF`
3458 *
3459 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
3460 * instead.
3461 *
3462 * This function operates on double-precision floating point values, use
3463 * SDL_powf for single-precision floats.
3464 *
3465 * This function may use a different approximation across different versions,
3466 * platforms and configurations. i.e, it can return a different value given
3467 * the same input on different machines or operating systems, or if SDL is
3468 * updated.
3469 *
3470 * \param x the base.
3471 * \param y the exponent.
3472 * \returns `x` raised to the power `y`.
3473 *
3474 * \threadsafety It is safe to call this function from any thread.
3475 *
3476 * \since This function is available since SDL 3.0.0.
3477 *
3478 * \sa SDL_powf
3479 * \sa SDL_exp
3480 * \sa SDL_log
3481 */
3482extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
3483
3484/**
3485 * Raise `x` to the power `y`
3486 *
3487 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
3488 *
3489 * Range: `-INF <= z <= INF`
3490 *
3491 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
3492 * instead.
3493 *
3494 * This function operates on single-precision floating point values, use
3495 * SDL_powf for double-precision floats.
3496 *
3497 * This function may use a different approximation across different versions,
3498 * platforms and configurations. i.e, it can return a different value given
3499 * the same input on different machines or operating systems, or if SDL is
3500 * updated.
3501 *
3502 * \param x the base.
3503 * \param y the exponent.
3504 * \returns `x` raised to the power `y`.
3505 *
3506 * \threadsafety It is safe to call this function from any thread.
3507 *
3508 * \since This function is available since SDL 3.0.0.
3509 *
3510 * \sa SDL_pow
3511 * \sa SDL_expf
3512 * \sa SDL_logf
3513 */
3514extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
3515
3516/**
3517 * Round `x` to the nearest integer.
3518 *
3519 * Rounds `x` to the nearest integer. Values halfway between integers will be
3520 * rounded away from zero.
3521 *
3522 * Domain: `-INF <= x <= INF`
3523 *
3524 * Range: `-INF <= y <= INF`, y integer
3525 *
3526 * This function operates on double-precision floating point values, use
3527 * SDL_roundf for single-precision floats. To get the result as an integer
3528 * type, use SDL_lround.
3529 *
3530 * \param x floating point value.
3531 * \returns the nearest integer to `x`.
3532 *
3533 * \threadsafety It is safe to call this function from any thread.
3534 *
3535 * \since This function is available since SDL 3.0.0.
3536 *
3537 * \sa SDL_roundf
3538 * \sa SDL_lround
3539 * \sa SDL_floor
3540 * \sa SDL_ceil
3541 * \sa SDL_trunc
3542 */
3543extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
3544
3545/**
3546 * Round `x` to the nearest integer.
3547 *
3548 * Rounds `x` to the nearest integer. Values halfway between integers will be
3549 * rounded away from zero.
3550 *
3551 * Domain: `-INF <= x <= INF`
3552 *
3553 * Range: `-INF <= y <= INF`, y integer
3554 *
3555 * This function operates on double-precision floating point values, use
3556 * SDL_roundf for single-precision floats. To get the result as an integer
3557 * type, use SDL_lroundf.
3558 *
3559 * \param x floating point value.
3560 * \returns the nearest integer to `x`.
3561 *
3562 * \threadsafety It is safe to call this function from any thread.
3563 *
3564 * \since This function is available since SDL 3.0.0.
3565 *
3566 * \sa SDL_round
3567 * \sa SDL_lroundf
3568 * \sa SDL_floorf
3569 * \sa SDL_ceilf
3570 * \sa SDL_truncf
3571 */
3572extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
3573
3574/**
3575 * Round `x` to the nearest integer representable as a long
3576 *
3577 * Rounds `x` to the nearest integer. Values halfway between integers will be
3578 * rounded away from zero.
3579 *
3580 * Domain: `-INF <= x <= INF`
3581 *
3582 * Range: `MIN_LONG <= y <= MAX_LONG`
3583 *
3584 * This function operates on double-precision floating point values, use
3585 * SDL_lround for single-precision floats. To get the result as a
3586 * floating-point type, use SDL_round.
3587 *
3588 * \param x floating point value.
3589 * \returns the nearest integer to `x`.
3590 *
3591 * \threadsafety It is safe to call this function from any thread.
3592 *
3593 * \since This function is available since SDL 3.0.0.
3594 *
3595 * \sa SDL_lroundf
3596 * \sa SDL_round
3597 * \sa SDL_floor
3598 * \sa SDL_ceil
3599 * \sa SDL_trunc
3600 */
3601extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
3602
3603/**
3604 * Round `x` to the nearest integer representable as a long
3605 *
3606 * Rounds `x` to the nearest integer. Values halfway between integers will be
3607 * rounded away from zero.
3608 *
3609 * Domain: `-INF <= x <= INF`
3610 *
3611 * Range: `MIN_LONG <= y <= MAX_LONG`
3612 *
3613 * This function operates on single-precision floating point values, use
3614 * SDL_lroundf for double-precision floats. To get the result as a
3615 * floating-point type, use SDL_roundf,
3616 *
3617 * \param x floating point value.
3618 * \returns the nearest integer to `x`.
3619 *
3620 * \threadsafety It is safe to call this function from any thread.
3621 *
3622 * \since This function is available since SDL 3.0.0.
3623 *
3624 * \sa SDL_lround
3625 * \sa SDL_roundf
3626 * \sa SDL_floorf
3627 * \sa SDL_ceilf
3628 * \sa SDL_truncf
3629 */
3630extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
3631
3632/**
3633 * Scale `x` by an integer power of two.
3634 *
3635 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
3636 *
3637 * Domain: `-INF <= x <= INF`, `n` integer
3638 *
3639 * Range: `-INF <= y <= INF`
3640 *
3641 * This function operates on double-precision floating point values, use
3642 * SDL_scalbnf for single-precision floats.
3643 *
3644 * \param x floating point value to be scaled.
3645 * \param n integer exponent.
3646 * \returns `x * 2^n`.
3647 *
3648 * \threadsafety It is safe to call this function from any thread.
3649 *
3650 * \since This function is available since SDL 3.0.0.
3651 *
3652 * \sa SDL_scalbnf
3653 * \sa SDL_pow
3654 */
3655extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
3656
3657/**
3658 * Scale `x` by an integer power of two.
3659 *
3660 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
3661 *
3662 * Domain: `-INF <= x <= INF`, `n` integer
3663 *
3664 * Range: `-INF <= y <= INF`
3665 *
3666 * This function operates on single-precision floating point values, use
3667 * SDL_scalbn for double-precision floats.
3668 *
3669 * \param x floating point value to be scaled.
3670 * \param n integer exponent.
3671 * \returns `x * 2^n`.
3672 *
3673 * \threadsafety It is safe to call this function from any thread.
3674 *
3675 * \since This function is available since SDL 3.0.0.
3676 *
3677 * \sa SDL_scalbn
3678 * \sa SDL_powf
3679 */
3680extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
3681
3682/**
3683 * Compute the sine of `x`.
3684 *
3685 * Domain: `-INF <= x <= INF`
3686 *
3687 * Range: `-1 <= y <= 1`
3688 *
3689 * This function operates on double-precision floating point values, use
3690 * SDL_sinf for single-precision floats.
3691 *
3692 * This function may use a different approximation across different versions,
3693 * platforms and configurations. i.e, it can return a different value given
3694 * the same input on different machines or operating systems, or if SDL is
3695 * updated.
3696 *
3697 * \param x floating point value, in radians.
3698 * \returns sine of `x`.
3699 *
3700 * \threadsafety It is safe to call this function from any thread.
3701 *
3702 * \since This function is available since SDL 3.0.0.
3703 *
3704 * \sa SDL_sinf
3705 * \sa SDL_asin
3706 * \sa SDL_cos
3707 */
3708extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
3709
3710/**
3711 * Compute the sine of `x`.
3712 *
3713 * Domain: `-INF <= x <= INF`
3714 *
3715 * Range: `-1 <= y <= 1`
3716 *
3717 * This function operates on single-precision floating point values, use
3718 * SDL_sinf for double-precision floats.
3719 *
3720 * This function may use a different approximation across different versions,
3721 * platforms and configurations. i.e, it can return a different value given
3722 * the same input on different machines or operating systems, or if SDL is
3723 * updated.
3724 *
3725 * \param x floating point value, in radians.
3726 * \returns sine of `x`.
3727 *
3728 * \threadsafety It is safe to call this function from any thread.
3729 *
3730 * \since This function is available since SDL 3.0.0.
3731 *
3732 * \sa SDL_sin
3733 * \sa SDL_asinf
3734 * \sa SDL_cosf
3735 */
3736extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
3737
3738/**
3739 * Compute the square root of `x`.
3740 *
3741 * Domain: `0 <= x <= INF`
3742 *
3743 * Range: `0 <= y <= INF`
3744 *
3745 * This function operates on double-precision floating point values, use
3746 * SDL_sqrtf for single-precision floats.
3747 *
3748 * This function may use a different approximation across different versions,
3749 * platforms and configurations. i.e, it can return a different value given
3750 * the same input on different machines or operating systems, or if SDL is
3751 * updated.
3752 *
3753 * \param x floating point value. Must be greater than or equal to 0.
3754 * \returns square root of `x`.
3755 *
3756 * \threadsafety It is safe to call this function from any thread.
3757 *
3758 * \since This function is available since SDL 3.0.0.
3759 *
3760 * \sa SDL_sqrtf
3761 */
3762extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
3763
3764/**
3765 * Compute the square root of `x`.
3766 *
3767 * Domain: `0 <= x <= INF`
3768 *
3769 * Range: `0 <= y <= INF`
3770 *
3771 * This function operates on single-precision floating point values, use
3772 * SDL_sqrt for double-precision floats.
3773 *
3774 * This function may use a different approximation across different versions,
3775 * platforms and configurations. i.e, it can return a different value given
3776 * the same input on different machines or operating systems, or if SDL is
3777 * updated.
3778 *
3779 * \param x floating point value. Must be greater than or equal to 0.
3780 * \returns square root of `x`.
3781 *
3782 * \threadsafety It is safe to call this function from any thread.
3783 *
3784 * \since This function is available since SDL 3.0.0.
3785 *
3786 * \sa SDL_sqrt
3787 */
3788extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
3789
3790/**
3791 * Compute the tangent of `x`.
3792 *
3793 * Domain: `-INF <= x <= INF`
3794 *
3795 * Range: `-INF <= y <= INF`
3796 *
3797 * This function operates on double-precision floating point values, use
3798 * SDL_tanf for single-precision floats.
3799 *
3800 * This function may use a different approximation across different versions,
3801 * platforms and configurations. i.e, it can return a different value given
3802 * the same input on different machines or operating systems, or if SDL is
3803 * updated.
3804 *
3805 * \param x floating point value, in radians.
3806 * \returns tangent of `x`.
3807 *
3808 * \threadsafety It is safe to call this function from any thread.
3809 *
3810 * \since This function is available since SDL 3.0.0.
3811 *
3812 * \sa SDL_tanf
3813 * \sa SDL_sin
3814 * \sa SDL_cos
3815 * \sa SDL_atan
3816 * \sa SDL_atan2
3817 */
3818extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
3819
3820/**
3821 * Compute the tangent of `x`.
3822 *
3823 * Domain: `-INF <= x <= INF`
3824 *
3825 * Range: `-INF <= y <= INF`
3826 *
3827 * This function operates on single-precision floating point values, use
3828 * SDL_tanf for double-precision floats.
3829 *
3830 * This function may use a different approximation across different versions,
3831 * platforms and configurations. i.e, it can return a different value given
3832 * the same input on different machines or operating systems, or if SDL is
3833 * updated.
3834 *
3835 * \param x floating point value, in radians.
3836 * \returns tangent of `x`.
3837 *
3838 * \threadsafety It is safe to call this function from any thread.
3839 *
3840 * \since This function is available since SDL 3.0.0.
3841 *
3842 * \sa SDL_tan
3843 * \sa SDL_sinf
3844 * \sa SDL_cosf
3845 * \sa SDL_atanf
3846 * \sa SDL_atan2f
3847 */
3848extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
3849
3850/* The SDL implementation of iconv() returns these error codes */
3851#define SDL_ICONV_ERROR (size_t)-1
3852#define SDL_ICONV_E2BIG (size_t)-2
3853#define SDL_ICONV_EILSEQ (size_t)-3
3854#define SDL_ICONV_EINVAL (size_t)-4
3855
3856typedef struct SDL_iconv_data_t *SDL_iconv_t;
3857
3858/**
3859 * This function allocates a context for the specified character set
3860 * conversion.
3861 *
3862 * \param tocode The target character encoding, must not be NULL.
3863 * \param fromcode The source character encoding, must not be NULL.
3864 * \returns a handle that must be freed with SDL_iconv_close, or
3865 * SDL_ICONV_ERROR on failure.
3866 *
3867 * \since This function is available since SDL 3.0.0.
3868 *
3869 * \sa SDL_iconv
3870 * \sa SDL_iconv_close
3871 * \sa SDL_iconv_string
3872 */
3873extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
3874 const char *fromcode);
3875
3876/**
3877 * This function frees a context used for character set conversion.
3878 *
3879 * \param cd The character set conversion handle.
3880 * \returns 0 on success, or -1 on failure.
3881 *
3882 * \since This function is available since SDL 3.0.0.
3883 *
3884 * \sa SDL_iconv
3885 * \sa SDL_iconv_open
3886 * \sa SDL_iconv_string
3887 */
3888extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
3889
3890/**
3891 * This function converts text between encodings, reading from and writing to
3892 * a buffer.
3893 *
3894 * It returns the number of succesful conversions.
3895 *
3896 * \param cd The character set conversion context, created in
3897 * SDL_iconv_open().
3898 * \param inbuf Address of variable that points to the first character of the
3899 * input sequence.
3900 * \param inbytesleft The number of bytes in the input buffer.
3901 * \param outbuf Address of variable that points to the output buffer.
3902 * \param outbytesleft The number of bytes in the output buffer.
3903 * \returns the number of conversions on success, else SDL_ICONV_E2BIG is
3904 * returned when the output buffer is too small, or SDL_ICONV_EILSEQ
3905 * is returned when an invalid input sequence is encountered, or
3906 * SDL_ICONV_EINVAL is returned when an incomplete input sequence is
3907 * encountered.
3908 *
3909 * On exit:
3910 *
3911 * - inbuf will point to the beginning of the next multibyte
3912 * sequence. On error, this is the location of the problematic
3913 * input sequence. On success, this is the end of the input
3914 * sequence. - inbytesleft will be set to the number of bytes left
3915 * to convert, which will be 0 on success. - outbuf will point to
3916 * the location where to store the next output byte. - outbytesleft
3917 * will be set to the number of bytes left in the output buffer.
3918 *
3919 * \since This function is available since SDL 3.0.0.
3920 *
3921 * \sa SDL_iconv_open
3922 * \sa SDL_iconv_close
3923 * \sa SDL_iconv_string
3924 */
3925extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
3926 size_t *inbytesleft, char **outbuf,
3927 size_t *outbytesleft);
3928
3929/**
3930 * Helper function to convert a string's encoding in one call.
3931 *
3932 * This function converts a buffer or string between encodings in one pass.
3933 *
3934 * The string does not need to be NULL-terminated; this function operates on
3935 * the number of bytes specified in `inbytesleft` whether there is a NULL
3936 * character anywhere in the buffer.
3937 *
3938 * The returned string is owned by the caller, and should be passed to
3939 * SDL_free when no longer needed.
3940 *
3941 * \param tocode the character encoding of the output string. Examples are
3942 * "UTF-8", "UCS-4", etc.
3943 * \param fromcode the character encoding of data in `inbuf`.
3944 * \param inbuf the string to convert to a different encoding.
3945 * \param inbytesleft the size of the input string _in bytes_.
3946 * \returns a new string, converted to the new encoding, or NULL on error.
3947 *
3948 * \since This function is available since SDL 3.0.0.
3949 *
3950 * \sa SDL_iconv_open
3951 * \sa SDL_iconv_close
3952 * \sa SDL_iconv
3953 */
3954extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
3955 const char *fromcode,
3956 const char *inbuf,
3957 size_t inbytesleft);
3958
3959/* Some helper macros for common cases... */
3960#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
3961#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
3962#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
3963#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
3964
3965/* force builds using Clang's static analysis tools to use literal C runtime
3966 here, since there are possibly tests that are ineffective otherwise. */
3967#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
3968
3969/* The analyzer knows about strlcpy even when the system doesn't provide it */
3970#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
3971size_t strlcpy(char *dst, const char *src, size_t size);
3972#endif
3973
3974/* The analyzer knows about strlcat even when the system doesn't provide it */
3975#if !defined(HAVE_STRLCAT) && !defined(strlcat)
3976size_t strlcat(char *dst, const char *src, size_t size);
3977#endif
3978
3979#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
3980size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
3981#endif
3982
3983#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
3984size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
3985#endif
3986
3987/* Starting LLVM 16, the analyser errors out if these functions do not have
3988 their prototype defined (clang-diagnostic-implicit-function-declaration) */
3989#include <stdio.h>
3990#include <stdlib.h>
3991#include <strings.h>
3992
3993#define SDL_malloc malloc
3994#define SDL_calloc calloc
3995#define SDL_realloc realloc
3996#define SDL_free free
3997#ifndef SDL_memcpy
3998#define SDL_memcpy memcpy
3999#endif
4000#ifndef SDL_memmove
4001#define SDL_memmove memmove
4002#endif
4003#ifndef SDL_memset
4004#define SDL_memset memset
4005#endif
4006#define SDL_memcmp memcmp
4007#define SDL_strlcpy strlcpy
4008#define SDL_strlcat strlcat
4009#define SDL_strlen strlen
4010#define SDL_wcslen wcslen
4011#define SDL_wcslcpy wcslcpy
4012#define SDL_wcslcat wcslcat
4013#define SDL_strdup strdup
4014#define SDL_wcsdup wcsdup
4015#define SDL_strchr strchr
4016#define SDL_strrchr strrchr
4017#define SDL_strstr strstr
4018#define SDL_wcsstr wcsstr
4019#define SDL_strtok_r strtok_r
4020#define SDL_strcmp strcmp
4021#define SDL_wcscmp wcscmp
4022#define SDL_strncmp strncmp
4023#define SDL_wcsncmp wcsncmp
4024#define SDL_strcasecmp strcasecmp
4025#define SDL_strncasecmp strncasecmp
4026#define SDL_strpbrk strpbrk
4027#define SDL_sscanf sscanf
4028#define SDL_vsscanf vsscanf
4029#define SDL_snprintf snprintf
4030#define SDL_vsnprintf vsnprintf
4031#endif
4032
4033/**
4034 * Multiply two integers, checking for overflow.
4035 *
4036 * If `a * b` would overflow, return SDL_FALSE.
4037 *
4038 * Otherwise store `a * b` via ret and return SDL_TRUE.
4039 *
4040 * \param a the multiplicand.
4041 * \param b the multiplier.
4042 * \param ret on non-overflow output, stores the multiplication result. May
4043 * not be NULL.
4044 * \returns SDL_FALSE on overflow, SDL_TRUE if result is multiplied without
4045 * overflow.
4046 *
4047 * \threadsafety It is safe to call this function from any thread.
4048 *
4049 * \since This function is available since SDL 3.0.0.
4050 */
4051SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
4052{
4053 if (a != 0 && b > SDL_SIZE_MAX / a) {
4054 return SDL_FALSE;
4055 }
4056 *ret = a * b;
4057 return SDL_TRUE;
4058}
4059
4060#ifndef SDL_WIKI_DOCUMENTATION_SECTION
4061#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
4062/* This needs to be wrapped in an inline rather than being a direct #define,
4063 * because __builtin_mul_overflow() is type-generic, but we want to be
4064 * consistent about interpreting a and b as size_t. */
4065SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
4066{
4067 return (__builtin_mul_overflow(a, b, ret) == 0);
4068}
4069#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
4070#endif
4071#endif
4072
4073/**
4074 * Add two integers, checking for overflow.
4075 *
4076 * If `a + b` would overflow, return -1.
4077 *
4078 * Otherwise store `a + b` via ret and return 0.
4079 *
4080 * \param a the first addend.
4081 * \param b the second addend.
4082 * \param ret on non-overflow output, stores the addition result. May not be
4083 * NULL.
4084 * \returns SDL_FALSE on overflow, SDL_TRUE if result is added without
4085 * overflow.
4086 *
4087 * \threadsafety It is safe to call this function from any thread.
4088 *
4089 * \since This function is available since SDL 3.0.0.
4090 */
4091SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
4092{
4093 if (b > SDL_SIZE_MAX - a) {
4094 return SDL_FALSE;
4095 }
4096 *ret = a + b;
4097 return SDL_TRUE;
4098}
4099
4100#ifndef SDL_WIKI_DOCUMENTATION_SECTION
4101#if SDL_HAS_BUILTIN(__builtin_add_overflow)
4102/* This needs to be wrapped in an inline rather than being a direct #define,
4103 * the same as the call to __builtin_mul_overflow() above. */
4104SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
4105{
4106 return (__builtin_add_overflow(a, b, ret) == 0);
4107}
4108#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
4109#endif
4110#endif
4111
4112/* This is a generic function pointer which should be cast to the type you expect */
4113#ifdef SDL_WIKI_DOCUMENTATION_SECTION
4114
4115/**
4116 * A generic function pointer.
4117 *
4118 * In theory, generic function pointers should use this, instead of `void *`,
4119 * since some platforms could treat code addresses differently than data
4120 * addresses. Although in current times no popular platforms make this
4121 * distinction, it is more correct and portable to use the correct type for a
4122 * generic pointer.
4123 *
4124 * If for some reason you need to force this typedef to be an actual `void *`,
4125 * perhaps to work around a compiler or existing code, you can define
4126 * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
4127 *
4128 * \since This datatype is available since SDL 3.0.0.
4129 */
4130typedef void (*SDL_FunctionPointer)(void);
4131#elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
4132typedef void *SDL_FunctionPointer;
4133#else
4134typedef void (*SDL_FunctionPointer)(void);
4135#endif
4136
4137/* Ends C function definitions when using C++ */
4138#ifdef __cplusplus
4139}
4140#endif
4141#include <SDL3/SDL_close_code.h>
4142
4143#endif /* SDL_stdinc_h_ */
#define SDL_ALLOC_SIZE(p)
#define SDL_ALLOC_SIZE2(p1, p2)
#define SDL_FORCE_INLINE
#define SDL_MALLOC
void SDL_DestroyEnvironment(SDL_Environment *env)
SDL_Environment * SDL_CreateEnvironment(SDL_bool populated)
wchar_t * SDL_wcsdup(const wchar_t *wstr)
double SDL_sqrt(double x)
int SDL_atoi(const char *str)
#define SDL_memset
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
SDL_bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name)
unsigned long long SDL_strtoull(const char *str, char **endp, int base)
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)
const char * SDL_getenv_unsafe(const char *name)
int SDL_abs(int x)
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3)
char * SDL_ulltoa(unsigned long long value, char *str, int radix)
size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Sint32 SDL_rand_r(Uint64 *state, Sint32 n)
double SDL_tan(double x)
uint8_t Uint8
Definition SDL_stdinc.h:317
char * SDL_ltoa(long value, char *str, int radix)
#define SDL_TRUE
Definition SDL_stdinc.h:291
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)
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:791
int(* SDL_CompareCallback_r)(void *userdata, const void *a, const void *b)
#define SDL_OUT_BYTECAP(x)
Definition SDL_stdinc.h:530
char * SDL_strrchr(const char *str, int c)
#define SDL_SIZE_MAX
Definition SDL_stdinc.h:82
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
uint16_t Uint16
Definition SDL_stdinc.h:335
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
char ** SDL_GetEnvironmentVariables(SDL_Environment *env)
SDL_bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, SDL_bool overwrite)
float SDL_atanf(float x)
int SDL_isprint(int x)
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:544
int SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
void SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
char * SDL_itoa(int value, char *str, int radix)
float SDL_copysignf(float x, float y)
SDL_MALLOC char * SDL_strndup(const char *str, size_t maxlen)
char * SDL_strupr(char *str)
float SDL_acosf(float x)
size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
struct SDL_Environment SDL_Environment
Definition SDL_stdinc.h:994
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:526
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)
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)
#define SDL_FALSE
Definition SDL_stdinc.h:282
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)
SDL_bool SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
double SDL_acos(double x)
wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
char * SDL_lltoa(long long value, char *str, int radix)
int(* SDL_CompareCallback)(const void *a, const void *b)
float SDL_sinf(float x)
int SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...) SDL_WPRINTF_VARARG_FUNC(3)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3)
#define SDL_SCANF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:546
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:533
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:344
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:527
double SDL_scalbn(double x, int n)
char * SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
int SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
double SDL_fmod(double x, double y)
double SDL_fabs(double x)
int SDL_ispunct(int x)
float SDL_truncf(float x)
char * SDL_strpbrk(const char *str, const char *breakset)
double SDL_log10(double x)
SDL_MALLOC size_t size
Definition SDL_stdinc.h:717
float SDL_expf(float x)
#define SDL_WPRINTF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:548
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_isinf(double x)
float SDL_log10f(float x)
void(* SDL_free_func)(void *mem)
Definition SDL_stdinc.h:851
int SDL_memcmp(const void *s1, const void *s2, size_t len)
const char * SDL_getenv(const char *name)
float SDL_roundf(float x)
double SDL_strtod(const char *str, char **endp)
long SDL_lroundf(float x)
char * SDL_ultoa(unsigned long value, char *str, int radix)
double SDL_atof(const char *str)
const char * SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name)
char * SDL_strnstr(const char *haystack, const char *needle, size_t maxlen)
Uint32 SDL_rand_bits(void)
size_t SDL_wcsnlen(const wchar_t *wstr, size_t maxlen)
unsigned long SDL_strtoul(const char *str, char **endp, int base)
float SDL_floorf(float x)
int SDL_strcmp(const char *str1, const char *str2)
double SDL_cos(double x)
#define SDL_PRINTF_FORMAT_STRING
Definition SDL_stdinc.h:532
float SDL_fmodf(float x, float y)
void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
SDL_MALLOC void * SDL_malloc(size_t size)
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:543
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:567
float SDL_atan2f(float y, float x)
int SDL_isupper(int x)
int SDL_unsetenv_unsafe(const char *name)
long SDL_wcstol(const wchar_t *str, wchar_t **endp, int base)
float SDL_fabsf(float x)
uint64_t Uint64
Definition SDL_stdinc.h:375
long long SDL_strtoll(const char *str, char **endp, int base)
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
SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
void SDL_free(void *mem)
SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
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:812
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:545
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:353
float SDL_powf(float x, float y)
SDL_Environment * SDL_GetEnvironment(void)
size_t SDL_strlen(const char *str)
#define SDL_memmove
Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len)
bool SDL_bool
Definition SDL_stdinc.h:301
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)
void *(* SDL_realloc_func)(void *mem, size_t size)
Definition SDL_stdinc.h:833
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:528
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:547
double SDL_trunc(double x)
int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)

◆ SDL_const_cast

#define SDL_const_cast (   type,
  expression 
)    ((type)(expression))

Definition at line 203 of file SDL_stdinc.h.

◆ SDL_copyp

#define SDL_copyp (   dst,
  src 
)
Value:
{ SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
SDL_memcpy((dst), (src), sizeof(*(src)))
#define SDL_copyp(dst, src)

Definition at line 1490 of file SDL_stdinc.h.

1491 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
1492 SDL_memcpy((dst), (src), sizeof(*(src)))

◆ SDL_FALSE

#define SDL_FALSE   false

A boolean false.

Since
This macro is available since SDL 3.0.0.
See also
SDL_bool

Definition at line 282 of file SDL_stdinc.h.

◆ SDL_FLT_EPSILON

#define SDL_FLT_EPSILON   1.1920928955078125e-07F /* 0x0.000002p0 */

Epsilon constant, used for comparing floating-point numbers.

Equals by default to platform-defined FLT_EPSILON, or 1.1920928955078125e-07F if that's not available.

Since
This macro is available since SDL 3.0.0.

Definition at line 415 of file SDL_stdinc.h.

◆ SDL_FOURCC

#define SDL_FOURCC (   A,
  B,
  C,
 
)
Value:
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:202

Define a four character code as a Uint32.

Parameters
Athe first ASCII character.
Bthe second ASCII character.
Cthe third ASCII character.
Dthe fourth ASCII character.
Returns
the four characters converted into a Uint32, one character per-byte.

\threadsafety It is safe to call this macro from any thread.

Since
This macro is available since SDL 3.0.0.

Definition at line 222 of file SDL_stdinc.h.

◆ SDL_HAS_BUILTIN

#define SDL_HAS_BUILTIN (   x)    0

Check if the compiler supports a given builtin. Supported by virtually all clang versions and recent gcc. Use this instead of checking the clang version if possible.

Definition at line 93 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Definition at line 3852 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Definition at line 3853 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Definition at line 3854 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Definition at line 3851 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_locale

#define SDL_iconv_utf8_locale (   S)    SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)

Definition at line 3960 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs2

#define SDL_iconv_utf8_ucs2 (   S)    (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)

Definition at line 3961 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs4

#define SDL_iconv_utf8_ucs4 (   S)    (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)

Definition at line 3962 of file SDL_stdinc.h.

◆ SDL_iconv_wchar_utf8

#define SDL_iconv_wchar_utf8 (   S)    SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))

Definition at line 3963 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

Definition at line 526 of file SDL_stdinc.h.

◆ SDL_INIT_INTERFACE

#define SDL_INIT_INTERFACE (   iface)
Value:
do { \
SDL_zerop(iface); \
(iface)->version = sizeof(*(iface)); \
} while (0)

A macro to initialize an SDL interface.

This macro will initialize an SDL interface structure and should be called before you fill out the fields with your implementation.

You can use it like this:

// Fill in the interface function pointers with your implementation
iface.seek = ...
stream = SDL_OpenIO(&iface, NULL);
#define NULL
SDL_IOStream * SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
#define SDL_INIT_INTERFACE(iface)
Definition SDL_stdinc.h:658
Sint64(* seek)(void *userdata, Sint64 offset, SDL_IOWhence whence)

If you are using designated initializers, you can use the size of the interface as the version, e.g.

.version = sizeof(iface),
.seek = ...
};
stream = SDL_OpenIO(&iface, NULL);

\threadsafety It is safe to call this macro from any thread.

Since
This macro is available since SDL 3.0.0.
See also
SDL_IOStreamInterface
SDL_StorageInterface
SDL_VirtualJoystickDesc

Definition at line 658 of file SDL_stdinc.h.

659 { \
660 SDL_zerop(iface); \
661 (iface)->version = sizeof(*(iface)); \
662 } while (0)

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 527 of file SDL_stdinc.h.

◆ SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string with encoding errors.

This tends to render as something like a question mark in most places.

Since
This macro is available since SDL 3.0.0.
See also
SDL_StepUTF8

Definition at line 2256 of file SDL_stdinc.h.

◆ SDL_max

#define SDL_max (   x,
 
)    (((x) > (y)) ? (x) : (y))

Definition at line 1220 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

#define SDL_MAX_SINT16   ((Sint16)0x7FFF) /* 32767 */

Definition at line 327 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

#define SDL_MAX_SINT32   ((Sint32)0x7FFFFFFF) /* 2147483647 */

Definition at line 345 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

#define SDL_MAX_SINT64   SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */

Definition at line 365 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

#define SDL_MAX_SINT8   ((Sint8)0x7F) /* 127 */

Definition at line 309 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 393 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

#define SDL_MAX_UINT16   ((Uint16)0xFFFF) /* 65535 */

Definition at line 336 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

#define SDL_MAX_UINT32   ((Uint32)0xFFFFFFFFu) /* 4294967295 */

Definition at line 354 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

#define SDL_MAX_UINT64   SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */

Definition at line 376 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

#define SDL_MAX_UINT8   ((Uint8)0xFF) /* 255 */

Definition at line 318 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 1487 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 1518 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 1529 of file SDL_stdinc.h.

◆ SDL_min

#define SDL_min (   x,
 
)    (((x) < (y)) ? (x) : (y))

Definition at line 1219 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

#define SDL_MIN_SINT16   ((Sint16)(~0x7FFF)) /* -32768 */

Definition at line 328 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

#define SDL_MIN_SINT32   ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */

Definition at line 346 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

#define SDL_MIN_SINT64   ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */

Definition at line 366 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

#define SDL_MIN_SINT8   ((Sint8)(~0x7F)) /* -128 */

Definition at line 310 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 394 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

#define SDL_MIN_UINT16   ((Uint16)0x0000) /* 0 */

Definition at line 337 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

#define SDL_MIN_UINT32   ((Uint32)0x00000000) /* 0 */

Definition at line 355 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

#define SDL_MIN_UINT64   SDL_UINT64_C(0x0000000000000000) /* 0 */

Definition at line 377 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

#define SDL_MIN_UINT8   ((Uint8)0x00) /* 0 */

Definition at line 319 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 530 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 529 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 531 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 528 of file SDL_stdinc.h.

◆ SDL_PI_D

#define SDL_PI_D   3.141592653589793238462643383279502884

pi (double)

Definition at line 2531 of file SDL_stdinc.h.

◆ SDL_PI_F

#define SDL_PI_F   3.141592653589793238462643383279502884F

pi (float)

Definition at line 2534 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 532 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 543 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 544 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 471 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 431 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 478 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 442 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 485 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 492 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 453 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 464 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

#define SDL_reinterpret_cast (   type,
  expression 
)    ((type)(expression))

Definition at line 201 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 533 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 545 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 546 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 266 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 82 of file SDL_stdinc.h.

◆ SDL_stack_alloc

#define SDL_stack_alloc (   type,
  count 
)    (type*)alloca(sizeof(type)*(count))

Definition at line 666 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 667 of file SDL_stdinc.h.

◆ SDL_static_cast

#define SDL_static_cast (   type,
  expression 
)    ((type)(expression))

Definition at line 202 of file SDL_stdinc.h.

◆ SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG (   arg)    #arg

Macro useful for building other macros with strings in them.

For example:

#define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
Since
This macro is available since SDL 3.0.0.

Definition at line 118 of file SDL_stdinc.h.

◆ SDL_TRUE

#define SDL_TRUE   true

A boolean true.

Since
This macro is available since SDL 3.0.0.
See also
SDL_bool

Definition at line 291 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 267 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 547 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 548 of file SDL_stdinc.h.

◆ SDL_zero

#define SDL_zero (   x)    SDL_memset(&(x), 0, sizeof((x)))

Definition at line 1532 of file SDL_stdinc.h.

◆ SDL_zeroa

#define SDL_zeroa (   x)    SDL_memset((x), 0, sizeof((x)))

Definition at line 1534 of file SDL_stdinc.h.

◆ SDL_zerop

#define SDL_zerop (   x)    SDL_memset((x), 0, sizeof(*(x)))

Definition at line 1533 of file SDL_stdinc.h.

Typedef Documentation

◆ SDL_bool

typedef bool SDL_bool

A boolean type: true or false.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_TRUE
SDL_FALSE

Definition at line 301 of file SDL_stdinc.h.

◆ SDL_calloc_func

typedef void *(* SDL_calloc_func) (size_t nmemb, size_t size)

A callback used to implement SDL_calloc().

SDL will always ensure that the passed nmemb and size are both greater than 0.

Parameters
nmembthe number of elements in the array.
sizethe size of each element of the array.
Returns
a pointer to the allocated array, or NULL if allocation failed.

\threadsafety It should be safe to call this callback from any thread.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_calloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 812 of file SDL_stdinc.h.

◆ SDL_CompareCallback

typedef int(* SDL_CompareCallback) (const void *a, const void *b)

Definition at line 1208 of file SDL_stdinc.h.

◆ SDL_CompareCallback_r

typedef int(* SDL_CompareCallback_r) (void *userdata, const void *a, const void *b)

Definition at line 1212 of file SDL_stdinc.h.

◆ SDL_Environment

A thread-safe set of environment variables

Since
This struct is available since SDL 3.0.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable
SDL_DestroyEnvironment

Definition at line 994 of file SDL_stdinc.h.

◆ SDL_free_func

typedef void(* SDL_free_func) (void *mem)

A callback used to implement SDL_free().

SDL will always ensure that the passed mem is a non-NULL pointer.

Parameters
mema pointer to allocated memory.

\threadsafety It should be safe to call this callback from any thread.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_free
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 851 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 4134 of file SDL_stdinc.h.

◆ SDL_iconv_t

typedef struct SDL_iconv_data_t* SDL_iconv_t

Definition at line 3856 of file SDL_stdinc.h.

◆ SDL_malloc_func

typedef void *(* SDL_malloc_func) (size_t size)

A callback used to implement SDL_malloc().

SDL will always ensure that the passed size is greater than 0.

Parameters
sizethe size to allocate.
Returns
a pointer to the allocated memory, or NULL if allocation failed.

\threadsafety It should be safe to call this callback from any thread.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_malloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 791 of file SDL_stdinc.h.

◆ SDL_realloc_func

typedef void *(* SDL_realloc_func) (void *mem, size_t size)

A callback used to implement SDL_realloc().

SDL will always ensure that the passed size is greater than 0.

Parameters
mema pointer to allocated memory to reallocate, or NULL.
sizethe new size of the memory.
Returns
a pointer to the newly allocated memory, or NULL if allocation failed.

\threadsafety It should be safe to call this callback from any thread.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_realloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 833 of file SDL_stdinc.h.

◆ SDL_Time

typedef Sint64 SDL_Time

SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970).

They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS() and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with SDL_TimeToWindows() and SDL_TimeFromWindows().

Since
This macro is available since SDL 3.0.0.
See also
SDL_MAX_SINT64
SDL_MIN_SINT64

Definition at line 392 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 326 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 344 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

Since
This macro is available since SDL 3.0.0.
See also
SDL_SINT64_C

Definition at line 364 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 308 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 335 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 353 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

Since
This macro is available since SDL 3.0.0.
See also
SDL_UINT64_C

Definition at line 375 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 317 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

CategoryStdinc

This is a general header that includes C language support. It implements a subset of the C runtime APIs, but with an SDL_ prefix. For most common use cases, these should behave the same way as their C runtime equivalents, but they may differ in how or whether they handle certain edge cases. When in doubt, consult the documentation for details.

◆ SDL_abs()

int SDL_abs ( int  x)
extern

◆ SDL_acos()

double SDL_acos ( double  x)
extern

Compute the arc cosine of x.

The definition of y = acos(x) is x = cos(y).

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

This function operates on double-precision floating point values, use SDL_acosf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
arc cosine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_acosf
SDL_asin
SDL_cos

◆ SDL_acosf()

float SDL_acosf ( float  x)
extern

Compute the arc cosine of x.

The definition of y = acos(x) is x = cos(y).

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

This function operates on single-precision floating point values, use SDL_acos for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
arc cosine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_acos
SDL_asinf
SDL_cosf

◆ SDL_aligned_alloc()

SDL_MALLOC void * SDL_aligned_alloc ( size_t  alignment,
size_t  size 
)
extern

Allocate memory aligned to a specific alignment.

The memory returned by this function must be freed with SDL_aligned_free(), not SDL_free().

If alignment is less than the size of void *, it will be increased to match that.

The returned memory address will be a multiple of the alignment value, and the size of the memory allocated will be a multiple of the alignment value.

Parameters
alignmentthe alignment of the memory.
sizethe size to allocate.
Returns
a pointer to the aligned memory, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_aligned_free

◆ SDL_aligned_free()

void SDL_aligned_free ( void *  mem)
extern

Free memory allocated by SDL_aligned_alloc().

The pointer is no longer valid after this call and cannot be dereferenced anymore.

If mem is NULL, this function does nothing.

Parameters
mema pointer previously returned by SDL_aligned_alloc(), or NULL.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_aligned_alloc

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( )
extern

Change the size of allocated memory.

The memory returned by this function must be freed with SDL_free().

If size is 0, it will be set to 1. Note that this is unlike some other C runtime realloc implementations, which may treat realloc(mem, 0) the same way as free(mem).

If mem is NULL, the behavior of this function is equivalent to SDL_malloc(). Otherwise, the function can have one of three possible outcomes:

  • If it returns the same pointer as mem, it means that mem was resized in place without freeing.
  • If it returns a different non-NULL pointer, it means that mem was freed and cannot be dereferenced anymore.
  • If it returns NULL (indicating failure), then mem will remain valid and must still be freed with SDL_free().
Parameters
mema pointer to allocated memory to reallocate, or NULL.
sizethe new size of the memory.
Returns
a pointer to the newly allocated memory, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_free
SDL_malloc
SDL_calloc

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( ,
 
)
extern

Allocate a zero-initialized array.

The memory returned by this function must be freed with SDL_free().

If either of nmemb or size is 0, they will both be set to 1.

Parameters
nmembthe number of elements in the array.
sizethe size of each element of the array.
Returns
a pointer to the allocated array, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_free
SDL_malloc
SDL_realloc

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

The definition of y = asin(x) is x = sin(y).

Domain: -1 <= x <= 1

Range: -Pi/2 <= y <= Pi/2

This function operates on double-precision floating point values, use SDL_asinf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
arc sine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_asinf
SDL_acos
SDL_sin

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

The definition of y = asin(x) is x = sin(y).

Domain: -1 <= x <= 1

Range: -Pi/2 <= y <= Pi/2

This function operates on single-precision floating point values, use SDL_asin for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
arc sine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_asin
SDL_acosf
SDL_sinf

◆ SDL_asprintf()

int SDL_asprintf ( char **  strp,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
  ... 
)
extern

◆ SDL_atan()

double SDL_atan ( double  x)
extern

Compute the arc tangent of x.

The definition of y = atan(x) is x = tan(y).

Domain: -INF <= x <= INF

Range: -Pi/2 <= y <= Pi/2

This function operates on double-precision floating point values, use SDL_atanf for single-precision floats.

To calculate the arc tangent of y / x, use SDL_atan2.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
arc tangent of of x in radians, or 0 if x = 0.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atanf
SDL_atan2
SDL_tan

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

Compute the arc tangent of y / x, using the signs of x and y to adjust the result's quadrant.

The definition of z = atan2(x, y) is y = x tan(z), where the quadrant of z is determined based on the signs of x and y.

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -Pi/2 <= y <= Pi/2

This function operates on double-precision floating point values, use SDL_atan2f for single-precision floats.

To calculate the arc tangent of a single value, use SDL_atan.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
yfloating point value of the numerator (y coordinate).
xfloating point value of the denominator (x coordinate).
Returns
arc tangent of of y / x in radians, or, if x = 0, either -Pi/2, 0, or Pi/2, depending on the value of y.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atan2f
SDL_atan
SDL_tan

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

Compute the arc tangent of y / x, using the signs of x and y to adjust the result's quadrant.

The definition of z = atan2(x, y) is y = x tan(z), where the quadrant of z is determined based on the signs of x and y.

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -Pi/2 <= y <= Pi/2

This function operates on single-precision floating point values, use SDL_atan2 for double-precision floats.

To calculate the arc tangent of a single value, use SDL_atanf.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
yfloating point value of the numerator (y coordinate).
xfloating point value of the denominator (x coordinate).
Returns
arc tangent of of y / x in radians, or, if x = 0, either -Pi/2, 0, or Pi/2, depending on the value of y.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atan2f
SDL_atan
SDL_tan

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

The definition of y = atan(x) is x = tan(y).

Domain: -INF <= x <= INF

Range: -Pi/2 <= y <= Pi/2

This function operates on single-precision floating point values, use SDL_atan for dboule-precision floats.

To calculate the arc tangent of y / x, use SDL_atan2f.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
arc tangent of of x in radians, or 0 if x = 0.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atan
SDL_atan2f
SDL_tanf

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

The result of calling SDL_atof(str) is equivalent to SDL_strtod(str, NULL).

Parameters
strThe null-terminated string to read. Must not be NULL.
Returns
The parsed double.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atoi
SDL_strtol
SDL_strtoul
SDL_strtoll
SDL_strtoull
SDL_strtod

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

The result of calling SDL_atoi(str) is equivalent to (int)SDL_strtol(str, NULL, 10).

Parameters
strThe null-terminated string to read. Must not be NULL.
Returns
The parsed int.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atof
SDL_strtol
SDL_strtoul
SDL_strtoll
SDL_strtoull
SDL_strtod
SDL_itoa

◆ SDL_bsearch()

void * SDL_bsearch ( const void *  key,
const void *  base,
size_t  nmemb,
size_t  size,
SDL_CompareCallback  compare 
)
extern

◆ SDL_bsearch_r()

void * SDL_bsearch_r ( const void *  key,
const void *  base,
size_t  nmemb,
size_t  size,
SDL_CompareCallback_r  compare,
void *  userdata 
)
extern

◆ SDL_ceil()

double SDL_ceil ( double  x)
extern

Compute the ceiling of x.

The ceiling of x is the smallest integer y such that y > x, i.e x rounded up to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_ceilf for single-precision floats.

Parameters
xfloating point value.
Returns
the ceiling of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_ceilf
SDL_floor
SDL_trunc
SDL_round
SDL_lround

◆ SDL_ceilf()

float SDL_ceilf ( float  x)
extern

Compute the ceiling of x.

The ceiling of x is the smallest integer y such that y > x, i.e x rounded up to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_ceil for double-precision floats.

Parameters
xfloating point value.
Returns
the ceiling of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_ceil
SDL_floorf
SDL_truncf
SDL_roundf
SDL_lroundf

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)
extern

Copy the sign of one floating-point value to another.

The definition of copysign is that copysign(x, y) = abs(x) * sign(y).

Domain: -INF <= x <= INF, -INF <= y <= f

Range: -INF <= z <= INF

This function operates on double-precision floating point values, use SDL_copysignf for single-precision floats.

Parameters
xfloating point value to use as the magnitude.
yfloating point value to use as the sign.
Returns
the floating point value with the sign of y and the magnitude of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_copysignf
SDL_fabs

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)
extern

Copy the sign of one floating-point value to another.

The definition of copysign is that copysign(x, y) = abs(x) * sign(y).

Domain: -INF <= x <= INF, -INF <= y <= f

Range: -INF <= z <= INF

This function operates on single-precision floating point values, use SDL_copysign for double-precision floats.

Parameters
xfloating point value to use as the magnitude.
yfloating point value to use as the sign.
Returns
the floating point value with the sign of y and the magnitude of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_copysignf
SDL_fabsf

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on double-precision floating point values, use SDL_cosf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
cosine of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_cosf
SDL_acos
SDL_sin

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on single-precision floating point values, use SDL_cos for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
cosine of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_cos
SDL_acosf
SDL_sinf

◆ SDL_crc16()

Uint16 SDL_crc16 ( Uint16  crc,
const void *  data,
size_t  len 
)
extern

◆ SDL_crc32()

Uint32 SDL_crc32 ( Uint32  crc,
const void *  data,
size_t  len 
)
extern

◆ SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment ( SDL_bool  populated)
extern

Create a set of environment variables

Parameters
populatedSDL_TRUE to initialize it from the C runtime environment, SDL_FALSE to create an empty environment.
Returns
a pointer to the new environment or NULL on failure; call SDL_GetError() for more information.

\threadsafety If populated is SDL_FALSE, it is safe to call this function from any thread, otherwise it is safe if no other threads are calling setenv() or unsetenv()

Since
This function is available since SDL 3.0.0.
See also
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable
SDL_DestroyEnvironment

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

\threadsafety It is safe to call this function from any thread, as long as the environment is no longer in use.

Since
This function is available since SDL 3.0.0.
See also
SDL_CreateEnvironment

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

The definition of y = exp(x) is y = e^x, where e is the base of the natural logarithm. The inverse is the natural logarithm, SDL_log.

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

The output will overflow if exp(x) is too large to be represented.

This function operates on double-precision floating point values, use SDL_expf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
value of e^x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_expf
SDL_log

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

The definition of y = exp(x) is y = e^x, where e is the base of the natural logarithm. The inverse is the natural logarithm, SDL_logf.

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

The output will overflow if exp(x) is too large to be represented.

This function operates on single-precision floating point values, use SDL_exp for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value.
Returns
value of e^x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_exp
SDL_logf

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

This function operates on double-precision floating point values, use SDL_copysignf for single-precision floats.

Parameters
xfloating point value to use as the magnitude.
Returns
the absolute value of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_fabsf

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

This function operates on single-precision floating point values, use SDL_copysignf for double-precision floats.

Parameters
xfloating point value to use as the magnitude.
Returns
the absolute value of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_fabs

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

The floor of x is the largest integer y such that y > x, i.e x rounded down to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_floorf for single-precision floats.

Parameters
xfloating point value.
Returns
the floor of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_floorf
SDL_ceil
SDL_trunc
SDL_round
SDL_lround

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

The floor of x is the largest integer y such that y > x, i.e x rounded down to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_floorf for double-precision floats.

Parameters
xfloating point value.
Returns
the floor of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_floor
SDL_ceilf
SDL_truncf
SDL_roundf
SDL_lroundf

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

Domain: -INF <= x <= INF, -INF <= y <= INF, y != 0

Range: -y <= z <= y

This function operates on double-precision floating point values, use SDL_fmodf for single-precision floats.

Parameters
xthe numerator.
ythe denominator. Must not be 0.
Returns
the remainder of x / y.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_fmodf
SDL_modf
SDL_trunc
SDL_ceil
SDL_floor
SDL_round
SDL_lround

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

Domain: -INF <= x <= INF, -INF <= y <= INF, y != 0

Range: -y <= z <= y

This function operates on single-precision floating point values, use SDL_fmod for single-precision floats.

Parameters
xthe numerator.
ythe denominator. Must not be 0.
Returns
the remainder of x / y.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_fmod
SDL_truncf
SDL_modff
SDL_ceilf
SDL_floorf
SDL_roundf
SDL_lroundf

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

The pointer is no longer valid after this call and cannot be dereferenced anymore.

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_malloc
SDL_calloc
SDL_realloc

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

This function uses SDL's cached copy of the environment and is thread-safe.

Parameters
namethe name of the variable to get.
Returns
a pointer to the value of the variable or NULL if it can't be found.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_getenv_unsafe()

const char * SDL_getenv_unsafe ( const char *  name)
extern

Get the value of a variable in the environment.

This function bypasses SDL's cached copy of the environment and is not thread-safe.

Parameters
namethe name of the variable to get.
Returns
a pointer to the value of the variable or NULL if it can't be found.

\threadsafety This function is not thread safe, consider using SDL_getenv() instead.

Since
This function is available since SDL 3.0.0.
See also
SDL_getenv

◆ SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment ( void  )
extern

Get the process environment.

This is initialized at application start and is not affected by setenv() and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and SDL_UnsetEnvironmentVariable() if you want to modify this environment, or SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist in the C runtime environment after SDL_Quit().

Returns
a pointer to the environment for the process or NULL on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable

◆ SDL_GetEnvironmentVariable()

const char * SDL_GetEnvironmentVariable ( SDL_Environment env,
const char *  name 
)
extern

Get the value of a variable in the environment.

Parameters
envthe environment to query.
namethe name of the variable to get.
Returns
a pointer to the value of the variable or NULL if it can't be found.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable

◆ SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables ( SDL_Environment env)
extern

Get all variables in the environment.

Parameters
envthe environment to query.
Returns
a NULL terminated array of pointers to environment variables in the form "variable=value" or NULL on failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable

◆ SDL_GetMemoryFunctions()

void SDL_GetMemoryFunctions ( SDL_malloc_func malloc_func,
SDL_calloc_func calloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func 
)
extern

Get the current set of SDL memory functions.

Parameters
malloc_funcfilled with malloc function.
calloc_funcfilled with calloc function.
realloc_funcfilled with realloc function.
free_funcfilled with free function.

\threadsafety This does not hold a lock, so do not call this in the unlikely event of a background thread calling SDL_SetMemoryFunctions simultaneously.

Since
This function is available since SDL 3.0.0.
See also
SDL_SetMemoryFunctions
SDL_GetOriginalMemoryFunctions

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )
extern

Get the number of outstanding (unfreed) allocations.

Returns
the number of allocations.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_GetOriginalMemoryFunctions()

void SDL_GetOriginalMemoryFunctions ( SDL_malloc_func malloc_func,
SDL_calloc_func calloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func 
)
extern

Get the original set of SDL memory functions.

This is what SDL_malloc and friends will use by default, if there has been no call to SDL_SetMemoryFunctions. This is not necessarily using the C runtime's malloc functions behind the scenes! Different platforms and build configurations might do any number of unexpected things.

Parameters
malloc_funcfilled with malloc function.
calloc_funcfilled with calloc function.
realloc_funcfilled with realloc function.
free_funcfilled with free function.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_iconv()

size_t SDL_iconv ( SDL_iconv_t  cd,
const char **  inbuf,
size_t *  inbytesleft,
char **  outbuf,
size_t *  outbytesleft 
)
extern

This function converts text between encodings, reading from and writing to a buffer.

It returns the number of succesful conversions.

Parameters
cdThe character set conversion context, created in SDL_iconv_open().
inbufAddress of variable that points to the first character of the input sequence.
inbytesleftThe number of bytes in the input buffer.
outbufAddress of variable that points to the output buffer.
outbytesleftThe number of bytes in the output buffer.
Returns
the number of conversions on success, else SDL_ICONV_E2BIG is returned when the output buffer is too small, or SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered, or SDL_ICONV_EINVAL is returned when an incomplete input sequence is encountered.

On exit:

  • inbuf will point to the beginning of the next multibyte sequence. On error, this is the location of the problematic input sequence. On success, this is the end of the input sequence. - inbytesleft will be set to the number of bytes left to convert, which will be 0 on success. - outbuf will point to the location where to store the next output byte. - outbytesleft will be set to the number of bytes left in the output buffer.
Since
This function is available since SDL 3.0.0.
See also
SDL_iconv_open
SDL_iconv_close
SDL_iconv_string

◆ SDL_iconv_close()

int SDL_iconv_close ( SDL_iconv_t  cd)
extern

This function frees a context used for character set conversion.

Parameters
cdThe character set conversion handle.
Returns
0 on success, or -1 on failure.
Since
This function is available since SDL 3.0.0.
See also
SDL_iconv
SDL_iconv_open
SDL_iconv_string

◆ SDL_iconv_open()

SDL_iconv_t SDL_iconv_open ( const char *  tocode,
const char *  fromcode 
)
extern

This function allocates a context for the specified character set conversion.

Parameters
tocodeThe target character encoding, must not be NULL.
fromcodeThe source character encoding, must not be NULL.
Returns
a handle that must be freed with SDL_iconv_close, or SDL_ICONV_ERROR on failure.
Since
This function is available since SDL 3.0.0.
See also
SDL_iconv
SDL_iconv_close
SDL_iconv_string

◆ SDL_iconv_string()

char * SDL_iconv_string ( const char *  tocode,
const char *  fromcode,
const char *  inbuf,
size_t  inbytesleft 
)
extern

Helper function to convert a string's encoding in one call.

This function converts a buffer or string between encodings in one pass.

The string does not need to be NULL-terminated; this function operates on the number of bytes specified in inbytesleft whether there is a NULL character anywhere in the buffer.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters
tocodethe character encoding of the output string. Examples are "UTF-8", "UCS-4", etc.
fromcodethe character encoding of data in inbuf.
inbufthe string to convert to a different encoding.
inbytesleftthe size of the input string in bytes.
Returns
a new string, converted to the new encoding, or NULL on error.
Since
This function is available since SDL 3.0.0.
See also
SDL_iconv_open
SDL_iconv_close
SDL_iconv

◆ SDL_isalnum()

int SDL_isalnum ( int  x)
extern

Query if a character is alphabetic (a letter) or a number.

WARNING: Regardless of system locale, this will only treat ASCII values for English 'a-z', 'A-Z', and '0-9' as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isalpha()

int SDL_isalpha ( int  x)
extern

Query if a character is alphabetic (a letter).

WARNING: Regardless of system locale, this will only treat ASCII values for English 'a-z' and 'A-Z' as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isblank()

int SDL_isblank ( int  x)
extern

Report if a character is blank (a space or tab).

WARNING: Regardless of system locale, this will only treat ASCII values 0x20 (space) or 0x9 (tab) as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_iscntrl()

int SDL_iscntrl ( int  x)
extern

Report if a character is a control character.

WARNING: Regardless of system locale, this will only treat ASCII values 0 through 0x1F, and 0x7F, as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isdigit()

int SDL_isdigit ( int  x)
extern

Report if a character is a numeric digit.

WARNING: Regardless of system locale, this will only treat ASCII values '0' (0x30) through '9' (0x39), as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isgraph()

int SDL_isgraph ( int  x)
extern

Report if a character is any "printable" except space.

Be advised that "printable" has a definition that goes back to text terminals from the dawn of computing, making this a sort of special case function that is not suitable for Unicode (or most any) text management.

WARNING: Regardless of system locale, this is equivalent to ‘(SDL_isprint(x)) && ((x) != ’ ')`.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_isprint

◆ SDL_isinf()

int SDL_isinf ( double  x)
extern

Return whether the value is infinity.

Parameters
xdouble-precision floating point value.
Returns
non-zero if the value is infinity, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_isinff

◆ SDL_isinff()

int SDL_isinff ( float  x)
extern

Return whether the value is infinity.

Parameters
xfloating point value.
Returns
non-zero if the value is infinity, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_isinf

◆ SDL_islower()

int SDL_islower ( int  x)
extern

Report if a character is lower case.

WARNING: Regardless of system locale, this will only treat ASCII values 'a' through 'z' as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isnan()

int SDL_isnan ( double  x)
extern

Return whether the value is NaN.

Parameters
xdouble-precision floating point value.
Returns
non-zero if the value is NaN, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_isnanf

◆ SDL_isnanf()

int SDL_isnanf ( float  x)
extern

Return whether the value is NaN.

Parameters
xfloating point value.
Returns
non-zero if the value is NaN, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_isnan

◆ SDL_isprint()

int SDL_isprint ( int  x)
extern

Report if a character is "printable".

Be advised that "printable" has a definition that goes back to text terminals from the dawn of computing, making this a sort of special case function that is not suitable for Unicode (or most any) text management.

WARNING: Regardless of system locale, this will only treat ASCII values ' ' (0x20) through '~' (0x7E) as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_ispunct()

int SDL_ispunct ( int  x)
extern

Report if a character is a punctuation mark.

WARNING: Regardless of system locale, this is equivalent to ((SDL_isgraph(x)) && (!SDL_isalnum(x))).

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_isgraph
SDL_isalnum

◆ SDL_isspace()

int SDL_isspace ( int  x)
extern

Report if a character is whitespace.

WARNING: Regardless of system locale, this will only treat the following ASCII values as true:

  • space (0x20)
  • tab (0x09)
  • newline (0x0A)
  • vertical tab (0x0B)
  • form feed (0x0C)
  • return (0x0D)
Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isupper()

int SDL_isupper ( int  x)
extern

Report if a character is upper case.

WARNING: Regardless of system locale, this will only treat ASCII values 'A' through 'Z' as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_isxdigit()

int SDL_isxdigit ( int  x)
extern

Report if a character is a hexadecimal digit.

WARNING: Regardless of system locale, this will only treat ASCII values 'A' through 'F', 'a' through 'f', and '0' through '9', as true.

Parameters
xcharacter value to check.
Returns
non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_itoa()

char * SDL_itoa ( int  value,
char *  str,
int  radix 
)
extern

◆ SDL_lltoa()

char * SDL_lltoa ( long long  value,
char *  str,
int  radix 
)
extern

◆ SDL_log()

double SDL_log ( double  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on double-precision floating point values, use SDL_logf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value. Must be greater than 0.
Returns
the natural logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_logf
SDL_log10
SDL_exp

◆ SDL_log10()

double SDL_log10 ( double  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on double-precision floating point values, use SDL_log10f for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value. Must be greater than 0.
Returns
the logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_log10f
SDL_log
SDL_pow

◆ SDL_log10f()

float SDL_log10f ( float  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on single-precision floating point values, use SDL_log10 for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value. Must be greater than 0.
Returns
the logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_log10
SDL_logf
SDL_powf

◆ SDL_logf()

float SDL_logf ( float  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on single-precision floating point values, use SDL_log for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value. Must be greater than 0.
Returns
the natural logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_log
SDL_expf

◆ SDL_lround()

long SDL_lround ( double  x)
extern

Round x to the nearest integer representable as a long

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

This function operates on double-precision floating point values, use SDL_lround for single-precision floats. To get the result as a floating-point type, use SDL_round.

Parameters
xfloating point value.
Returns
the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_lroundf
SDL_round
SDL_floor
SDL_ceil
SDL_trunc

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

This function operates on single-precision floating point values, use SDL_lroundf for double-precision floats. To get the result as a floating-point type, use SDL_roundf,

Parameters
xfloating point value.
Returns
the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_lround
SDL_roundf
SDL_floorf
SDL_ceilf
SDL_truncf

◆ SDL_ltoa()

char * SDL_ltoa ( long  value,
char *  str,
int  radix 
)
extern

◆ SDL_malloc()

SDL_MALLOC void * SDL_malloc ( size_t  size)
extern

Allocate uninitialized memory.

The allocated memory returned by this function must be freed with SDL_free().

If size is 0, it will be set to 1.

If you want to allocate memory aligned to a specific alignment, consider using SDL_aligned_alloc().

Parameters
sizethe size to allocate.
Returns
a pointer to the allocated memory, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_free
SDL_calloc
SDL_realloc
SDL_aligned_alloc

◆ SDL_memcmp()

int SDL_memcmp ( const void *  s1,
const void *  s2,
size_t  len 
)
extern

◆ SDL_memcpy()

void * SDL_memcpy ( SDL_OUT_BYTECAP(len) void *  dst,
SDL_IN_BYTECAP(len) const void *  src,
size_t  len 
)
extern

Copy non-overlapping memory.

The memory regions must not overlap. If they do, use SDL_memmove() instead.

Parameters
dstThe destination memory region. Must not be NULL, and must not overlap with src.
srcThe source memory region. Must not be NULL, and must not overlap with dst.
lenThe length in bytes of both dst and src.
Returns
dst.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_memmove

◆ SDL_memmove()

void * SDL_memmove ( SDL_OUT_BYTECAP(len) void *  dst,
SDL_IN_BYTECAP(len) const void *  src,
size_t  len 
)
extern

Copy memory.

It is okay for the memory regions to overlap. If you are confident that the regions never overlap, using SDL_memcpy() may improve performance.

Parameters
dstThe destination memory region. Must not be NULL.
srcThe source memory region. Must not be NULL.
lenThe length in bytes of both dst and src.
Returns
dst.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_memcpy

◆ SDL_memset()

void * SDL_memset ( SDL_OUT_BYTECAP(len) void *  dst,
int  c,
size_t  len 
)
extern

◆ SDL_memset4()

void * SDL_memset4 ( void *  dst,
Uint32  val,
size_t  dwords 
)
extern

◆ SDL_modf()

double SDL_modf ( double  x,
double *  y 
)
extern

Split x into integer and fractional parts

This function operates on double-precision floating point values, use SDL_modff for single-precision floats.

Parameters
xfloating point value.
youtput pointer to store the integer part of x.
Returns
the fractional part of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_modff
SDL_trunc
SDL_fmod

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

This function operates on single-precision floating point values, use SDL_modf for double-precision floats.

Parameters
xfloating point value.
youtput pointer to store the integer part of x.
Returns
the fractional part of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_modf
SDL_truncf
SDL_fmodf

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)
extern

Raise x to the power y

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -INF <= z <= INF

If y is the base of the natural logarithm (e), consider using SDL_exp instead.

This function operates on double-precision floating point values, use SDL_powf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xthe base.
ythe exponent.
Returns
x raised to the power y.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_powf
SDL_exp
SDL_log

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -INF <= z <= INF

If y is the base of the natural logarithm (e), consider using SDL_exp instead.

This function operates on single-precision floating point values, use SDL_powf for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xthe base.
ythe exponent.
Returns
x raised to the power y.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_pow
SDL_expf
SDL_logf

◆ SDL_qsort()

void SDL_qsort ( void *  base,
size_t  nmemb,
size_t  size,
SDL_CompareCallback  compare 
)
extern

◆ SDL_qsort_r()

void SDL_qsort_r ( void *  base,
size_t  nmemb,
size_t  size,
SDL_CompareCallback_r  compare,
void *  userdata 
)
extern

◆ SDL_rand()

Sint32 SDL_rand ( Sint32  n)
extern

Generate a pseudo-random number less than n for positive n

The method used is faster and of better quality than rand() % n. Odds are roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and much worse as n gets bigger.

Example: to simulate a d6 use SDL_rand(6) + 1 The +1 converts 0..5 to 1..6

If you want to generate a pseudo-random number in the full range of Sint32, you should use: (Sint32)SDL_rand_bits()

If you want reproducible output, be sure to initialize with SDL_srand() first.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters
nthe number of possible outcomes. n must be positive.
Returns
a random value in the range of [0 .. n-1].

\threadsafety All calls should be made from a single thread

Since
This function is available since SDL 3.0.0.
See also
SDL_srand
SDL_randf

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

You likely want to use SDL_rand() to get a psuedo-random number instead.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Returns
a random value in the range of [0-SDL_MAX_UINT32].

\threadsafety All calls should be made from a single thread

Since
This function is available since SDL 3.0.0.
See also
SDL_rand
SDL_randf
SDL_srand

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 state)
extern

Generate 32 pseudo-random bits.

You likely want to use SDL_rand_r() to get a psuedo-random number instead.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters
statea pointer to the current random number state, this may not be NULL.
Returns
a random value in the range of [0-SDL_MAX_UINT32].

\threadsafety This function is thread-safe, as long as the state pointer isn't shared between threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_rand_r
SDL_randf_r

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 state,
Sint32  n 
)
extern

Generate a pseudo-random number less than n for positive n

The method used is faster and of better quality than rand() % n. Odds are roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and much worse as n gets bigger.

Example: to simulate a d6 use SDL_rand_r(state, 6) + 1 The +1 converts 0..5 to 1..6

If you want to generate a pseudo-random number in the full range of Sint32, you should use: (Sint32)SDL_rand_bits_r(state)

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters
statea pointer to the current random number state, this may not be NULL.
nthe number of possible outcomes. n must be positive.
Returns
a random value in the range of [0 .. n-1].

\threadsafety This function is thread-safe, as long as the state pointer isn't shared between threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_rand
SDL_rand_bits_r
SDL_randf_r

◆ SDL_randf()

float SDL_randf ( void  )
extern

Generate a uniform pseudo-random floating point number less than 1.0

If you want reproducible output, be sure to initialize with SDL_srand() first.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Returns
a random value in the range of [0.0, 1.0).

\threadsafety All calls should be made from a single thread

Since
This function is available since SDL 3.0.0.
See also
SDL_srand
SDL_rand

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 state)
extern

Generate a uniform pseudo-random floating point number less than 1.0

If you want reproducible output, be sure to initialize with SDL_srand() first.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters
statea pointer to the current random number state, this may not be NULL.
Returns
a random value in the range of [0.0, 1.0).

\threadsafety This function is thread-safe, as long as the state pointer isn't shared between threads.

Since
This function is available since SDL 3.0.0.
See also
SDL_rand_bits_r
SDL_rand_r
SDL_randf

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_roundf for single-precision floats. To get the result as an integer type, use SDL_lround.

Parameters
xfloating point value.
Returns
the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_roundf
SDL_lround
SDL_floor
SDL_ceil
SDL_trunc

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_roundf for single-precision floats. To get the result as an integer type, use SDL_lroundf.

Parameters
xfloating point value.
Returns
the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_round
SDL_lroundf
SDL_floorf
SDL_ceilf
SDL_truncf

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

Multiplies x by the nth power of the floating point radix (always 2).

Domain: -INF <= x <= INF, n integer

Range: -INF <= y <= INF

This function operates on double-precision floating point values, use SDL_scalbnf for single-precision floats.

Parameters
xfloating point value to be scaled.
ninteger exponent.
Returns
x * 2^n.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_scalbnf
SDL_pow

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

Multiplies x by the nth power of the floating point radix (always 2).

Domain: -INF <= x <= INF, n integer

Range: -INF <= y <= INF

This function operates on single-precision floating point values, use SDL_scalbn for double-precision floats.

Parameters
xfloating point value to be scaled.
ninteger exponent.
Returns
x * 2^n.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_scalbn
SDL_powf

◆ SDL_setenv_unsafe()

int SDL_setenv_unsafe ( const char *  name,
const char *  value,
int  overwrite 
)
extern

Set the value of a variable in the environment.

Parameters
namethe name of the variable to set.
valuethe value of the variable to set.
overwrite1 to overwrite the variable if it exists, 0 to return success without setting the variable if it already exists.
Returns
0 on success, -1 on error.

\threadsafety This function is not thread safe, consider using SDL_SetEnvironmentVariable() instead.

Since
This function is available since SDL 3.0.0.
See also
SDL_SetEnvironmentVariable

◆ SDL_SetEnvironmentVariable()

SDL_bool SDL_SetEnvironmentVariable ( SDL_Environment env,
const char *  name,
const char *  value,
SDL_bool  overwrite 
)
extern

Set the value of a variable in the environment.

Parameters
envthe environment to modify.
namethe name of the variable to set.
valuethe value of the variable to set.
overwriteSDL_TRUE to overwrite the variable if it exists, SDL_FALSE to return success without setting the variable if it already exists.
Returns
SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_UnsetEnvironmentVariable

◆ SDL_SetMemoryFunctions()

SDL_bool SDL_SetMemoryFunctions ( SDL_malloc_func  malloc_func,
SDL_calloc_func  calloc_func,
SDL_realloc_func  realloc_func,
SDL_free_func  free_func 
)
extern

Replace SDL's memory allocation functions with a custom set.

It is not safe to call this function once any allocations have been made, as future calls to SDL_free will use the new allocator, even if they came from an SDL_malloc made with the old one!

If used, usually this needs to be the first call made into the SDL library, if not the very first thing done at program startup time.

Parameters
malloc_funccustom malloc function.
calloc_funccustom calloc function.
realloc_funccustom realloc function.
free_funccustom free function.
Returns
SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread, but one should not replace the memory functions once any allocations are made!

Since
This function is available since SDL 3.0.0.
See also
SDL_GetMemoryFunctions
SDL_GetOriginalMemoryFunctions

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on double-precision floating point values, use SDL_sinf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
sine of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_sinf
SDL_asin
SDL_cos

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on single-precision floating point values, use SDL_sinf for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
sine of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_sin
SDL_asinf
SDL_cosf

◆ SDL_size_add_check_overflow()

SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow ( size_t  a,
size_t  b,
size_t *  ret 
)

Add two integers, checking for overflow.

If a + b would overflow, return -1.

Otherwise store a + b via ret and return 0.

Parameters
athe first addend.
bthe second addend.
reton non-overflow output, stores the addition result. May not be NULL.
Returns
SDL_FALSE on overflow, SDL_TRUE if result is added without overflow.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

Definition at line 4091 of file SDL_stdinc.h.

4092{
4093 if (b > SDL_SIZE_MAX - a) {
4094 return SDL_FALSE;
4095 }
4096 *ret = a + b;
4097 return SDL_TRUE;
4098}

References SDL_FALSE, SDL_SIZE_MAX, and SDL_TRUE.

◆ SDL_size_mul_check_overflow()

SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow ( size_t  a,
size_t  b,
size_t *  ret 
)

Multiply two integers, checking for overflow.

If a * b would overflow, return SDL_FALSE.

Otherwise store a * b via ret and return SDL_TRUE.

Parameters
athe multiplicand.
bthe multiplier.
reton non-overflow output, stores the multiplication result. May not be NULL.
Returns
SDL_FALSE on overflow, SDL_TRUE if result is multiplied without overflow.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

Definition at line 4051 of file SDL_stdinc.h.

4052{
4053 if (a != 0 && b > SDL_SIZE_MAX / a) {
4054 return SDL_FALSE;
4055 }
4056 *ret = a * b;
4057 return SDL_TRUE;
4058}

References SDL_FALSE, SDL_SIZE_MAX, and SDL_TRUE.

◆ SDL_snprintf()

int SDL_snprintf ( SDL_OUT_Z_CAP(maxlen) char *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
  ... 
)
extern

◆ SDL_sqrt()

double SDL_sqrt ( double  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

This function operates on double-precision floating point values, use SDL_sqrtf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value. Must be greater than or equal to 0.
Returns
square root of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_sqrtf

◆ SDL_sqrtf()

float SDL_sqrtf ( float  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

This function operates on single-precision floating point values, use SDL_sqrt for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value. Must be greater than or equal to 0.
Returns
square root of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_sqrt

◆ SDL_srand()

void SDL_srand ( Uint64  seed)
extern

Seeds the pseudo-random number generator.

Reusing the seed number will cause SDL_rand_*() to repeat the same stream of 'random' numbers.

Parameters
seedthe value to use as a random number seed, or 0 to use SDL_GetPerformanceCounter().

\threadsafety This should be called on the same thread that calls SDL_rand*()

Since
This function is available since SDL 3.0.0.
See also
SDL_rand
SDL_rand_bits
SDL_randf

◆ SDL_sscanf()

int SDL_sscanf ( const char *  text,
SDL_SCANF_FORMAT_STRING const char *  fmt,
  ... 
)
extern

◆ SDL_StepUTF8()

Uint32 SDL_StepUTF8 ( const char **  pstr,
size_t *  pslen 
)
extern

Decode a UTF-8 string, one Unicode codepoint at a time.

This will return the first Unicode codepoint in the UTF-8 encoded string in *pstr, and then advance *pstr past any consumed bytes before returning.

It will not access more than *pslen bytes from the string. *pslen will be adjusted, as well, subtracting the number of bytes consumed.

pslen is allowed to be NULL, in which case the string must be NULL-terminated, as the function will blindly read until it sees the NULL char.

if *pslen is zero, it assumes the end of string is reached and returns a zero codepoint regardless of the contents of the string buffer.

If the resulting codepoint is zero (a NULL terminator), or *pslen is zero, it will not advance *pstr or *pslen at all.

Generally this function is called in a loop until it returns zero, adjusting its parameters each iteration.

If an invalid UTF-8 sequence is encountered, this function returns SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte (which is to say, a multibyte sequence might produce several SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid UTF-8 sequence).

Several things can generate invalid UTF-8 sequences, including overlong encodings, the use of UTF-16 surrogate values, and truncated data. Please refer to RFC3629 for details.

Parameters
pstra pointer to a UTF-8 string pointer to be read and adjusted.
pslena pointer to the number of bytes in the string, to be read and adjusted. NULL is allowed.
Returns
the first Unicode codepoint in the string.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_strcasecmp()

int SDL_strcasecmp ( const char *  str1,
const char *  str2 
)
extern

Compare two null-terminated UTF-8 strings, case-insensitively.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_strcasestr()

char * SDL_strcasestr ( const char *  haystack,
const char *  needle 
)
extern

◆ SDL_strchr()

char * SDL_strchr ( const char *  str,
int  c 
)
extern

◆ SDL_strcmp()

int SDL_strcmp ( const char *  str1,
const char *  str2 
)
extern

Compare two null-terminated UTF-8 strings.

Due to the nature of UTF-8 encoding, this will work with Unicode strings, since effectively this function just compares bytes until it hits a null-terminating character. Also due to the nature of UTF-8, this can be used with SDL_qsort() to put strings in (roughly) alphabetical order.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_strdup()

SDL_MALLOC char * SDL_strdup ( const char *  str)
extern

◆ SDL_strlcat()

size_t SDL_strlcat ( SDL_INOUT_Z_CAP(maxlen) char *  dst,
const char *  src,
size_t  maxlen 
)
extern

Concatenate strings.

This function appends up to maxlen - SDL_strlen(dst) - 1 characters from src to the end of the string in dst, then appends a null terminator.

src and dst must not overlap.

If maxlen - SDL_strlen(dst) - 1 is less than or equal to 0, then dst is unmodified.

Parameters
dstThe destination buffer already containing the first null-terminated string. Must not be NULL and must not overlap with src.
srcThe second null-terminated string. Must not be NULL, and must not overlap with dst.
maxlenThe length (in characters) of the destination buffer.
Returns
The length (in characters, excluding the null terminator) of the string in dst plus the length of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_strlcpy

◆ SDL_strlcpy()

size_t SDL_strlcpy ( SDL_OUT_Z_CAP(maxlen) char *  dst,
const char *  src,
size_t  maxlen 
)
extern

Copy a string.

This function copies up to maxlen - 1 characters from src to dst, then appends a null terminator.

If maxlen is 0, no characters are copied and no null terminator is written.

If you want to copy an UTF-8 string but need to ensure that multi-byte sequences are not truncated, consider using SDL_utf8strlcpy().

Parameters
dstThe destination buffer. Must not be NULL, and must not overlap with src.
srcThe null-terminated string to copy. Must not be NULL, and must not overlap with dst.
maxlenThe length (in characters) of the destination buffer.
Returns
The length (in characters, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_strlcat
SDL_utf8strlcpy

◆ SDL_strlen()

size_t SDL_strlen ( const char *  str)
extern

◆ SDL_strlwr()

char * SDL_strlwr ( char *  str)
extern

Convert a string to lowercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.

This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'A' through 'Z' to their lowercase equivalents in-place, returning the original str pointer.

Parameters
strthe string to convert in-place. Can not be NULL.
Returns
the str pointer passed into this function.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_strupr

◆ SDL_strncasecmp()

int SDL_strncasecmp ( const char *  str1,
const char *  str2,
size_t  maxlen 
)
extern

Compare two UTF-8 strings, case-insensitively, up to a number of bytes.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Note that while this function is intended to be used with UTF-8, maxlen specifies a byte limit! If the limit lands in the middle of a multi-byte UTF-8 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.

maxlen specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
maxlenthe maximum number of bytes to compare.
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_strncmp()

int SDL_strncmp ( const char *  str1,
const char *  str2,
size_t  maxlen 
)
extern

Compare two UTF-8 strings up to a number of bytes.

Due to the nature of UTF-8 encoding, this will work with Unicode strings, since effectively this function just compares bytes until it hits a null-terminating character. Also due to the nature of UTF-8, this can be used with SDL_qsort() to put strings in (roughly) alphabetical order.

Note that while this function is intended to be used with UTF-8, it is doing a bytewise comparison, and maxlen specifies a byte limit! If the limit lands in the middle of a multi-byte UTF-8 sequence, it will only compare a portion of the final character.

maxlen specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
maxlenthe maximum number of bytes to compare.
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_strndup()

SDL_MALLOC char * SDL_strndup ( const char *  str,
size_t  maxlen 
)
extern

◆ SDL_strnlen()

size_t SDL_strnlen ( const char *  str,
size_t  maxlen 
)
extern

◆ SDL_strnstr()

char * SDL_strnstr ( const char *  haystack,
const char *  needle,
size_t  maxlen 
)
extern

◆ SDL_strpbrk()

char * SDL_strpbrk ( const char *  str,
const char *  breakset 
)
extern

Searches a string for the first occurence of any character contained in a breakset, and returns a pointer from the string to that character.

Parameters
strThe null-terminated string to be searched. Must not be NULL, and must not overlap with breakset.
breaksetA null-terminated string containing the list of characters to look for. Must not be NULL, and must not overlap with str.
Returns
A pointer to the location, in str, of the first occurence of a character present in the breakset, or NULL if none is found.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_strrchr()

char * SDL_strrchr ( const char *  str,
int  c 
)
extern

◆ SDL_strrev()

char * SDL_strrev ( char *  str)
extern

◆ SDL_strstr()

char * SDL_strstr ( const char *  haystack,
const char *  needle 
)
extern

◆ SDL_strtod()

double SDL_strtod ( const char *  str,
char **  endp 
)
extern

Parse a double from a string.

This function makes fewer guarantees than the C runtime strtod:

  • Only decimal notation is guaranteed to be supported. The handling of scientific and hexadecimal notation is unspecified.
  • Whether or not INF and NAN can be parsed is unspecified.
  • The precision of the result is unspecified.
Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
Returns
The parsed double, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoll
SDL_strtoul
SDL_strtoull

◆ SDL_strtok_r()

char * SDL_strtok_r ( char *  s1,
const char *  s2,
char **  saveptr 
)
extern

◆ SDL_strtol()

long SDL_strtol ( const char *  str,
char **  endp,
int  base 
)
extern

Parse a long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long, the result is clamped to the minimum and maximum representable long values.

Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
The parsed long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atoi
SDL_atof
SDL_strtoul
SDL_strtoll
SDL_strtoull
SDL_strtod
SDL_ltoa
SDL_wcstol

◆ SDL_strtoll()

long long SDL_strtoll ( const char *  str,
char **  endp,
int  base 
)
extern

Parse a long long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long long, the result is clamped to the minimum and maximum representable long long values.

Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
The parsed long long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoul
SDL_strtoull
SDL_strtod
SDL_lltoa

◆ SDL_strtoul()

unsigned long SDL_strtoul ( const char *  str,
char **  endp,
int  base 
)
extern

Parse an unsigned long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside an unsigned long, the result is clamped to the maximum representable unsigned long value.

Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
The parsed unsigned long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoll
SDL_strtoull
SDL_strtod
SDL_ultoa

◆ SDL_strtoull()

unsigned long long SDL_strtoull ( const char *  str,
char **  endp,
int  base 
)
extern

Parse an unsigned long long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside an unsigned long long, the result is clamped to the maximum representable unsigned long long value.

Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
The parsed unsigned long long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoll
SDL_strtoul
SDL_strtod
SDL_ulltoa

◆ SDL_strupr()

char * SDL_strupr ( char *  str)
extern

Convert a string to uppercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to uppercase.

This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'a' through 'z' to their uppercase equivalents in-place, returning the original str pointer.

Parameters
strthe string to convert in-place. Can not be NULL.
Returns
the str pointer passed into this function.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_strlwr

◆ SDL_swprintf()

int SDL_swprintf ( SDL_OUT_Z_CAP(maxlen) wchar_t *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const wchar_t *  fmt,
  ... 
)
extern

◆ SDL_tan()

double SDL_tan ( double  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on double-precision floating point values, use SDL_tanf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
tangent of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_tanf
SDL_sin
SDL_cos
SDL_atan
SDL_atan2

◆ SDL_tanf()

float SDL_tanf ( float  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on single-precision floating point values, use SDL_tanf for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
tangent of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_tan
SDL_sinf
SDL_cosf
SDL_atanf
SDL_atan2f

◆ SDL_tolower()

int SDL_tolower ( int  x)
extern

Convert low-ASCII English letters to lowercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.

This function returns the lowercase equivalent of x. If a character cannot be converted, or is already lowercase, this function returns x.

Parameters
xcharacter value to check.
Returns
lowercase version of x, or x if no conversion available.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_toupper()

int SDL_toupper ( int  x)
extern

Convert low-ASCII English letters to uppercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'a' through 'z' to uppercase.

This function returns the uppercase equivalent of x. If a character cannot be converted, or is already uppercase, this function returns x.

Parameters
xcharacter value to check.
Returns
capitalized version of x, or x if no conversion available.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_trunc()

double SDL_trunc ( double  x)
extern

Truncate x to an integer.

Rounds x to the next closest integer to 0. This is equivalent to removing the fractional part of x, leaving only the integer part.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_truncf for single-precision floats.

Parameters
xfloating point value.
Returns
x truncated to an integer.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_truncf
SDL_fmod
SDL_ceil
SDL_floor
SDL_round
SDL_lround

◆ SDL_truncf()

float SDL_truncf ( float  x)
extern

Truncate x to an integer.

Rounds x to the next closest integer to 0. This is equivalent to removing the fractional part of x, leaving only the integer part.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_truncf for double-precision floats.

Parameters
xfloating point value.
Returns
x truncated to an integer.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_trunc
SDL_fmodf
SDL_ceilf
SDL_floorf
SDL_roundf
SDL_lroundf

◆ SDL_UCS4ToUTF8()

char * SDL_UCS4ToUTF8 ( Uint32  codepoint,
char *  dst 
)
extern

Convert a single Unicode codepoint to UTF-8.

The buffer pointed to by dst must be at least 4 bytes long, as this function may generate between 1 and 4 bytes of output.

This function returns the first byte after the newly-written UTF-8 sequence, which is useful for encoding multiple codepoints in a loop, or knowing where to write a NULL-terminator character to end the string (in either case, plan to have a buffer of more than 4 bytes!).

If codepoint is an invalid value (outside the Unicode range, or a UTF-16 surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the codepoint instead, and not set an error.

If dst is NULL, this returns NULL immediately without writing to the pointer and without setting an error.

Parameters
codepointa Unicode codepoint to convert to UTF-8.
dstthe location to write the encoded UTF-8. Must point to at least 4 bytes!
Returns
the first byte past the newly-written UTF-8 sequence.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_uitoa()

char * SDL_uitoa ( unsigned int  value,
char *  str,
int  radix 
)
extern

◆ SDL_ulltoa()

char * SDL_ulltoa ( unsigned long long  value,
char *  str,
int  radix 
)
extern

◆ SDL_ultoa()

char * SDL_ultoa ( unsigned long  value,
char *  str,
int  radix 
)
extern

◆ SDL_unsetenv_unsafe()

int SDL_unsetenv_unsafe ( const char *  name)
extern

Clear a variable from the environment.

Parameters
namethe name of the variable to unset.
Returns
0 on success, -1 on error.

\threadsafety This function is not thread safe, consider using SDL_UnsetEnvironmentVariable() instead.

Since
This function is available since SDL 3.0.0.
See also
SDL_UnsetEnvironmentVariable

◆ SDL_UnsetEnvironmentVariable()

SDL_bool SDL_UnsetEnvironmentVariable ( SDL_Environment env,
const char *  name 
)
extern

Clear a variable from the environment.

Parameters
envthe environment to modify.
namethe name of the variable to unset.
Returns
SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable

◆ SDL_utf8strlcpy()

size_t SDL_utf8strlcpy ( SDL_OUT_Z_CAP(dst_bytes) char *  dst,
const char *  src,
size_t  dst_bytes 
)
extern

Copy an UTF-8 string.

This function copies up to dst_bytes - 1 bytes from src to dst while also ensuring that the string written to dst does not end in a truncated multi-byte sequence. Finally, it appends a null terminator.

src and dst must not overlap.

Note that unlike SDL_strlcpy(), this function returns the number of bytes written, not the length of src.

Parameters
dstThe destination buffer. Must not be NULL, and must not overlap with src.
srcThe null-terminated UTF-8 string to copy. Must not be NULL, and must not overlap with dst.
dst_bytesThe length (in bytes) of the destination buffer. Must not be 0.
Returns
The number of bytes written, excluding the null terminator.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_strlcpy

◆ SDL_utf8strlen()

size_t SDL_utf8strlen ( const char *  str)
extern

◆ SDL_utf8strnlen()

size_t SDL_utf8strnlen ( const char *  str,
size_t  bytes 
)
extern

◆ SDL_vasprintf()

int SDL_vasprintf ( char **  strp,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

◆ SDL_vsnprintf()

int SDL_vsnprintf ( SDL_OUT_Z_CAP(maxlen) char *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

◆ SDL_vsscanf()

int SDL_vsscanf ( const char *  text,
SDL_SCANF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

◆ SDL_vswprintf()

int SDL_vswprintf ( SDL_OUT_Z_CAP(maxlen) wchar_t *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const wchar_t *  fmt,
va_list  ap 
)
extern

◆ SDL_wcscasecmp()

int SDL_wcscasecmp ( const wchar_t *  str1,
const wchar_t *  str2 
)
extern

Compare two null-terminated wide strings, case-insensitively.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_wcscmp()

int SDL_wcscmp ( const wchar_t *  str1,
const wchar_t *  str2 
)
extern

Compare two null-terminated wide strings.

This only compares wchar_t values until it hits a null-terminating character; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_wcsdup()

wchar_t * SDL_wcsdup ( const wchar_t *  wstr)
extern

◆ SDL_wcslcat()

size_t SDL_wcslcat ( SDL_INOUT_Z_CAP(maxlen) wchar_t *  dst,
const wchar_t *  src,
size_t  maxlen 
)
extern

Concatenate wide strings.

This function appends up to maxlen - SDL_wcslen(dst) - 1 wide characters from src to the end of the wide string in dst, then appends a null terminator.

src and dst must not overlap.

If maxlen - SDL_wcslen(dst) - 1 is less than or equal to 0, then dst is unmodified.

Parameters
dstThe destination buffer already containing the first null-terminated wide string. Must not be NULL and must not overlap with src.
srcThe second null-terminated wide string. Must not be NULL, and must not overlap with dst.
maxlenThe length (in wide characters) of the destination buffer.
Returns
The length (in wide characters, excluding the null terminator) of the string in dst plus the length of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_wcslcpy

◆ SDL_wcslcpy()

size_t SDL_wcslcpy ( SDL_OUT_Z_CAP(maxlen) wchar_t *  dst,
const wchar_t *  src,
size_t  maxlen 
)
extern

Copy a wide string.

This function copies maxlen - 1 wide characters from src to dst, then appends a null terminator.

src and dst must not overlap.

If maxlen is 0, no wide characters are copied and no null terminator is written.

Parameters
dstThe destination buffer. Must not be NULL, and must not overlap with src.
srcThe null-terminated wide string to copy. Must not be NULL, and must not overlap with dst.
maxlenThe length (in wide characters) of the destination buffer.
Returns
The length (in wide characters, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_wcslcat

◆ SDL_wcslen()

size_t SDL_wcslen ( const wchar_t *  wstr)
extern

◆ SDL_wcsncasecmp()

int SDL_wcsncasecmp ( const wchar_t *  str1,
const wchar_t *  str2,
size_t  maxlen 
)
extern

Compare two wide strings, case-insensitively, up to a number of wchar_t.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Note that while this function might deal with variable-sized characters, maxlen specifies a wchar limit! If the limit lands in the middle of a multi-byte UTF-16 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.

maxlen specifies a maximum number of wchar_t values to compare; if the strings match to this number of wchar_t (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
maxlenthe maximum number of wchar_t values to compare.
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_wcsncmp()

int SDL_wcsncmp ( const wchar_t *  str1,
const wchar_t *  str2,
size_t  maxlen 
)
extern

Compare two wide strings up to a number of wchar_t values.

This only compares wchar_t values; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.

Note that while this function is intended to be used with UTF-16 (or UTF-32, depending on your platform's definition of wchar_t), it is comparing raw wchar_t values and not Unicode codepoints: maxlen specifies a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16 sequence, it will only compare a portion of the final character.

maxlen specifies a maximum number of wchar_t to compare; if the strings match to this number of wide chars (or both have matched to a null-terminator character before this count), they will be considered equal.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
maxlenthe maximum number of wchar_t to compare.
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

◆ SDL_wcsnlen()

size_t SDL_wcsnlen ( const wchar_t *  wstr,
size_t  maxlen 
)
extern

◆ SDL_wcsnstr()

wchar_t * SDL_wcsnstr ( const wchar_t *  haystack,
const wchar_t *  needle,
size_t  maxlen 
)
extern

◆ SDL_wcsstr()

wchar_t * SDL_wcsstr ( const wchar_t *  haystack,
const wchar_t *  needle 
)
extern

◆ SDL_wcstol()

long SDL_wcstol ( const wchar_t *  str,
wchar_t **  endp,
int  base 
)
extern

Parse a long from a wide string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long, the result is clamped to the minimum and maximum representable long values.

Parameters
strThe null-terminated wide string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid wide character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
The parsed long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.
See also
SDL_strtol

Variable Documentation

◆ size

size_t size

Definition at line 717 of file SDL_stdinc.h.