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

Go to the source code of this file.

Macros

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

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

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

Functions

void * alloca (size_t)
 

Basic data types

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

Floating-point constants

#define SDL_FLT_EPSILON   1.1920928955078125e-07F /* 0x0.000002p0 */
 
#define SDL_PRIs64   "lld"
 
#define SDL_PRIu64   "llu"
 
#define SDL_PRIx64   "llx"
 
#define SDL_PRIX64   "llX"
 
#define SDL_PRIs32   "d"
 
#define SDL_PRIu32   "u"
 
#define SDL_PRIx32   "x"
 
#define SDL_PRIX32   "X"
 
#define SDL_PRILL_PREFIX   "ll"
 
#define SDL_PRILLd   SDL_PRILL_PREFIX "d"
 
#define SDL_PRILLu   SDL_PRILL_PREFIX "u"
 
#define SDL_PRILLx   SDL_PRILL_PREFIX "x"
 
#define SDL_PRILLX   SDL_PRILL_PREFIX "X"
 
#define SDL_IN_BYTECAP(x)
 
#define SDL_INOUT_Z_CAP(x)
 
#define SDL_OUT_Z_CAP(x)
 
#define SDL_OUT_CAP(x)
 
#define SDL_OUT_BYTECAP(x)
 
#define SDL_OUT_Z_BYTECAP(x)
 
#define SDL_PRINTF_FORMAT_STRING
 
#define SDL_SCANF_FORMAT_STRING
 
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
 
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
 
#define SDL_SCANF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
 
#define SDL_WPRINTF_VARARG_FUNCV(fmtargnumber)
 
#define SDL_INIT_INTERFACE(iface)
 
#define SDL_stack_alloc(type, count)   (type*)alloca(sizeof(type)*(count))
 
#define SDL_stack_free(data)
 
#define SDL_min(x, y)   (((x) < (y)) ? (x) : (y))
 
#define SDL_max(x, y)   (((x) > (y)) ? (x) : (y))
 
#define SDL_clamp(x, a, b)   (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
 
#define SDL_memcpy   memcpy
 
#define SDL_copyp(dst, src)
 
#define SDL_memmove   memmove
 
#define SDL_memset   memset
 
#define SDL_zero(x)   SDL_memset(&(x), 0, sizeof((x)))
 
#define SDL_zerop(x)   SDL_memset((x), 0, sizeof(*(x)))
 
#define SDL_zeroa(x)   SDL_memset((x), 0, sizeof((x)))
 
#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD
 
#define SDL_PI_D   3.141592653589793238462643383279502884
 
#define SDL_PI_F   3.141592653589793238462643383279502884F
 
#define SDL_ICONV_ERROR   (size_t)-1
 
#define SDL_ICONV_E2BIG   (size_t)-2
 
#define SDL_ICONV_EILSEQ   (size_t)-3
 
#define SDL_ICONV_EINVAL   (size_t)-4
 
#define SDL_iconv_utf8_locale(S)   SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
 
#define SDL_iconv_utf8_ucs2(S)   SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
 
#define SDL_iconv_utf8_ucs4(S)   SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))
 
#define SDL_iconv_wchar_utf8(S)   SDL_iconv_string("UTF-8", "WCHAR_T", SDL_reinterpret_cast(const char *, S), (SDL_wcslen(S)+1)*sizeof(wchar_t))
 
typedef void *(* SDL_malloc_func) (size_t size)
 
typedef void *(* SDL_calloc_func) (size_t nmemb, size_t size)
 
typedef void *(* SDL_realloc_func) (void *mem, size_t size)
 
typedef void(* SDL_free_func) (void *mem)
 
typedef struct SDL_Environment SDL_Environment
 
typedef int(* SDL_CompareCallback) (const void *a, const void *b)
 
typedef int(* SDL_CompareCallback_r) (void *userdata, const void *a, const void *b)
 
typedef struct SDL_iconv_data_t * SDL_iconv_t
 
typedef void(* SDL_FunctionPointer) (void)
 
SDL_MALLOC size_t size
 
SDL_MALLOC void * SDL_malloc (size_t size)
 
