SDL 3.0
SDL_stdinc.h File Reference
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.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:

Go to the source code of this file.

Macros

#define bool   unsigned char
 
#define false   0
 
#define true   1
 
#define __bool_true_false_are_defined   1
 
#define SDL_SIZE_MAX   ((size_t) -1)
 
#define SDL_COMPILE_TIME_ASSERT(name, x)    typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 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_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 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_PRILL_PREFIX   "ll"
 
#define SDL_PRILLd   SDL_PRILL_PREFIX "d"
 
#define SDL_PRILLu   SDL_PRILL_PREFIX "u"
 
#define SDL_PRILLx   SDL_PRILL_PREFIX "x"
 
#define SDL_PRILLX   SDL_PRILL_PREFIX "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_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)
 
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 (bool populated)
 
const char * SDL_GetEnvironmentVariable (SDL_Environment *env, const char *name)
 
char ** SDL_GetEnvironmentVariables (SDL_Environment *env)
 
bool SDL_SetEnvironmentVariable (SDL_Environment *env, const char *name, const char *value, bool overwrite)
 
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)
 
Uint32 SDL_murmur3_32 (const void *data, size_t len, Uint32 seed)
 
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)
 
Uint32 SDL_StepBackUTF8 (const char *start, const char **pstr)
 
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 bool SDL_size_mul_check_overflow (size_t a, size_t b, size_t *ret)
 
SDL_FORCE_INLINE bool SDL_size_add_check_overflow (size_t a, size_t b, size_t *ret)
 

Macro Definition Documentation

◆ __bool_true_false_are_defined

#define __bool_true_false_are_defined   1

Definition at line 56 of file SDL_stdinc.h.

◆ bool

#define bool   unsigned char

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.

Definition at line 53 of file SDL_stdinc.h.

◆ false

#define false   0

Definition at line 54 of file SDL_stdinc.h.

◆ 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.1.3.

Definition at line 136 of file SDL_stdinc.h.

◆ SDL_clamp

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

Definition at line 1470 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 112 of file SDL_stdinc.h.

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

1741 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
1742 SDL_memcpy((dst), (src), sizeof(*(src)))

◆ 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.1.3.

Definition at line 432 of file SDL_stdinc.h.

◆ SDL_FOURCC

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

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.1.3.

Definition at line 253 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 124 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Definition at line 4134 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Definition at line 4135 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Definition at line 4136 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Definition at line 4133 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 4242 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 4243 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 4244 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 4245 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

Definition at line 562 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:675
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.1.3.
See also
SDL_IOStreamInterface
SDL_StorageInterface
SDL_VirtualJoystickDesc

Definition at line 675 of file SDL_stdinc.h.

676 { \
677 SDL_zerop(iface); \
678 (iface)->version = sizeof(*(iface)); \
679 } while (0)

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 563 of file SDL_stdinc.h.

◆ SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they encounter 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.1.3.
See also
SDL_StepBackUTF8
SDL_StepUTF8

Definition at line 2507 of file SDL_stdinc.h.

◆ SDL_max

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

Definition at line 1469 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 344 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 362 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 382 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 326 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 410 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 353 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 371 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 393 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 335 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 1737 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 1768 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 1779 of file SDL_stdinc.h.

◆ SDL_min

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

Definition at line 1468 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 345 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 363 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 383 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 327 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 411 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 354 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 372 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 394 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 336 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 566 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 565 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 567 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 564 of file SDL_stdinc.h.

◆ SDL_PI_D

#define SDL_PI_D   3.141592653589793238462643383279502884

pi (double)

Definition at line 2813 of file SDL_stdinc.h.

◆ SDL_PI_F

#define SDL_PI_F   3.141592653589793238462643383279502884F

pi (float)

Definition at line 2816 of file SDL_stdinc.h.

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 517 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 520 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 523 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 526 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 529 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 568 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 579 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 580 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 488 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 448 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 495 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 459 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 502 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 509 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 470 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 481 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 232 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 569 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 581 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 582 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 297 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 94 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 683 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 684 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 233 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.1.3.

