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

Macro Definition Documentation

◆ __bool_true_false_are_defined

#define __bool_true_false_are_defined   1

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

◆ false

#define false   0

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

◆ SDL_clamp

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

Return a value clamped to a range.

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

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

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2172 of file SDL_stdinc.h.

◆ SDL_COMPILE_TIME_ASSERT

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

Definition at line 229 of file SDL_stdinc.h.

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

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

◆ SDL_FOURCC

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

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

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Output buffer was too small.

Definition at line 5881 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Invalid input sequence was encountered.

Definition at line 5882 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5883 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5880 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_locale

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

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

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

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

Definition at line 5930 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs2

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

Convert a UTF-8 string to UCS-2.

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

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

Definition at line 5944 of file SDL_stdinc.h.

◆ SDL_iconv_utf8_ucs4

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

Convert a UTF-8 string to UCS-4.

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

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

Definition at line 5958 of file SDL_stdinc.h.

◆ SDL_iconv_wchar_utf8

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

Convert a wchar_t string to UTF-8.

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

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

Definition at line 5972 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

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

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

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

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

◆ SDL_max

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

Return the greater of two values.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2148 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 455 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 473 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 493 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 437 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 521 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 464 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 482 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 504 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 446 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 2503 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 2559 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 2607 of file SDL_stdinc.h.

◆ SDL_min

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

Return the lesser of two values.

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

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

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

Since
This macro is available since SDL 3.2.0.

Definition at line 2130 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 456 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 474 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 494 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 438 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 522 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 465 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 483 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 505 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 447 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 1144 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 1143 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 1145 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 1142 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 4471 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 4483 of file SDL_stdinc.h.

◆ SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX   "ll"

Definition at line 807 of file SDL_stdinc.h.

◆ SDL_PRILLd

#define SDL_PRILLd   SDL_PRILL_PREFIX "d"

Definition at line 810 of file SDL_stdinc.h.

◆ SDL_PRILLu

#define SDL_PRILLu   SDL_PRILL_PREFIX "u"

Definition at line 813 of file SDL_stdinc.h.

◆ SDL_PRILLx

#define SDL_PRILLx   SDL_PRILL_PREFIX "x"

Definition at line 816 of file SDL_stdinc.h.

◆ SDL_PRILLX

#define SDL_PRILLX   SDL_PRILL_PREFIX "X"

Definition at line 819 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1146 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1157 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1158 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 776 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 736 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 783 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 747 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 790 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 797 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 758 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 769 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 343 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1147 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 1159 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 1160 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 408 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 177 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 1307 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 1308 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 344 of file SDL_stdinc.h.

◆ SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG (   arg)    #arg

Macro useful for building other macros with strings in them.

For example:

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

Definition at line 260 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 420 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 1161 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV (   fmtargnumber)

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

◆ SDL_zeroa

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

Clear an array's memory to zero.

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

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

Parameters
xan array to clear.

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

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

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

◆ true

#define true   1

Definition at line 94 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 1465 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 1876 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 1989 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 1648 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 1504 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6148 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 5806 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 1444 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 1486 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 520 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 454 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 472 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 492 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 436 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 463 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 481 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 503 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 445 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

◆ SDL_abs()

int SDL_abs ( int  x)
extern

Compute the absolute value of x.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_acos()