SDL_MALLOC SDL_ALLOC_SIZE2 (1, 2) void *SDL_calloc(size_t nmemb
 
 SDL_ALLOC_SIZE (2) void *SDL_realloc(void *mem
 
void SDL_free (void *mem)
 
void SDL_GetOriginalMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
 
void SDL_GetMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
 
bool SDL_SetMemoryFunctions (SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
 
SDL_MALLOC void * SDL_aligned_alloc (size_t alignment, size_t size)
 
void SDL_aligned_free (void *mem)
 
int SDL_GetNumAllocations (void)
 
SDL_Environment * SDL_GetEnvironment (void)
 
SDL_Environment * SDL_CreateEnvironment (bool populated)
 
const char * SDL_GetEnvironmentVariable (SDL_Environment *env, const char *name)
 
char ** SDL_GetEnvironmentVariables (SDL_Environment *env)
 
bool SDL_SetEnvironmentVariable (SDL_Environment *env, const char *name, const char *value, bool overwrite)
 
bool SDL_UnsetEnvironmentVariable (SDL_Environment *env, const char *name)
 
void SDL_DestroyEnvironment (SDL_Environment *env)
 
const char * SDL_getenv (const char *name)
 
const char * SDL_getenv_unsafe (const char *name)
 
int SDL_setenv_unsafe (const char *name, const char *value, int overwrite)
 
int SDL_unsetenv_unsafe (const char *name)
 
void SDL_qsort (void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void * SDL_bsearch (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void SDL_qsort_r (void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
void * SDL_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
int SDL_abs (int x)
 
int SDL_isalpha (int x)
 
int SDL_isalnum (int x)
 
int SDL_isblank (int x)
 
int SDL_iscntrl (int x)
 
int SDL_isdigit (int x)
 
int SDL_isxdigit (int x)
 
int SDL_ispunct (int x)
 
int SDL_isspace (int x)
 
int SDL_isupper (int x)
 
int SDL_islower (int x)
 
int SDL_isprint (int x)
 
int SDL_isgraph (int x)
 
int SDL_toupper (int x)
 
int SDL_tolower (int x)
 
Uint16 SDL_crc16 (Uint16 crc, const void *data, size_t len)
 
Uint32 SDL_crc32 (Uint32 crc, const void *data, size_t len)
 
Uint32 SDL_murmur3_32 (const void *data, size_t len, Uint32 seed)
 
void * SDL_memcpy (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memmove (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memset (SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
 
void * SDL_memset4 (void *dst, Uint32 val, size_t dwords)
 
int SDL_memcmp (const void *s1, const void *s2, size_t len)
 
size_t SDL_wcslen (const wchar_t *wstr)
 
size_t SDL_wcsnlen (const wchar_t *wstr, size_t maxlen)
 
size_t SDL_wcslcpy (SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
size_t SDL_wcslcat (SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
wchar_t * SDL_wcsdup (const wchar_t *wstr)
 
wchar_t * SDL_wcsstr (const wchar_t *haystack, const wchar_t *needle)
 
wchar_t * SDL_wcsnstr (const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
 
int SDL_wcscmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
int SDL_wcscasecmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncasecmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
long SDL_wcstol (const wchar_t *str, wchar_t **endp, int base)
 
size_t SDL_strlen (const char *str)
 
size_t SDL_strnlen (const char *str, size_t maxlen)
 
size_t SDL_strlcpy (SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
size_t SDL_utf8strlcpy (SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
 
size_t SDL_strlcat (SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
SDL_MALLOC char * SDL_strdup (const char *str)
 
SDL_MALLOC char * SDL_strndup (const char *str, size_t maxlen)
 
char * SDL_strrev (char *str)
 
char * SDL_strupr (char *str)
 
char * SDL_strlwr (char *str)
 
char * SDL_strchr (const char *str, int c)
 
char * SDL_strrchr (const char *str, int c)
 
char * SDL_strstr (const char *haystack, const char *needle)
 
char * SDL_strnstr (const char *haystack, const char *needle, size_t maxlen)
 
char * SDL_strcasestr (const char *haystack, const char *needle)
 
char * SDL_strtok_r (char *str, const char *delim, char **saveptr)
 
size_t SDL_utf8strlen (const char *str)
 
size_t SDL_utf8strnlen (const char *str, size_t bytes)
 
char * SDL_itoa (int value, char *str, int radix)
 
char * SDL_uitoa (unsigned int value, char *str, int radix)
 
char * SDL_ltoa (long value, char *str, int radix)
 
char * SDL_ultoa (unsigned long value, char *str, int radix)
 
char * SDL_lltoa (long long value, char *str, int radix)
 
char * SDL_ulltoa (unsigned long long value, char *str, int radix)
 
int SDL_atoi (const char *str)
 
double SDL_atof (const char *str)
 
long SDL_strtol (const char *str, char **endp, int base)
 
unsigned long SDL_strtoul (const char *str, char **endp, int base)
 
long long SDL_strtoll (const char *str, char **endp, int base)
 
unsigned long long SDL_strtoull (const char *str, char **endp, int base)
 
double SDL_strtod (const char *str, char **endp)
 
int SDL_strcmp (const char *str1, const char *str2)
 
int SDL_strncmp (const char *str1, const char *str2, size_t maxlen)
 
int SDL_strcasecmp (const char *str1, const char *str2)
 
int SDL_strncasecmp (const char *str1, const char *str2, size_t maxlen)
 
char * SDL_strpbrk (const char *str, const char *breakset)
 
Uint32 SDL_StepUTF8 (const char **pstr, size_t *pslen)
 
Uint32 SDL_StepBackUTF8 (const char *start, const char **pstr)
 
char * SDL_UCS4ToUTF8 (Uint32 codepoint, char *dst)
 
int SDL_sscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
 
int SDL_vsscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2)
 
int SDL_snprintf (SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(3)
 
int SDL_swprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...) SDL_WPRINTF_VARARG_FUNC(3)
 
int SDL_vsnprintf (SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3)
 
int SDL_vswprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3)
 
int SDL_asprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
 
int SDL_vasprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
 
void SDL_srand (Uint64 seed)
 
Sint32 SDL_rand (Sint32 n)
 
float SDL_randf (void)
 
Uint32 SDL_rand_bits (void)
 
Sint32 SDL_rand_r (Uint64 *state, Sint32 n)
 
float SDL_randf_r (Uint64 *state)
 
Uint32 SDL_rand_bits_r (Uint64 *state)
 
double SDL_acos (double x)
 
float SDL_acosf (float x)
 
double SDL_asin (double x)
 
float SDL_asinf (float x)
 
double SDL_atan (double x)
 
float SDL_atanf (float x)
 
double SDL_atan2 (double y, double x)
 
float SDL_atan2f (float y, float x)
 
double SDL_ceil (double x)
 
float SDL_ceilf (float x)
 
double SDL_copysign (double x, double y)
 
float SDL_copysignf (float x, float y)
 
double SDL_cos (double x)
 
float SDL_cosf (float x)
 
double SDL_exp (double x)
 
float SDL_expf (float x)
 
double SDL_fabs (double x)
 
float SDL_fabsf (float x)
 
double SDL_floor (double x)
 
float SDL_floorf (float x)
 
double SDL_trunc (double x)
 
float SDL_truncf (float x)
 
double SDL_fmod (double x, double y)
 
float SDL_fmodf (float x, float y)
 
int SDL_isinf (double x)
 
int SDL_isinff (float x)
 
int SDL_isnan (double x)
 
int SDL_isnanf (float x)
 
double SDL_log (double x)
 
float SDL_logf (float x)
 
double SDL_log10 (double x)
 
float SDL_log10f (float x)
 
double SDL_modf (double x, double *y)
 
float SDL_modff (float x, float *y)
 
double SDL_pow (double x, double y)
 
float SDL_powf (float x, float y)
 
double SDL_round (double x)
 
float SDL_roundf (float x)
 
long SDL_lround (double x)
 
long SDL_lroundf (float x)
 
double SDL_scalbn (double x, int n)
 
float SDL_scalbnf (float x, int n)
 
double SDL_sin (double x)
 
float SDL_sinf (float x)
 
double SDL_sqrt (double x)
 
float SDL_sqrtf (float x)
 
double SDL_tan (double x)
 
float SDL_tanf (float x)
 
SDL_iconv_t SDL_iconv_open (const char *tocode, const char *fromcode)
 
int SDL_iconv_close (SDL_iconv_t cd)
 
size_t SDL_iconv (SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
 
char * SDL_iconv_string (const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
 
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow (size_t a, size_t b, size_t *ret)
 
SDL_FORCE_INLINE bool SDL_size_add_check_overflow (size_t a, size_t b, size_t *ret)
 

Macro Definition Documentation

◆ __bool_true_false_are_defined

#define __bool_true_false_are_defined   1

Definition at line 102 of file SDL_stdinc.h.

◆ bool

#define bool   unsigned char

CategoryStdinc

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

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

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

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

Definition at line 99 of file SDL_stdinc.h.

◆ false

#define false   0

Definition at line 100 of file SDL_stdinc.h.

◆ SDL_arraysize

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

The number of elements in a static array.

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

This macro looks like it double-evaluates the argument, but it does so inside of sizeof, so there are no side-effects here, as expressions do not actually run any code in these cases.

Since
This macro is available since SDL 3.2.0.

Definition at line 252 of file SDL_stdinc.h.

◆ SDL_clamp

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

Return a value clamped to a range.

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

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

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2179 of file SDL_stdinc.h.

◆ SDL_COMPILE_TIME_ASSERT

#define SDL_COMPILE_TIME_ASSERT (   name,
  x 
)     typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]

Definition at line 236 of file SDL_stdinc.h.

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

◆ SDL_copyp

#define SDL_copyp (   dst,
  src 
)
Value:
{ SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
SDL_memcpy((dst), (src), sizeof(*(src)))
#define SDL_copyp(dst, src)

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 2538 of file SDL_stdinc.h.

2539 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
2540 SDL_memcpy((dst), (src), sizeof(*(src)))

◆ SDL_FLT_EPSILON

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

Epsilon constant, used for comparing floating-point numbers.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 550 of file SDL_stdinc.h.

◆ SDL_FOURCC

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

Define a four character code as a Uint32.

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 371 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Output buffer was too small.

Definition at line 5888 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5889 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5890 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5887 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_locale

#define SDL_iconv_utf8_locale (   S)    SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)

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

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

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.
Since
This macro is available since SDL 3.2.0.

Definition at line 5937 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs2

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

Convert a UTF-8 string to UCS-2.

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

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.
Since
This macro is available since SDL 3.2.0.

Definition at line 5951 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs4

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

Convert a UTF-8 string to UCS-4.

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

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.
Since
This macro is available since SDL 3.2.0.

Definition at line 5965 of file SDL_stdinc.h.

◆ SDL_iconv_wchar_utf8

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

Convert a wchar_t string to UTF-8.

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

Parameters
Sthe string to convert.
Returns
a new string, converted to the new encoding, or NULL on error.
Since
This macro is available since SDL 3.2.0.

Definition at line 5979 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

Definition at line 1147 of file SDL_stdinc.h.

◆ SDL_INIT_INTERFACE

#define SDL_INIT_INTERFACE (   iface)
Value:
do { \
SDL_zerop(iface); \
(iface)->version = sizeof(*(iface)); \
} while (0)

A macro to initialize an SDL interface.

This macro will initialize an SDL interface structure and should be called before you fill out the fields with your implementation.

You can use it like this:

// Fill in the interface function pointers with your implementation
iface.seek = ...
stream = SDL_OpenIO(&iface, NULL);
#define NULL
SDL_IOStream * SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
#define SDL_INIT_INTERFACE(iface)
Sint64(* seek)(void *userdata, Sint64 offset, SDL_IOWhence whence)

If you are using designated initializers, you can use the size of the interface as the version, e.g.

.version = sizeof(iface),
.seek = ...
};
stream = SDL_OpenIO(&iface, NULL);

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

Since
This macro is available since SDL 3.2.0.
See also
SDL_IOStreamInterface
SDL_StorageInterface
SDL_VirtualJoystickDesc

Definition at line 1262 of file SDL_stdinc.h.

1263 { \
1264 SDL_zerop(iface); \
1265 (iface)->version = sizeof(*(iface)); \
1266 } while (0)

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 1148 of file SDL_stdinc.h.

◆ SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

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

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

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

Definition at line 3983 of file SDL_stdinc.h.

◆ SDL_max

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

Return the greater of two values.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2155 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 462 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 480 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 500 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 444 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 528 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 471 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 489 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 511 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 453 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 2510 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2566 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 2614 of file SDL_stdinc.h.

◆ SDL_min

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

Return the lesser of two values.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2137 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 463 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 481 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 501 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 445 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 529 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 472 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 490 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 512 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 454 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 1151 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 1150 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 1152 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 1149 of file SDL_stdinc.h.

◆ SDL_PI_D

#define SDL_PI_D   3.141592653589793238462643383279502884

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

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

Definition at line 4478 of file SDL_stdinc.h.

◆ SDL_PI_F

#define SDL_PI_F   3.141592653589793238462643383279502884F

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

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

Definition at line 4490 of file SDL_stdinc.h.

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 814 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 817 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 820 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 823 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 826 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1153 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1164 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1165 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 783 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 743 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 790 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 754 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 797 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 804 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 765 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 776 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 350 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1154 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 1166 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1167 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 415 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 184 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 1314 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 1315 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 351 of file SDL_stdinc.h.

◆ SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG (   arg)    #arg

Macro useful for building other macros with strings in them.

For example:

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

Definition at line 267 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 427 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1168 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1169 of file SDL_stdinc.h.

◆ SDL_zero

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

Clear an object's memory to zero.

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

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

Parameters
xthe object to clear.

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

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

Definition at line 2634 of file SDL_stdinc.h.

◆ SDL_zeroa

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

Clear an array's memory to zero.

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

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

Parameters
xan array to clear.

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

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

Definition at line 2672 of file SDL_stdinc.h.

◆ SDL_zerop

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

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

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

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

Parameters
xa pointer to the object to clear.

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

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

Definition at line 2653 of file SDL_stdinc.h.

◆ true

#define true   1

Definition at line 101 of file SDL_stdinc.h.

Typedef Documentation

◆ SDL_calloc_func

typedef void *(* SDL_calloc_func) (size_t nmemb, size_t size)

A callback used to implement SDL_calloc().

SDL will always ensure that the passed nmemb and size are both greater than 0.

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

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

Since
This datatype is available since SDL 3.2.0.
See also
SDL_calloc
SDL_GetOriginalMemoryFunctions
SDL_GetMemoryFunctions
SDL_SetMemoryFunctions

Definition at line 1472 of file SDL_stdinc.h.

◆ SDL_CompareCallback

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

A callback used with SDL sorting and binary search functions.

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

Definition at line 1883 of file SDL_stdinc.h.

◆ SDL_CompareCallback_r

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

A callback used with SDL sorting and binary search functions.

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

Definition at line 1996 of file SDL_stdinc.h.

◆ SDL_Environment

A thread-safe set of environment variables

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

Definition at line 1655 of file SDL_stdinc.h.

◆ SDL_free_func

typedef void(* SDL_free_func) (void *mem)

A callback used to implement SDL_free().

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

Parameters
mema pointer to allocated memory.

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

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

Definition at line 1511 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6159 of file SDL_stdinc.h.

◆ SDL_iconv_t

typedef struct SDL_iconv_data_t* SDL_iconv_t

An opaque handle representing string encoding conversion state.

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

Definition at line 5813 of file SDL_stdinc.h.

◆ SDL_malloc_func

typedef void *(* SDL_malloc_func) (size_t size)

A callback used to implement SDL_malloc().

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

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

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

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

Definition at line 1451 of file SDL_stdinc.h.

◆ SDL_realloc_func

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

A callback used to implement SDL_realloc().

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

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

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

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

Definition at line 1493 of file SDL_stdinc.h.

◆ SDL_Time

typedef Sint64 SDL_Time

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

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

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

Definition at line 527 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 461 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 479 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

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

Definition at line 499 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 443 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 470 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 488 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

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

Definition at line 510 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 452 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

◆ SDL_abs()

int SDL_abs ( int  x)
extern

Compute the absolute value of x.

Parameters
xan integer value.
Returns
the absolute value of x.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_acos()

double SDL_acos ( double  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_acosf()

float SDL_acosf ( float  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_aligned_alloc()

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

Allocate memory aligned to a specific alignment.

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

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

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

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

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

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

◆ SDL_aligned_free()

void SDL_aligned_free ( void *  mem)
extern

Free memory allocated by SDL_aligned_alloc().

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

If mem is NULL, this function does nothing.

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

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

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

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( 2  )
extern

Change the size of allocated memory.

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

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

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

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

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

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

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

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

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( 1  ,
2   
)
extern

Allocate a zero-initialized array.

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

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

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

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

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

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

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asprintf()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_atan()

double SDL_atan ( double  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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

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

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

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

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

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

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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

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

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

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

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

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

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

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

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

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

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

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

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

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

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

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

◆ SDL_bsearch()

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

Perform a binary search on a previously sorted array.

For example:

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

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

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

◆ SDL_bsearch_r()

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

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

For example:

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

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

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

◆ SDL_ceil()

double SDL_ceil ( double  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_ceilf()

float SDL_ceilf ( float  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_crc16()

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

Calculate a CRC-16 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_crc32()

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

Calculate a CRC-32 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment ( bool  populated)
extern

Create a set of environment variables

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

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

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

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment *  env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

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

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

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

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

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

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

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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_getenv_unsafe()

const char * SDL_getenv_unsafe ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

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

◆ SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment ( void  )
extern

Get the process environment.

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

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

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

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

◆ SDL_GetEnvironmentVariable()

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

Get the value of a variable in the environment.

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

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

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

◆ SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables ( SDL_Environment *  env)
extern

Get all variables in the environment.

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

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

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

◆ SDL_GetMemoryFunctions()

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

Get the current set of SDL memory functions.

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

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

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

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )
extern

Get the number of outstanding (unfreed) allocations.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_GetOriginalMemoryFunctions()

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

Get the original set of SDL memory functions.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iconv()

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

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

It returns the number of successful conversions on success. On error, SDL_ICONV_E2BIG is returned when the output buffer is too small, or SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered, or SDL_ICONV_EINVAL is returned when an incomplete input sequence is encountered.

On exit:

  • inbuf will point to the beginning of the next multibyte sequence. On error, this is the location of the problematic input sequence. On success, this is the end of the input sequence.
  • inbytesleft will be set to the number of bytes left to convert, which will be 0 on success.
  • outbuf will point to the location where to store the next output byte.
  • outbytesleft will be set to the number of bytes left in the output buffer.
Parameters
cdThe character set conversion context, created in SDL_iconv_open().
inbufAddress of variable that points to the first character of the input sequence.
inbytesleftThe number of bytes in the input buffer.
outbufAddress of variable that points to the output buffer.
outbytesleftThe number of bytes in the output buffer.
Returns
the number of conversions on success, or a negative error code.
Since
This function is available since SDL 3.2.0.
See also
SDL_iconv_open
SDL_iconv_close
SDL_iconv_string

◆ SDL_iconv_close()

int SDL_iconv_close ( SDL_iconv_t  cd)
extern

This function frees a context used for character set conversion.

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

◆ SDL_iconv_open()

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

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

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

◆ SDL_iconv_string()

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

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

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

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

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

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

◆ SDL_isalnum()

int SDL_isalnum ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isalpha()

int SDL_isalpha ( int  x)
extern

Query if a character is alphabetic (a letter).

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isblank()

int SDL_isblank ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iscntrl()

int SDL_iscntrl ( int  x)
extern

Report if a character is a control character.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isdigit()

int SDL_isdigit ( int  x)
extern

Report if a character is a numeric digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isgraph()

int SDL_isgraph ( int  x)
extern

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

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

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

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

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

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

◆ SDL_isinf()

int SDL_isinf ( double  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_isinff()

int SDL_isinff ( float  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_islower()

int SDL_islower ( int  x)
extern

Report if a character is lower case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isnan()

int SDL_isnan ( double  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isnanf()

int SDL_isnanf ( float  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isprint()

int SDL_isprint ( int  x)
extern

Report if a character is "printable".

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_ispunct()

int SDL_ispunct ( int  x)
extern

Report if a character is a punctuation mark.

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

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

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

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

◆ SDL_isspace()

int SDL_isspace ( int  x)
extern

Report if a character is whitespace.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isupper()

int SDL_isupper ( int  x)
extern

Report if a character is upper case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isxdigit()

int SDL_isxdigit ( int  x)
extern

Report if a character is a hexadecimal digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_itoa()

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

Convert an integer into a string.

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

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

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

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

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

◆ SDL_lltoa()

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

Convert a long long integer into a string.

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

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

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

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

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

◆ SDL_log()

double SDL_log ( double  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10()

double SDL_log10 ( double  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10f()

float SDL_log10f ( float  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_logf()

float SDL_logf ( float  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_lround()

long SDL_lround ( double  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_ltoa()

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

Convert a long integer into a string.

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

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

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

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

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

◆ SDL_malloc()

SDL_MALLOC void * SDL_malloc ( size_t  size)
extern

Allocate uninitialized memory.

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

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

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

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

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

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

◆ SDL_memcmp()

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

Compare two buffers of memory.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memcpy()

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

Copy non-overlapping memory.

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

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

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

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

◆ SDL_memmove()

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

Copy memory ranges that might overlap.

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

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

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

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

◆ SDL_memset()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memset4()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_modf()

double SDL_modf ( double  x,
double *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_murmur3_32()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_qsort()

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

Sort an array.

For example:

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

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

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

◆ SDL_qsort_r()

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

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

For example:

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

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

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

◆ SDL_rand()

Sint32 SDL_rand ( Sint32  n)
extern

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

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

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

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 *  state)
extern

Generate 32 pseudo-random bits.

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

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

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

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

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

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 *  state,
Sint32  n 
)
extern

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

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

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

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

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

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

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

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

◆ SDL_randf()

float SDL_randf ( void  )
extern

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 *  state)
extern

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

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

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

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

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

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

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_setenv_unsafe()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetEnvironmentVariable()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetMemoryFunctions()

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

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

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

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

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

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

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

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_size_add_check_overflow()

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

Add two integers, checking for overflow.

If a + b would overflow, return false.

Otherwise store a + b via ret and return true.

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 6116 of file SDL_stdinc.h.

6117{
6118 if (b > SDL_SIZE_MAX - a) {
6119 return false;
6120 }
6121 *ret = a + b;
6122 return true;
6123}

References SDL_SIZE_MAX.

◆ SDL_size_mul_check_overflow()

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

Multiply two integers, checking for overflow.

If a * b would overflow, return false.

Otherwise store a * b via ret and return true.

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 6077 of file SDL_stdinc.h.

6078{
6079 if (a != 0 && b > SDL_SIZE_MAX / a) {
6080 return false;
6081 }
6082 *ret = a * b;
6083 return true;
6084}

References SDL_SIZE_MAX.

◆ SDL_snprintf()

int SDL_snprintf ( SDL_OUT_Z_CAP(maxlen) char *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
  ... 
)
extern

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_sqrt()

double SDL_sqrt ( double  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

◆ SDL_sqrtf()

float SDL_sqrtf ( float  x)
extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

◆ SDL_srand()

void SDL_srand ( Uint64  seed)
extern

Seeds the pseudo-random number generator.

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

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

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

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

◆ SDL_sscanf()

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_StepBackUTF8()

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

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

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

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

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

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

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

Parameters
starta pointer to the beginning of the UTF-8 string.
pstra pointer to a UTF-8 string pointer to be read and adjusted.
Returns
the previous Unicode codepoint in the string.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_StepUTF8()

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

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

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

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

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strcasecmp()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strcasestr()

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

Search a UTF-8 string for the first instance of a specific substring, case-insensitively.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strchr()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strcmp()

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

Compare two null-terminated UTF-8 strings.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strdup()

SDL_MALLOC char * SDL_strdup ( const char *  str)
extern

Allocate a copy of a string.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strlcat()

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

Concatenate strings.

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

src and dst must not overlap.

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

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

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

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

◆ SDL_strlcpy()

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

Copy a string.

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

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

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

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

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

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

◆ SDL_strlen()

size_t SDL_strlen ( const char *  str)
extern

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

Counts the bytes in str, excluding the null terminator.

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

Parameters
strThe null-terminated string to read. Must not be NULL.
Returns
the length (in bytes, excluding the null terminator) of src.

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

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

Referenced by SDL_AppIterate().

◆ SDL_strlwr()

char * SDL_strlwr ( char *  str)
extern

Convert a string to lowercase.

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

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

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

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

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

◆ SDL_strncasecmp()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strncmp()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strndup()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strnlen()

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

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

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

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

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

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

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

◆ SDL_strnstr()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strpbrk()

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strrchr()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strrev()

char * SDL_strrev ( char *  str)
extern

Reverse a string's contents.

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

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

Parameters
strthe string to reverse.
Returns
str.

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strstr()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strtod()

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

Parse a double from a string.

This function makes fewer guarantees than the C runtime strtod:

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

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

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

◆ SDL_strtok_r()

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

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

Break a string up into a series of tokens.

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_strtol()

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

Parse a long from a string.

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

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

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

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

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

◆ SDL_strtoll()

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

Parse a long long from a string.

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

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

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

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

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

◆ SDL_strtoul()

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

Parse an unsigned long from a string.

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

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

Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
the parsed unsigned long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoll
SDL_strtoull
SDL_strtod
SDL_ultoa

◆ SDL_strtoull()

unsigned long long SDL_strtoull ( const char *  str,
char **  endp,
int  base 
)
extern

Parse an unsigned long long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside an unsigned long long, the result is clamped to the maximum representable unsigned long long value.

Parameters
strThe null-terminated string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
the parsed unsigned long long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_atoi
SDL_atof
SDL_strtol
SDL_strtoll
SDL_strtoul
SDL_strtod
SDL_ulltoa

◆ SDL_strupr()

char * SDL_strupr ( char *  str)
extern

Convert a string to uppercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to uppercase.

This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'a' through 'z' to their uppercase equivalents in-place, returning the original str pointer.

Parameters
strthe string to convert in-place. Can not be NULL.
Returns
the str pointer passed into this function.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_strlwr

◆ SDL_swprintf()

int SDL_swprintf ( SDL_OUT_Z_CAP(maxlen) wchar_t *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const wchar_t *  fmt,
  ... 
)
extern

This works exactly like swprintf() but doesn't require access to a C runtime.

Format a wide string of up to maxlen-1 wchar_t values, converting each '' item with values provided through variable arguments.

While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen count. Note that if maxlen is zero, however, no wide characters will be written at all.

This function returns the number of wide characters (not codepoints) that should be written, excluding the null-terminator character. If this returns a number >= maxlen, it means the output string was truncated. A negative return value means an error occurred.

Referencing the output string's pointer with a format item is undefined behavior.

Parameters
textthe buffer to write the wide string into. Must not be NULL.
maxlenthe maximum wchar_t values to write, including the null-terminator.
fmta printf-style format string. Must not be NULL.
...a list of values to be used with the format string.
Returns
the number of wide characters that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_tan()

double SDL_tan ( double  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on double-precision floating point values, use SDL_tanf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
tangent of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_tanf
SDL_sin
SDL_cos
SDL_atan
SDL_atan2

◆ SDL_tanf()

float SDL_tanf ( float  x)
extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on single-precision floating point values, use SDL_tan for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters
xfloating point value, in radians.
Returns
tangent of x.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_tan
SDL_sinf
SDL_cosf
SDL_atanf
SDL_atan2f

◆ SDL_tolower()

int SDL_tolower ( int  x)
extern

Convert low-ASCII English letters to lowercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.

This function returns the lowercase equivalent of x. If a character cannot be converted, or is already lowercase, this function returns x.

Parameters
xcharacter value to check.
Returns
lowercase version of x, or x if no conversion available.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_toupper()

int SDL_toupper ( int  x)
extern

Convert low-ASCII English letters to uppercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'a' through 'z' to uppercase.

This function returns the uppercase equivalent of x. If a character cannot be converted, or is already uppercase, this function returns x.

Parameters
xcharacter value to check.
Returns
capitalized version of x, or x if no conversion available.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_trunc()

double SDL_trunc ( double  x)
extern

Truncate x to an integer.

Rounds x to the next closest integer to 0. This is equivalent to removing the fractional part of x, leaving only the integer part.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_truncf for single-precision floats.

Parameters
xfloating point value.
Returns
x truncated to an integer.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_truncf
SDL_fmod
SDL_ceil
SDL_floor
SDL_round
SDL_lround

◆ SDL_truncf()

float SDL_truncf ( float  x)
extern

Truncate x to an integer.

Rounds x to the next closest integer to 0. This is equivalent to removing the fractional part of x, leaving only the integer part.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_trunc for double-precision floats.

Parameters
xfloating point value.
Returns
x truncated to an integer.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_trunc
SDL_fmodf
SDL_ceilf
SDL_floorf
SDL_roundf
SDL_lroundf

◆ SDL_UCS4ToUTF8()

char * SDL_UCS4ToUTF8 ( Uint32  codepoint,
char *  dst 
)
extern

Convert a single Unicode codepoint to UTF-8.

The buffer pointed to by dst must be at least 4 bytes long, as this function may generate between 1 and 4 bytes of output.

This function returns the first byte after the newly-written UTF-8 sequence, which is useful for encoding multiple codepoints in a loop, or knowing where to write a NULL-terminator character to end the string (in either case, plan to have a buffer of more than 4 bytes!).

If codepoint is an invalid value (outside the Unicode range, or a UTF-16 surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the codepoint instead, and not set an error.

If dst is NULL, this returns NULL immediately without writing to the pointer and without setting an error.

Parameters
codepointa Unicode codepoint to convert to UTF-8.
dstthe location to write the encoded UTF-8. Must point to at least 4 bytes!
Returns
the first byte past the newly-written UTF-8 sequence.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_uitoa()

char * SDL_uitoa ( unsigned int  value,
char *  str,
int  radix 
)
extern

Convert an unsigned integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters
valuethe unsigned integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_itoa
SDL_ultoa
SDL_ulltoa

◆ SDL_ulltoa()

char * SDL_ulltoa ( unsigned long long  value,
char *  str,
int  radix 
)
extern

Convert an unsigned long long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters
valuethe unsigned long long integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_lltoa
SDL_uitoa
SDL_ultoa

◆ SDL_ultoa()

char * SDL_ultoa ( unsigned long  value,
char *  str,
int  radix 
)
extern

Convert an unsigned long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters
valuethe unsigned long integer to convert.
strthe buffer to write the string into.
radixthe radix to use for string generation.
Returns
str.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_ltoa
SDL_uitoa
SDL_ulltoa

◆ SDL_unsetenv_unsafe()

int SDL_unsetenv_unsafe ( const char *  name)
extern

Clear a variable from the environment.

Parameters
namethe name of the variable to unset.
Returns
0 on success, -1 on error.

\threadsafety This function is not thread safe, consider using SDL_UnsetEnvironmentVariable() instead.

Since
This function is available since SDL 3.2.0.
See also
SDL_UnsetEnvironmentVariable

◆ SDL_UnsetEnvironmentVariable()

bool SDL_UnsetEnvironmentVariable ( SDL_Environment *  env,
const char *  name 
)
extern

Clear a variable from the environment.

Parameters
envthe environment to modify.
namethe name of the variable to unset.
Returns
true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_GetEnvironment
SDL_CreateEnvironment
SDL_GetEnvironmentVariable
SDL_GetEnvironmentVariables
SDL_SetEnvironmentVariable
SDL_UnsetEnvironmentVariable

◆ SDL_utf8strlcpy()

size_t SDL_utf8strlcpy ( SDL_OUT_Z_CAP(dst_bytes) char *  dst,
const char *  src,
size_t  dst_bytes 
)
extern

Copy an UTF-8 string.

This function copies up to dst_bytes - 1 bytes from src to dst while also ensuring that the string written to dst does not end in a truncated multi-byte sequence. Finally, it appends a null terminator.

src and dst must not overlap.

Note that unlike SDL_strlcpy(), this function returns the number of bytes written, not the length of src.

Parameters
dstThe destination buffer. Must not be NULL, and must not overlap with src.
srcThe null-terminated UTF-8 string to copy. Must not be NULL, and must not overlap with dst.
dst_bytesThe length (in bytes) of the destination buffer. Must not be 0.
Returns
the number of bytes written, excluding the null terminator.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_strlcpy

◆ SDL_utf8strlen()

size_t SDL_utf8strlen ( const char *  str)
extern

Count the number of codepoints in a UTF-8 string.

Counts the codepoints, not bytes, in str, excluding the null terminator.

If you need to count the bytes in a string instead, consider using SDL_strlen().

Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.

Parameters
strThe null-terminated UTF-8 string to read. Must not be NULL.
Returns
The length (in codepoints, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_utf8strnlen
SDL_strlen

◆ SDL_utf8strnlen()

size_t SDL_utf8strnlen ( const char *  str,
size_t  bytes 
)
extern

Count the number of codepoints in a UTF-8 string, up to n bytes.

Counts the codepoints, not bytes, in str, excluding the null terminator.

If you need to count the bytes in a string instead, consider using SDL_strnlen().

The counting stops at bytes bytes (not codepoints!). This seems counterintuitive, but makes it easy to express the total size of the string's buffer.

Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.

Parameters
strThe null-terminated UTF-8 string to read. Must not be NULL.
bytesThe maximum amount of bytes to count.
Returns
The length (in codepoints, excluding the null terminator) of src but never more than maxlen.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_utf8strlen
SDL_strnlen

◆ SDL_vasprintf()

int SDL_vasprintf ( char **  strp,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

This works exactly like vasprintf() but doesn't require access to a C runtime.

Functions identically to SDL_asprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters
strpon output, is set to the new string. Must not be NULL.
fmta printf-style format string. Must not be NULL.
apa va_list values to be used with the format string.
Returns
the number of bytes in the newly-allocated string, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_vsnprintf()

int SDL_vsnprintf ( SDL_OUT_Z_CAP(maxlen) char *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

This works exactly like vsnprintf() but doesn't require access to a C runtime.

Functions identically to SDL_snprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters
textthe buffer to write the string into. Must not be NULL.
maxlenthe maximum bytes to write, including the null-terminator.
fmta printf-style format string. Must not be NULL.
apa va_list values to be used with the format string.
Returns
the number of bytes that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_vsscanf()

int SDL_vsscanf ( const char *  text,
SDL_SCANF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

This works exactly like vsscanf() but doesn't require access to a C runtime.

Functions identically to SDL_sscanf(), except it takes a va_list instead of using ... variable arguments.

Parameters
textthe string to scan. Must not be NULL.
fmta printf-style format string. Must not be NULL.
apa va_list of pointers to values to be filled in with scanned items.
Returns
the number of items that matched the format string.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_vswprintf()

int SDL_vswprintf ( SDL_OUT_Z_CAP(maxlen) wchar_t *  text,
size_t  maxlen,
SDL_PRINTF_FORMAT_STRING const wchar_t *  fmt,
va_list  ap 
)
extern

This works exactly like vswprintf() but doesn't require access to a C runtime.

Functions identically to SDL_swprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters
textthe buffer to write the string into. Must not be NULL.
maxlenthe maximum wide characters to write, including the null-terminator.
fmta printf-style format wide string. Must not be NULL.
apa va_list values to be used with the format string.
Returns
the number of wide characters that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcscasecmp()

int SDL_wcscasecmp ( const wchar_t *  str1,
const wchar_t *  str2 
)
extern

Compare two null-terminated wide strings, case-insensitively.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcscmp()

int SDL_wcscmp ( const wchar_t *  str1,
const wchar_t *  str2 
)
extern

Compare two null-terminated wide strings.

This only compares wchar_t values until it hits a null-terminating character; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsdup()

wchar_t * SDL_wcsdup ( const wchar_t *  wstr)
extern

Allocate a copy of a wide string.

This allocates enough space for a null-terminated copy of wstr, using SDL_malloc, and then makes a copy of the string into this space.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters
wstrthe string to copy.
Returns
a pointer to the newly-allocated wide string.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcslcat()

size_t SDL_wcslcat ( SDL_INOUT_Z_CAP(maxlen) wchar_t *  dst,
const wchar_t *  src,
size_t  maxlen 
)
extern

Concatenate wide strings.

This function appends up to maxlen - SDL_wcslen(dst) - 1 wide characters from src to the end of the wide string in dst, then appends a null terminator.

src and dst must not overlap.

If maxlen - SDL_wcslen(dst) - 1 is less than or equal to 0, then dst is unmodified.

Parameters
dstThe destination buffer already containing the first null-terminated wide string. Must not be NULL and must not overlap with src.
srcThe second null-terminated wide string. Must not be NULL, and must not overlap with dst.
maxlenThe length (in wide characters) of the destination buffer.
Returns
the length (in wide characters, excluding the null terminator) of the string in dst plus the length of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_wcslcpy

◆ SDL_wcslcpy()

size_t SDL_wcslcpy ( SDL_OUT_Z_CAP(maxlen) wchar_t *  dst,
const wchar_t *  src,
size_t  maxlen 
)
extern

Copy a wide string.

This function copies maxlen - 1 wide characters from src to dst, then appends a null terminator.

src and dst must not overlap.

If maxlen is 0, no wide characters are copied and no null terminator is written.

Parameters
dstThe destination buffer. Must not be NULL, and must not overlap with src.
srcThe null-terminated wide string to copy. Must not be NULL, and must not overlap with dst.
maxlenThe length (in wide characters) of the destination buffer.
Returns
the length (in wide characters, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_wcslcat

◆ SDL_wcslen()

size_t SDL_wcslen ( const wchar_t *  wstr)
extern

This works exactly like wcslen() but doesn't require access to a C runtime.

Counts the number of wchar_t values in wstr, excluding the null terminator.

Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.

Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).

Parameters
wstrThe null-terminated wide string to read. Must not be NULL.
Returns
the length (in wchar_t values, excluding the null terminator) of wstr.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_wcsnlen
SDL_utf8strlen
SDL_utf8strnlen

◆ SDL_wcsncasecmp()

int SDL_wcsncasecmp ( const wchar_t *  str1,
const wchar_t *  str2,
size_t  maxlen 
)
extern

Compare two wide strings, case-insensitively, up to a number of wchar_t.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Note that while this function might deal with variable-sized characters, maxlen specifies a wchar limit! If the limit lands in the middle of a multi-byte UTF-16 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.

maxlen specifies a maximum number of wchar_t values to compare; if the strings match to this number of wchar_t (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
maxlenthe maximum number of wchar_t values to compare.
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsncmp()

int SDL_wcsncmp ( const wchar_t *  str1,
const wchar_t *  str2,
size_t  maxlen 
)
extern

Compare two wide strings up to a number of wchar_t values.

This only compares wchar_t values; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.

Note that while this function is intended to be used with UTF-16 (or UTF-32, depending on your platform's definition of wchar_t), it is comparing raw wchar_t values and not Unicode codepoints: maxlen specifies a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16 sequence, it will only compare a portion of the final character.

maxlen specifies a maximum number of wchar_t to compare; if the strings match to this number of wide chars (or both have matched to a null-terminator character before this count), they will be considered equal.

Parameters
str1the first string to compare. NULL is not permitted!
str2the second string to compare. NULL is not permitted!
maxlenthe maximum number of wchar_t to compare.
Returns
less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsnlen()

size_t SDL_wcsnlen ( const wchar_t *  wstr,
size_t  maxlen 
)
extern

This works exactly like wcsnlen() but doesn't require access to a C runtime.

Counts up to a maximum of maxlen wchar_t values in wstr, excluding the null terminator.

Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.

Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).

Also, maxlen is a count of wide characters, not bytes!

Parameters
wstrThe null-terminated wide string to read. Must not be NULL.
maxlenThe maximum amount of wide characters to count.
Returns
the length (in wide characters, excluding the null terminator) of wstr but never more than maxlen.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_wcslen
SDL_utf8strlen
SDL_utf8strnlen

◆ SDL_wcsnstr()

wchar_t * SDL_wcsnstr ( const wchar_t *  haystack,
const wchar_t *  needle,
size_t  maxlen 
)
extern

Search a wide string, up to n wide chars, for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator value to end the string, or maxlen wide character have been examined. It is possible to use this function on a wide string without a null terminator.

Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.

Parameters
haystackthe wide string to search. Must not be NULL.
needlethe wide string to search for. Must not be NULL.
maxlenthe maximum number of wide characters to search in haystack.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcsstr()

wchar_t * SDL_wcsstr ( const wchar_t *  haystack,
const wchar_t *  needle 
)
extern

Search a wide string for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string.

Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.

Parameters
haystackthe wide string to search. Must not be NULL.
needlethe wide string to search for. Must not be NULL.
Returns
a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.

◆ SDL_wcstol()

long SDL_wcstol ( const wchar_t *  str,
wchar_t **  endp,
int  base 
)
extern

Parse a long from a wide string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long, the result is clamped to the minimum and maximum representable long values.

Parameters
strThe null-terminated wide string to read. Must not be NULL.
endpIf not NULL, the address of the first invalid wide character (i.e. the next character after the parsed number) will be written to this pointer.
baseThe base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
Returns
the parsed long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.2.0.
See also
SDL_strtol

Variable Documentation

◆ size

size_t size

Definition at line 1372 of file SDL_stdinc.h.