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_EnvironmentSDL_GetEnvironment (void)
 
SDL_EnvironmentSDL_CreateEnvironment (bool populated)
 
const char * SDL_GetEnvironmentVariable (SDL_Environment *env, const char *name)
 
char ** SDL_GetEnvironmentVariables (SDL_Environment *env)
 
bool SDL_SetEnvironmentVariable (SDL_Environment *env, const char *name, const char *value, bool overwrite)
 
bool SDL_UnsetEnvironmentVariable (SDL_Environment *env, const char *name)
 
void SDL_DestroyEnvironment (SDL_Environment *env)
 
const char * SDL_getenv (const char *name)
 
const char * SDL_getenv_unsafe (const char *name)
 
int SDL_setenv_unsafe (const char *name, const char *value, int overwrite)
 
int SDL_unsetenv_unsafe (const char *name)
 
void SDL_qsort (void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void * SDL_bsearch (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
 
void SDL_qsort_r (void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
void * SDL_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
 
int SDL_abs (int x)
 
int SDL_isalpha (int x)
 
int SDL_isalnum (int x)
 
int SDL_isblank (int x)
 
int SDL_iscntrl (int x)
 
int SDL_isdigit (int x)
 
int SDL_isxdigit (int x)
 
int SDL_ispunct (int x)
 
int SDL_isspace (int x)
 
int SDL_isupper (int x)
 
int SDL_islower (int x)
 
int SDL_isprint (int x)
 
int SDL_isgraph (int x)
 
int SDL_toupper (int x)
 
int SDL_tolower (int x)
 
Uint16 SDL_crc16 (Uint16 crc, const void *data, size_t len)
 
Uint32 SDL_crc32 (Uint32 crc, const void *data, size_t len)
 
Uint32 SDL_murmur3_32 (const void *data, size_t len, Uint32 seed)
 
void * SDL_memcpy (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memmove (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
 
void * SDL_memset (SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
 
void * SDL_memset4 (void *dst, Uint32 val, size_t dwords)
 
int SDL_memcmp (const void *s1, const void *s2, size_t len)
 
size_t SDL_wcslen (const wchar_t *wstr)
 
size_t SDL_wcsnlen (const wchar_t *wstr, size_t maxlen)
 
size_t SDL_wcslcpy (SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
size_t SDL_wcslcat (SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
 
wchar_t * SDL_wcsdup (const wchar_t *wstr)
 
wchar_t * SDL_wcsstr (const wchar_t *haystack, const wchar_t *needle)
 
wchar_t * SDL_wcsnstr (const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
 
int SDL_wcscmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
int SDL_wcscasecmp (const wchar_t *str1, const wchar_t *str2)
 
int SDL_wcsncasecmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
 
long SDL_wcstol (const wchar_t *str, wchar_t **endp, int base)
 
size_t SDL_strlen (const char *str)
 
size_t SDL_strnlen (const char *str, size_t maxlen)
 
size_t SDL_strlcpy (SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
size_t SDL_utf8strlcpy (SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
 
size_t SDL_strlcat (SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
 
SDL_MALLOC char * SDL_strdup (const char *str)
 
SDL_MALLOC char * SDL_strndup (const char *str, size_t maxlen)
 
char * SDL_strrev (char *str)
 
char * SDL_strupr (char *str)
 
char * SDL_strlwr (char *str)
 
char * SDL_strchr (const char *str, int c)
 
char * SDL_strrchr (const char *str, int c)
 
char * SDL_strstr (const char *haystack, const char *needle)
 
char * SDL_strnstr (const char *haystack, const char *needle, size_t maxlen)
 
char * SDL_strcasestr (const char *haystack, const char *needle)
 
char * SDL_strtok_r (char *str, const char *delim, char **saveptr)
 
size_t SDL_utf8strlen (const char *str)
 
size_t SDL_utf8strnlen (const char *str, size_t bytes)
 
char * SDL_itoa (int value, char *str, int radix)
 
char * SDL_uitoa (unsigned int value, char *str, int radix)
 
char * SDL_ltoa (long value, char *str, int radix)
 
char * SDL_ultoa (unsigned long value, char *str, int radix)
 
char * SDL_lltoa (long long value, char *str, int radix)
 
char * SDL_ulltoa (unsigned long long value, char *str, int radix)
 
int SDL_atoi (const char *str)
 
double SDL_atof (const char *str)
 
long SDL_strtol (const char *str, char **endp, int base)
 
unsigned long SDL_strtoul (const char *str, char **endp, int base)
 
long long SDL_strtoll (const char *str, char **endp, int base)
 
unsigned long long SDL_strtoull (const char *str, char **endp, int base)
 
double SDL_strtod (const char *str, char **endp)
 
int SDL_strcmp (const char *str1, const char *str2)
 
int SDL_strncmp (const char *str1, const char *str2, size_t maxlen)
 
int SDL_strcasecmp (const char *str1, const char *str2)
 
int SDL_strncasecmp (const char *str1, const char *str2, size_t maxlen)
 
char * SDL_strpbrk (const char *str, const char *breakset)
 
Uint32 SDL_StepUTF8 (const char **pstr, size_t *pslen)
 
Uint32 SDL_StepBackUTF8 (const char *start, const char **pstr)
 
char * SDL_UCS4ToUTF8 (Uint32 codepoint, char *dst)
 
int SDL_sscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
 
int SDL_vsscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2)
 
int SDL_snprintf (SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(3)
 
int SDL_swprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...) SDL_WPRINTF_VARARG_FUNC(3)
 
int SDL_vsnprintf (SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3)
 
int SDL_vswprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3)
 
int SDL_asprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
 
int SDL_vasprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
 
void SDL_srand (Uint64 seed)
 
Sint32 SDL_rand (Sint32 n)
 
float SDL_randf (void)
 
Uint32 SDL_rand_bits (void)
 
Sint32 SDL_rand_r (Uint64 *state, Sint32 n)
 
float SDL_randf_r (Uint64 *state)
 
Uint32 SDL_rand_bits_r (Uint64 *state)
 
double SDL_acos (double x)
 
float SDL_acosf (float x)
 
double SDL_asin (double x)
 
float SDL_asinf (float x)
 
double SDL_atan (double x)
 
float SDL_atanf (float x)
 
double SDL_atan2 (double y, double x)
 
float SDL_atan2f (float y, float x)
 
double SDL_ceil (double x)
 
float SDL_ceilf (float x)
 
double SDL_copysign (double x, double y)
 
float SDL_copysignf (float x, float y)
 
double SDL_cos (double x)
 
float SDL_cosf (float x)
 
double SDL_exp (double x)
 
float SDL_expf (float x)
 
double SDL_fabs (double x)
 
float SDL_fabsf (float x)
 
double SDL_floor (double x)
 
float SDL_floorf (float x)
 
double SDL_trunc (double x)
 
float SDL_truncf (float x)
 
double SDL_fmod (double x, double y)
 
float SDL_fmodf (float x, float y)
 
int SDL_isinf (double x)
 
int SDL_isinff (float x)
 
int SDL_isnan (double x)
 
int SDL_isnanf (float x)
 
double SDL_log (double x)
 
float SDL_logf (float x)
 
double SDL_log10 (double x)
 
float SDL_log10f (float x)
 
double SDL_modf (double x, double *y)
 
float SDL_modff (float x, float *y)
 
double SDL_pow (double x, double y)
 
float SDL_powf (float x, float y)
 
double SDL_round (double x)
 
float SDL_roundf (float x)
 
long SDL_lround (double x)
 
long SDL_lroundf (float x)
 
double SDL_scalbn (double x, int n)
 
float SDL_scalbnf (float x, int n)
 
double SDL_sin (double x)
 
float SDL_sinf (float x)
 
double SDL_sqrt (double x)
 
float SDL_sqrtf (float x)
 
double SDL_tan (double x)
 
float SDL_tanf (float x)
 
SDL_iconv_t SDL_iconv_open (const char *tocode, const char *fromcode)
 
int SDL_iconv_close (SDL_iconv_t cd)
 
size_t SDL_iconv (SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
 
char * SDL_iconv_string (const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
 
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow (size_t a, size_t b, size_t *ret)
 
SDL_FORCE_INLINE bool SDL_size_add_check_overflow (size_t a, size_t b, size_t *ret)
 

Macro Definition Documentation

◆ __bool_true_false_are_defined

#define __bool_true_false_are_defined   1

Definition at line 102 of file SDL_stdinc.h.

◆ bool

#define bool   unsigned char

CategoryStdinc

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

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

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

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

Definition at line 99 of file SDL_stdinc.h.

◆ false

#define false   0

Definition at line 100 of file SDL_stdinc.h.

◆ SDL_arraysize

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

The number of elements in a static array.

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 252 of file SDL_stdinc.h.

◆ SDL_clamp

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

Return a value clamped to a range.

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

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

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2180 of file SDL_stdinc.h.

◆ SDL_COMPILE_TIME_ASSERT

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

Definition at line 236 of file SDL_stdinc.h.

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

◆ SDL_const_cast

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

Definition at line 346 of file SDL_stdinc.h.

◆ SDL_copyp

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 2539 of file SDL_stdinc.h.

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

◆ SDL_FLT_EPSILON

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

Epsilon constant, used for comparing floating-point numbers.

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

Since
This macro is available since SDL 3.2.0.

Definition at line 544 of file SDL_stdinc.h.

◆ SDL_FOURCC

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

Define a four character code as a Uint32.

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 365 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Output buffer was too small.

Definition at line 5895 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5896 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5897 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5894 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_locale

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

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

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5948 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs2

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

Convert a UTF-8 string to UCS-2.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5964 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs4

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

Convert a UTF-8 string to UCS-4.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5980 of file SDL_stdinc.h.

◆ SDL_iconv_wchar_utf8

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

Convert a wchar_t string to UTF-8.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 5996 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

Definition at line 1141 of file SDL_stdinc.h.

◆ SDL_INIT_INTERFACE

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

A macro to initialize an SDL interface.

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

You can use it like this:

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

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

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

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

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

Definition at line 1256 of file SDL_stdinc.h.

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

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 1142 of file SDL_stdinc.h.

◆ SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

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

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

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

Definition at line 3984 of file SDL_stdinc.h.

◆ SDL_max

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

Return the greater of two values.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2156 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 456 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 474 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 494 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 438 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 522 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 465 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 483 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 505 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 447 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 2511 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2567 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 2615 of file SDL_stdinc.h.

◆ SDL_min

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

Return the lesser of two values.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2138 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 457 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 475 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 495 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 439 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 523 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 466 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 484 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 506 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 448 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 1145 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 1144 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 1146 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 1143 of file SDL_stdinc.h.

◆ SDL_PI_D

#define SDL_PI_D   3.141592653589793238462643383279502884

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

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

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

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 808 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 811 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 814 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 817 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 820 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1147 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1158 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1159 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 777 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 737 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 784 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 748 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 791 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 798 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 759 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 770 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 344 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1148 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 1160 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1161 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 409 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 184 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 1308 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 1309 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 345 of file SDL_stdinc.h.

◆ SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG (   arg)    #arg

Macro useful for building other macros with strings in them.

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

Definition at line 261 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 421 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1162 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1163 of file SDL_stdinc.h.

◆ SDL_zero

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

Clear an object's memory to zero.

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

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

Parameters
xthe object to clear.

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

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

Definition at line 2635 of file SDL_stdinc.h.

◆ SDL_zeroa

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

Clear an array's memory to zero.

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

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

Parameters
xan array to clear.

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

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

Definition at line 2673 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 2654 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 1466 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 1884 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 1997 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 1649 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 1505 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6176 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 5814 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 1445 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 1487 of file SDL_stdinc.h.

◆ SDL_Time

typedef Sint64 SDL_Time

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

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

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

Definition at line 521 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 455 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 473 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

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

Definition at line 493 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 437 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 464 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 482 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

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

Definition at line 504 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.2.0.

Definition at line 446 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

◆ SDL_abs()

int SDL_abs ( int  x)
extern

Compute the absolute value of x.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_acos()

double SDL_acos ( double  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_acosf()

float SDL_acosf ( float  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_aligned_alloc()

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

Allocate memory aligned to a specific alignment.

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

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

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

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

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

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

◆ SDL_aligned_free()

void SDL_aligned_free ( void *  mem)
extern

Free memory allocated by SDL_aligned_alloc().

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

If mem is NULL, this function does nothing.

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

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

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

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( )
extern

Change the size of allocated memory.

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

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

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

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

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

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

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

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

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( ,
 
)
extern

Allocate a zero-initialized array.

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

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

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

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

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

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

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asprintf()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_atan()

double SDL_atan ( double  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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

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

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

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

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

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

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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

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

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

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

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

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

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

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

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

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

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

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

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

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

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

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

◆ SDL_bsearch()

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

Perform a binary search on a previously sorted array.

For example:

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

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

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

◆ SDL_bsearch_r()

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

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

For example:

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

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

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

◆ SDL_ceil()

double SDL_ceil ( double  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_ceilf()

float SDL_ceilf ( float  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_crc16()

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

Calculate a CRC-16 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_crc32()

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

Calculate a CRC-32 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment ( bool  populated)
extern

Create a set of environment variables

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

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

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

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

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

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

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

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

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

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

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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_getenv_unsafe()

const char * SDL_getenv_unsafe ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

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

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

◆ SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment ( void  )
extern

Get the process environment.

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

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

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

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

◆ SDL_GetEnvironmentVariable()

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

Get the value of a variable in the environment.

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

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

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

◆ SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables ( SDL_Environment env)
extern

Get all variables in the environment.

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

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

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

◆ SDL_GetMemoryFunctions()

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

Get the current set of SDL memory functions.

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

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

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

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )
extern

Get the number of outstanding (unfreed) allocations.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_GetOriginalMemoryFunctions()

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

Get the original set of SDL memory functions.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iconv()

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

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

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

On exit:

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

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

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

◆ SDL_iconv_close()

int SDL_iconv_close ( SDL_iconv_t  cd)
extern

This function frees a context used for character set conversion.

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

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

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

◆ SDL_iconv_open()

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

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

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

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

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

◆ SDL_iconv_string()

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

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

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

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

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

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

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

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

◆ SDL_isalnum()

int SDL_isalnum ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isalpha()

int SDL_isalpha ( int  x)
extern

Query if a character is alphabetic (a letter).

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isblank()

int SDL_isblank ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iscntrl()

int SDL_iscntrl ( int  x)
extern

Report if a character is a control character.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isdigit()

int SDL_isdigit ( int  x)
extern

Report if a character is a numeric digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isgraph()

int SDL_isgraph ( int  x)
extern

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

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

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

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

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

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

◆ SDL_isinf()

int SDL_isinf ( double  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_isinff()

int SDL_isinff ( float  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_islower()

int SDL_islower ( int  x)
extern

Report if a character is lower case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isnan()

int SDL_isnan ( double  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isnanf()

int SDL_isnanf ( float  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isprint()

int SDL_isprint ( int  x)
extern

Report if a character is "printable".

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_ispunct()

int SDL_ispunct ( int  x)
extern

Report if a character is a punctuation mark.

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

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

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

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

◆ SDL_isspace()

int SDL_isspace ( int  x)
extern

Report if a character is whitespace.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isupper()

int SDL_isupper ( int  x)
extern

Report if a character is upper case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isxdigit()

int SDL_isxdigit ( int  x)
extern

Report if a character is a hexadecimal digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_itoa()

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

Convert an integer into a string.

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

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

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

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

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

◆ SDL_lltoa()

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

Convert a long long integer into a string.

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

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

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

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

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

◆ SDL_log()

double SDL_log ( double  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10()

double SDL_log10 ( double  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10f()

float SDL_log10f ( float  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_logf()

float SDL_logf ( float  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_lround()

long SDL_lround ( double  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_ltoa()

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

Convert a long integer into a string.

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

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

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

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

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

◆ SDL_malloc()

SDL_MALLOC void * SDL_malloc ( size_t  size)
extern

Allocate uninitialized memory.

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

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

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

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

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

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

◆ SDL_memcmp()

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

Compare two buffers of memory.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memcpy()

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

Copy non-overlapping memory.

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

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

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

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

◆ SDL_memmove()

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

Copy memory ranges that might overlap.

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

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

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

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

◆ SDL_memset()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memset4()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_modf()

double SDL_modf ( double  x,
double *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_murmur3_32()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_qsort()

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

Sort an array.

For example:

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

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

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

◆ SDL_qsort_r()

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

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

For example:

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

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

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

◆ SDL_rand()

Sint32 SDL_rand ( Sint32  n)
extern

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

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

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

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 state)
extern

Generate 32 pseudo-random bits.

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

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

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

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

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

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 state,
Sint32  n 
)
extern

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

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

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

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

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

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

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

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

◆ SDL_randf()

float SDL_randf ( void  )
extern

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 state)
extern

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

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

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

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

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

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

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_setenv_unsafe()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetEnvironmentVariable()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetMemoryFunctions()

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

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

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

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

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

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

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

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_size_add_check_overflow()

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

Add two integers, checking for overflow.

If a + b would overflow, return false.

Otherwise store a + b via ret and return true.

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 6133 of file SDL_stdinc.h.

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

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

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

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