double SDL_acos ( double  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_acosf()

float SDL_acosf ( float  x)
extern

Compute the arc cosine of x.

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

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

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

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

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

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

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

◆ SDL_aligned_alloc()

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

Allocate memory aligned to a specific alignment.

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

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

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

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

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

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

◆ SDL_aligned_free()

void SDL_aligned_free ( void *  mem)
extern

Free memory allocated by SDL_aligned_alloc().

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

If mem is NULL, this function does nothing.

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

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

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

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( 2  )
extern

Change the size of allocated memory.

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

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

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

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

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

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

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

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

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( 1  ,
2   
)
extern

Allocate a zero-initialized array.

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

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

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

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

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

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

◆ SDL_asin()

double SDL_asin ( double  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asinf()

float SDL_asinf ( float  x)
extern

Compute the arc sine of x.

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

Domain: -1 <= x <= 1

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

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

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

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

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

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

◆ SDL_asprintf()

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

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_atan()

double SDL_atan ( double  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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

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

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

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

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

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

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

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

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

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

Range: -Pi <= y <= Pi

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

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

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

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

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

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

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

Parse a double from a string.

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

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

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

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

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

Parse an int from a string.

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

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

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

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

◆ SDL_bsearch()

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

Perform a binary search on a previously sorted array.

For example:

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

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

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

◆ SDL_bsearch_r()

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

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

For example:

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

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

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

◆ SDL_ceil()

double SDL_ceil ( double  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_ceilf()

float SDL_ceilf ( float  x)
extern

Compute the ceiling of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the ceiling of x.

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

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

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)
extern

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

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

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

Range: -INF <= z <= INF

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

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

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

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

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_cosf()

float SDL_cosf ( float  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_crc16()

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

Calculate a CRC-16 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_crc32()

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

Calculate a CRC-32 value.

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment ( bool  populated)
extern

Create a set of environment variables

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

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

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

◆ SDL_DestroyEnvironment()

void SDL_DestroyEnvironment ( SDL_Environment *  env)
extern

Destroy a set of environment variables.

Parameters
envthe environment to destroy.

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

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

◆ SDL_exp()

double SDL_exp ( double  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_expf()

float SDL_expf ( float  x)
extern

Compute the exponential of x.

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

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

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

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

◆ SDL_fabs()

double SDL_fabs ( double  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

◆ SDL_fabsf()

float SDL_fabsf ( float  x)
extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

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

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

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

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

Referenced by SDL_RectsEqualEpsilon().

◆ SDL_floor()

double SDL_floor ( double  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_floorf()

float SDL_floorf ( float  x)
extern

Compute the floor of x.

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

Domain: -INF <= x <= INF

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

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

Parameters
xfloating point value.
Returns
the floor of x.

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

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

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)
extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

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

Range: -y <= z <= y

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

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

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

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

◆ SDL_free()

void SDL_free ( void *  mem)
extern

Free allocated memory.

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

If mem is NULL, this function does nothing.

Parameters
mema pointer to allocated memory, or NULL.

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

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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_getenv_unsafe()

const char * SDL_getenv_unsafe ( const char *  name)
extern

Get the value of a variable in the environment.

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

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

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

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

◆ SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment ( void  )
extern

Get the process environment.

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

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

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

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

◆ SDL_GetEnvironmentVariable()

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

Get the value of a variable in the environment.

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

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

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

◆ SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables ( SDL_Environment *  env)
extern

Get all variables in the environment.

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

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

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

◆ SDL_GetMemoryFunctions()

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

Get the current set of SDL memory functions.

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

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

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

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )
extern

Get the number of outstanding (unfreed) allocations.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_GetOriginalMemoryFunctions()

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

Get the original set of SDL memory functions.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iconv()

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

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

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

On exit:

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

◆ SDL_iconv_close()

int SDL_iconv_close ( SDL_iconv_t  cd)
extern

This function frees a context used for character set conversion.

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

◆ SDL_iconv_open()

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

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

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

◆ SDL_iconv_string()

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

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

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

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

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

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

◆ SDL_isalnum()

int SDL_isalnum ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isalpha()

int SDL_isalpha ( int  x)
extern

Query if a character is alphabetic (a letter).

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isblank()

int SDL_isblank ( int  x)
extern

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_iscntrl()

int SDL_iscntrl ( int  x)
extern

Report if a character is a control character.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isdigit()

int SDL_isdigit ( int  x)
extern

Report if a character is a numeric digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isgraph()

int SDL_isgraph ( int  x)
extern

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

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

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

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

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

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

◆ SDL_isinf()

int SDL_isinf ( double  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_isinff()

int SDL_isinff ( float  x)
extern

Return whether the value is infinity.

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

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

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

◆ SDL_islower()

int SDL_islower ( int  x)
extern

Report if a character is lower case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isnan()

int SDL_isnan ( double  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isnanf()

int SDL_isnanf ( float  x)
extern

Return whether the value is NaN.

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

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

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

◆ SDL_isprint()

int SDL_isprint ( int  x)
extern

Report if a character is "printable".

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_ispunct()

int SDL_ispunct ( int  x)
extern

Report if a character is a punctuation mark.

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

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

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

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

◆ SDL_isspace()

int SDL_isspace ( int  x)
extern

Report if a character is whitespace.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isupper()

int SDL_isupper ( int  x)
extern

Report if a character is upper case.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_isxdigit()

int SDL_isxdigit ( int  x)
extern

Report if a character is a hexadecimal digit.

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_itoa()

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

Convert an integer into a string.

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

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

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

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

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

◆ SDL_lltoa()

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

Convert a long long integer into a string.

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

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

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

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

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

◆ SDL_log()

double SDL_log ( double  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10()

double SDL_log10 ( double  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_log10f()

float SDL_log10f ( float  x)
extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_logf()

float SDL_logf ( float  x)
extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

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

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

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

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

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

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

◆ SDL_lround()

long SDL_lround ( double  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_lroundf()

long SDL_lroundf ( float  x)
extern

Round x to the nearest integer representable as a long

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

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

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

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

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

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

◆ SDL_ltoa()

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

Convert a long integer into a string.

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

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

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

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

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

◆ SDL_malloc()

SDL_MALLOC void * SDL_malloc ( size_t  size)
extern

Allocate uninitialized memory.

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

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

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

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

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

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

◆ SDL_memcmp()

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

Compare two buffers of memory.

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memcpy()

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

Copy non-overlapping memory.

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

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

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

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

◆ SDL_memmove()

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

Copy memory ranges that might overlap.

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

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

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

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

◆ SDL_memset()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_memset4()

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_modf()

double SDL_modf ( double  x,
double *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_modff()

float SDL_modff ( float  x,
float *  y 
)
extern

Split x into integer and fractional parts

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

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

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

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

◆ SDL_murmur3_32()

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

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

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

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

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

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

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

Since
This function is available since SDL 3.2.0.

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)
extern

Raise x to the power y

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

Range: -INF <= z <= INF

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

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

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

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

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

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

◆ SDL_qsort()

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

Sort an array.

For example:

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

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

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

◆ SDL_qsort_r()

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

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

For example:

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

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

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

◆ SDL_rand()

Sint32 SDL_rand ( Sint32  n)
extern

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

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

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

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits()

Uint32 SDL_rand_bits ( void  )
extern

Generate 32 pseudo-random bits.

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_rand_bits_r()

Uint32 SDL_rand_bits_r ( Uint64 *  state)
extern

Generate 32 pseudo-random bits.

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

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

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

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

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

◆ SDL_rand_r()

Sint32 SDL_rand_r ( Uint64 *  state,
Sint32  n 
)
extern

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

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

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

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

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

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

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

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

◆ SDL_randf()

float SDL_randf ( void  )
extern

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

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

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

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

\threadsafety All calls should be made from a single thread

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

◆ SDL_randf_r()

float SDL_randf_r ( Uint64 *  state)
extern

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

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

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

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

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

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

◆ SDL_round()

double SDL_round ( double  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_roundf()

float SDL_roundf ( float  x)
extern

Round x to the nearest integer.

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

Domain: -INF <= x <= INF

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

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

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

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

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

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)
extern

Scale x by an integer power of two.

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

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

Range: -INF <= y <= INF

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

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

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

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

◆ SDL_setenv_unsafe()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetEnvironmentVariable()

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

Set the value of a variable in the environment.

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

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

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

◆ SDL_SetMemoryFunctions()

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

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

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

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

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

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

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

◆ SDL_sin()

double SDL_sin ( double  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_sinf()

float SDL_sinf ( float  x)
extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

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

◆ SDL_size_add_check_overflow()

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

Add two integers, checking for overflow.

If a + b would overflow, return false.

Otherwise store a + b via ret and return true.

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

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

Since
This function is available since SDL 3.2.0.

Definition at line 6105 of file SDL_stdinc.h.

6106{
6107 if (b > SDL_SIZE_MAX - a) {
6108 return false;
6109 }
6110 *ret = a + b;
6111 return true;
6112}

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

6067{
6068 if (a != 0 && b > SDL_SIZE_MAX / a) {
6069 return false;
6070 }
6071 *ret = a * b;
6072 return true;
6073}

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