SDL 3.0
SDL_stdinc.h File Reference
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
#include <string.h>
#include <wchar.h>
#include <stdint.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_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)   ((void)(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)   SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
 
#define SDL_iconv_utf8_ucs4(S)   SDL_reinterpret_cast(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", SDL_reinterpret_cast(const 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 *str, const char *delim, 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 102 of file SDL_stdinc.h.

◆ bool

#define bool   unsigned char

CategoryStdinc

SDL provides its own implementation of some of the most important C runtime functions.

Using these functions allows an app to have access to common C functionality without depending on a specific C runtime (or a C runtime at all). More importantly, the SDL implementations work identically across platforms, so apps can avoid surprises like snprintf() behaving differently between Windows and Linux builds, or itoa() only existing on some platforms.

For many of the most common functions, like SDL_memcpy, SDL might just call through to the usual C runtime behind the scenes, if it makes sense to do so (if it's faster and always available/reliable on a given platform), reducing library size and offering the most optimized option.

SDL also offers other C-runtime-adjacent functionality in this header that either isn't, strictly speaking, part of any C runtime standards, like SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better options, like SDL_strlcpy(), which functions as a safer form of strcpy().

Definition at line 99 of file SDL_stdinc.h.

◆ false

#define false   0

Definition at line 100 of file SDL_stdinc.h.

◆ SDL_arraysize

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

The number of elements in a static array.

This will compile but return incorrect results for a pointer to an array; it has to be an array the compiler knows the size of.

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

Definition at line 252 of file SDL_stdinc.h.

◆ SDL_clamp

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

Return a value clamped to a range.

If x is outside the range a values between a and b, the returned value will be a or b as appropriate. Otherwise, x is returned.

This macro will produce incorrect results if b is less than a.

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the < and > operators. However, it double-evaluates all its parameters, so do not use expressions with side-effects here.

Parameters
xthe value to compare.
athe low end value.
bthe high end value.
Returns
x, clamped between a and b.

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

Since
This macro is available since SDL 3.2.0.

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

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

◆ SDL_const_cast

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

Definition at line 346 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)

A macro to copy memory between objects, with basic type checking.

SDL_memcpy and SDL_memmove do not care where you copy memory to and from, which can lead to bugs. This macro aims to avoid most of those bugs by making sure that the source and destination are both pointers to objects that are the same size. It does not check that the objects are the same type, just that the copy will not overflow either object.

The size check happens at compile time, and the compiler will throw an error if the objects are different sizes.

Generally this is intended to copy a single object, not an array.

This macro looks like it double-evaluates its parameters, but the extras them are in sizeof sections, which generate no code nor side-effects.

Parameters
dsta pointer to the destination object. Must not be NULL.
srca pointer to the source object. Must not be NULL.

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

Since
This function is available since SDL 3.2.0.

Definition at line 2540 of file SDL_stdinc.h.

2541 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
2542 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.2.0.

Definition at line 544 of file SDL_stdinc.h.

◆ SDL_FOURCC

#define SDL_FOURCC (   A,
  B,
  C,
 
)
Value:

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

Definition at line 365 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Output buffer was too small.

Definition at line 5896 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5897 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5898 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5895 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)

Convert a UTF-8 string to the current locale's character encoding.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5949 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs2

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

Convert a UTF-8 string to UCS-2.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5965 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs4

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

Convert a UTF-8 string to UCS-4.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5981 of file SDL_stdinc.h.

◆ SDL_iconv_wchar_utf8

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

Convert a wchar_t string to UTF-8.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5997 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

Definition at line 1141 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)
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.2.0.
See also
SDL_IOStreamInterface
SDL_StorageInterface
SDL_VirtualJoystickDesc

Definition at line 1256 of file SDL_stdinc.h.

1257 { \
1258 SDL_zerop(iface); \
1259 (iface)->version = sizeof(*(iface)); \
1260 } while (0)

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 1142 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.2.0.
See also
SDL_StepBackUTF8
SDL_StepUTF8

Definition at line 3985 of file SDL_stdinc.h.

◆ SDL_max

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

Return the greater of two values.

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the > operator. However, it double-evaluates both its parameters, so do not use expressions with side-effects here.

Parameters
xthe first value to compare.
ythe second value to compare.
Returns
the greater of x and y.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2157 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 456 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 474 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 494 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 438 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 522 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 465 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 483 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 505 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 447 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 2512 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2568 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 2616 of file SDL_stdinc.h.

◆ SDL_min

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

Return the lesser of two values.

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the < operator. However, it double-evaluates both its parameters, so do not use expressions with side-effects here.

