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

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

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5862 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5863 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5860 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 5910 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 5924 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 5938 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 5952 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 3956 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 2128 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 2483 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2539 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 2587 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 2110 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 4451 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 4463 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 2607 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 2645 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 2626 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 1445 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 1856 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 1969 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 1628 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 1484 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6124 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 5786 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 1424 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 1466 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().

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

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

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

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

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( ,
 
)
extern

Allocate a zero-initialized array.

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

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

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

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

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

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

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asprintf()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_atan()

double SDL_atan ( double  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

Range: -Pi/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_atan2
SDL_atan
SDL_tan

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

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

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

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

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

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

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

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

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

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

◆ SDL_bsearch()

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

Perform a binary search on a previously sorted array.

For example:

typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *a, const void *b)
{
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
}
}
data values[] = {
{ 1, "first" }, { 2, "second" }, { 3, "third" }
};
data key = { 2, NULL };
data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
#define SDL_arraysize(array)
Definition SDL_stdinc.h: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_copysign
SDL_fabsf

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_crc16()

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

Calculate a CRC-16 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_crc32()

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

Calculate a CRC-32 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment ( bool  populated)
extern

Create a set of environment variables

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

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

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

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

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

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

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

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

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

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

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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

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

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_ltoa()

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

Convert a long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 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 the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller. Use SDL_aligned_alloc() if you need to allocate memory aligned to an alignment greater than this guarantee.

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

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

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

◆ SDL_memcmp()

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

Compare two buffers of memory.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memcpy()

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

Copy non-overlapping memory.

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

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

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

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

◆ SDL_memmove()

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

Copy memory ranges that might overlap.

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

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

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

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

◆ SDL_memset()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memset4()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_modf()

double SDL_modf ( double  x,
double *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_murmur3_32()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_qsort()

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

Sort an array.

For example:

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

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

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

◆ SDL_qsort_r()

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

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

For example:

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

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

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

◆ SDL_rand()

Sint32 SDL_rand ( Sint32  n)
extern

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

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

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

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 state)
extern

Generate 32 pseudo-random bits.

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

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

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

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

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

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 state,
Sint32  n 
)
extern

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

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

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

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

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

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

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

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

◆ SDL_randf()

float SDL_randf ( void  )
extern

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 state)
extern

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

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

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

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

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

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

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_setenv_unsafe()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetEnvironmentVariable()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetMemoryFunctions()

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

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

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

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

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

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

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

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_size_add_check_overflow()

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

Add two integers, checking for overflow.

If a + b would overflow, return false.

Otherwise store a + b via ret and return true.

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 6081 of file SDL_stdinc.h.

6082{
6083 if (b > SDL_SIZE_MAX - a) {
6084 return false;
6085 }
6086 *ret = a + b;
6087 return true;
6088}

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

6043{
6044 if (a != 0 && b > SDL_SIZE_MAX / a) {
6045 return false;
6046 }
6047 *ret = a * b;
6048 return true;
6049}

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_tan for double-precision floats.

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

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

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

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

◆ SDL_tolower()

int SDL_tolower ( int  x)
extern

Convert low-ASCII English letters to lowercase.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_toupper()

int SDL_toupper ( int  x)
extern

Convert low-ASCII English letters to uppercase.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_trunc()

double SDL_trunc ( double  x)
extern

Truncate x to an integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_truncf()

float SDL_truncf ( float  x)
extern

Truncate x to an integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_UCS4ToUTF8()

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

Convert a single Unicode codepoint to UTF-8.

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_uitoa()

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

Convert an unsigned integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 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 1345 of file SDL_stdinc.h.