Definition at line 149 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 309 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 583 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 584 of file SDL_stdinc.h.

◆ SDL_zero

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

Definition at line 1782 of file SDL_stdinc.h.

◆ SDL_zeroa

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

Definition at line 1784 of file SDL_stdinc.h.

◆ SDL_zerop

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

Definition at line 1783 of file SDL_stdinc.h.

◆ true

#define true   1

Definition at line 55 of file SDL_stdinc.h.

Typedef Documentation

◆ 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.1.3.
See also
SDL_calloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 829 of file SDL_stdinc.h.

◆ SDL_CompareCallback

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

A callback used with SDL sorting and binary search functions.

Parameters
aa pointer to the first element being compared.
ba pointer to the second element being compared.
Returns
-1 if a should be sorted before b, 1 if b should be sorted before a, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.
Since
This callback is available since SDL 3.1.3.
See also
SDL_bsearch
SDL_qsort

Definition at line 1239 of file SDL_stdinc.h.

◆ SDL_CompareCallback_r

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

A callback used with SDL sorting and binary search functions.

Parameters
userdatathe userdata pointer passed to the sort function.
aa pointer to the first element being compared.
ba pointer to the second element being compared.
Returns
-1 if a should be sorted before b, 1 if b should be sorted before a, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.
Since
This callback is available since SDL 3.1.3.
See also
SDL_qsort_r
SDL_bsearch_r

Definition at line 1352 of file SDL_stdinc.h.

◆ SDL_Environment

A thread-safe set of environment variables

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

Definition at line 1011 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.1.3.
See also
SDL_free
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 868 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 4417 of file SDL_stdinc.h.

◆ SDL_iconv_t

typedef struct SDL_iconv_data_t* SDL_iconv_t

Definition at line 4138 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.1.3.
See also
SDL_malloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 808 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.1.3.
See also
SDL_realloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 850 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.1.3.
See also
SDL_MAX_SINT64
SDL_MIN_SINT64

Definition at line 409 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 343 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 361 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

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

Definition at line 381 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 325 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 352 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 370 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

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

Definition at line 392 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 334 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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

Perform a binary search on a previously sorted array.

For example:

typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *a, const void *b)
{
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
}
}
data values[] = {
{ 1, "first" }, { 2, "second" }, { 3, "third" }
};
data key = { 2, NULL };
data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
#define SDL_arraysize(array)
Definition SDL_stdinc.h:136
Parameters
keya pointer to a key equal to the element being searched for.
basea pointer to the start of the array.
nmembthe number of elements in the array.
sizethe size of the elements in the array.
comparea function used to compare elements in the array.
Returns
a pointer to the matching element in the array, or NULL if not found.

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

Since
This function is available since SDL 3.1.3.
See also
SDL_bsearch_r
SDL_qsort

◆ 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

Perform a binary search on a previously sorted array, passing a userdata pointer to the compare function.

For example:

typedef enum {
sort_increasing,
sort_decreasing,
} sort_method;
typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *userdata, const void *a, const void *b)
{
sort_method method = (sort_method)(uintptr_t)userdata;
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->key < B->key) {
return (method == sort_increasing) ? -1 : 1;
} else if (B->key < A->key) {
return (method == sort_increasing) ? 1 : -1;
} else {
return 0;
}
}
data values[] = {
{ 1, "first" }, { 2, "second" }, { 3, "third" }
};
data key = { 2, NULL };
data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
Parameters
keya pointer to a key equal to the element being searched for.
basea pointer to the start of the array.
nmembthe number of elements in the array.
sizethe size of the elements in the array.
comparea function used to compare elements in the array.
userdataa pointer to pass to the compare function.
Returns
a pointer to the matching element in the array, or NULL if not found.

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

Since
This function is available since SDL 3.1.3.
See also
SDL_bsearch
SDL_qsort_r

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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 ( bool  populated)
extern

Create a set of environment variables

Parameters
populatedtrue to initialize it from the C runtime environment, 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 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
See also
SDL_modf
SDL_truncf
SDL_fmodf

◆ SDL_murmur3_32()