Parameters
xthe first value to compare.
ythe second value to compare.
Returns
the lesser of x and y.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2139 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 457 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 475 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 495 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 439 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 523 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 466 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 484 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 506 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 448 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 1145 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 1144 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 1146 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 1143 of file SDL_stdinc.h.

◆ SDL_PI_D

#define SDL_PI_D   3.141592653589793238462643383279502884

The value of Pi, as a double-precision floating point literal.

Since
This macro is available since SDL 3.2.0.
See also
SDL_PI_F pi (double)

Definition at line 4480 of file SDL_stdinc.h.

◆ SDL_PI_F

#define SDL_PI_F   3.141592653589793238462643383279502884F

The value of Pi, as a single-precision floating point literal.

Since
This macro is available since SDL 3.2.0.
See also
SDL_PI_D pi (float)

Definition at line 4492 of file SDL_stdinc.h.

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 808 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 811 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 814 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 817 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 820 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1147 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1158 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1159 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 777 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 737 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 784 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 748 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 791 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 798 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 759 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 770 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 344 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1148 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 1160 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1161 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 409 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 184 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 1309 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)    ((void)(data))

Definition at line 1310 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 345 of file SDL_stdinc.h.

◆ SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG (   arg)    #arg

Macro useful for building other macros with strings in them.

Parameters
argthe text to turn into a string literal.
Since
This macro is available since SDL 3.2.0.

Definition at line 261 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 421 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1162 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1163 of file SDL_stdinc.h.

◆ SDL_zero

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

Clear an object's memory to zero.

This is wrapper over SDL_memset that handles calculating the object size, so there's no chance of copy/paste errors, and the code is cleaner.

This requires an object, not a pointer to an object, nor an array.

Parameters
xthe object to clear.

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

Since
This macro is available since SDL 3.2.0.
See also
SDL_zerop
SDL_zeroa

Definition at line 2636 of file SDL_stdinc.h.

◆ SDL_zeroa

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

Clear an array's memory to zero.

This is wrapper over SDL_memset that handles calculating the array size, so there's no chance of copy/paste errors, and the code is cleaner.

This requires an array, not an object, nor a pointer to an object.

Parameters
xan array to clear.

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

Since
This macro is available since SDL 3.2.0.
See also
SDL_zero
SDL_zerop

Definition at line 2674 of file SDL_stdinc.h.

◆ SDL_zerop

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

Clear an object's memory to zero, using a pointer.

This is wrapper over SDL_memset that handles calculating the object size, so there's no chance of copy/paste errors, and the code is cleaner.

This requires a pointer to an object, not an object itself, nor an array.

Parameters
xa pointer to the object to clear.

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

Since
This macro is available since SDL 3.2.0.
See also
SDL_zero
SDL_zeroa

Definition at line 2655 of file SDL_stdinc.h.

◆ true

#define true   1

Definition at line 101 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.2.0.
See also
SDL_calloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 1467 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.2.0.
See also
SDL_bsearch
SDL_qsort

Definition at line 1885 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.2.0.
See also
SDL_qsort_r
SDL_bsearch_r

Definition at line 1998 of file SDL_stdinc.h.

◆ SDL_Environment

A thread-safe set of environment variables

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

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

Definition at line 1506 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6177 of file SDL_stdinc.h.

◆ SDL_iconv_t

typedef struct SDL_iconv_data_t* SDL_iconv_t

An opaque handle representing string encoding conversion state.

Since
This datatype is available since SDL 3.2.0.
See also
SDL_iconv_open

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

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

Definition at line 1488 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 datatype is available since SDL 3.2.0.
See also
SDL_MAX_SINT64
SDL_MIN_SINT64

Definition at line 521 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 455 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 473 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

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

Definition at line 493 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 437 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 464 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 482 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

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

Definition at line 504 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 446 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

◆ SDL_abs()

int SDL_abs ( int  x)
extern

Compute the absolute value of x.

Parameters
xan integer value.
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.2.0.

◆ 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.2.0.
See also
SDL_acosf
SDL_asin
SDL_cos

◆ SDL_acosf()

