SDL 3.0
SDL_stdinc.h File Reference
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
+ Include dependency graph for SDL_stdinc.h:

Go to the source code of this file.

Macros

#define bool   unsigned char
 
#define false   0
 
#define true   1
 
#define __bool_true_false_are_defined   1
 
#define SDL_SIZE_MAX   ((size_t) -1)
 
#define SDL_COMPILE_TIME_ASSERT(name, x)    typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
 
#define SDL_arraysize(array)   (sizeof(array)/sizeof(array[0]))
 
#define SDL_STRINGIFY_ARG(arg)   #arg
 
Cast operators

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

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

Functions

void * alloca (size_t)
 

Basic data types

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

Floating-point constants

#define SDL_FLT_EPSILON   1.1920928955078125e-07F /* 0x0.000002p0 */
 
#define SDL_PRIs64   "lld"
 
#define SDL_PRIu64   "llu"
 
#define SDL_PRIx64   "llx"
 
#define SDL_PRIX64   "llX"
 
#define SDL_PRIs32   "d"
 
#define SDL_PRIu32   "u"
 
#define SDL_PRIx32   "x"
 
#define SDL_PRIX32   "X"
 
#define SDL_PRILL_PREFIX   "ll"
 
#define SDL_PRILLd   SDL_PRILL_PREFIX "d"
 
#define SDL_PRILLu   SDL_PRILL_PREFIX "u"
 
#define SDL_PRILLx   SDL_PRILL_PREFIX "x"
 
#define SDL_PRILLX   SDL_PRILL_PREFIX "X"
 
#define SDL_IN_BYTECAP(x)
 
#define SDL_INOUT_Z_CAP(x)
 
#define SDL_OUT_Z_CAP(x)
 
#define SDL_OUT_CAP(x)
 
#define SDL_OUT_BYTECAP(x)
 
#define SDL_OUT_Z_BYTECAP(x)
 
#define SDL_PRINTF_FORMAT_STRING
 
#define SDL_SCANF_FORMAT_STRING
 
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
 
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
 
#define SDL_SCANF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
 
#define SDL_WPRINTF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_INIT_INTERFACE(iface)
 
#define SDL_stack_alloc(type, count)   (type*)alloca(sizeof(type)*(count))
 
#define SDL_stack_free(data)
 
#define SDL_min(x, y)   (((x) < (y)) ? (x) : (y))
 
#define SDL_max(x, y)   (((x) > (y)) ? (x) : (y))
 
#define SDL_clamp(x, a, b)   (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
 
#define SDL_memcpy   memcpy
 
#define SDL_copyp(dst, src)
 
#define SDL_memmove   memmove
 
#define SDL_memset   memset
 
#define SDL_zero(x)   SDL_memset(&(x), 0, sizeof((x)))
 
#define SDL_zerop(x)   SDL_memset((x), 0, sizeof(*(x)))
 
#define SDL_zeroa(x)   SDL_memset((x), 0, sizeof((x)))
 
#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD
 
#define SDL_PI_D   3.141592653589793238462643383279502884
 
#define SDL_PI_F   3.141592653589793238462643383279502884F
 
#define SDL_ICONV_ERROR   (size_t)-1
 
#define SDL_ICONV_E2BIG   (size_t)-2
 
#define SDL_ICONV_EILSEQ   (size_t)-3
 
#define SDL_ICONV_EINVAL   (size_t)-4
 
#define SDL_iconv_utf8_locale(S)   SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_utf8_ucs2(S)   (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_utf8_ucs4(S)   (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_wchar_utf8(S)   SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
 
typedef void *(* SDL_malloc_func) (size_t size)
 
typedef void *(* SDL_calloc_func) (size_t nmemb, size_t size)
 
typedef void *(* SDL_realloc_func) (void *mem, size_t size)
 
typedef void(* SDL_free_func) (void *mem)
 
typedef struct SDL_Environment SDL_Environment
 
typedef int(* SDL_CompareCallback) (const void *a, const void *b)
 
typedef int(* SDL_CompareCallback_r) (void *userdata, const void *a, const void *b)
 
typedef struct SDL_iconv_data_t * SDL_iconv_t
 
typedef void(* SDL_FunctionPointer) (void)
 
SDL_MALLOC size_t size
 
SDL_MALLOC void * SDL_malloc (size_t size)
 
