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

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

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

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

Definition at line 2469 of file SDL_stdinc.h.

2470 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
2471 SDL_memcpy((dst), (src), sizeof(*(src)))

◆ SDL_FLT_EPSILON

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

Epsilon constant, used for comparing floating-point numbers.

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

Since
This macro is available since SDL 3.1.3.

Definition at line 497 of file SDL_stdinc.h.

◆ SDL_FOURCC

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

Define a four character code as a Uint32.

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

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

Since
This macro is available since SDL 3.1.3.

Definition at line 318 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Output buffer was too small.

Definition at line 5813 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5814 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5815 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

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

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

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

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

Definition at line 5904 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

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

Definition at line 1205 of file SDL_stdinc.h.

1206 { \
1207 SDL_zerop(iface); \
1208 (iface)->version = sizeof(*(iface)); \
1209 } while (0)

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 1093 of file SDL_stdinc.h.

◆ SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they encounter a UTF-8 string with encoding errors.

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

Since
This macro is available since SDL 3.1.3.
See also
SDL_StepBackUTF8
SDL_StepUTF8

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

Definition at line 2086 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 409 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 427 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 447 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 391 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 475 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 418 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 436 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 458 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 400 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 2441 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2497 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

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

Definition at line 2068 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 410 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 428 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 448 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 392 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 476 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 419 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 437 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 459 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 401 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 1096 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 1095 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 1097 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 1094 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.1.3.
See also
SDL_PI_F pi (double)

Definition at line 4403 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.1.3.
See also
SDL_PI_D pi (float)

Definition at line 4415 of file SDL_stdinc.h.

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 759 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 762 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 765 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 768 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 771 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1098 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1109 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1110 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 730 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 690 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 737 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 701 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 744 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 751 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 712 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 723 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 297 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1099 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 1111 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1112 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 362 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 131 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 1257 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 1258 of file SDL_stdinc.h.

◆ SDL_static_cast

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

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

Definition at line 214 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 374 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1113 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1114 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.1.3.
See also
SDL_zerop
SDL_zeroa

Definition at line 2565 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.1.3.
See also
SDL_zero
SDL_zeroa

Definition at line 2603 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.1.3.
See also
SDL_zero
SDL_zeroa

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

Definition at line 1403 of file SDL_stdinc.h.

◆ SDL_CompareCallback

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

A callback used with SDL sorting and binary search functions.

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

Definition at line 1814 of file SDL_stdinc.h.

◆ SDL_CompareCallback_r

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

A callback used with SDL sorting and binary search functions.

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

Definition at line 1927 of file SDL_stdinc.h.

◆ SDL_Environment

A thread-safe set of environment variables

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

Definition at line 1586 of file SDL_stdinc.h.

◆ SDL_free_func

typedef void(* SDL_free_func) (void *mem)

A callback used to implement SDL_free().

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

Parameters
mema pointer to allocated memory.

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

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

Definition at line 1442 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6077 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.1.3.
See also
SDL_iconv_open

Definition at line 5738 of file SDL_stdinc.h.

◆ SDL_malloc_func

typedef void *(* SDL_malloc_func) (size_t size)

A callback used to implement SDL_malloc().

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

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

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

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

Definition at line 1382 of file SDL_stdinc.h.

◆ SDL_realloc_func

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

A callback used to implement SDL_realloc().

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

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

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

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

Definition at line 1424 of file SDL_stdinc.h.

◆ SDL_Time

typedef Sint64 SDL_Time

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

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

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

Definition at line 474 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 408 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 426 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

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

Definition at line 446 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 390 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 417 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.1.3.

Definition at line 435 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

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

Definition at line 457 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.1.3.

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

◆ SDL_acos()