float SDL_acosf ( float  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_aligned_alloc()

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

Allocate memory aligned to a specific alignment.

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

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

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

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

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

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

◆ SDL_aligned_free()

void SDL_aligned_free ( void *  mem)
extern

Free memory allocated by SDL_aligned_alloc().

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

If mem is NULL, this function does nothing.

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

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

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

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( )
extern

Change the size of allocated memory.

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

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

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

  • If it returns the same pointer as mem, it means that mem was resized in place without freeing.
  • If it returns a different non-NULL pointer, it means that mem was freed and cannot be dereferenced anymore.
  • If it returns NULL (indicating failure), then mem will remain valid and must still be freed with SDL_free().

If the allocation is successfully resized, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller.

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.2.0.
See also
SDL_free
SDL_malloc
SDL_calloc

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( ,
 
)
extern

Allocate a zero-initialized array.

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

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

If the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller.

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.2.0.
See also
SDL_free
SDL_malloc
SDL_realloc

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asprintf()

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

This works exactly like asprintf() but doesn't require access to a C runtime.

Functions identically to SDL_snprintf(), except it allocates a buffer large enough to hold the output string on behalf of the caller.

On success, this function returns the number of bytes (not characters) comprising the output string, not counting the null-terminator character, and sets *strp to the newly-allocated string.

On error, this function returns a negative number, and the value of *strp is undefined.

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

Parameters
strpon output, is set to the new string. Must not be NULL.
fmta printf-style format string. Must not be NULL.
...a list of values to be used with the format string.
Returns
the number of bytes in the newly-allocated string, not counting the null-terminator char, or a negative value on error.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_atanf
SDL_atan2
SDL_tan

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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.2.0.
See also
SDL_atan2f
SDL_atan
SDL_tan

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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.2.0.
See also
SDL_atan2
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.2.0.
See also
SDL_atan
SDL_atan2f
SDL_tanf

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

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

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

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

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

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

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

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

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

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

◆ SDL_bsearch()

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

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:252
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.2.0.
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.2.0.
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.2.0.
See also
SDL_ceilf
SDL_floor
SDL_trunc
SDL_round
SDL_lround

◆ SDL_ceilf()

float SDL_ceilf ( float  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

Since
This function is available since SDL 3.2.0.
See also
SDL_copysign
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.2.0.
See also
SDL_cosf
SDL_acos
SDL_sin

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_crc16()

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

Calculate a CRC-16 value.

https://en.wikipedia.org/wiki/Cyclic_redundancy_check

This function can be called multiple times, to stream data to be checksummed in blocks. Each call must provide the previous CRC-16 return value to be updated with the next block. The first call to this function for a set of blocks should pass in a zero CRC value.

Parameters
crcthe current checksum for this data set, or 0 for a new data set.
dataa new block of data to add to the checksum.
lenthe size, in bytes, of the new block of data.
Returns
a CRC-16 checksum value of all blocks in the data set.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_crc32()

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

Calculate a CRC-32 value.

https://en.wikipedia.org/wiki/Cyclic_redundancy_check

This function can be called multiple times, to stream data to be checksummed in blocks. Each call must provide the previous CRC-32 return value to be updated with the next block. The first call to this function for a set of blocks should pass in a zero CRC value.

Parameters
crcthe current checksum for this data set, or 0 for a new data set.
dataa new block of data to add to the checksum.
lenthe size, in bytes, of the new block of data.
Returns
a CRC-32 checksum value of all blocks in the data set.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable
SDL_DestroyEnvironment

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

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

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

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

This function operates on double-precision floating point values, use SDL_fabsf 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.2.0.
See also
SDL_fabsf

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

This function operates on single-precision floating point values, use SDL_fabs 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.2.0.
See also
SDL_fabs

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

This function operates on single-precision floating point values, use SDL_floor 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.2.0.
See also
SDL_floor
SDL_ceilf
SDL_truncf
SDL_roundf
SDL_lroundf

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

This function operates on single-precision floating point values, use SDL_fmod for double-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.2.0.
See also
SDL_fmod
SDL_truncf
SDL_modff
SDL_ceilf
SDL_floorf
SDL_roundf
SDL_lroundf

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

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

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

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

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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

The name of the variable is case sensitive on all platforms.

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

◆ SDL_getenv_unsafe()

const char * SDL_getenv_unsafe ( const char *  name)
extern

Get the value of a variable in the environment.

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

On some platforms, this may make case-insensitive matches, while other platforms are case-sensitive. It is best to be precise with strings used for queries through this interface. SDL_getenv is always case-sensitive, however.

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.2.0.
See also
SDL_getenv

◆ SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment ( void  )
extern

Get the process environment.

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

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

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

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

◆ SDL_GetEnvironmentVariable()

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

Get the value of a variable in the environment.

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

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

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

◆ SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables ( SDL_Environment env)
extern

Get all variables in the environment.

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

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

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

◆ SDL_GetMemoryFunctions()

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

Get the current set of SDL memory functions.

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

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

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

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )
extern

Get the number of outstanding (unfreed) allocations.

Returns
the number of allocations or -1 if allocation counting is disabled.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_GetOriginalMemoryFunctions()

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

Get the original set of SDL memory functions.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iconv()

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

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

It returns the number of successful conversions on success. On error, 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.
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, or a negative error code.

\threadsafety Do not use the same SDL_iconv_t from two threads at once.

Since
This function is available since SDL 3.2.0.
See also
SDL_iconv_open
SDL_iconv_close
SDL_iconv_string

◆ SDL_iconv_close()

int SDL_iconv_close ( SDL_iconv_t  cd)
extern

This function frees a context used for character set conversion.

Parameters
cdThe character set conversion handle.
Returns
0 on success, or -1 on failure.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_iconv
SDL_iconv_open
SDL_iconv_string

◆ SDL_iconv_open()

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

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

Parameters
tocodeThe target character encoding, must not be NULL.
fromcodeThe source character encoding, must not be NULL.
Returns
a handle that must be freed with SDL_iconv_close, or SDL_ICONV_ERROR on failure.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_iconv
SDL_iconv_close
SDL_iconv_string

◆ SDL_iconv_string()

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

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

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

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

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

Parameters
tocodethe character encoding of the output string. Examples are "UTF-8", "UCS-4", etc.
fromcodethe character encoding of data in inbuf.
inbufthe string to convert to a different encoding.
inbytesleftthe size of the input string in bytes.
Returns
a new string, converted to the new encoding, or NULL on error.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_iconv_open
SDL_iconv_close
SDL_iconv

◆ SDL_isalnum()

int SDL_isalnum ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isalpha()

int SDL_isalpha ( int  x)
extern

Query if a character is alphabetic (a letter).

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isblank()

int SDL_isblank ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iscntrl()

int SDL_iscntrl ( int  x)
extern

Report if a character is a control character.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isdigit()

int SDL_isdigit ( int  x)
extern

Report if a character is a numeric digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isgraph()

int SDL_isgraph ( int  x)
extern

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

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

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

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

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

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

◆ SDL_isinf()

int SDL_isinf ( double  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_isinff()

int SDL_isinff ( float  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_islower()

int SDL_islower ( int  x)
extern

Report if a character is lower case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isnan()

int SDL_isnan ( double  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isnanf()

int SDL_isnanf ( float  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isprint()

int SDL_isprint ( int  x)
extern

Report if a character is "printable".

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_ispunct()

int SDL_ispunct ( int  x)
extern

Report if a character is a punctuation mark.

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

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

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

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

◆ SDL_isspace()

int SDL_isspace ( int  x)
extern

Report if a character is whitespace.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isupper()

int SDL_isupper ( int  x)
extern

Report if a character is upper case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isxdigit()

int SDL_isxdigit ( int  x)
extern

Report if a character is a hexadecimal digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_itoa()

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

Convert an integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).

Parameters
valuethe integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_uitoa
SDL_ltoa
SDL_lltoa

◆ SDL_lltoa()

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

Convert a long long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).

Parameters
valuethe long long integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_ulltoa
SDL_itoa
SDL_ltoa

◆ 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.2.0.
See also
SDL_logf
SDL_log10
SDL_exp

◆ SDL_log10()

double SDL_log10 ( double  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10f()

float SDL_log10f ( float  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_logf()

float SDL_logf ( float  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_lround()

long SDL_lround ( double  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

This function operates on double-precision floating point values, use SDL_lroundf 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.2.0.
See also
SDL_lroundf
SDL_round
SDL_floor
SDL_ceil
SDL_trunc

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

This function operates on single-precision floating point values, use SDL_lround 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.2.0.
See also
SDL_lround
SDL_roundf
SDL_floorf
SDL_ceilf
SDL_truncf

◆ SDL_ltoa()

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

Convert a long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).

Parameters
valuethe long integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_ultoa
SDL_itoa
SDL_lltoa

◆ 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 the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller. Use SDL_aligned_alloc() if you need to allocate memory aligned to an alignment greater than this guarantee.

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.2.0.
See also
SDL_free
SDL_calloc
SDL_realloc
SDL_aligned_alloc

◆ SDL_memcmp()

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

Compare two buffers of memory.

Parameters
s1the first buffer to compare. NULL is not permitted!
s2the second buffer to compare. NULL is not permitted!
lenthe number of bytes to compare between the buffers.
Returns
less than zero if s1 is "less than" s2, greater than zero if s1 is "greater than" s2, and zero if the buffers match exactly for len bytes.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_memmove

◆ SDL_memmove()

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

Copy memory ranges that might overlap.

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.2.0.
See also
SDL_memcpy

◆ SDL_memset()

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

Initialize all bytes of buffer of memory to a specific value.

This function will set len bytes, pointed to by dst, to the value specified in c.

Despite c being an int instead of a char, this only operates on bytes; c must be a value between 0 and 255, inclusive.

Parameters
dstthe destination memory region. Must not be NULL.
cthe byte value to set.
lenthe length, in bytes, to set in dst.
Returns
dst.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memset4()

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

Initialize all 32-bit words of buffer of memory to a specific value.

This function will set a buffer of dwords Uint32 values, pointed to by dst, to the value specified in val.

Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited to a range of 0-255.

Parameters
dstthe destination memory region. Must not be NULL.
valthe Uint32 value to set.
dwordsthe number of Uint32 values to set in dst.
Returns
dst.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_modff
SDL_trunc
SDL_fmod

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_murmur3_32()

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

Calculate a 32-bit MurmurHash3 value for a block of data.

https://en.wikipedia.org/wiki/MurmurHash

A seed may be specified, which changes the final results consistently, but this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous result from this function back into itself as the next seed value to calculate a hash in chunks; it won't produce the same hash as it would if the same data was provided in a single call.

If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not cryptographically secure, so it shouldn't be used for hashing top-secret data.

Parameters
datathe data to be hashed.
lenthe size of data, in bytes.
seeda value that alters the final hash value.
Returns
a Murmur3 32-bit hash value.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_powf
SDL_exp
SDL_log

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

This function operates on single-precision floating point values, use SDL_pow 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.2.0.
See also
SDL_pow
SDL_expf
SDL_logf

◆ SDL_qsort()

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

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.2.0.
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.2.0.
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.2.0.
See also
SDL_srand
SDL_randf

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 state)
extern

Generate 32 pseudo-random bits.

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

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

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

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

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

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 state,
Sint32  n 
)
extern

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

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

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

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

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

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

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

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

◆ SDL_randf()

float SDL_randf ( void  )
extern

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 state)
extern

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

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

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

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

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

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

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

This function operates on single-precision floating point values, use SDL_round for double-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.2.0.
See also
SDL_round
SDL_lroundf
SDL_floorf
SDL_ceilf
SDL_truncf

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_setenv_unsafe()

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

Set the value of a variable in the environment.

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

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

Since
This function is available since SDL 3.2.0.
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.2.0.
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.2.0.
See also
SDL_GetMemoryFunctions
SDL_GetOriginalMemoryFunctions

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on single-precision floating point values, use SDL_sin 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.2.0.
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 false.

Otherwise store a + b via ret and return true.

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

Definition at line 6134 of file SDL_stdinc.h.

6135{
6136 if (b > SDL_SIZE_MAX - a) {
6137 return false;
6138 }
6139 *ret = a + b;
6140 return true;
6141}

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

Definition at line 6095 of file SDL_stdinc.h.

6096{
6097 if (a != 0 && b > SDL_SIZE_MAX / a) {
6098 return false;
6099 }
6100 *ret = a * b;
6101 return true;
6102}

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

This works exactly like snprintf() but doesn't require access to a C runtime.

Format a string of up to maxlen-1 bytes, converting each '' item with values provided through variable arguments.

While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen count. Note that if maxlen is zero, however, no bytes will be written at all.

This function returns the number of bytes (not characters) that should be written, excluding the null-terminator character. If this returns a number >= maxlen, it means the output string was truncated. A negative return value means an error occurred.

Referencing the output string's pointer with a format item is undefined behavior.

Parameters
textthe buffer to write the string into. Must not be NULL.
maxlenthe maximum bytes to write, including the null-terminator.
fmta printf-style format string. Must not be NULL.
...a list of values to be used with the format string.
Returns
the number of bytes that should be written, not counting the null-terminator char, or a negative value on error.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_sqrtf

◆ SDL_sqrtf()

float SDL_sqrtf ( float  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

◆ SDL_srand()

void SDL_srand ( Uint64  seed)
extern

Seeds the pseudo-random number generator.

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

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

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

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

◆ SDL_sscanf()

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

This works exactly like sscanf() but doesn't require access to a C runtime.

Scan a string, matching a format string, converting each '' item and storing it to pointers provided through variable arguments.

Parameters
textthe string to scan. Must not be NULL.
fmta printf-style format string. Must not be NULL.
...a list of pointers to values to be filled in with scanned items.
Returns
the number of items that matched the format string.

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

Since
This function is available since SDL 3.2.0.

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

◆ SDL_strcasecmp()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strcasestr()

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

Search a UTF-8 string for the first instance of a specific substring, 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 strings 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
haystackthe string to search. Must not be NULL.
needlethe string to search for. Must not be NULL.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strchr()

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

Search a string for the first instance of a specific byte.

The search ends once it finds the requested byte value, or a null terminator byte to end the string.

Note that this looks for bytes, not characters, so you cannot match against a Unicode codepoint > 255, regardless of character encoding.

Parameters
strthe string to search. Must not be NULL.
cthe byte value to search for.
Returns
a pointer to the first instance of c in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

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

◆ SDL_strdup()

SDL_MALLOC char * SDL_strdup ( const char *  str)
extern

Allocate a copy of a string.

This allocates enough space for a null-terminated copy of str, using SDL_malloc, and then makes a copy of the string into this space.

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

Parameters
strthe string to copy.
Returns
a pointer to the newly-allocated string.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_strlcpy

◆ SDL_strlcpy()

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

Copy a string.

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

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

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

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

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

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

◆ SDL_strlen()

size_t SDL_strlen ( const char *  str)
extern

This works exactly like strlen() but doesn't require access to a C runtime.

Counts the bytes in str, excluding the null terminator.

If you need the length of a UTF-8 string, consider using SDL_utf8strlen().

Parameters
strThe null-terminated string to read. Must not be NULL.
Returns
the length (in bytes, 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.2.0.
See also
SDL_strnlen
SDL_utf8strlen
SDL_utf8strnlen

Referenced by SDL_AppIterate().

◆ 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.2.0.
See also
SDL_strupr

◆ SDL_strncasecmp()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strncmp()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strndup()

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

Allocate a copy of a string, up to n characters.

This allocates enough space for a null-terminated copy of str, up to maxlen bytes, using SDL_malloc, and then makes a copy of the string into this space.

If the string is longer than maxlen bytes, the returned string will be maxlen bytes long, plus a null-terminator character that isn't included in the count.

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

Parameters
strthe string to copy.
maxlenthe maximum length of the copied string, not counting the null-terminator character.
Returns
a pointer to the newly-allocated string.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strnlen()

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

This works exactly like strnlen() but doesn't require access to a C runtime.

Counts up to a maximum of maxlen bytes in str, excluding the null terminator.

If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().

Parameters
strThe null-terminated string to read. Must not be NULL.
maxlenThe maximum amount of bytes to count.
Returns
the length (in bytes, excluding the null terminator) of src but never more than maxlen.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_strlen
SDL_utf8strlen
SDL_utf8strnlen

◆ SDL_strnstr()

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

Search a string, up to n bytes, for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string, or maxlen bytes have been examined. It is possible to use this function on a string without a null terminator.

Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.

Parameters
haystackthe string to search. Must not be NULL.
needlethe string to search for. Must not be NULL.
maxlenthe maximum number of bytes to search in haystack.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strpbrk()

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

Searches a string for the first occurrence 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 occurrence 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.2.0.

◆ SDL_strrchr()

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

Search a string for the last instance of a specific byte.

The search must go until it finds a null terminator byte to end the string.

Note that this looks for bytes, not characters, so you cannot match against a Unicode codepoint > 255, regardless of character encoding.

Parameters
strthe string to search. Must not be NULL.
cthe byte value to search for.
Returns
a pointer to the last instance of c in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strrev()

char * SDL_strrev ( char *  str)
extern

Reverse a string's contents.

This reverses a null-terminated string in-place. Only the content of the string is reversed; the null-terminator character remains at the end of the reversed string.

WARNING: This function reverses the bytes of the string, not the codepoints. If str is a UTF-8 string with Unicode codepoints > 127, this will ruin the string data. You should only use this function on strings that are completely comprised of low ASCII characters.

Parameters
strthe string to reverse.
Returns
str.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strstr()

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

Search a string for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string.

Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.

Parameters
haystackthe string to search. Must not be NULL.
needlethe string to search for. Must not be NULL.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoll
SDL_strtoul
SDL_strtoull

◆ SDL_strtok_r()

char * SDL_strtok_r ( char *  str,
const char *  delim,
char **  saveptr 
)
extern

This works exactly like strtok_r() but doesn't require access to a C runtime.

Break a string up into a series of tokens.

To start tokenizing a new string, str should be the non-NULL address of the string to start tokenizing. Future calls to get the next token from the same string should specify a NULL.

Note that this function will overwrite pieces of str with null chars to split it into tokens. This function cannot be used with const/read-only strings!

saveptr just needs to point to a char * that can be overwritten; SDL will use this to save tokenizing state between calls. It is initialized if str is non-NULL, and used to resume tokenizing when str is NULL.

Parameters
strthe string to tokenize, or NULL to continue tokenizing.
delimthe delimiter string that separates tokens.
saveptrpointer to a char *, used for ongoing state.
Returns
A pointer to the next token, or NULL if no tokens remain.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_atoi
SDL_atof
SDL_strtoul
SDL_strtoll
SDL_strtoull
SDL_strtod
SDL_ltoa
SDL_wcstol

◆ SDL_strtoll()

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

Parse a long long from a string.

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

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

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

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

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

◆ SDL_strtoul()

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

Parse an unsigned long from a string.

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

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

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

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

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

◆ SDL_strtoull()

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

Parse an unsigned long long from a string.

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

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

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

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

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

◆ SDL_strupr()

char * SDL_strupr ( char *  str)
extern

Convert a string to uppercase.

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

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

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

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

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

◆ SDL_swprintf()

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

This works exactly like swprintf() but doesn't require access to a C runtime.

Format a wide string of up to maxlen-1 wchar_t values, converting each '' item with values provided through variable arguments.

While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen count. Note that if maxlen is zero, however, no wide characters will be written at all.

This function returns the number of wide characters (not codepoints) that should be written, excluding the null-terminator character. If this returns a number >= maxlen, it means the output string was truncated. A negative return value means an error occurred.

Referencing the output string's pointer with a format item is undefined behavior.

Parameters
textthe buffer to write the wide string into. Must not be NULL.
maxlenthe maximum wchar_t values to write, including the null-terminator.
fmta printf-style format string. Must not be NULL.
...a list of values to be used with the format string.
Returns
the number of wide characters that should be written, not counting the null-terminator char, or a negative value on error.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_tanf
SDL_sin
SDL_cos
SDL_atan
SDL_atan2

◆ SDL_tanf()

float SDL_tanf ( float  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on single-precision floating point values, use SDL_tan 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.2.0.
See also
SDL_tan
SDL_sinf
SDL_cosf
SDL_atanf
SDL_atan2f

◆ SDL_tolower()

int SDL_tolower ( int  x)
extern

Convert low-ASCII English letters to lowercase.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_toupper()

int SDL_toupper ( int  x)
extern

Convert low-ASCII English letters to uppercase.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_trunc()

double SDL_trunc ( double  x)
extern

Truncate x to an integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_truncf()

float SDL_truncf ( float  x)
extern

Truncate x to an integer.

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

Domain: -INF <= x <= INF

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

This function operates on single-precision floating point values, use SDL_trunc 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.2.0.
See also
SDL_trunc
SDL_fmodf
SDL_ceilf
SDL_floorf
SDL_roundf
SDL_lroundf

◆ SDL_UCS4ToUTF8()

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

Convert a single Unicode codepoint to UTF-8.

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_uitoa()

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

Convert an unsigned integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters
valuethe unsigned integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_itoa
SDL_ultoa
SDL_ulltoa

◆ SDL_ulltoa()

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

Convert an unsigned long long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters
valuethe unsigned long long integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_lltoa
SDL_uitoa
SDL_ultoa

◆ SDL_ultoa()

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

Convert an unsigned long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters
valuethe unsigned long integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_ltoa
SDL_uitoa
SDL_ulltoa

◆ 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.2.0.
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.2.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable

◆ SDL_utf8strlcpy()

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

Copy an UTF-8 string.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_utf8strlen()

size_t SDL_utf8strlen ( const char *  str)
extern

Count the number of codepoints in a UTF-8 string.

Counts the codepoints, not bytes, in str, excluding the null terminator.

If you need to count the bytes in a string instead, consider using SDL_strlen().

Since this handles Unicode, it expects the strings 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), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.

Parameters
strThe null-terminated UTF-8 string to read. Must not be NULL.
Returns
The length (in codepoints, 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.2.0.
See also
SDL_utf8strnlen
SDL_strlen

◆ SDL_utf8strnlen()

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

Count the number of codepoints in a UTF-8 string, up to n bytes.

Counts the codepoints, not bytes, in str, excluding the null terminator.

If you need to count the bytes in a string instead, consider using SDL_strnlen().

The counting stops at bytes bytes (not codepoints!). This seems counterintuitive, but makes it easy to express the total size of the string's buffer.

Since this handles Unicode, it expects the strings 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), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.

Parameters
strThe null-terminated UTF-8 string to read. Must not be NULL.
bytesThe maximum amount of bytes to count.
Returns
The length (in codepoints, excluding the null terminator) of src but never more than maxlen.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_utf8strlen
SDL_strnlen

◆ SDL_vasprintf()

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

This works exactly like vasprintf() but doesn't require access to a C runtime.

Functions identically to SDL_asprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters
strpon output, is set to the new string. Must not be NULL.
fmta printf-style format string. Must not be NULL.
apa va_list values to be used with the format string.
Returns
the number of bytes in the newly-allocated string, not counting the null-terminator char, or a negative value on error.

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

Since
This function is available since SDL 3.2.0.

◆ 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

This works exactly like vsnprintf() but doesn't require access to a C runtime.

Functions identically to SDL_snprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters
textthe buffer to write the string into. Must not be NULL.
maxlenthe maximum bytes to write, including the null-terminator.
fmta printf-style format string. Must not be NULL.
apa va_list values to be used with the format string.
Returns
the number of bytes that should be written, not counting the null-terminator char, or a negative value on error.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_vsscanf()

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

This works exactly like vsscanf() but doesn't require access to a C runtime.

Functions identically to SDL_sscanf(), except it takes a va_list instead of using ... variable arguments.

Parameters
textthe string to scan. Must not be NULL.
fmta printf-style format string. Must not be NULL.
apa va_list of pointers to values to be filled in with scanned items.
Returns
the number of items that matched the format string.

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

Since
This function is available since SDL 3.2.0.

◆ 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

This works exactly like vswprintf() but doesn't require access to a C runtime.

Functions identically to SDL_swprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters
textthe buffer to write the string into. Must not be NULL.
maxlenthe maximum wide characters to write, including the null-terminator.
fmta printf-style format wide string. Must not be NULL.
apa va_list values to be used with the format string.
Returns
the number of wide characters that should be written, not counting the null-terminator char, or a negative value on error.

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

Since
This function is available since SDL 3.2.0.

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

◆ SDL_wcscmp()

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

Compare two null-terminated wide strings.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsdup()

wchar_t * SDL_wcsdup ( const wchar_t *  wstr)
extern

Allocate a copy of a wide string.

This allocates enough space for a null-terminated copy of wstr, using SDL_malloc, and then makes a copy of the string into this space.

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

Parameters
wstrthe string to copy.
Returns
a pointer to the newly-allocated wide string.

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

Since
This function is available since SDL 3.2.0.

◆ 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.2.0.
See also
SDL_wcslcpy

◆ SDL_wcslcpy()

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

Copy a wide string.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_wcslen()

size_t SDL_wcslen ( const wchar_t *  wstr)
extern

This works exactly like wcslen() but doesn't require access to a C runtime.

Counts the number of wchar_t values in wstr, excluding the null terminator.

Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.

Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).

Parameters
wstrThe null-terminated wide string to read. Must not be NULL.
Returns
the length (in wchar_t values, excluding the null terminator) of wstr.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_wcsnlen
SDL_utf8strlen
SDL_utf8strnlen

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

◆ SDL_wcsncmp()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsnlen()

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

This works exactly like wcsnlen() but doesn't require access to a C runtime.

Counts up to a maximum of maxlen wchar_t values in wstr, excluding the null terminator.

Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.

Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).

Also, maxlen is a count of wide characters, not bytes!

Parameters
wstrThe null-terminated wide string to read. Must not be NULL.
maxlenThe maximum amount of wide characters to count.
Returns
the length (in wide characters, excluding the null terminator) of wstr but never more than maxlen.

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

Since
This function is available since SDL 3.2.0.
See also
SDL_wcslen
SDL_utf8strlen
SDL_utf8strnlen

◆ SDL_wcsnstr()

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

Search a wide string, up to n wide chars, for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator value to end the string, or maxlen wide character have been examined. It is possible to use this function on a wide string without a null terminator.

Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.

Parameters
haystackthe wide string to search. Must not be NULL.
needlethe wide string to search for. Must not be NULL.
maxlenthe maximum number of wide characters to search in haystack.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsstr()

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

Search a wide string for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string.

Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.

Parameters
haystackthe wide string to search. Must not be NULL.
needlethe wide string to search for. Must not be NULL.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

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

Since
This function is available since SDL 3.2.0.

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

Variable Documentation

◆ size

size_t size

Definition at line 1367 of file SDL_stdinc.h.