SDL_MALLOC SDL_ALLOC_SIZE2 (1, 2) void *SDL_calloc(size_t nmemb
 
 SDL_ALLOC_SIZE (2) void *SDL_realloc(void *mem
 
void SDL_free (void *mem)
 
void SDL_GetOriginalMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
 
void SDL_GetMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
 
bool SDL_SetMemoryFunctions (SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
 
SDL_MALLOC void * SDL_aligned_alloc (size_t alignment, size_t size)
 
void SDL_aligned_free (void *mem)
 
int SDL_GetNumAllocations (void)
 
SDL_EnvironmentSDL_GetEnvironment (void)
 
SDL_EnvironmentSDL_CreateEnvironment (bool populated)
 
const char * SDL_GetEnvironmentVariable (SDL_Environment *env, const char *name)
 
char ** SDL_GetEnvironmentVariables (SDL_Environment *env)
 
bool SDL_SetEnvironmentVariable (SDL_Environment *env, const char *name, const char *value, bool overwrite)
 
bool SDL_UnsetEnvironmentVariable (SDL_Environment *env, const char *name)
 
void SDL_DestroyEnvironment (SDL_Environment *env)
 
const char * SDL_getenv (const char *name)
 
const char * SDL_getenv_unsafe (const char *name)
 
int SDL_setenv_unsafe (const char *name, const char *value, int overwrite)
 
int SDL_unsetenv_unsafe (const char *name)
 
void SDL_qsort (void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void * SDL_bsearch (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void SDL_qsort_r (void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
void * SDL_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
int SDL_abs (int x)
 
int SDL_isalpha (int x)
 
int SDL_isalnum (int x)
 
int SDL_isblank (int x)
 
int SDL_iscntrl (int x)
 
int SDL_isdigit (int x)
 
int SDL_isxdigit (int x)
 
int SDL_ispunct (int x)
 
int SDL_isspace (int x)
 
int SDL_isupper (int x)
 
int SDL_islower (int x)
 
int SDL_isprint (int x)
 
int SDL_isgraph (int x)
 
int SDL_toupper (int x)
 
int SDL_tolower (int x)
 
Uint16 SDL_crc16 (Uint16 crc, const void *data, size_t len)
 
Uint32 SDL_crc32 (Uint32 crc, const void *data, size_t len)
 
Uint32 SDL_murmur3_32 (const void *data, size_t len, Uint32 seed)
 
void * SDL_memcpy (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memmove (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memset (SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
 
void * SDL_memset4 (void *dst, Uint32 val, size_t dwords)
 
int SDL_memcmp (const void *s1, const void *s2, size_t len)
 
size_t SDL_wcslen (const wchar_t *wstr)
 
size_t SDL_wcsnlen (const wchar_t *wstr, size_t maxlen)
 
size_t SDL_wcslcpy (SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
size_t SDL_wcslcat (SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
wchar_t * SDL_wcsdup (const wchar_t *wstr)
 
wchar_t * SDL_wcsstr (const wchar_t *haystack, const wchar_t *needle)
 
wchar_t * SDL_wcsnstr (const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
 
int SDL_wcscmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
int SDL_wcscasecmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncasecmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
long SDL_wcstol (const wchar_t *str, wchar_t **endp, int base)
 
size_t SDL_strlen (const char *str)
 
size_t SDL_strnlen (const char *str, size_t maxlen)
 
size_t SDL_strlcpy (SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
size_t SDL_utf8strlcpy (SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
 
size_t SDL_strlcat (SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
SDL_MALLOC char * SDL_strdup (const char *str)
 
SDL_MALLOC char * SDL_strndup (const char *str, size_t maxlen)
 
char * SDL_strrev (char *str)
 
char * SDL_strupr (char *str)
 
char * SDL_strlwr (char *str)
 
char * SDL_strchr (const char *str, int c)
 
char * SDL_strrchr (const char *str, int c)
 
char * SDL_strstr (const char *haystack, const char *needle)
 
char * SDL_strnstr (const char *haystack, const char *needle, size_t maxlen)
 
char * SDL_strcasestr (const char *haystack, const char *needle)
 
char * SDL_strtok_r (char *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 75 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 72 of file SDL_stdinc.h.

◆ false

#define false   0

Definition at line 73 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 225 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 2140 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 209 of file SDL_stdinc.h.

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

2500 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
2501 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 523 of file SDL_stdinc.h.

◆ SDL_FOURCC

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

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 344 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Output buffer was too small.

Definition at line 5849 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5850 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5851 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5848 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.
Since
This macro is available since SDL 3.2.0.

Definition at line 5898 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs2

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

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.
Since
This macro is available since SDL 3.2.0.

Definition at line 5912 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs4

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

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.
Since
This macro is available since SDL 3.2.0.

Definition at line 5926 of file SDL_stdinc.h.

◆ SDL_iconv_wchar_utf8

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

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.
Since
This macro is available since SDL 3.2.0.

Definition at line 5940 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

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

1236 { \
1237 SDL_zerop(iface); \
1238 (iface)->version = sizeof(*(iface)); \
1239 } while (0)

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 1121 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 3944 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 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 2116 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 435 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 453 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 473 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 417 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 501 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 444 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 462 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 484 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 426 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 2471 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2527 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

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

◆ SDL_MIN_SINT16

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

Definition at line 436 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 454 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 474 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 418 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 502 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 445 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 463 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 485 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 427 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 1124 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 1123 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 1125 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 1122 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 4439 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 4451 of file SDL_stdinc.h.

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 787 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 790 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 793 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 796 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 799 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1126 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1137 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1138 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 756 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 716 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 763 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 727 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 770 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 777 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 738 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 749 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 323 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1127 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 1139 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1140 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 388 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 157 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 1287 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 1288 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 324 of file SDL_stdinc.h.

◆ SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG (   arg)    #arg

Macro useful for building other macros with strings in them.

For example:

#define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
Parameters
argthe text to turn into a string literal.
Since
This macro is available since SDL 3.2.0.

Definition at line 240 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 400 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1141 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1142 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 2595 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_zeroa

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

◆ true

#define true   1

Definition at line 74 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 1433 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 1844 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 1957 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 1616 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 1472 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6113 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 5774 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 1412 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 1454 of file SDL_stdinc.h.

◆ SDL_Time

typedef Sint64 SDL_Time

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

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

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

Definition at line 500 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 434 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 452 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 472 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 416 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 443 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 461 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 483 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 425 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().
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.

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/2 <= y <= Pi/2

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

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

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

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

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

Since
This function is available since SDL 3.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/2 <= y <= Pi/2

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

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

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

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

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

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

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

Since
This function is available since SDL 3.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:225
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_copysignf
SDL_fabsf

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

Since
This function is available since SDL 3.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_copysignf for single-precision floats.

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

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

Since
This function is available since SDL 3.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_copysignf for double-precision floats.

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

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

Since
This function is available since SDL 3.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_floorf for double-precision floats.

Parameters
xfloating point value.
Returns
the floor of x.

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

Since
This function is available since SDL 3.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 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_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.

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.

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 succesful 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.
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.
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.
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.
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 hexidecimal, 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 hexidecimal, 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_lround for single-precision floats. To get the result as a floating-point type, use SDL_round.

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

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

Since
This function is available since SDL 3.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_lroundf for double-precision floats. To get the result as a floating-point type, use SDL_roundf,

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

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

Since
This function is available since SDL 3.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 hexidecimal, 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 you want to allocate memory aligned to a specific alignment, consider using SDL_aligned_alloc().

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

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

Since
This function is available since SDL 3.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_powf for double-precision floats.

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

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

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

Since
This function is available since SDL 3.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 double-precision floating point values, use SDL_roundf for single-precision floats. To get the result as an integer type, use SDL_lroundf.

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

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

Since
This function is available since SDL 3.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 6070 of file SDL_stdinc.h.

6071{
6072 if (b > SDL_SIZE_MAX - a) {
6073 return false;
6074 }
6075 *ret = a + b;
6076 return true;
6077}

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 6031 of file SDL_stdinc.h.

6032{
6033 if (a != 0 && b > SDL_SIZE_MAX / a) {
6034 return false;
6035 }
6036 *ret = a * b;
6037 return true;
6038}

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 occurence of any character contained in a breakset, and returns a pointer from the string to that character.

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

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

Since
This function is available since SDL 3.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_tanf for double-precision floats.

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

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

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

Since
This function is available since SDL 3.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_truncf for double-precision floats.

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

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

Since
This function is available since SDL 3.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 hexidecimal, 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 hexidecimal, 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 hexidecimal, 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 1338 of file SDL_stdinc.h.