double SDL_acos ( double  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_acosf()

float SDL_acosf ( float  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_aligned_alloc()

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

Allocate memory aligned to a specific alignment.

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

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

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

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

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

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

◆ SDL_aligned_free()

void SDL_aligned_free ( void *  mem)
extern

Free memory allocated by SDL_aligned_alloc().

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

If mem is NULL, this function does nothing.

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

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

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

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( )
extern

Change the size of allocated memory.

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

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

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

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

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

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

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( ,
 
)
extern

Allocate a zero-initialized array.

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

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

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

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

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

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asprintf()

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

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

◆ SDL_atan()

double SDL_atan ( double  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

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

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

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

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

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

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

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

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

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

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

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

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

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

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

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

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

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

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

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

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

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

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

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

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

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

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

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

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

◆ SDL_bsearch()

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

Perform a binary search on a previously sorted array.

For example:

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

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

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

◆ SDL_bsearch_r()

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

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

For example:

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

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

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

◆ SDL_ceil()

double SDL_ceil ( double  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_ceilf()

float SDL_ceilf ( float  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_crc16()

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

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

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

◆ SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment ( bool  populated)
extern

Create a set of environment variables

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

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

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

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

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

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

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

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

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

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

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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_getenv_unsafe()

const char * SDL_getenv_unsafe ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

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

◆ SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment ( void  )
extern

Get the process environment.

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

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

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

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

◆ SDL_GetEnvironmentVariable()

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

Get the value of a variable in the environment.

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

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

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

◆ SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables ( SDL_Environment env)
extern

Get all variables in the environment.

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

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

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

◆ SDL_GetMemoryFunctions()

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

Get the current set of SDL memory functions.

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

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

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

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )
extern

Get the number of outstanding (unfreed) allocations.

Returns
the number of allocations 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.1.3.

◆ SDL_GetOriginalMemoryFunctions()

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

Get the original set of SDL memory functions.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_iconv()

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

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

It returns the number of succesful conversions 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.1.3.
See also
SDL_iconv_open
SDL_iconv_close
SDL_iconv_string

◆ SDL_iconv_close()

int SDL_iconv_close ( SDL_iconv_t  cd)
extern

This function frees a context used for character set conversion.

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

◆ SDL_iconv_open()

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

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

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

◆ SDL_iconv_string()

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

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

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

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

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

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

◆ SDL_isalnum()

int SDL_isalnum ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isalpha()

int SDL_isalpha ( int  x)
extern

Query if a character is alphabetic (a letter).

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isblank()

int SDL_isblank ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_iscntrl()

int SDL_iscntrl ( int  x)
extern

Report if a character is a control character.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isdigit()

int SDL_isdigit ( int  x)
extern

Report if a character is a numeric digit.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isgraph()

int SDL_isgraph ( int  x)
extern

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

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

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

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

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

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

◆ SDL_isinf()

int SDL_isinf ( double  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_isinff()

int SDL_isinff ( float  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_islower()

int SDL_islower ( int  x)
extern

Report if a character is lower case.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isnan()

int SDL_isnan ( double  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isnanf()

int SDL_isnanf ( float  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isprint()

int SDL_isprint ( int  x)
extern

Report if a character is "printable".

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_ispunct()

int SDL_ispunct ( int  x)
extern

Report if a character is a punctuation mark.

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

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

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

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

◆ SDL_isspace()

int SDL_isspace ( int  x)
extern

Report if a character is whitespace.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isupper()

int SDL_isupper ( int  x)
extern

Report if a character is upper case.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_isxdigit()

int SDL_isxdigit ( int  x)
extern

Report if a character is a hexadecimal digit.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_itoa()

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

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

◆ SDL_log10()

double SDL_log10 ( double  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10f()

float SDL_log10f ( float  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_logf()

float SDL_logf ( float  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_lround()

long SDL_lround ( double  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_ltoa()

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

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.1.3.
See also
SDL_ultoa
SDL_itoa
SDL_lltoa

◆ SDL_malloc()

SDL_MALLOC void * SDL_malloc ( size_t  size)
extern

Allocate uninitialized memory.

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

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

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

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

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

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

◆ SDL_memcmp()

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

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

◆ SDL_memcpy()

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

Copy non-overlapping memory.

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

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

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

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

◆ SDL_memmove()

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

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

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

◆ SDL_modf()

double SDL_modf ( double  x,
double *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_murmur3_32()

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

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

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_qsort()

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

Sort an array.

For example:

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

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

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

◆ SDL_qsort_r()

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

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

For example:

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

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

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

◆ SDL_rand()

Sint32 SDL_rand ( Sint32  n)
extern

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

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

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

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 state)
extern

Generate 32 pseudo-random bits.

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

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

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

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

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

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 state,
Sint32  n 
)
extern

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

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

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

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

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

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

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

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

◆ SDL_randf()

float SDL_randf ( void  )
extern

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 state)
extern

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

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

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

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

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

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

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_setenv_unsafe()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetEnvironmentVariable()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetMemoryFunctions()

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

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

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

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

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

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

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

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on single-precision floating point values, use SDL_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.1.3.
See also
SDL_sin
SDL_asinf
SDL_cosf

◆ SDL_size_add_check_overflow()

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

Add two integers, checking for overflow.

If a + b would overflow, return 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.1.3.

Definition at line 6034 of file SDL_stdinc.h.

6035{
6036 if (b > SDL_SIZE_MAX - a) {
6037 return false;
6038 }
6039 *ret = a + b;
6040 return true;
6041}

References SDL_SIZE_MAX.

◆ SDL_size_mul_check_overflow()

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

Multiply two integers, checking for overflow.

If a * b would overflow, return false.

Otherwise store a * b via ret and return true.

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

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

Since
This function is available since SDL 3.1.3.

Definition at line 5995 of file SDL_stdinc.h.

5996{
5997 if (a != 0 && b > SDL_SIZE_MAX / a) {
5998 return false;
5999 }
6000 *ret = a * b;
6001 return true;
6002}

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

◆ SDL_sqrt()

double SDL_sqrt ( double  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

◆ SDL_sqrtf()

float SDL_sqrtf ( float  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

◆ SDL_srand()

void SDL_srand ( Uint64  seed)
extern

Seeds the pseudo-random number generator.

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

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

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

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

◆ SDL_sscanf()

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

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

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

◆ SDL_StepUTF8()

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

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

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

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

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_strcasecmp()

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_strcasestr()

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

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

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

◆ SDL_strcmp()

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

Compare two null-terminated UTF-8 strings.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_strdup()

SDL_MALLOC char * SDL_strdup ( const char *  str)
extern

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

◆ SDL_strlcat()

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

Concatenate strings.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_strlcpy()

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

Copy a string.

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

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

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

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

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

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

◆ SDL_strlen()

size_t SDL_strlen ( const char *  str)
extern

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.1.3.
See also
SDL_strnlen
SDL_utf8strlen
SDL_utf8strnlen

◆ SDL_strlwr()

char * SDL_strlwr ( char *  str)
extern

Convert a string to lowercase.

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

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

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

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

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

◆ SDL_strncasecmp()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_strncmp()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_strndup()

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

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

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

◆ SDL_strpbrk()

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_strrchr()

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

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

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

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

◆ SDL_strtod()

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

Parse a double from a string.

This function makes fewer guarantees than the C runtime strtod:

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

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

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

◆ SDL_strtok_r()

char * SDL_strtok_r ( char *  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.1.3.

◆ SDL_strtol()

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

Parse a long from a string.

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

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

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

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

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

◆ SDL_strtoll()

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

Parse a long long from a string.

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

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

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

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

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

◆ SDL_strtoul()

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

Parse an unsigned long from a string.

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

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

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

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

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

◆ SDL_strtoull()

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

Parse an unsigned long long from a string.

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

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

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

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

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

◆ SDL_strupr()

char * SDL_strupr ( char *  str)
extern

Convert a string to uppercase.

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

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

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

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

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

◆ SDL_swprintf()

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

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

◆ SDL_tan()

double SDL_tan ( double  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

◆ SDL_tanf()

float SDL_tanf ( float  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

◆ SDL_tolower()

int SDL_tolower ( int  x)
extern

Convert low-ASCII English letters to lowercase.

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_toupper()

int SDL_toupper ( int  x)
extern

Convert low-ASCII English letters to uppercase.

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_trunc()

double SDL_trunc ( double  x)
extern

Truncate x to an integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_truncf()

float SDL_truncf ( float  x)
extern

Truncate x to an integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_UCS4ToUTF8()

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

Convert a single Unicode codepoint to UTF-8.

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_uitoa()

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

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

◆ SDL_UnsetEnvironmentVariable()

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

Clear a variable from the environment.

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

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

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

◆ SDL_utf8strlcpy()

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

Copy an UTF-8 string.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_utf8strlen()

size_t SDL_utf8strlen ( const char *  str)
extern

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

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

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

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

◆ SDL_wcscasecmp()

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_wcscmp()

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

Compare two null-terminated wide strings.

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_wcsdup()

wchar_t * SDL_wcsdup ( const wchar_t *  wstr)
extern

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

◆ SDL_wcslcat()

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

Concatenate wide strings.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_wcslcpy()

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

Copy a wide string.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_wcslen()

size_t SDL_wcslen ( const wchar_t *  wstr)
extern

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

◆ SDL_wcsncmp()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.1.3.

◆ SDL_wcsnlen()

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

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

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

◆ SDL_wcstol()

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

Parse a long from a wide string.

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

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

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

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

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

Variable Documentation

◆ size

size_t size

Definition at line 1308 of file SDL_stdinc.h.