Uint32 SDL_murmur3_32 ( const void *  data,
size_t  len,
Uint32  seed 
)
extern

◆ 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.1.3.
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.1.3.
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

Sort an array.

For example:

typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *a, const void *b)
{
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
}
}
data values[] = {
{ 3, "third" }, { 1, "first" }, { 2, "second" }
};
SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
Parameters
basea pointer to the start of the array.
nmembthe number of elements in the array.
sizethe size of the elements in the array.
comparea function used to compare elements in the array.

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

Since
This function is available since SDL 3.1.3.
See also
SDL_bsearch
SDL_qsort_r

◆ SDL_qsort_r()

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

Sort an array, passing a userdata pointer to the compare function.

For example:

typedef enum {
sort_increasing,
sort_decreasing,
} sort_method;
typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *userdata, const void *a, const void *b)
{
sort_method method = (sort_method)(uintptr_t)userdata;
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->key < B->key) {
return (method == sort_increasing) ? -1 : 1;
} else if (B->key < A->key) {
return (method == sort_increasing) ? 1 : -1;
} else {
return 0;
}
}
data values[] = {
{ 3, "third" }, { 1, "first" }, { 2, "second" }
};
SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
Parameters
basea pointer to the start of the array.
nmembthe number of elements in the array.
sizethe size of the elements in the array.
comparea function used to compare elements in the array.
userdataa pointer to pass to the compare function.

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

Since
This function is available since SDL 3.1.3.
See also
SDL_bsearch_r
SDL_qsort

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
See also
SDL_SetEnvironmentVariable

◆ SDL_SetEnvironmentVariable()

bool SDL_SetEnvironmentVariable ( SDL_Environment env,
const char *  name,
const char *  value,
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.
overwritetrue to overwrite the variable if it exists, false to return success without setting the variable if it already exists.
Returns
true on success or 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.1.3.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_UnsetEnvironmentVariable

◆ SDL_SetMemoryFunctions()

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
true on success or 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.1.3.
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.1.3.
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.1.3.
See also
SDL_sin
SDL_asinf
SDL_cosf

◆ SDL_size_add_check_overflow()

SDL_FORCE_INLINE 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
false on overflow, 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.1.3.

Definition at line 4374 of file SDL_stdinc.h.

4375{
4376 if (b > SDL_SIZE_MAX - a) {
4377 return false;
4378 }
4379 *ret = a + b;
4380 return true;
4381}

References SDL_SIZE_MAX.

◆ SDL_size_mul_check_overflow()

SDL_FORCE_INLINE 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 false.

Otherwise store a * b via ret and return true.

Parameters
athe multiplicand.
bthe multiplier.
reton non-overflow output, stores the multiplication result, may not be NULL.
Returns
false on overflow, 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.1.3.

Definition at line 4335 of file SDL_stdinc.h.

4336{
4337 if (a != 0 && b > SDL_SIZE_MAX / a) {
4338 return false;
4339 }
4340 *ret = a * b;
4341 return true;
4342}

References SDL_SIZE_MAX.

◆ 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.1.3.
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.1.3.
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.1.3.
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_StepBackUTF8()

Uint32 SDL_StepBackUTF8 ( const char *  start,
const char **  pstr 
)
extern

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

This will go to the start of the previous Unicode codepoint in the string, move *pstr to that location and return that codepoint.

If *pstr is already at the start of the string), it will not advance *pstr at all.

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

If an invalid UTF-8 sequence is encountered, this function returns SDL_INVALID_UNICODE_CODEPOINT.

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
starta pointer to the beginning of the UTF-8 string.
pstra pointer to a UTF-8 string pointer to be read and adjusted.
Returns
the previous Unicode codepoint in the string.

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

Since
This function is available since SDL 3.2.0.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.
See also
SDL_UnsetEnvironmentVariable

◆ SDL_UnsetEnvironmentVariable()

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
true on success or 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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.
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.1.3.
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.1.3.

◆ 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.1.3.

◆ 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.1.3.
See also
SDL_strtol

Variable Documentation

◆ size

size_t size

Definition at line 734 of file SDL_stdinc.h.