SDL 3.0
SDL_stdinc.h File Reference
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
+ Include dependency graph for SDL_stdinc.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SDL_SIZE_MAX   ((size_t) -1)
 
#define SDL_HAS_BUILTIN(x)   0
 
#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_FALSE   false
 
#define SDL_TRUE   true
 
#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 bool SDL_bool
 
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_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_WSCANF_VARARG_FUNC(fmtargnumber)
 
#define SDL_COMPILE_TIME_ASSERT(name, x)    typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
 
#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 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)
 
SDL_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)
 
const char * SDL_getenv (const char *name)
 
int SDL_setenv (const char *name, const char *value, int overwrite)
 
int SDL_unsetenv (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)
 
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 *s1, const char *s2, 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 (Sint64 value, char *str, int radix)
 
char * SDL_ulltoa (Uint64 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)
 
Sint64 SDL_strtoll (const char *str, char **endp, int base)
 
Uint64 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)
 
Uint32 SDL_StepUTF8 (const char **pstr, size_t *pslen)
 
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, const wchar_t *fmt, va_list ap)
 
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 SDL_bool SDL_size_mul_check_overflow (size_t a, size_t b, size_t *ret)
 
SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow (size_t a, size_t b, size_t *ret)
 

Macro Definition Documentation

◆ SDL_arraysize

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

The number of elements in an array.

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

Definition at line 103 of file SDL_stdinc.h.

◆ SDL_clamp

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

Definition at line 687 of file SDL_stdinc.h.

◆ SDL_COMPILE_TIME_ASSERT

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

Definition at line 482 of file SDL_stdinc.h.

511{
512 DUMMY_ENUM_VALUE
513} SDL_DUMMY_ENUM;
514
515SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
516#endif
517#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
518/** \endcond */
519
520#include <SDL3/SDL_begin_code.h>
521/* Set up for C function definitions, even when using C++ */
522#ifdef __cplusplus
523extern "C" {
524#endif
525
526#ifndef SDL_DISABLE_ALLOCA
527#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
528#define SDL_stack_free(data)
529#else
530#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
531#define SDL_stack_free(data) SDL_free(data)
532#endif
533
534extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
535extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
536extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
537extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
538
539typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
540typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
541typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
542typedef void (SDLCALL *SDL_free_func)(void *mem);
543
544/**
545 * Get the original set of SDL memory functions.
546 *
547 * This is what SDL_malloc and friends will use by default, if there has been
548 * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
549 * runtime's `malloc` functions behind the scenes! Different platforms and
550 * build configurations might do any number of unexpected things.
551 *
552 * \param malloc_func filled with malloc function.
553 * \param calloc_func filled with calloc function.
554 * \param realloc_func filled with realloc function.
555 * \param free_func filled with free function.
556 *
557 * \threadsafety It is safe to call this function from any thread.
558 *
559 * \since This function is available since SDL 3.0.0.
560 */
561extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
562 SDL_calloc_func *calloc_func,
563 SDL_realloc_func *realloc_func,
564 SDL_free_func *free_func);
565
566/**
567 * Get the current set of SDL memory functions.
568 *
569 * \param malloc_func filled with malloc function.
570 * \param calloc_func filled with calloc function.
571 * \param realloc_func filled with realloc function.
572 * \param free_func filled with free function.
573 *
574 * \threadsafety This does not hold a lock, so do not call this in the
575 * unlikely event of a background thread calling
576 * SDL_SetMemoryFunctions simultaneously.
577 *
578 * \since This function is available since SDL 3.0.0.
579 *
580 * \sa SDL_SetMemoryFunctions
581 * \sa SDL_GetOriginalMemoryFunctions
582 */
583extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
584 SDL_calloc_func *calloc_func,
585 SDL_realloc_func *realloc_func,
586 SDL_free_func *free_func);
587
588/**
589 * Replace SDL's memory allocation functions with a custom set.
590 *
591 * It is not safe to call this function once any allocations have been made,
592 * as future calls to SDL_free will use the new allocator, even if they came
593 * from an SDL_malloc made with the old one!
594 *
595 * If used, usually this needs to be the first call made into the SDL library,
596 * if not the very first thing done at program startup time.
597 *
598 * \param malloc_func custom malloc function.
599 * \param calloc_func custom calloc function.
600 * \param realloc_func custom realloc function.
601 * \param free_func custom free function.
602 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
603 * for more information.
604 *
605 * \threadsafety It is safe to call this function from any thread, but one
606 * should not replace the memory functions once any allocations
607 * are made!
608 *
609 * \since This function is available since SDL 3.0.0.
610 *
611 * \sa SDL_GetMemoryFunctions
612 * \sa SDL_GetOriginalMemoryFunctions
613 */
614extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
615 SDL_calloc_func calloc_func,
616 SDL_realloc_func realloc_func,
617 SDL_free_func free_func);
618
619/**
620 * Allocate memory aligned to a specific value.
621 *
622 * If `alignment` is less than the size of `void *`, then it will be increased
623 * to match that.
624 *
625 * The returned memory address will be a multiple of the alignment value, and
626 * the amount of memory allocated will be a multiple of the alignment value.
627 *
628 * The memory returned by this function must be freed with SDL_aligned_free(),
629 * and _not_ SDL_free.
630 *
631 * \param alignment the alignment requested.
632 * \param size the size to allocate.
633 * \returns a pointer to the aligned memory.
634 *
635 * \threadsafety It is safe to call this function from any thread.
636 *
637 * \since This function is available since SDL 3.0.0.
638 *
639 * \sa SDL_aligned_free
640 */
641extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
642
643/**
644 * Free memory allocated by SDL_aligned_alloc().
645 *
646 * The pointer is no longer valid after this call and cannot be dereferenced
647 * anymore.
648 *
649 * \param mem a pointer previously returned by SDL_aligned_alloc.
650 *
651 * \threadsafety It is safe to call this function from any thread.
652 *
653 * \since This function is available since SDL 3.0.0.
654 *
655 * \sa SDL_aligned_alloc
656 */
657extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
658
659/**
660 * Get the number of outstanding (unfreed) allocations.
661 *
662 * \returns the number of allocations.
663 *
664 * \threadsafety It is safe to call this function from any thread.
665 *
666 * \since This function is available since SDL 3.0.0.
667 */
668extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
669
670extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
671extern SDL_DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
672extern SDL_DECLSPEC int SDLCALL SDL_unsetenv(const char *name);
673
674typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
675extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
676extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
677
678typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
679extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
680extern 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);
681
682extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
683
684/* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
685#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
686#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
687#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
688
689/**
690 * Query if a character is alphabetic (a letter).
691 *
692 * **WARNING**: Regardless of system locale, this will only treat ASCII values
693 * for English 'a-z' and 'A-Z' as true.
694 *
695 * \param x character value to check.
696 * \returns non-zero if x falls within the character class, zero otherwise.
697 *
698 * \threadsafety It is safe to call this function from any thread.
699 *
700 * \since This function is available since SDL 3.0.0.
701 */
702extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
703
704/**
705 * Query if a character is alphabetic (a letter) or a number.
706 *
707 * **WARNING**: Regardless of system locale, this will only treat ASCII values
708 * for English 'a-z', 'A-Z', and '0-9' as true.
709 *
710 * \param x character value to check.
711 * \returns non-zero if x falls within the character class, zero otherwise.
712 *
713 * \threadsafety It is safe to call this function from any thread.
714 *
715 * \since This function is available since SDL 3.0.0.
716 */
717extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
718
719/**
720 * Report if a character is blank (a space or tab).
721 *
722 * **WARNING**: Regardless of system locale, this will only treat ASCII values
723 * 0x20 (space) or 0x9 (tab) as true.
724 *
725 * \param x character value to check.
726 * \returns non-zero if x falls within the character class, zero otherwise.
727 *
728 * \threadsafety It is safe to call this function from any thread.
729 *
730 * \since This function is available since SDL 3.0.0.
731 */
732extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
733
734/**
735 * Report if a character is a control character.
736 *
737 * **WARNING**: Regardless of system locale, this will only treat ASCII values
738 * 0 through 0x1F, and 0x7F, as true.
739 *
740 * \param x character value to check.
741 * \returns non-zero if x falls within the character class, zero otherwise.
742 *
743 * \threadsafety It is safe to call this function from any thread.
744 *
745 * \since This function is available since SDL 3.0.0.
746 */
747extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
748
749/**
750 * Report if a character is a numeric digit.
751 *
752 * **WARNING**: Regardless of system locale, this will only treat ASCII values
753 * '0' (0x30) through '9' (0x39), as true.
754 *
755 * \param x character value to check.
756 * \returns non-zero if x falls within the character class, zero otherwise.
757 *
758 * \threadsafety It is safe to call this function from any thread.
759 *
760 * \since This function is available since SDL 3.0.0.
761 */
762extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
763
764/**
765 * Report if a character is a hexadecimal digit.
766 *
767 * **WARNING**: Regardless of system locale, this will only treat ASCII values
768 * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
769 *
770 * \param x character value to check.
771 * \returns non-zero if x falls within the character class, zero otherwise.
772 *
773 * \threadsafety It is safe to call this function from any thread.
774 *
775 * \since This function is available since SDL 3.0.0.
776 */
777extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
778
779/**
780 * Report if a character is a punctuation mark.
781 *
782 * **WARNING**: Regardless of system locale, this is equivalent to
783 * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
784 *
785 * \param x character value to check.
786 * \returns non-zero if x falls within the character class, zero otherwise.
787 *
788 * \threadsafety It is safe to call this function from any thread.
789 *
790 * \since This function is available since SDL 3.0.0.
791 *
792 * \sa SDL_isgraph
793 * \sa SDL_isalnum
794 */
795extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
796
797/**
798 * Report if a character is whitespace.
799 *
800 * **WARNING**: Regardless of system locale, this will only treat the
801 * following ASCII values as true:
802 *
803 * - space (0x20)
804 * - tab (0x09)
805 * - newline (0x0A)
806 * - vertical tab (0x0B)
807 * - form feed (0x0C)
808 * - return (0x0D)
809 *
810 * \param x character value to check.
811 * \returns non-zero if x falls within the character class, zero otherwise.
812 *
813 * \threadsafety It is safe to call this function from any thread.
814 *
815 * \since This function is available since SDL 3.0.0.
816 */
817extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
818
819/**
820 * Report if a character is upper case.
821 *
822 * **WARNING**: Regardless of system locale, this will only treat ASCII values
823 * 'A' through 'Z' as true.
824 *
825 * \param x character value to check.
826 * \returns non-zero if x falls within the character class, zero otherwise.
827 *
828 * \threadsafety It is safe to call this function from any thread.
829 *
830 * \since This function is available since SDL 3.0.0.
831 */
832extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
833
834/**
835 * Report if a character is lower case.
836 *
837 * **WARNING**: Regardless of system locale, this will only treat ASCII values
838 * 'a' through 'z' as true.
839 *
840 * \param x character value to check.
841 * \returns non-zero if x falls within the character class, zero otherwise.
842 *
843 * \threadsafety It is safe to call this function from any thread.
844 *
845 * \since This function is available since SDL 3.0.0.
846 */
847extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
848
849/**
850 * Report if a character is "printable".
851 *
852 * Be advised that "printable" has a definition that goes back to text
853 * terminals from the dawn of computing, making this a sort of special case
854 * function that is not suitable for Unicode (or most any) text management.
855 *
856 * **WARNING**: Regardless of system locale, this will only treat ASCII values
857 * ' ' (0x20) through '~' (0x7E) as true.
858 *
859 * \param x character value to check.
860 * \returns non-zero if x falls within the character class, zero otherwise.
861 *
862 * \threadsafety It is safe to call this function from any thread.
863 *
864 * \since This function is available since SDL 3.0.0.
865 */
866extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
867
868/**
869 * Report if a character is any "printable" except space.
870 *
871 * Be advised that "printable" has a definition that goes back to text
872 * terminals from the dawn of computing, making this a sort of special case
873 * function that is not suitable for Unicode (or most any) text management.
874 *
875 * **WARNING**: Regardless of system locale, this is equivalent to
876 * `(SDL_isprint(x)) && ((x) != ' ')`.
877 *
878 * \param x character value to check.
879 * \returns non-zero if x falls within the character class, zero otherwise.
880 *
881 * \threadsafety It is safe to call this function from any thread.
882 *
883 * \since This function is available since SDL 3.0.0.
884 *
885 * \sa SDL_isprint
886 */
887extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
888
889/**
890 * Convert low-ASCII English letters to uppercase.
891 *
892 * **WARNING**: Regardless of system locale, this will only convert ASCII
893 * values 'a' through 'z' to uppercase.
894 *
895 * This function returns the uppercase equivalent of `x`. If a character
896 * cannot be converted, or is already uppercase, this function returns `x`.
897 *
898 * \param x character value to check.
899 * \returns capitalized version of x, or x if no conversion available.
900 *
901 * \threadsafety It is safe to call this function from any thread.
902 *
903 * \since This function is available since SDL 3.0.0.
904 */
905extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
906
907/**
908 * Convert low-ASCII English letters to lowercase.
909 *
910 * **WARNING**: Regardless of system locale, this will only convert ASCII
911 * values 'A' through 'Z' to lowercase.
912 *
913 * This function returns the lowercase equivalent of `x`. If a character
914 * cannot be converted, or is already lowercase, this function returns `x`.
915 *
916 * \param x character value to check.
917 * \returns lowercase version of x, or x if no conversion available.
918 *
919 * \threadsafety It is safe to call this function from any thread.
920 *
921 * \since This function is available since SDL 3.0.0.
922 */
923extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
924
925extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
926extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
927
928extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
929
930/* Take advantage of compiler optimizations for memcpy */
931#ifndef SDL_SLOW_MEMCPY
932#ifdef SDL_memcpy
933#undef SDL_memcpy
934#endif
935#define SDL_memcpy memcpy
936#endif
937
938#define SDL_copyp(dst, src) \
939 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
940 SDL_memcpy((dst), (src), sizeof(*(src)))
941
942extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
943
944/* Take advantage of compiler optimizations for memmove */
945#ifndef SDL_SLOW_MEMMOVE
946#ifdef SDL_memmove
947#undef SDL_memmove
948#endif
949#define SDL_memmove memmove
950#endif
951
952extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
953extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
954
955/* Take advantage of compiler optimizations for memset */
956#ifndef SDL_SLOW_MEMSET
957#ifdef SDL_memset
958#undef SDL_memset
959#endif
960#define SDL_memset memset
961#endif
962
963#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
964#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
965#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
966
967extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
968
969extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
970extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
971extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
972extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
973extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
974extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
975extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
976
977/**
978 * Compare two null-terminated wide strings.
979 *
980 * This only compares wchar_t values until it hits a null-terminating
981 * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
982 * depending on your platform's wchar_t size), or uses valid Unicode values.
983 *
984 * \param str1 the first string to compare. NULL is not permitted!
985 * \param str2 the second string to compare. NULL is not permitted!
986 * \returns less than zero if str1 is "less than" str2, greater than zero if
987 * str1 is "greater than" str2, and zero if the strings match
988 * exactly.
989 *
990 * \threadsafety It is safe to call this function from any thread.
991 *
992 * \since This function is available since SDL 3.0.0.
993 */
994extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
995
996/**
997 * Compare two wide strings up to a number of wchar_t values.
998 *
999 * This only compares wchar_t values; it does not care if the string is
1000 * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
1001 * or uses valid Unicode values.
1002 *
1003 * Note that while this function is intended to be used with UTF-16 (or
1004 * UTF-32, depending on your platform's definition of wchar_t), it is
1005 * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
1006 * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
1007 * sequence, it will only compare a portion of the final character.
1008 *
1009 * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
1010 * match to this number of wide chars (or both have matched to a
1011 * null-terminator character before this count), they will be considered
1012 * equal.
1013 *
1014 * \param str1 the first string to compare. NULL is not permitted!
1015 * \param str2 the second string to compare. NULL is not permitted!
1016 * \param maxlen the maximum number of wchar_t to compare.
1017 * \returns less than zero if str1 is "less than" str2, greater than zero if
1018 * str1 is "greater than" str2, and zero if the strings match
1019 * exactly.
1020 *
1021 * \threadsafety It is safe to call this function from any thread.
1022 *
1023 * \since This function is available since SDL 3.0.0.
1024 */
1025extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
1026
1027/**
1028 * Compare two null-terminated wide strings, case-insensitively.
1029 *
1030 * This will work with Unicode strings, using a technique called
1031 * "case-folding" to handle the vast majority of case-sensitive human
1032 * languages regardless of system locale. It can deal with expanding values: a
1033 * German Eszett character can compare against two ASCII 's' chars and be
1034 * considered a match, for example. A notable exception: it does not handle
1035 * the Turkish 'i' character; human language is complicated!
1036 *
1037 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
1038 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
1039 * handles Unicode, it expects the string to be well-formed and not a
1040 * null-terminated string of arbitrary bytes. Characters that are not valid
1041 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
1042 * CHARACTER), which is to say two strings of random bits may turn out to
1043 * match if they convert to the same amount of replacement characters.
1044 *
1045 * \param str1 the first string to compare. NULL is not permitted!
1046 * \param str2 the second string to compare. NULL is not permitted!
1047 * \returns less than zero if str1 is "less than" str2, greater than zero if
1048 * str1 is "greater than" str2, and zero if the strings match
1049 * exactly.
1050 *
1051 * \threadsafety It is safe to call this function from any thread.
1052 *
1053 * \since This function is available since SDL 3.0.0.
1054 */
1055extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
1056
1057/**
1058 * Compare two wide strings, case-insensitively, up to a number of wchar_t.
1059 *
1060 * This will work with Unicode strings, using a technique called
1061 * "case-folding" to handle the vast majority of case-sensitive human
1062 * languages regardless of system locale. It can deal with expanding values: a
1063 * German Eszett character can compare against two ASCII 's' chars and be
1064 * considered a match, for example. A notable exception: it does not handle
1065 * the Turkish 'i' character; human language is complicated!
1066 *
1067 * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
1068 * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
1069 * handles Unicode, it expects the string to be well-formed and not a
1070 * null-terminated string of arbitrary bytes. Characters that are not valid
1071 * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
1072 * CHARACTER), which is to say two strings of random bits may turn out to
1073 * match if they convert to the same amount of replacement characters.
1074 *
1075 * Note that while this function might deal with variable-sized characters,
1076 * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
1077 * multi-byte UTF-16 sequence, it may convert a portion of the final character
1078 * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
1079 * to overflow a buffer.
1080 *
1081 * `maxlen` specifies a maximum number of wchar_t values to compare; if the
1082 * strings match to this number of wchar_t (or both have matched to a
1083 * null-terminator character before this number of bytes), they will be
1084 * considered equal.
1085 *
1086 * \param str1 the first string to compare. NULL is not permitted!
1087 * \param str2 the second string to compare. NULL is not permitted!
1088 * \param maxlen the maximum number of wchar_t values to compare.
1089 * \returns less than zero if str1 is "less than" str2, greater than zero if
1090 * str1 is "greater than" str2, and zero if the strings match
1091 * exactly.
1092 *
1093 * \threadsafety It is safe to call this function from any thread.
1094 *
1095 * \since This function is available since SDL 3.0.0.
1096 */
1097extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
1098
1099extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
1100
1101extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
1102extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
1103extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
1104extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
1105extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
1106extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
1107extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
1108extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
1109
1110/**
1111 * Convert a string to uppercase.
1112 *
1113 * **WARNING**: Regardless of system locale, this will only convert ASCII
1114 * values 'A' through 'Z' to uppercase.
1115 *
1116 * This function operates on a null-terminated string of bytes--even if it is
1117 * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
1118 * uppercase equivalents in-place, returning the original `str` pointer.
1119 *
1120 * \param str the string to convert in-place. Can not be NULL.
1121 * \returns the `str` pointer passed into this function.
1122 *
1123 * \threadsafety It is safe to call this function from any thread.
1124 *
1125 * \since This function is available since SDL 3.0.0.
1126 *
1127 * \sa SDL_strlwr
1128 */
1129extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
1130
1131/**
1132 * Convert a string to lowercase.
1133 *
1134 * **WARNING**: Regardless of system locale, this will only convert ASCII
1135 * values 'A' through 'Z' to lowercase.
1136 *
1137 * This function operates on a null-terminated string of bytes--even if it is
1138 * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
1139 * lowercase equivalents in-place, returning the original `str` pointer.
1140 *
1141 * \param str the string to convert in-place. Can not be NULL.
1142 * \returns the `str` pointer passed into this function.
1143 *
1144 * \threadsafety It is safe to call this function from any thread.
1145 *
1146 * \since This function is available since SDL 3.0.0.
1147 *
1148 * \sa SDL_strupr
1149 */
1150extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
1151
1152extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
1153extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
1154extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
1155extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
1156extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
1157extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
1158extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
1159extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
1160
1161extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
1162extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
1163extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
1164extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
1165extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
1166extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
1167
1168extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
1169extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
1170extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
1171extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
1172extern SDL_DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
1173extern SDL_DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
1174extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
1175
1176/**
1177 * Compare two null-terminated UTF-8 strings.
1178 *
1179 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
1180 * since effectively this function just compares bytes until it hits a
1181 * null-terminating character. Also due to the nature of UTF-8, this can be
1182 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
1183 *
1184 * \param str1 the first string to compare. NULL is not permitted!
1185 * \param str2 the second string to compare. NULL is not permitted!
1186 * \returns less than zero if str1 is "less than" str2, greater than zero if
1187 * str1 is "greater than" str2, and zero if the strings match
1188 * exactly.
1189 *
1190 * \threadsafety It is safe to call this function from any thread.
1191 *
1192 * \since This function is available since SDL 3.0.0.
1193 */
1194extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
1195
1196/**
1197 * Compare two UTF-8 strings up to a number of bytes.
1198 *
1199 * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
1200 * since effectively this function just compares bytes until it hits a
1201 * null-terminating character. Also due to the nature of UTF-8, this can be
1202 * used with SDL_qsort() to put strings in (roughly) alphabetical order.
1203 *
1204 * Note that while this function is intended to be used with UTF-8, it is
1205 * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
1206 * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
1207 * compare a portion of the final character.
1208 *
1209 * `maxlen` specifies a maximum number of bytes to compare; if the strings
1210 * match to this number of bytes (or both have matched to a null-terminator
1211 * character before this number of bytes), they will be considered equal.
1212 *
1213 * \param str1 the first string to compare. NULL is not permitted!
1214 * \param str2 the second string to compare. NULL is not permitted!
1215 * \param maxlen the maximum number of _bytes_ to compare.
1216 * \returns less than zero if str1 is "less than" str2, greater than zero if
1217 * str1 is "greater than" str2, and zero if the strings match
1218 * exactly.
1219 *
1220 * \threadsafety It is safe to call this function from any thread.
1221 *
1222 * \since This function is available since SDL 3.0.0.
1223 */
1224extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
1225
1226/**
1227 * Compare two null-terminated UTF-8 strings, case-insensitively.
1228 *
1229 * This will work with Unicode strings, using a technique called
1230 * "case-folding" to handle the vast majority of case-sensitive human
1231 * languages regardless of system locale. It can deal with expanding values: a
1232 * German Eszett character can compare against two ASCII 's' chars and be
1233 * considered a match, for example. A notable exception: it does not handle
1234 * the Turkish 'i' character; human language is complicated!
1235 *
1236 * Since this handles Unicode, it expects the string to be well-formed UTF-8
1237 * and not a null-terminated string of arbitrary bytes. Bytes that are not
1238 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
1239 * CHARACTER), which is to say two strings of random bits may turn out to
1240 * match if they convert to the same amount of replacement characters.
1241 *
1242 * \param str1 the first string to compare. NULL is not permitted!
1243 * \param str2 the second string to compare. NULL is not permitted!
1244 * \returns less than zero if str1 is "less than" str2, greater than zero if
1245 * str1 is "greater than" str2, and zero if the strings match
1246 * exactly.
1247 *
1248 * \threadsafety It is safe to call this function from any thread.
1249 *
1250 * \since This function is available since SDL 3.0.0.
1251 */
1252extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
1253
1254
1255/**
1256 * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
1257 *
1258 * This will work with Unicode strings, using a technique called
1259 * "case-folding" to handle the vast majority of case-sensitive human
1260 * languages regardless of system locale. It can deal with expanding values: a
1261 * German Eszett character can compare against two ASCII 's' chars and be
1262 * considered a match, for example. A notable exception: it does not handle
1263 * the Turkish 'i' character; human language is complicated!
1264 *
1265 * Since this handles Unicode, it expects the string to be well-formed UTF-8
1266 * and not a null-terminated string of arbitrary bytes. Bytes that are not
1267 * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
1268 * CHARACTER), which is to say two strings of random bits may turn out to
1269 * match if they convert to the same amount of replacement characters.
1270 *
1271 * Note that while this function is intended to be used with UTF-8, `maxlen`
1272 * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
1273 * UTF-8 sequence, it may convert a portion of the final character to one or
1274 * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
1275 * a buffer.
1276 *
1277 * `maxlen` specifies a maximum number of bytes to compare; if the strings
1278 * match to this number of bytes (or both have matched to a null-terminator
1279 * character before this number of bytes), they will be considered equal.
1280 *
1281 * \param str1 the first string to compare. NULL is not permitted!
1282 * \param str2 the second string to compare. NULL is not permitted!
1283 * \param maxlen the maximum number of bytes to compare.
1284 * \returns less than zero if str1 is "less than" str2, greater than zero if
1285 * str1 is "greater than" str2, and zero if the strings match
1286 * exactly.
1287 *
1288 * \threadsafety It is safe to call this function from any thread.
1289 *
1290 * \since This function is available since SDL 3.0.0.
1291 */
1292extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
1293
1294/**
1295 * The Unicode REPLACEMENT CHARACTER codepoint.
1296 *
1297 * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
1298 * with encoding errors.
1299 *
1300 * This tends to render as something like a question mark in most places.
1301 *
1302 * \since This macro is available since SDL 3.0.0.
1303 *
1304 * \sa SDL_StepUTF8
1305 */
1306#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
1307
1308/**
1309 * Decode a UTF-8 string, one Unicode codepoint at a time.
1310 *
1311 * This will return the first Unicode codepoint in the UTF-8 encoded string in
1312 * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
1313 *
1314 * It will not access more than `*pslen` bytes from the string. `*pslen` will
1315 * be adjusted, as well, subtracting the number of bytes consumed.
1316 *
1317 * `pslen` is allowed to be NULL, in which case the string _must_ be
1318 * NULL-terminated, as the function will blindly read until it sees the NULL
1319 * char.
1320 *
1321 * if `*pslen` is zero, it assumes the end of string is reached and returns a
1322 * zero codepoint regardless of the contents of the string buffer.
1323 *
1324 * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
1325 * zero, it will not advance `*pstr` or `*pslen` at all.
1326 *
1327 * Generally this function is called in a loop until it returns zero,
1328 * adjusting its parameters each iteration.
1329 *
1330 * If an invalid UTF-8 sequence is encountered, this function returns
1331 * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
1332 * (which is to say, a multibyte sequence might produce several
1333 * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
1334 * UTF-8 sequence).
1335 *
1336 * Several things can generate invalid UTF-8 sequences, including overlong
1337 * encodings, the use of UTF-16 surrogate values, and truncated data. Please
1338 * refer to
1339 * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
1340 * for details.
1341 *
1342 * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
1343 * \param pslen a pointer to the number of bytes in the string, to be read and
1344 * adjusted. NULL is allowed.
1345 * \returns the first Unicode codepoint in the string.
1346 *
1347 * \threadsafety It is safe to call this function from any thread.
1348 *
1349 * \since This function is available since SDL 3.0.0.
1350 */
1351extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
1352
1353/**
1354 * Convert a single Unicode codepoint to UTF-8.
1355 *
1356 * The buffer pointed to by `dst` must be at least 4 bytes long, as this
1357 * function may generate between 1 and 4 bytes of output.
1358 *
1359 * This function returns the first byte _after_ the newly-written UTF-8
1360 * sequence, which is useful for encoding multiple codepoints in a loop, or
1361 * knowing where to write a NULL-terminator character to end the string (in
1362 * either case, plan to have a buffer of _more_ than 4 bytes!).
1363 *
1364 * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
1365 * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
1366 * codepoint instead, and not set an error.
1367 *
1368 * If `dst` is NULL, this returns NULL immediately without writing to the
1369 * pointer and without setting an error.
1370 *
1371 * \param codepoint a Unicode codepoint to convert to UTF-8.
1372 * \param dst the location to write the encoded UTF-8. Must point to at least
1373 * 4 bytes!
1374 * \returns the first byte past the newly-written UTF-8 sequence.
1375 *
1376 * \threadsafety It is safe to call this function from any thread.
1377 *
1378 * \since This function is available since SDL 3.0.0.
1379 */
1380extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
1381
1382
1383extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
1384extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
1385extern 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);
1386extern 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);
1387extern 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);
1388extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap);
1389extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
1390extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
1391
1392/**
1393 * Seeds the pseudo-random number generator.
1394 *
1395 * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
1396 * of 'random' numbers.
1397 *
1398 * \param seed the value to use as a random number seed, or 0 to use
1399 * SDL_GetPerformanceCounter().
1400 *
1401 * \threadsafety This should be called on the same thread that calls
1402 * SDL_rand*()
1403 *
1404 * \since This function is available since SDL 3.0.0.
1405 *
1406 * \sa SDL_rand
1407 * \sa SDL_rand_bits
1408 * \sa SDL_randf
1409 */
1410extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
1411
1412/**
1413 * Generate a pseudo-random number less than n for positive n
1414 *
1415 * The method used is faster and of better quality than `rand() % n`. Odds are
1416 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
1417 * much worse as n gets bigger.
1418 *
1419 * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
1420 * 1..6
1421 *
1422 * If you want to generate a pseudo-random number in the full range of Sint32,
1423 * you should use: (Sint32)SDL_rand_bits()
1424 *
1425 * If you want reproducible output, be sure to initialize with SDL_srand()
1426 * first.
1427 *
1428 * There are no guarantees as to the quality of the random sequence produced,
1429 * and this should not be used for security (cryptography, passwords) or where
1430 * money is on the line (loot-boxes, casinos). There are many random number
1431 * libraries available with different characteristics and you should pick one
1432 * of those to meet any serious needs.
1433 *
1434 * \param n the number of possible outcomes. n must be positive.
1435 * \returns a random value in the range of [0 .. n-1].
1436 *
1437 * \threadsafety All calls should be made from a single thread
1438 *
1439 * \since This function is available since SDL 3.0.0.
1440 *
1441 * \sa SDL_srand
1442 * \sa SDL_randf
1443 */
1444extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
1445
1446/**
1447 * Generate a uniform pseudo-random floating point number less than 1.0
1448 *
1449 * If you want reproducible output, be sure to initialize with SDL_srand()
1450 * first.
1451 *
1452 * There are no guarantees as to the quality of the random sequence produced,
1453 * and this should not be used for security (cryptography, passwords) or where
1454 * money is on the line (loot-boxes, casinos). There are many random number
1455 * libraries available with different characteristics and you should pick one
1456 * of those to meet any serious needs.
1457 *
1458 * \returns a random value in the range of [0.0, 1.0).
1459 *
1460 * \threadsafety All calls should be made from a single thread
1461 *
1462 * \since This function is available since SDL 3.0.0.
1463 *
1464 * \sa SDL_srand
1465 * \sa SDL_rand
1466 */
1467extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
1468
1469/**
1470 * Generate 32 pseudo-random bits.
1471 *
1472 * You likely want to use SDL_rand() to get a psuedo-random number instead.
1473 *
1474 * There are no guarantees as to the quality of the random sequence produced,
1475 * and this should not be used for security (cryptography, passwords) or where
1476 * money is on the line (loot-boxes, casinos). There are many random number
1477 * libraries available with different characteristics and you should pick one
1478 * of those to meet any serious needs.
1479 *
1480 * \returns a random value in the range of [0-SDL_MAX_UINT32].
1481 *
1482 * \threadsafety All calls should be made from a single thread
1483 *
1484 * \since This function is available since SDL 3.0.0.
1485 *
1486 * \sa SDL_rand
1487 * \sa SDL_randf
1488 * \sa SDL_srand
1489 */
1490extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
1491
1492/**
1493 * Generate a pseudo-random number less than n for positive n
1494 *
1495 * The method used is faster and of better quality than `rand() % n`. Odds are
1496 * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
1497 * much worse as n gets bigger.
1498 *
1499 * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
1500 * 0..5 to 1..6
1501 *
1502 * If you want to generate a pseudo-random number in the full range of Sint32,
1503 * you should use: (Sint32)SDL_rand_bits_r(state)
1504 *
1505 * There are no guarantees as to the quality of the random sequence produced,
1506 * and this should not be used for security (cryptography, passwords) or where
1507 * money is on the line (loot-boxes, casinos). There are many random number
1508 * libraries available with different characteristics and you should pick one
1509 * of those to meet any serious needs.
1510 *
1511 * \param state a pointer to the current random number state, this may not be
1512 * NULL.
1513 * \param n the number of possible outcomes. n must be positive.
1514 * \returns a random value in the range of [0 .. n-1].
1515 *
1516 * \threadsafety This function is thread-safe, as long as the state pointer
1517 * isn't shared between threads.
1518 *
1519 * \since This function is available since SDL 3.0.0.
1520 *
1521 * \sa SDL_rand
1522 * \sa SDL_rand_bits_r
1523 * \sa SDL_randf_r
1524 */
1525extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
1526
1527/**
1528 * Generate a uniform pseudo-random floating point number less than 1.0
1529 *
1530 * If you want reproducible output, be sure to initialize with SDL_srand()
1531 * first.
1532 *
1533 * There are no guarantees as to the quality of the random sequence produced,
1534 * and this should not be used for security (cryptography, passwords) or where
1535 * money is on the line (loot-boxes, casinos). There are many random number
1536 * libraries available with different characteristics and you should pick one
1537 * of those to meet any serious needs.
1538 *
1539 * \param state a pointer to the current random number state, this may not be
1540 * NULL.
1541 * \returns a random value in the range of [0.0, 1.0).
1542 *
1543 * \threadsafety This function is thread-safe, as long as the state pointer
1544 * isn't shared between threads.
1545 *
1546 * \since This function is available since SDL 3.0.0.
1547 *
1548 * \sa SDL_rand_bits_r
1549 * \sa SDL_rand_r
1550 * \sa SDL_randf
1551 */
1552extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
1553
1554/**
1555 * Generate 32 pseudo-random bits.
1556 *
1557 * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
1558 *
1559 * There are no guarantees as to the quality of the random sequence produced,
1560 * and this should not be used for security (cryptography, passwords) or where
1561 * money is on the line (loot-boxes, casinos). There are many random number
1562 * libraries available with different characteristics and you should pick one
1563 * of those to meet any serious needs.
1564 *
1565 * \param state a pointer to the current random number state, this may not be
1566 * NULL.
1567 * \returns a random value in the range of [0-SDL_MAX_UINT32].
1568 *
1569 * \threadsafety This function is thread-safe, as long as the state pointer
1570 * isn't shared between threads.
1571 *
1572 * \since This function is available since SDL 3.0.0.
1573 *
1574 * \sa SDL_rand_r
1575 * \sa SDL_randf_r
1576 */
1577extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
1578
1579
1580#ifndef SDL_PI_D
1581#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
1582#endif
1583#ifndef SDL_PI_F
1584#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
1585#endif
1586
1587/**
1588 * Compute the arc cosine of `x`.
1589 *
1590 * The definition of `y = acos(x)` is `x = cos(y)`.
1591 *
1592 * Domain: `-1 <= x <= 1`
1593 *
1594 * Range: `0 <= y <= Pi`
1595 *
1596 * This function operates on double-precision floating point values, use
1597 * SDL_acosf for single-precision floats.
1598 *
1599 * This function may use a different approximation across different versions,
1600 * platforms and configurations. i.e, it can return a different value given
1601 * the same input on different machines or operating systems, or if SDL is
1602 * updated.
1603 *
1604 * \param x floating point value.
1605 * \returns arc cosine of `x`, in radians.
1606 *
1607 * \threadsafety It is safe to call this function from any thread.
1608 *
1609 * \since This function is available since SDL 3.0.0.
1610 *
1611 * \sa SDL_acosf
1612 * \sa SDL_asin
1613 * \sa SDL_cos
1614 */
1615extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
1616
1617/**
1618 * Compute the arc cosine of `x`.
1619 *
1620 * The definition of `y = acos(x)` is `x = cos(y)`.
1621 *
1622 * Domain: `-1 <= x <= 1`
1623 *
1624 * Range: `0 <= y <= Pi`
1625 *
1626 * This function operates on single-precision floating point values, use
1627 * SDL_acos for double-precision floats.
1628 *
1629 * This function may use a different approximation across different versions,
1630 * platforms and configurations. i.e, it can return a different value given
1631 * the same input on different machines or operating systems, or if SDL is
1632 * updated.
1633 *
1634 * \param x floating point value.
1635 * \returns arc cosine of `x`, in radians.
1636 *
1637 * \threadsafety It is safe to call this function from any thread.
1638 *
1639 * \since This function is available since SDL 3.0.0.
1640 *
1641 * \sa SDL_acos
1642 * \sa SDL_asinf
1643 * \sa SDL_cosf
1644 */
1645extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
1646
1647/**
1648 * Compute the arc sine of `x`.
1649 *
1650 * The definition of `y = asin(x)` is `x = sin(y)`.
1651 *
1652 * Domain: `-1 <= x <= 1`
1653 *
1654 * Range: `-Pi/2 <= y <= Pi/2`
1655 *
1656 * This function operates on double-precision floating point values, use
1657 * SDL_asinf for single-precision floats.
1658 *
1659 * This function may use a different approximation across different versions,
1660 * platforms and configurations. i.e, it can return a different value given
1661 * the same input on different machines or operating systems, or if SDL is
1662 * updated.
1663 *
1664 * \param x floating point value.
1665 * \returns arc sine of `x`, in radians.
1666 *
1667 * \threadsafety It is safe to call this function from any thread.
1668 *
1669 * \since This function is available since SDL 3.0.0.
1670 *
1671 * \sa SDL_asinf
1672 * \sa SDL_acos
1673 * \sa SDL_sin
1674 */
1675extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
1676
1677/**
1678 * Compute the arc sine of `x`.
1679 *
1680 * The definition of `y = asin(x)` is `x = sin(y)`.
1681 *
1682 * Domain: `-1 <= x <= 1`
1683 *
1684 * Range: `-Pi/2 <= y <= Pi/2`
1685 *
1686 * This function operates on single-precision floating point values, use
1687 * SDL_asin for double-precision floats.
1688 *
1689 * This function may use a different approximation across different versions,
1690 * platforms and configurations. i.e, it can return a different value given
1691 * the same input on different machines or operating systems, or if SDL is
1692 * updated.
1693 *
1694 * \param x floating point value.
1695 * \returns arc sine of `x`, in radians.
1696 *
1697 * \threadsafety It is safe to call this function from any thread.
1698 *
1699 * \since This function is available since SDL 3.0.0.
1700 *
1701 * \sa SDL_asin
1702 * \sa SDL_acosf
1703 * \sa SDL_sinf
1704 */
1705extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
1706
1707/**
1708 * Compute the arc tangent of `x`.
1709 *
1710 * The definition of `y = atan(x)` is `x = tan(y)`.
1711 *
1712 * Domain: `-INF <= x <= INF`
1713 *
1714 * Range: `-Pi/2 <= y <= Pi/2`
1715 *
1716 * This function operates on double-precision floating point values, use
1717 * SDL_atanf for single-precision floats.
1718 *
1719 * To calculate the arc tangent of y / x, use SDL_atan2.
1720 *
1721 * This function may use a different approximation across different versions,
1722 * platforms and configurations. i.e, it can return a different value given
1723 * the same input on different machines or operating systems, or if SDL is
1724 * updated.
1725 *
1726 * \param x floating point value.
1727 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
1728 *
1729 * \threadsafety It is safe to call this function from any thread.
1730 *
1731 * \since This function is available since SDL 3.0.0.
1732 *
1733 * \sa SDL_atanf
1734 * \sa SDL_atan2
1735 * \sa SDL_tan
1736 */
1737extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
1738
1739/**
1740 * Compute the arc tangent of `x`.
1741 *
1742 * The definition of `y = atan(x)` is `x = tan(y)`.
1743 *
1744 * Domain: `-INF <= x <= INF`
1745 *
1746 * Range: `-Pi/2 <= y <= Pi/2`
1747 *
1748 * This function operates on single-precision floating point values, use
1749 * SDL_atan for dboule-precision floats.
1750 *
1751 * To calculate the arc tangent of y / x, use SDL_atan2f.
1752 *
1753 * This function may use a different approximation across different versions,
1754 * platforms and configurations. i.e, it can return a different value given
1755 * the same input on different machines or operating systems, or if SDL is
1756 * updated.
1757 *
1758 * \param x floating point value.
1759 * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
1760 *
1761 * \threadsafety It is safe to call this function from any thread.
1762 *
1763 * \since This function is available since SDL 3.0.0.
1764 *
1765 * \sa SDL_atan
1766 * \sa SDL_atan2f
1767 * \sa SDL_tanf
1768 */
1769extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
1770
1771/**
1772 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
1773 * the result's quadrant.
1774 *
1775 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
1776 * of z is determined based on the signs of x and y.
1777 *
1778 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
1779 *
1780 * Range: `-Pi/2 <= y <= Pi/2`
1781 *
1782 * This function operates on double-precision floating point values, use
1783 * SDL_atan2f for single-precision floats.
1784 *
1785 * To calculate the arc tangent of a single value, use SDL_atan.
1786 *
1787 * This function may use a different approximation across different versions,
1788 * platforms and configurations. i.e, it can return a different value given
1789 * the same input on different machines or operating systems, or if SDL is
1790 * updated.
1791 *
1792 * \param y floating point value of the numerator (y coordinate).
1793 * \param x floating point value of the denominator (x coordinate).
1794 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
1795 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
1796 *
1797 * \threadsafety It is safe to call this function from any thread.
1798 *
1799 * \since This function is available since SDL 3.0.0.
1800 *
1801 * \sa SDL_atan2f
1802 * \sa SDL_atan
1803 * \sa SDL_tan
1804 */
1805extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
1806
1807/**
1808 * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
1809 * the result's quadrant.
1810 *
1811 * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
1812 * of z is determined based on the signs of x and y.
1813 *
1814 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
1815 *
1816 * Range: `-Pi/2 <= y <= Pi/2`
1817 *
1818 * This function operates on single-precision floating point values, use
1819 * SDL_atan2 for double-precision floats.
1820 *
1821 * To calculate the arc tangent of a single value, use SDL_atanf.
1822 *
1823 * This function may use a different approximation across different versions,
1824 * platforms and configurations. i.e, it can return a different value given
1825 * the same input on different machines or operating systems, or if SDL is
1826 * updated.
1827 *
1828 * \param y floating point value of the numerator (y coordinate).
1829 * \param x floating point value of the denominator (x coordinate).
1830 * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
1831 * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
1832 *
1833 * \threadsafety It is safe to call this function from any thread.
1834 *
1835 * \since This function is available since SDL 3.0.0.
1836 *
1837 * \sa SDL_atan2f
1838 * \sa SDL_atan
1839 * \sa SDL_tan
1840 */
1841extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
1842
1843/**
1844 * Compute the ceiling of `x`.
1845 *
1846 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
1847 * rounded up to the nearest integer.
1848 *
1849 * Domain: `-INF <= x <= INF`
1850 *
1851 * Range: `-INF <= y <= INF`, y integer
1852 *
1853 * This function operates on double-precision floating point values, use
1854 * SDL_ceilf for single-precision floats.
1855 *
1856 * \param x floating point value.
1857 * \returns the ceiling of `x`.
1858 *
1859 * \threadsafety It is safe to call this function from any thread.
1860 *
1861 * \since This function is available since SDL 3.0.0.
1862 *
1863 * \sa SDL_ceilf
1864 * \sa SDL_floor
1865 * \sa SDL_trunc
1866 * \sa SDL_round
1867 * \sa SDL_lround
1868 */
1869extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
1870
1871/**
1872 * Compute the ceiling of `x`.
1873 *
1874 * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
1875 * rounded up to the nearest integer.
1876 *
1877 * Domain: `-INF <= x <= INF`
1878 *
1879 * Range: `-INF <= y <= INF`, y integer
1880 *
1881 * This function operates on single-precision floating point values, use
1882 * SDL_ceil for double-precision floats.
1883 *
1884 * \param x floating point value.
1885 * \returns the ceiling of `x`.
1886 *
1887 * \threadsafety It is safe to call this function from any thread.
1888 *
1889 * \since This function is available since SDL 3.0.0.
1890 *
1891 * \sa SDL_ceil
1892 * \sa SDL_floorf
1893 * \sa SDL_truncf
1894 * \sa SDL_roundf
1895 * \sa SDL_lroundf
1896 */
1897extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
1898
1899/**
1900 * Copy the sign of one floating-point value to another.
1901 *
1902 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
1903 *
1904 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
1905 *
1906 * Range: `-INF <= z <= INF`
1907 *
1908 * This function operates on double-precision floating point values, use
1909 * SDL_copysignf for single-precision floats.
1910 *
1911 * \param x floating point value to use as the magnitude.
1912 * \param y floating point value to use as the sign.
1913 * \returns the floating point value with the sign of y and the magnitude of
1914 * x.
1915 *
1916 * \threadsafety It is safe to call this function from any thread.
1917 *
1918 * \since This function is available since SDL 3.0.0.
1919 *
1920 * \sa SDL_copysignf
1921 * \sa SDL_fabs
1922 */
1923extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
1924
1925/**
1926 * Copy the sign of one floating-point value to another.
1927 *
1928 * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
1929 *
1930 * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
1931 *
1932 * Range: `-INF <= z <= INF`
1933 *
1934 * This function operates on single-precision floating point values, use
1935 * SDL_copysign for double-precision floats.
1936 *
1937 * \param x floating point value to use as the magnitude.
1938 * \param y floating point value to use as the sign.
1939 * \returns the floating point value with the sign of y and the magnitude of
1940 * x.
1941 *
1942 * \threadsafety It is safe to call this function from any thread.
1943 *
1944 * \since This function is available since SDL 3.0.0.
1945 *
1946 * \sa SDL_copysignf
1947 * \sa SDL_fabsf
1948 */
1949extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
1950
1951/**
1952 * Compute the cosine of `x`.
1953 *
1954 * Domain: `-INF <= x <= INF`
1955 *
1956 * Range: `-1 <= y <= 1`
1957 *
1958 * This function operates on double-precision floating point values, use
1959 * SDL_cosf for single-precision floats.
1960 *
1961 * This function may use a different approximation across different versions,
1962 * platforms and configurations. i.e, it can return a different value given
1963 * the same input on different machines or operating systems, or if SDL is
1964 * updated.
1965 *
1966 * \param x floating point value, in radians.
1967 * \returns cosine of `x`.
1968 *
1969 * \threadsafety It is safe to call this function from any thread.
1970 *
1971 * \since This function is available since SDL 3.0.0.
1972 *
1973 * \sa SDL_cosf
1974 * \sa SDL_acos
1975 * \sa SDL_sin
1976 */
1977extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
1978
1979/**
1980 * Compute the cosine of `x`.
1981 *
1982 * Domain: `-INF <= x <= INF`
1983 *
1984 * Range: `-1 <= y <= 1`
1985 *
1986 * This function operates on single-precision floating point values, use
1987 * SDL_cos for double-precision floats.
1988 *
1989 * This function may use a different approximation across different versions,
1990 * platforms and configurations. i.e, it can return a different value given
1991 * the same input on different machines or operating systems, or if SDL is
1992 * updated.
1993 *
1994 * \param x floating point value, in radians.
1995 * \returns cosine of `x`.
1996 *
1997 * \threadsafety It is safe to call this function from any thread.
1998 *
1999 * \since This function is available since SDL 3.0.0.
2000 *
2001 * \sa SDL_cos
2002 * \sa SDL_acosf
2003 * \sa SDL_sinf
2004 */
2005extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
2006
2007/**
2008 * Compute the exponential of `x`.
2009 *
2010 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
2011 * natural logarithm. The inverse is the natural logarithm, SDL_log.
2012 *
2013 * Domain: `-INF <= x <= INF`
2014 *
2015 * Range: `0 <= y <= INF`
2016 *
2017 * The output will overflow if `exp(x)` is too large to be represented.
2018 *
2019 * This function operates on double-precision floating point values, use
2020 * SDL_expf for single-precision floats.
2021 *
2022 * This function may use a different approximation across different versions,
2023 * platforms and configurations. i.e, it can return a different value given
2024 * the same input on different machines or operating systems, or if SDL is
2025 * updated.
2026 *
2027 * \param x floating point value.
2028 * \returns value of `e^x`.
2029 *
2030 * \threadsafety It is safe to call this function from any thread.
2031 *
2032 * \since This function is available since SDL 3.0.0.
2033 *
2034 * \sa SDL_expf
2035 * \sa SDL_log
2036 */
2037extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
2038
2039/**
2040 * Compute the exponential of `x`.
2041 *
2042 * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
2043 * natural logarithm. The inverse is the natural logarithm, SDL_logf.
2044 *
2045 * Domain: `-INF <= x <= INF`
2046 *
2047 * Range: `0 <= y <= INF`
2048 *
2049 * The output will overflow if `exp(x)` is too large to be represented.
2050 *
2051 * This function operates on single-precision floating point values, use
2052 * SDL_exp for double-precision floats.
2053 *
2054 * This function may use a different approximation across different versions,
2055 * platforms and configurations. i.e, it can return a different value given
2056 * the same input on different machines or operating systems, or if SDL is
2057 * updated.
2058 *
2059 * \param x floating point value.
2060 * \returns value of `e^x`.
2061 *
2062 * \threadsafety It is safe to call this function from any thread.
2063 *
2064 * \since This function is available since SDL 3.0.0.
2065 *
2066 * \sa SDL_exp
2067 * \sa SDL_logf
2068 */
2069extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
2070
2071/**
2072 * Compute the absolute value of `x`
2073 *
2074 * Domain: `-INF <= x <= INF`
2075 *
2076 * Range: `0 <= y <= INF`
2077 *
2078 * This function operates on double-precision floating point values, use
2079 * SDL_copysignf for single-precision floats.
2080 *
2081 * \param x floating point value to use as the magnitude.
2082 * \returns the absolute value of `x`.
2083 *
2084 * \threadsafety It is safe to call this function from any thread.
2085 *
2086 * \since This function is available since SDL 3.0.0.
2087 *
2088 * \sa SDL_fabsf
2089 */
2090extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
2091
2092/**
2093 * Compute the absolute value of `x`
2094 *
2095 * Domain: `-INF <= x <= INF`
2096 *
2097 * Range: `0 <= y <= INF`
2098 *
2099 * This function operates on single-precision floating point values, use
2100 * SDL_copysignf for double-precision floats.
2101 *
2102 * \param x floating point value to use as the magnitude.
2103 * \returns the absolute value of `x`.
2104 *
2105 * \threadsafety It is safe to call this function from any thread.
2106 *
2107 * \since This function is available since SDL 3.0.0.
2108 *
2109 * \sa SDL_fabs
2110 */
2111extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
2112
2113/**
2114 * Compute the floor of `x`.
2115 *
2116 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
2117 * rounded down to the nearest integer.
2118 *
2119 * Domain: `-INF <= x <= INF`
2120 *
2121 * Range: `-INF <= y <= INF`, y integer
2122 *
2123 * This function operates on double-precision floating point values, use
2124 * SDL_floorf for single-precision floats.
2125 *
2126 * \param x floating point value.
2127 * \returns the floor of `x`.
2128 *
2129 * \threadsafety It is safe to call this function from any thread.
2130 *
2131 * \since This function is available since SDL 3.0.0.
2132 *
2133 * \sa SDL_floorf
2134 * \sa SDL_ceil
2135 * \sa SDL_trunc
2136 * \sa SDL_round
2137 * \sa SDL_lround
2138 */
2139extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
2140
2141/**
2142 * Compute the floor of `x`.
2143 *
2144 * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
2145 * rounded down to the nearest integer.
2146 *
2147 * Domain: `-INF <= x <= INF`
2148 *
2149 * Range: `-INF <= y <= INF`, y integer
2150 *
2151 * This function operates on single-precision floating point values, use
2152 * SDL_floorf for double-precision floats.
2153 *
2154 * \param x floating point value.
2155 * \returns the floor of `x`.
2156 *
2157 * \threadsafety It is safe to call this function from any thread.
2158 *
2159 * \since This function is available since SDL 3.0.0.
2160 *
2161 * \sa SDL_floor
2162 * \sa SDL_ceilf
2163 * \sa SDL_truncf
2164 * \sa SDL_roundf
2165 * \sa SDL_lroundf
2166 */
2167extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
2168
2169/**
2170 * Truncate `x` to an integer.
2171 *
2172 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
2173 * the fractional part of `x`, leaving only the integer part.
2174 *
2175 * Domain: `-INF <= x <= INF`
2176 *
2177 * Range: `-INF <= y <= INF`, y integer
2178 *
2179 * This function operates on double-precision floating point values, use
2180 * SDL_truncf for single-precision floats.
2181 *
2182 * \param x floating point value.
2183 * \returns `x` truncated to an integer.
2184 *
2185 * \threadsafety It is safe to call this function from any thread.
2186 *
2187 * \since This function is available since SDL 3.0.0.
2188 *
2189 * \sa SDL_truncf
2190 * \sa SDL_fmod
2191 * \sa SDL_ceil
2192 * \sa SDL_floor
2193 * \sa SDL_round
2194 * \sa SDL_lround
2195 */
2196extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
2197
2198/**
2199 * Truncate `x` to an integer.
2200 *
2201 * Rounds `x` to the next closest integer to 0. This is equivalent to removing
2202 * the fractional part of `x`, leaving only the integer part.
2203 *
2204 * Domain: `-INF <= x <= INF`
2205 *
2206 * Range: `-INF <= y <= INF`, y integer
2207 *
2208 * This function operates on single-precision floating point values, use
2209 * SDL_truncf for double-precision floats.
2210 *
2211 * \param x floating point value.
2212 * \returns `x` truncated to an integer.
2213 *
2214 * \threadsafety It is safe to call this function from any thread.
2215 *
2216 * \since This function is available since SDL 3.0.0.
2217 *
2218 * \sa SDL_trunc
2219 * \sa SDL_fmodf
2220 * \sa SDL_ceilf
2221 * \sa SDL_floorf
2222 * \sa SDL_roundf
2223 * \sa SDL_lroundf
2224 */
2225extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
2226
2227/**
2228 * Return the floating-point remainder of `x / y`
2229 *
2230 * Divides `x` by `y`, and returns the remainder.
2231 *
2232 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
2233 *
2234 * Range: `-y <= z <= y`
2235 *
2236 * This function operates on double-precision floating point values, use
2237 * SDL_fmodf for single-precision floats.
2238 *
2239 * \param x the numerator.
2240 * \param y the denominator. Must not be 0.
2241 * \returns the remainder of `x / y`.
2242 *
2243 * \threadsafety It is safe to call this function from any thread.
2244 *
2245 * \since This function is available since SDL 3.0.0.
2246 *
2247 * \sa SDL_fmodf
2248 * \sa SDL_modf
2249 * \sa SDL_trunc
2250 * \sa SDL_ceil
2251 * \sa SDL_floor
2252 * \sa SDL_round
2253 * \sa SDL_lround
2254 */
2255extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
2256
2257/**
2258 * Return the floating-point remainder of `x / y`
2259 *
2260 * Divides `x` by `y`, and returns the remainder.
2261 *
2262 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
2263 *
2264 * Range: `-y <= z <= y`
2265 *
2266 * This function operates on single-precision floating point values, use
2267 * SDL_fmod for single-precision floats.
2268 *
2269 * \param x the numerator.
2270 * \param y the denominator. Must not be 0.
2271 * \returns the remainder of `x / y`.
2272 *
2273 * \threadsafety It is safe to call this function from any thread.
2274 *
2275 * \since This function is available since SDL 3.0.0.
2276 *
2277 * \sa SDL_fmod
2278 * \sa SDL_truncf
2279 * \sa SDL_modff
2280 * \sa SDL_ceilf
2281 * \sa SDL_floorf
2282 * \sa SDL_roundf
2283 * \sa SDL_lroundf
2284 */
2285extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
2286
2287/**
2288 * Return whether the value is infinity.
2289 *
2290 * \param x double-precision floating point value.
2291 * \returns non-zero if the value is infinity, 0 otherwise.
2292 *
2293 * \threadsafety It is safe to call this function from any thread.
2294 *
2295 * \since This function is available since SDL 3.0.0.
2296 *
2297 * \sa SDL_isinff
2298 */
2299extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
2300
2301/**
2302 * Return whether the value is infinity.
2303 *
2304 * \param x floating point value.
2305 * \returns non-zero if the value is infinity, 0 otherwise.
2306 *
2307 * \threadsafety It is safe to call this function from any thread.
2308 *
2309 * \since This function is available since SDL 3.0.0.
2310 *
2311 * \sa SDL_isinf
2312 */
2313extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
2314
2315/**
2316 * Return whether the value is NaN.
2317 *
2318 * \param x double-precision floating point value.
2319 * \returns non-zero if the value is NaN, 0 otherwise.
2320 *
2321 * \threadsafety It is safe to call this function from any thread.
2322 *
2323 * \since This function is available since SDL 3.0.0.
2324 *
2325 * \sa SDL_isnanf
2326 */
2327extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
2328
2329/**
2330 * Return whether the value is NaN.
2331 *
2332 * \param x floating point value.
2333 * \returns non-zero if the value is NaN, 0 otherwise.
2334 *
2335 * \threadsafety It is safe to call this function from any thread.
2336 *
2337 * \since This function is available since SDL 3.0.0.
2338 *
2339 * \sa SDL_isnan
2340 */
2341extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
2342
2343/**
2344 * Compute the natural logarithm of `x`.
2345 *
2346 * Domain: `0 < x <= INF`
2347 *
2348 * Range: `-INF <= y <= INF`
2349 *
2350 * It is an error for `x` to be less than or equal to 0.
2351 *
2352 * This function operates on double-precision floating point values, use
2353 * SDL_logf for single-precision floats.
2354 *
2355 * This function may use a different approximation across different versions,
2356 * platforms and configurations. i.e, it can return a different value given
2357 * the same input on different machines or operating systems, or if SDL is
2358 * updated.
2359 *
2360 * \param x floating point value. Must be greater than 0.
2361 * \returns the natural logarithm of `x`.
2362 *
2363 * \threadsafety It is safe to call this function from any thread.
2364 *
2365 * \since This function is available since SDL 3.0.0.
2366 *
2367 * \sa SDL_logf
2368 * \sa SDL_log10
2369 * \sa SDL_exp
2370 */
2371extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
2372
2373/**
2374 * Compute the natural logarithm of `x`.
2375 *
2376 * Domain: `0 < x <= INF`
2377 *
2378 * Range: `-INF <= y <= INF`
2379 *
2380 * It is an error for `x` to be less than or equal to 0.
2381 *
2382 * This function operates on single-precision floating point values, use
2383 * SDL_log for double-precision floats.
2384 *
2385 * This function may use a different approximation across different versions,
2386 * platforms and configurations. i.e, it can return a different value given
2387 * the same input on different machines or operating systems, or if SDL is
2388 * updated.
2389 *
2390 * \param x floating point value. Must be greater than 0.
2391 * \returns the natural logarithm of `x`.
2392 *
2393 * \threadsafety It is safe to call this function from any thread.
2394 *
2395 * \since This function is available since SDL 3.0.0.
2396 *
2397 * \sa SDL_log
2398 * \sa SDL_expf
2399 */
2400extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
2401
2402/**
2403 * Compute the base-10 logarithm of `x`.
2404 *
2405 * Domain: `0 < x <= INF`
2406 *
2407 * Range: `-INF <= y <= INF`
2408 *
2409 * It is an error for `x` to be less than or equal to 0.
2410 *
2411 * This function operates on double-precision floating point values, use
2412 * SDL_log10f for single-precision floats.
2413 *
2414 * This function may use a different approximation across different versions,
2415 * platforms and configurations. i.e, it can return a different value given
2416 * the same input on different machines or operating systems, or if SDL is
2417 * updated.
2418 *
2419 * \param x floating point value. Must be greater than 0.
2420 * \returns the logarithm of `x`.
2421 *
2422 * \threadsafety It is safe to call this function from any thread.
2423 *
2424 * \since This function is available since SDL 3.0.0.
2425 *
2426 * \sa SDL_log10f
2427 * \sa SDL_log
2428 * \sa SDL_pow
2429 */
2430extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
2431
2432/**
2433 * Compute the base-10 logarithm of `x`.
2434 *
2435 * Domain: `0 < x <= INF`
2436 *
2437 * Range: `-INF <= y <= INF`
2438 *
2439 * It is an error for `x` to be less than or equal to 0.
2440 *
2441 * This function operates on single-precision floating point values, use
2442 * SDL_log10 for double-precision floats.
2443 *
2444 * This function may use a different approximation across different versions,
2445 * platforms and configurations. i.e, it can return a different value given
2446 * the same input on different machines or operating systems, or if SDL is
2447 * updated.
2448 *
2449 * \param x floating point value. Must be greater than 0.
2450 * \returns the logarithm of `x`.
2451 *
2452 * \threadsafety It is safe to call this function from any thread.
2453 *
2454 * \since This function is available since SDL 3.0.0.
2455 *
2456 * \sa SDL_log10
2457 * \sa SDL_logf
2458 * \sa SDL_powf
2459 */
2460extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
2461
2462/**
2463 * Split `x` into integer and fractional parts
2464 *
2465 * This function operates on double-precision floating point values, use
2466 * SDL_modff for single-precision floats.
2467 *
2468 * \param x floating point value.
2469 * \param y output pointer to store the integer part of `x`.
2470 * \returns the fractional part of `x`.
2471 *
2472 * \threadsafety It is safe to call this function from any thread.
2473 *
2474 * \since This function is available since SDL 3.0.0.
2475 *
2476 * \sa SDL_modff
2477 * \sa SDL_trunc
2478 * \sa SDL_fmod
2479 */
2480extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
2481
2482/**
2483 * Split `x` into integer and fractional parts
2484 *
2485 * This function operates on single-precision floating point values, use
2486 * SDL_modf for double-precision floats.
2487 *
2488 * \param x floating point value.
2489 * \param y output pointer to store the integer part of `x`.
2490 * \returns the fractional part of `x`.
2491 *
2492 * \threadsafety It is safe to call this function from any thread.
2493 *
2494 * \since This function is available since SDL 3.0.0.
2495 *
2496 * \sa SDL_modf
2497 * \sa SDL_truncf
2498 * \sa SDL_fmodf
2499 */
2500extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
2501
2502/**
2503 * Raise `x` to the power `y`
2504 *
2505 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2506 *
2507 * Range: `-INF <= z <= INF`
2508 *
2509 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
2510 * instead.
2511 *
2512 * This function operates on double-precision floating point values, use
2513 * SDL_powf for single-precision floats.
2514 *
2515 * This function may use a different approximation across different versions,
2516 * platforms and configurations. i.e, it can return a different value given
2517 * the same input on different machines or operating systems, or if SDL is
2518 * updated.
2519 *
2520 * \param x the base.
2521 * \param y the exponent.
2522 * \returns `x` raised to the power `y`.
2523 *
2524 * \threadsafety It is safe to call this function from any thread.
2525 *
2526 * \since This function is available since SDL 3.0.0.
2527 *
2528 * \sa SDL_powf
2529 * \sa SDL_exp
2530 * \sa SDL_log
2531 */
2532extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
2533
2534/**
2535 * Raise `x` to the power `y`
2536 *
2537 * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
2538 *
2539 * Range: `-INF <= z <= INF`
2540 *
2541 * If `y` is the base of the natural logarithm (e), consider using SDL_exp
2542 * instead.
2543 *
2544 * This function operates on single-precision floating point values, use
2545 * SDL_powf for double-precision floats.
2546 *
2547 * This function may use a different approximation across different versions,
2548 * platforms and configurations. i.e, it can return a different value given
2549 * the same input on different machines or operating systems, or if SDL is
2550 * updated.
2551 *
2552 * \param x the base.
2553 * \param y the exponent.
2554 * \returns `x` raised to the power `y`.
2555 *
2556 * \threadsafety It is safe to call this function from any thread.
2557 *
2558 * \since This function is available since SDL 3.0.0.
2559 *
2560 * \sa SDL_pow
2561 * \sa SDL_expf
2562 * \sa SDL_logf
2563 */
2564extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
2565
2566/**
2567 * Round `x` to the nearest integer.
2568 *
2569 * Rounds `x` to the nearest integer. Values halfway between integers will be
2570 * rounded away from zero.
2571 *
2572 * Domain: `-INF <= x <= INF`
2573 *
2574 * Range: `-INF <= y <= INF`, y integer
2575 *
2576 * This function operates on double-precision floating point values, use
2577 * SDL_roundf for single-precision floats. To get the result as an integer
2578 * type, use SDL_lround.
2579 *
2580 * \param x floating point value.
2581 * \returns the nearest integer to `x`.
2582 *
2583 * \threadsafety It is safe to call this function from any thread.
2584 *
2585 * \since This function is available since SDL 3.0.0.
2586 *
2587 * \sa SDL_roundf
2588 * \sa SDL_lround
2589 * \sa SDL_floor
2590 * \sa SDL_ceil
2591 * \sa SDL_trunc
2592 */
2593extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
2594
2595/**
2596 * Round `x` to the nearest integer.
2597 *
2598 * Rounds `x` to the nearest integer. Values halfway between integers will be
2599 * rounded away from zero.
2600 *
2601 * Domain: `-INF <= x <= INF`
2602 *
2603 * Range: `-INF <= y <= INF`, y integer
2604 *
2605 * This function operates on double-precision floating point values, use
2606 * SDL_roundf for single-precision floats. To get the result as an integer
2607 * type, use SDL_lroundf.
2608 *
2609 * \param x floating point value.
2610 * \returns the nearest integer to `x`.
2611 *
2612 * \threadsafety It is safe to call this function from any thread.
2613 *
2614 * \since This function is available since SDL 3.0.0.
2615 *
2616 * \sa SDL_round
2617 * \sa SDL_lroundf
2618 * \sa SDL_floorf
2619 * \sa SDL_ceilf
2620 * \sa SDL_truncf
2621 */
2622extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
2623
2624/**
2625 * Round `x` to the nearest integer representable as a long
2626 *
2627 * Rounds `x` to the nearest integer. Values halfway between integers will be
2628 * rounded away from zero.
2629 *
2630 * Domain: `-INF <= x <= INF`
2631 *
2632 * Range: `MIN_LONG <= y <= MAX_LONG`
2633 *
2634 * This function operates on double-precision floating point values, use
2635 * SDL_lround for single-precision floats. To get the result as a
2636 * floating-point type, use SDL_round.
2637 *
2638 * \param x floating point value.
2639 * \returns the nearest integer to `x`.
2640 *
2641 * \threadsafety It is safe to call this function from any thread.
2642 *
2643 * \since This function is available since SDL 3.0.0.
2644 *
2645 * \sa SDL_lroundf
2646 * \sa SDL_round
2647 * \sa SDL_floor
2648 * \sa SDL_ceil
2649 * \sa SDL_trunc
2650 */
2651extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
2652
2653/**
2654 * Round `x` to the nearest integer representable as a long
2655 *
2656 * Rounds `x` to the nearest integer. Values halfway between integers will be
2657 * rounded away from zero.
2658 *
2659 * Domain: `-INF <= x <= INF`
2660 *
2661 * Range: `MIN_LONG <= y <= MAX_LONG`
2662 *
2663 * This function operates on single-precision floating point values, use
2664 * SDL_lroundf for double-precision floats. To get the result as a
2665 * floating-point type, use SDL_roundf,
2666 *
2667 * \param x floating point value.
2668 * \returns the nearest integer to `x`.
2669 *
2670 * \threadsafety It is safe to call this function from any thread.
2671 *
2672 * \since This function is available since SDL 3.0.0.
2673 *
2674 * \sa SDL_lround
2675 * \sa SDL_roundf
2676 * \sa SDL_floorf
2677 * \sa SDL_ceilf
2678 * \sa SDL_truncf
2679 */
2680extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
2681
2682/**
2683 * Scale `x` by an integer power of two.
2684 *
2685 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
2686 *
2687 * Domain: `-INF <= x <= INF`, `n` integer
2688 *
2689 * Range: `-INF <= y <= INF`
2690 *
2691 * This function operates on double-precision floating point values, use
2692 * SDL_scalbnf for single-precision floats.
2693 *
2694 * \param x floating point value to be scaled.
2695 * \param n integer exponent.
2696 * \returns `x * 2^n`.
2697 *
2698 * \threadsafety It is safe to call this function from any thread.
2699 *
2700 * \since This function is available since SDL 3.0.0.
2701 *
2702 * \sa SDL_scalbnf
2703 * \sa SDL_pow
2704 */
2705extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
2706
2707/**
2708 * Scale `x` by an integer power of two.
2709 *
2710 * Multiplies `x` by the `n`th power of the floating point radix (always 2).
2711 *
2712 * Domain: `-INF <= x <= INF`, `n` integer
2713 *
2714 * Range: `-INF <= y <= INF`
2715 *
2716 * This function operates on single-precision floating point values, use
2717 * SDL_scalbn for double-precision floats.
2718 *
2719 * \param x floating point value to be scaled.
2720 * \param n integer exponent.
2721 * \returns `x * 2^n`.
2722 *
2723 * \threadsafety It is safe to call this function from any thread.
2724 *
2725 * \since This function is available since SDL 3.0.0.
2726 *
2727 * \sa SDL_scalbn
2728 * \sa SDL_powf
2729 */
2730extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
2731
2732/**
2733 * Compute the sine of `x`.
2734 *
2735 * Domain: `-INF <= x <= INF`
2736 *
2737 * Range: `-1 <= y <= 1`
2738 *
2739 * This function operates on double-precision floating point values, use
2740 * SDL_sinf for single-precision floats.
2741 *
2742 * This function may use a different approximation across different versions,
2743 * platforms and configurations. i.e, it can return a different value given
2744 * the same input on different machines or operating systems, or if SDL is
2745 * updated.
2746 *
2747 * \param x floating point value, in radians.
2748 * \returns sine of `x`.
2749 *
2750 * \threadsafety It is safe to call this function from any thread.
2751 *
2752 * \since This function is available since SDL 3.0.0.
2753 *
2754 * \sa SDL_sinf
2755 * \sa SDL_asin
2756 * \sa SDL_cos
2757 */
2758extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
2759
2760/**
2761 * Compute the sine of `x`.
2762 *
2763 * Domain: `-INF <= x <= INF`
2764 *
2765 * Range: `-1 <= y <= 1`
2766 *
2767 * This function operates on single-precision floating point values, use
2768 * SDL_sinf for double-precision floats.
2769 *
2770 * This function may use a different approximation across different versions,
2771 * platforms and configurations. i.e, it can return a different value given
2772 * the same input on different machines or operating systems, or if SDL is
2773 * updated.
2774 *
2775 * \param x floating point value, in radians.
2776 * \returns sine of `x`.
2777 *
2778 * \threadsafety It is safe to call this function from any thread.
2779 *
2780 * \since This function is available since SDL 3.0.0.
2781 *
2782 * \sa SDL_sin
2783 * \sa SDL_asinf
2784 * \sa SDL_cosf
2785 */
2786extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
2787
2788/**
2789 * Compute the square root of `x`.
2790 *
2791 * Domain: `0 <= x <= INF`
2792 *
2793 * Range: `0 <= y <= INF`
2794 *
2795 * This function operates on double-precision floating point values, use
2796 * SDL_sqrtf for single-precision floats.
2797 *
2798 * This function may use a different approximation across different versions,
2799 * platforms and configurations. i.e, it can return a different value given
2800 * the same input on different machines or operating systems, or if SDL is
2801 * updated.
2802 *
2803 * \param x floating point value. Must be greater than or equal to 0.
2804 * \returns square root of `x`.
2805 *
2806 * \threadsafety It is safe to call this function from any thread.
2807 *
2808 * \since This function is available since SDL 3.0.0.
2809 *
2810 * \sa SDL_sqrtf
2811 */
2812extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
2813
2814/**
2815 * Compute the square root of `x`.
2816 *
2817 * Domain: `0 <= x <= INF`
2818 *
2819 * Range: `0 <= y <= INF`
2820 *
2821 * This function operates on single-precision floating point values, use
2822 * SDL_sqrt for double-precision floats.
2823 *
2824 * This function may use a different approximation across different versions,
2825 * platforms and configurations. i.e, it can return a different value given
2826 * the same input on different machines or operating systems, or if SDL is
2827 * updated.
2828 *
2829 * \param x floating point value. Must be greater than or equal to 0.
2830 * \returns square root of `x`.
2831 *
2832 * \threadsafety It is safe to call this function from any thread.
2833 *
2834 * \since This function is available since SDL 3.0.0.
2835 *
2836 * \sa SDL_sqrt
2837 */
2838extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
2839
2840/**
2841 * Compute the tangent of `x`.
2842 *
2843 * Domain: `-INF <= x <= INF`
2844 *
2845 * Range: `-INF <= y <= INF`
2846 *
2847 * This function operates on double-precision floating point values, use
2848 * SDL_tanf for single-precision floats.
2849 *
2850 * This function may use a different approximation across different versions,
2851 * platforms and configurations. i.e, it can return a different value given
2852 * the same input on different machines or operating systems, or if SDL is
2853 * updated.
2854 *
2855 * \param x floating point value, in radians.
2856 * \returns tangent of `x`.
2857 *
2858 * \threadsafety It is safe to call this function from any thread.
2859 *
2860 * \since This function is available since SDL 3.0.0.
2861 *
2862 * \sa SDL_tanf
2863 * \sa SDL_sin
2864 * \sa SDL_cos
2865 * \sa SDL_atan
2866 * \sa SDL_atan2
2867 */
2868extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
2869
2870/**
2871 * Compute the tangent of `x`.
2872 *
2873 * Domain: `-INF <= x <= INF`
2874 *
2875 * Range: `-INF <= y <= INF`
2876 *
2877 * This function operates on single-precision floating point values, use
2878 * SDL_tanf for double-precision floats.
2879 *
2880 * This function may use a different approximation across different versions,
2881 * platforms and configurations. i.e, it can return a different value given
2882 * the same input on different machines or operating systems, or if SDL is
2883 * updated.
2884 *
2885 * \param x floating point value, in radians.
2886 * \returns tangent of `x`.
2887 *
2888 * \threadsafety It is safe to call this function from any thread.
2889 *
2890 * \since This function is available since SDL 3.0.0.
2891 *
2892 * \sa SDL_tan
2893 * \sa SDL_sinf
2894 * \sa SDL_cosf
2895 * \sa SDL_atanf
2896 * \sa SDL_atan2f
2897 */
2898extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
2899
2900/* The SDL implementation of iconv() returns these error codes */
2901#define SDL_ICONV_ERROR (size_t)-1
2902#define SDL_ICONV_E2BIG (size_t)-2
2903#define SDL_ICONV_EILSEQ (size_t)-3
2904#define SDL_ICONV_EINVAL (size_t)-4
2905
2906typedef struct SDL_iconv_data_t *SDL_iconv_t;
2907
2908/**
2909 * This function allocates a context for the specified character set
2910 * conversion.
2911 *
2912 * \param tocode The target character encoding, must not be NULL.
2913 * \param fromcode The source character encoding, must not be NULL.
2914 * \returns a handle that must be freed with SDL_iconv_close, or
2915 * SDL_ICONV_ERROR on failure.
2916 *
2917 * \since This function is available since SDL 3.0.0.
2918 *
2919 * \sa SDL_iconv
2920 * \sa SDL_iconv_close
2921 * \sa SDL_iconv_string
2922 */
2923extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
2924 const char *fromcode);
2925
2926/**
2927 * This function frees a context used for character set conversion.
2928 *
2929 * \param cd The character set conversion handle.
2930 * \returns 0 on success, or -1 on failure.
2931 *
2932 * \since This function is available since SDL 3.0.0.
2933 *
2934 * \sa SDL_iconv
2935 * \sa SDL_iconv_open
2936 * \sa SDL_iconv_string
2937 */
2938extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
2939
2940/**
2941 * This function converts text between encodings, reading from and writing to
2942 * a buffer.
2943 *
2944 * It returns the number of succesful conversions.
2945 *
2946 * \param cd The character set conversion context, created in
2947 * SDL_iconv_open().
2948 * \param inbuf Address of variable that points to the first character of the
2949 * input sequence.
2950 * \param inbytesleft The number of bytes in the input buffer.
2951 * \param outbuf Address of variable that points to the output buffer.
2952 * \param outbytesleft The number of bytes in the output buffer.
2953 * \returns the number of conversions on success, else SDL_ICONV_E2BIG is
2954 * returned when the output buffer is too small, or SDL_ICONV_EILSEQ
2955 * is returned when an invalid input sequence is encountered, or
2956 * SDL_ICONV_EINVAL is returned when an incomplete input sequence is
2957 * encountered.
2958 *
2959 * On exit:
2960 *
2961 * - inbuf will point to the beginning of the next multibyte
2962 * sequence. On error, this is the location of the problematic
2963 * input sequence. On success, this is the end of the input
2964 * sequence. - inbytesleft will be set to the number of bytes left
2965 * to convert, which will be 0 on success. - outbuf will point to
2966 * the location where to store the next output byte. - outbytesleft
2967 * will be set to the number of bytes left in the output buffer.
2968 *
2969 * \since This function is available since SDL 3.0.0.
2970 *
2971 * \sa SDL_iconv_open
2972 * \sa SDL_iconv_close
2973 * \sa SDL_iconv_string
2974 */
2975extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
2976 size_t *inbytesleft, char **outbuf,
2977 size_t *outbytesleft);
2978
2979/**
2980 * Helper function to convert a string's encoding in one call.
2981 *
2982 * This function converts a buffer or string between encodings in one pass.
2983 *
2984 * The string does not need to be NULL-terminated; this function operates on
2985 * the number of bytes specified in `inbytesleft` whether there is a NULL
2986 * character anywhere in the buffer.
2987 *
2988 * The returned string is owned by the caller, and should be passed to
2989 * SDL_free when no longer needed.
2990 *
2991 * \param tocode the character encoding of the output string. Examples are
2992 * "UTF-8", "UCS-4", etc.
2993 * \param fromcode the character encoding of data in `inbuf`.
2994 * \param inbuf the string to convert to a different encoding.
2995 * \param inbytesleft the size of the input string _in bytes_.
2996 * \returns a new string, converted to the new encoding, or NULL on error.
2997 *
2998 * \since This function is available since SDL 3.0.0.
2999 *
3000 * \sa SDL_iconv_open
3001 * \sa SDL_iconv_close
3002 * \sa SDL_iconv
3003 */
3004extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
3005 const char *fromcode,
3006 const char *inbuf,
3007 size_t inbytesleft);
3008
3009/* Some helper macros for common cases... */
3010#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
3011#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
3012#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
3013#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
3014
3015/* force builds using Clang's static analysis tools to use literal C runtime
3016 here, since there are possibly tests that are ineffective otherwise. */
3017#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
3018
3019/* The analyzer knows about strlcpy even when the system doesn't provide it */
3020#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
3021size_t strlcpy(char *dst, const char *src, size_t size);
3022#endif
3023
3024/* The analyzer knows about strlcat even when the system doesn't provide it */
3025#if !defined(HAVE_STRLCAT) && !defined(strlcat)
3026size_t strlcat(char *dst, const char *src, size_t size);
3027#endif
3028
3029#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
3030size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
3031#endif
3032
3033#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
3034size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
3035#endif
3036
3037/* Starting LLVM 16, the analyser errors out if these functions do not have
3038 their prototype defined (clang-diagnostic-implicit-function-declaration) */
3039#include <stdio.h>
3040#include <stdlib.h>
3041#include <strings.h>
3042
3043#define SDL_malloc malloc
3044#define SDL_calloc calloc
3045#define SDL_realloc realloc
3046#define SDL_free free
3047#ifndef SDL_memcpy
3048#define SDL_memcpy memcpy
3049#endif
3050#ifndef SDL_memmove
3051#define SDL_memmove memmove
3052#endif
3053#ifndef SDL_memset
3054#define SDL_memset memset
3055#endif
3056#define SDL_memcmp memcmp
3057#define SDL_strlcpy strlcpy
3058#define SDL_strlcat strlcat
3059#define SDL_strlen strlen
3060#define SDL_wcslen wcslen
3061#define SDL_wcslcpy wcslcpy
3062#define SDL_wcslcat wcslcat
3063#define SDL_strdup strdup
3064#define SDL_wcsdup wcsdup
3065#define SDL_strchr strchr
3066#define SDL_strrchr strrchr
3067#define SDL_strstr strstr
3068#define SDL_wcsstr wcsstr
3069#define SDL_strtok_r strtok_r
3070#define SDL_strcmp strcmp
3071#define SDL_wcscmp wcscmp
3072#define SDL_strncmp strncmp
3073#define SDL_wcsncmp wcsncmp
3074#define SDL_strcasecmp strcasecmp
3075#define SDL_strncasecmp strncasecmp
3076#define SDL_sscanf sscanf
3077#define SDL_vsscanf vsscanf
3078#define SDL_snprintf snprintf
3079#define SDL_vsnprintf vsnprintf
3080#endif
3081
3082/**
3083 * Multiply two integers, checking for overflow.
3084 *
3085 * If `a * b` would overflow, return SDL_FALSE.
3086 *
3087 * Otherwise store `a * b` via ret and return SDL_TRUE.
3088 *
3089 * \param a the multiplicand.
3090 * \param b the multiplier.
3091 * \param ret on non-overflow output, stores the multiplication result. May
3092 * not be NULL.
3093 * \returns SDL_FALSE on overflow, SDL_TRUE if result is multiplied without
3094 * overflow.
3095 *
3096 * \threadsafety It is safe to call this function from any thread.
3097 *
3098 * \since This function is available since SDL 3.0.0.
3099 */
3100SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
3101{
3102 if (a != 0 && b > SDL_SIZE_MAX / a) {
3103 return SDL_FALSE;
3104 }
3105 *ret = a * b;
3106 return SDL_TRUE;
3107}
3108
3109#ifndef SDL_WIKI_DOCUMENTATION_SECTION
3110#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
3111/* This needs to be wrapped in an inline rather than being a direct #define,
3112 * because __builtin_mul_overflow() is type-generic, but we want to be
3113 * consistent about interpreting a and b as size_t. */
3114SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
3115{
3116 return (__builtin_mul_overflow(a, b, ret) == 0);
3117}
3118#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
3119#endif
3120#endif
3121
3122/**
3123 * Add two integers, checking for overflow.
3124 *
3125 * If `a + b` would overflow, return -1.
3126 *
3127 * Otherwise store `a + b` via ret and return 0.
3128 *
3129 * \param a the first addend.
3130 * \param b the second addend.
3131 * \param ret on non-overflow output, stores the addition result. May not be
3132 * NULL.
3133 * \returns SDL_FALSE on overflow, SDL_TRUE if result is added without
3134 * overflow.
3135 *
3136 * \threadsafety It is safe to call this function from any thread.
3137 *
3138 * \since This function is available since SDL 3.0.0.
3139 */
3140SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
3141{
3142 if (b > SDL_SIZE_MAX - a) {
3143 return SDL_FALSE;
3144 }
3145 *ret = a + b;
3146 return SDL_TRUE;
3147}
3148
3149#ifndef SDL_WIKI_DOCUMENTATION_SECTION
3150#if SDL_HAS_BUILTIN(__builtin_add_overflow)
3151/* This needs to be wrapped in an inline rather than being a direct #define,
3152 * the same as the call to __builtin_mul_overflow() above. */
3153SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
3154{
3155 return (__builtin_add_overflow(a, b, ret) == 0);
3156}
3157#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
3158#endif
3159#endif
3160
3161/* This is a generic function pointer which should be cast to the type you expect */
3162#ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
3163typedef void *SDL_FunctionPointer;
3164#else
3165typedef void (*SDL_FunctionPointer)(void);
3166#endif
3167
3168/* Ends C function definitions when using C++ */
3169#ifdef __cplusplus
3170}
3171#endif
3172#include <SDL3/SDL_close_code.h>
3173
3174#endif /* SDL_stdinc_h_ */
#define SDL_ALLOC_SIZE(p)
#define SDL_ALLOC_SIZE2(p1, p2)
#define SDL_FORCE_INLINE
#define SDL_MALLOC
wchar_t * SDL_wcsdup(const wchar_t *wstr)
double SDL_sqrt(double x)
int SDL_atoi(const char *str)
#define SDL_memset
Definition SDL_stdinc.h:960
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
float SDL_tanf(float x)
char * SDL_strtok_r(char *s1, const char *s2, char **saveptr)
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)
int SDL_tolower(int x)
float SDL_modff(float x, float *y)
double SDL_modf(double x, double *y)
int SDL_abs(int x)
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)
char * SDL_ltoa(long value, char *str, int radix)
#define SDL_TRUE
Definition SDL_stdinc.h:206
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)
int64_t Sint64
Definition SDL_stdinc.h:279
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)
Definition SDL_stdinc.h:539
int(* SDL_CompareCallback_r)(void *userdata, const void *a, const void *b)
Definition SDL_stdinc.h:678
#define SDL_OUT_BYTECAP(x)
Definition SDL_stdinc.h:445
char * SDL_strrchr(const char *str, int c)
#define SDL_SIZE_MAX
Definition SDL_stdinc.h:80
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
uint16_t Uint16
Definition SDL_stdinc.h:250
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
float SDL_atanf(float x)
int SDL_isprint(int x)
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:459
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)
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)
Definition SDL_stdinc.h:441
int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
float SDL_randf(void)
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)
#define SDL_FALSE
Definition SDL_stdinc.h:197
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)
SDL_bool SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
double SDL_acos(double x)
wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
int(* SDL_CompareCallback)(const void *a, const void *b)
Definition SDL_stdinc.h:674
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)
Definition SDL_stdinc.h:461
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
Definition SDL_stdinc.h:448
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:259
int SDL_setenv(const char *name, const char *value, int overwrite)
size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
#define SDL_INOUT_Z_CAP(x)
Definition SDL_stdinc.h:442
double SDL_scalbn(double x, int n)
int SDL_unsetenv(const char *name)
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)
char * SDL_lltoa(Sint64 value, char *str, int radix)
double SDL_fabs(double x)
Sint64 SDL_strtoll(const char *str, char **endp, int base)
int SDL_ispunct(int x)
float SDL_truncf(float x)
double SDL_log10(double x)
SDL_MALLOC size_t size
Definition SDL_stdinc.h:535
float SDL_expf(float x)
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)
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)
Definition SDL_stdinc.h:542
int SDL_memcmp(const void *s1, const void *s2, size_t len)
char * SDL_ulltoa(Uint64 value, char *str, int radix)
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)
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
Definition SDL_stdinc.h:447
float SDL_fmodf(float x, float y)
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap)
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)
Definition SDL_stdinc.h:458
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:482
float SDL_atan2f(float y, float x)
int SDL_isupper(int x)
long SDL_wcstol(const wchar_t *str, wchar_t **endp, int base)
float SDL_fabsf(float x)
uint64_t Uint64
Definition SDL_stdinc.h:290
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
Definition SDL_stdinc.h:935
SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
void SDL_free(void *mem)
SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
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)
Definition SDL_stdinc.h:540
#define SDL_SCANF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:460
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:268
float SDL_powf(float x, float y)
size_t SDL_strlen(const char *str)
#define SDL_memmove
Definition SDL_stdinc.h:949
Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len)
bool SDL_bool
Definition SDL_stdinc.h:216
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)
Definition SDL_stdinc.h:541
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)
Definition SDL_stdinc.h:443
#define SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:462
Uint64 SDL_strtoull(const char *str, char **endp, int base)
double SDL_trunc(double x)

◆ SDL_const_cast

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

Definition at line 132 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)
Definition SDL_stdinc.h:938

Definition at line 938 of file SDL_stdinc.h.

939 { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
940 SDL_memcpy((dst), (src), sizeof(*(src)))

◆ SDL_FALSE

#define SDL_FALSE   false

A boolean false.

Since
This macro is available since SDL 3.0.0.
See also
SDL_bool

Definition at line 197 of file SDL_stdinc.h.

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

Definition at line 330 of file SDL_stdinc.h.

◆ SDL_FOURCC

#define SDL_FOURCC (   A,
  B,
  C,
 
)
Value:
uint8_t Uint8
Definition SDL_stdinc.h:232
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:131

Definition at line 137 of file SDL_stdinc.h.

◆ SDL_HAS_BUILTIN

#define SDL_HAS_BUILTIN (   x)    0

Check if the compiler supports a given builtin. Supported by virtually all clang versions and recent gcc. Use this instead of checking the clang version if possible.

Definition at line 91 of file SDL_stdinc.h.

◆ SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG   (size_t)-2

Definition at line 2902 of file SDL_stdinc.h.

◆ SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ   (size_t)-3

Definition at line 2903 of file SDL_stdinc.h.

◆ SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL   (size_t)-4

Definition at line 2904 of file SDL_stdinc.h.

◆ SDL_ICONV_ERROR

#define SDL_ICONV_ERROR   (size_t)-1

Definition at line 2901 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)

Definition at line 3010 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)

Definition at line 3011 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)

Definition at line 3012 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))

Definition at line 3013 of file SDL_stdinc.h.

◆ SDL_IN_BYTECAP

#define SDL_IN_BYTECAP (   x)

Definition at line 441 of file SDL_stdinc.h.

◆ SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP (   x)

Definition at line 442 of file SDL_stdinc.h.

◆ SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT   0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

SDL_StepUTF8() reports this codepoint when it encounters 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.0.0.
See also
SDL_StepUTF8

Definition at line 1306 of file SDL_stdinc.h.

◆ SDL_max

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

Definition at line 686 of file SDL_stdinc.h.

◆ SDL_MAX_SINT16

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

Definition at line 242 of file SDL_stdinc.h.

◆ SDL_MAX_SINT32

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

Definition at line 260 of file SDL_stdinc.h.

◆ SDL_MAX_SINT64

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

Definition at line 280 of file SDL_stdinc.h.

◆ SDL_MAX_SINT8

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

Definition at line 224 of file SDL_stdinc.h.

◆ SDL_MAX_TIME

#define SDL_MAX_TIME   SDL_MAX_SINT64

Definition at line 308 of file SDL_stdinc.h.

◆ SDL_MAX_UINT16

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

Definition at line 251 of file SDL_stdinc.h.

◆ SDL_MAX_UINT32

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

Definition at line 269 of file SDL_stdinc.h.

◆ SDL_MAX_UINT64

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

Definition at line 291 of file SDL_stdinc.h.

◆ SDL_MAX_UINT8

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

Definition at line 233 of file SDL_stdinc.h.

◆ SDL_memcpy

#define SDL_memcpy   memcpy

Definition at line 935 of file SDL_stdinc.h.

◆ SDL_memmove

#define SDL_memmove   memmove

Definition at line 949 of file SDL_stdinc.h.

◆ SDL_memset

#define SDL_memset   memset

Definition at line 960 of file SDL_stdinc.h.

◆ SDL_min

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

Definition at line 685 of file SDL_stdinc.h.

◆ SDL_MIN_SINT16

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

Definition at line 243 of file SDL_stdinc.h.

◆ SDL_MIN_SINT32

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

Definition at line 261 of file SDL_stdinc.h.

◆ SDL_MIN_SINT64

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

Definition at line 281 of file SDL_stdinc.h.

◆ SDL_MIN_SINT8

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

Definition at line 225 of file SDL_stdinc.h.

◆ SDL_MIN_TIME

#define SDL_MIN_TIME   SDL_MIN_SINT64

Definition at line 309 of file SDL_stdinc.h.

◆ SDL_MIN_UINT16

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

Definition at line 252 of file SDL_stdinc.h.

◆ SDL_MIN_UINT32

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

Definition at line 270 of file SDL_stdinc.h.

◆ SDL_MIN_UINT64

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

Definition at line 292 of file SDL_stdinc.h.

◆ SDL_MIN_UINT8

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

Definition at line 234 of file SDL_stdinc.h.

◆ SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP (   x)

Definition at line 445 of file SDL_stdinc.h.

◆ SDL_OUT_CAP

#define SDL_OUT_CAP (   x)

Definition at line 444 of file SDL_stdinc.h.

◆ SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP (   x)

Definition at line 446 of file SDL_stdinc.h.

◆ SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP (   x)

Definition at line 443 of file SDL_stdinc.h.

◆ SDL_PI_D

#define SDL_PI_D   3.141592653589793238462643383279502884

pi (double)

Definition at line 1581 of file SDL_stdinc.h.

◆ SDL_PI_F

#define SDL_PI_F   3.141592653589793238462643383279502884F

pi (float)

Definition at line 1584 of file SDL_stdinc.h.

◆ SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 447 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 458 of file SDL_stdinc.h.

◆ SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV (   fmtargnumber)

Definition at line 459 of file SDL_stdinc.h.

◆ SDL_PRIs32

#define SDL_PRIs32   "d"

Definition at line 386 of file SDL_stdinc.h.

◆ SDL_PRIs64

#define SDL_PRIs64   "lld"

Definition at line 346 of file SDL_stdinc.h.

◆ SDL_PRIu32

#define SDL_PRIu32   "u"

Definition at line 393 of file SDL_stdinc.h.

◆ SDL_PRIu64

#define SDL_PRIu64   "llu"

Definition at line 357 of file SDL_stdinc.h.

◆ SDL_PRIx32

#define SDL_PRIx32   "x"

Definition at line 400 of file SDL_stdinc.h.

◆ SDL_PRIX32

#define SDL_PRIX32   "X"

Definition at line 407 of file SDL_stdinc.h.

◆ SDL_PRIx64

#define SDL_PRIx64   "llx"

Definition at line 368 of file SDL_stdinc.h.

◆ SDL_PRIX64

#define SDL_PRIX64   "llX"

Definition at line 379 of file SDL_stdinc.h.

◆ SDL_reinterpret_cast

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

Definition at line 130 of file SDL_stdinc.h.

◆ SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 448 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 460 of file SDL_stdinc.h.

◆ SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV (   fmtargnumber)

Definition at line 461 of file SDL_stdinc.h.

◆ SDL_SINT64_C

#define SDL_SINT64_C (   c)    c ## LL

Definition at line 181 of file SDL_stdinc.h.

◆ SDL_SIZE_MAX

#define SDL_SIZE_MAX   ((size_t) -1)

Definition at line 80 of file SDL_stdinc.h.

◆ SDL_stack_alloc

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

Definition at line 527 of file SDL_stdinc.h.

◆ SDL_stack_free

#define SDL_stack_free (   data)

Definition at line 528 of file SDL_stdinc.h.

◆ SDL_static_cast

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

Definition at line 131 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")`
Since
This macro is available since SDL 3.0.0.

Definition at line 116 of file SDL_stdinc.h.

◆ SDL_TRUE

#define SDL_TRUE   true

A boolean true.

Since
This macro is available since SDL 3.0.0.
See also
SDL_bool

Definition at line 206 of file SDL_stdinc.h.

◆ SDL_UINT64_C

#define SDL_UINT64_C (   c)    c ## ULL

Definition at line 182 of file SDL_stdinc.h.

◆ SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC (   fmtargnumber)

Definition at line 462 of file SDL_stdinc.h.

◆ SDL_WSCANF_VARARG_FUNC

#define SDL_WSCANF_VARARG_FUNC (   fmtargnumber)

Definition at line 463 of file SDL_stdinc.h.

◆ SDL_zero

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

Definition at line 963 of file SDL_stdinc.h.

◆ SDL_zeroa

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

Definition at line 965 of file SDL_stdinc.h.

◆ SDL_zerop

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

Definition at line 964 of file SDL_stdinc.h.

Typedef Documentation

◆ SDL_bool

typedef bool SDL_bool

A boolean type: true or false.

Since
This datatype is available since SDL 3.0.0.
See also
SDL_TRUE
SDL_FALSE

Definition at line 216 of file SDL_stdinc.h.

◆ SDL_calloc_func

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

Definition at line 540 of file SDL_stdinc.h.

◆ SDL_CompareCallback

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

Definition at line 674 of file SDL_stdinc.h.

◆ SDL_CompareCallback_r

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

Definition at line 678 of file SDL_stdinc.h.

◆ SDL_free_func

typedef void(* SDL_free_func) (void *mem)

Definition at line 542 of file SDL_stdinc.h.

◆ SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 3165 of file SDL_stdinc.h.

◆ SDL_iconv_t

typedef struct SDL_iconv_data_t* SDL_iconv_t

Definition at line 2906 of file SDL_stdinc.h.

◆ SDL_malloc_func

typedef void *(* SDL_malloc_func) (size_t size)

Definition at line 539 of file SDL_stdinc.h.

◆ SDL_realloc_func

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

Definition at line 541 of file SDL_stdinc.h.

◆ SDL_Time

typedef Sint64 SDL_Time

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

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

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

Definition at line 307 of file SDL_stdinc.h.

◆ Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 241 of file SDL_stdinc.h.

◆ Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 259 of file SDL_stdinc.h.

◆ Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

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

Definition at line 279 of file SDL_stdinc.h.

◆ Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 223 of file SDL_stdinc.h.

◆ Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 250 of file SDL_stdinc.h.

◆ Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 268 of file SDL_stdinc.h.

◆ Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

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

Definition at line 290 of file SDL_stdinc.h.

◆ Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
This macro is available since SDL 3.0.0.

Definition at line 232 of file SDL_stdinc.h.

Function Documentation

◆ alloca()

void * alloca ( size_t  )

CategoryStdinc

This is a general header that includes C language support. It implements a subset of the C runtime: these should all behave the same way as their C runtime equivalents, but with an SDL_ prefix.

◆ SDL_abs()

int SDL_abs ( int  x)
extern

◆ 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.0.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.0.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 value.

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

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

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

Parameters
alignmentthe alignment requested.
sizethe size to allocate.
Returns
a pointer to the aligned memory.

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

Since
This function is available since SDL 3.0.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.

Parameters
mema pointer previously returned by SDL_aligned_alloc.

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

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

◆ SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE ( )
extern

◆ SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 ( ,
 
)
extern

◆ 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.0.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.0.0.
See also
SDL_asin
SDL_acosf
SDL_sinf

◆ SDL_asprintf()

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

◆ 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.0.0.
See also
SDL_atanf
SDL_atan2
SDL_tan

◆ SDL_atan2()

double SDL_atan2 ( double  y,
double  x 
)
extern

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

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

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

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

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

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

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

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

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

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

◆ SDL_atan2f()

float SDL_atan2f ( float  y,
float  x 
)
extern

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

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

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

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

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

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

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

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

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

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

◆ SDL_atanf()

float SDL_atanf ( float  x)
extern

Compute the arc tangent of x.

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

Domain: -INF <= x <= INF

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

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

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

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

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

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

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

◆ SDL_atof()

double SDL_atof ( const char *  str)
extern

◆ SDL_atoi()

int SDL_atoi ( const char *  str)
extern

◆ SDL_bsearch()

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

◆ 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

◆ 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.0.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.0.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.0.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.0.0.
See also
SDL_copysignf
SDL_fabsf

◆ SDL_cos()

double SDL_cos ( double  x)
extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

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

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

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

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

Since
This function is available since SDL 3.0.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.0.0.
See also
SDL_cos
SDL_acosf
SDL_sinf

◆ SDL_crc16()

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

◆ SDL_crc32()

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

◆ 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.0.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.0.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_copysignf for single-precision floats.

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

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

Since
This function is available since SDL 3.0.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_copysignf for double-precision floats.

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

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

Since
This function is available since SDL 3.0.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.0.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_floorf for double-precision floats.

Parameters
xfloating point value.
Returns
the floor of x.

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

Since
This function is available since SDL 3.0.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.0.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 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.0.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

◆ SDL_getenv()

const char * SDL_getenv ( const char *  name)
extern

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

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

Since
This function is available since SDL 3.0.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.0.0.

◆ SDL_iconv()

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

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

It returns the number of succesful conversions.

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, else 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.
Since
This function is available since SDL 3.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.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.0.0.

◆ SDL_itoa()

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

◆ SDL_lltoa()

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

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

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

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

Since
This function is available since SDL 3.0.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_lroundf for double-precision floats. To get the result as a floating-point type, use SDL_roundf,

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

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

Since
This function is available since SDL 3.0.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

◆ SDL_malloc()

SDL_MALLOC void * SDL_malloc ( size_t  size)
extern

◆ SDL_memcmp()

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

◆ SDL_memcpy()

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

◆ SDL_memmove()

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

◆ SDL_memset()

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

◆ SDL_memset4()

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

◆ 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.0.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.0.0.
See also
SDL_modf
SDL_truncf
SDL_fmodf

◆ 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.0.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_powf for double-precision floats.

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

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

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

Since
This function is available since SDL 3.0.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

◆ SDL_qsort_r()

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

◆ 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.0.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.0.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.0.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.0.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.0.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.0.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.0.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 double-precision floating point values, use SDL_roundf for single-precision floats. To get the result as an integer type, use SDL_lroundf.

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

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

Since
This function is available since SDL 3.0.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.0.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.0.0.
See also
SDL_scalbn
SDL_powf

◆ SDL_setenv()

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

◆ SDL_SetMemoryFunctions()

SDL_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
SDL_TRUE on success or SDL_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.0.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.0.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_sinf 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.0.0.
See also
SDL_sin
SDL_asinf
SDL_cosf

◆ SDL_size_add_check_overflow()

SDL_FORCE_INLINE SDL_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 -1.

Otherwise store a + b via ret and return 0.

Parameters
athe first addend.
bthe second addend.
reton non-overflow output, stores the addition result. May not be NULL.
Returns
SDL_FALSE on overflow, SDL_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.0.0.

Definition at line 3140 of file SDL_stdinc.h.

3141{
3142 if (b > SDL_SIZE_MAX - a) {
3143 return SDL_FALSE;
3144 }
3145 *ret = a + b;
3146 return SDL_TRUE;
3147}

References SDL_FALSE, SDL_SIZE_MAX, and SDL_TRUE.

◆ SDL_size_mul_check_overflow()

SDL_FORCE_INLINE SDL_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 SDL_FALSE.

Otherwise store a * b via ret and return SDL_TRUE.

Parameters
athe multiplicand.
bthe multiplier.
reton non-overflow output, stores the multiplication result. May not be NULL.
Returns
SDL_FALSE on overflow, SDL_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.0.0.

Definition at line 3100 of file SDL_stdinc.h.

3101{
3102 if (a != 0 && b > SDL_SIZE_MAX / a) {
3103 return SDL_FALSE;
3104 }
3105 *ret = a * b;
3106 return SDL_TRUE;
3107}

References SDL_FALSE, SDL_SIZE_MAX, and SDL_TRUE.

◆ SDL_snprintf()

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

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

◆ 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.0.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.0.0.

◆ SDL_strcasestr()

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

◆ SDL_strchr()

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

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

◆ SDL_strdup()

SDL_MALLOC char * SDL_strdup ( const char *  str)
extern

◆ SDL_strlcat()

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

◆ SDL_strlcpy()

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

◆ SDL_strlen()

size_t SDL_strlen ( const char *  str)
extern

◆ 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.0.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.0.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.0.0.

◆ SDL_strndup()

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

◆ SDL_strnlen()

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

◆ SDL_strnstr()

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

◆ SDL_strrchr()

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

◆ SDL_strrev()

char * SDL_strrev ( char *  str)
extern

◆ SDL_strstr()

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

◆ SDL_strtod()

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

◆ SDL_strtok_r()

char * SDL_strtok_r ( char *  s1,
const char *  s2,
char **  saveptr 
)
extern

◆ SDL_strtol()

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

◆ SDL_strtoll()

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

◆ SDL_strtoul()

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

◆ SDL_strtoull()

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

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

◆ 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.0.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_tanf for double-precision floats.

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

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

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

Since
This function is available since SDL 3.0.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.0.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.0.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.0.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_truncf for double-precision floats.

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

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

Since
This function is available since SDL 3.0.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.0.0.

◆ SDL_uitoa()

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

◆ SDL_ulltoa()

char * SDL_ulltoa ( Uint64  value,
char *  str,
int  radix 
)
extern

◆ SDL_ultoa()

char * SDL_ultoa ( unsigned long  value,
char *  str,
int  radix 
)
extern

◆ SDL_unsetenv()

int SDL_unsetenv ( const char *  name)
extern

◆ SDL_utf8strlcpy()

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

◆ SDL_utf8strlen()

size_t SDL_utf8strlen ( const char *  str)
extern

◆ SDL_utf8strnlen()

size_t SDL_utf8strnlen ( const char *  str,
size_t  bytes 
)
extern

◆ SDL_vasprintf()

int SDL_vasprintf ( char **  strp,
SDL_PRINTF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

◆ 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

◆ SDL_vsscanf()

int SDL_vsscanf ( const char *  text,
SDL_SCANF_FORMAT_STRING const char *  fmt,
va_list  ap 
)
extern

◆ SDL_vswprintf()

int SDL_vswprintf ( SDL_OUT_Z_CAP(maxlen) wchar_t *  text,
size_t  maxlen,
const wchar_t *  fmt,
va_list  ap 
)
extern

◆ 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.0.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.0.0.

◆ SDL_wcsdup()

wchar_t * SDL_wcsdup ( const wchar_t *  wstr)
extern

◆ SDL_wcslcat()

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

◆ SDL_wcslcpy()

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

◆ SDL_wcslen()

size_t SDL_wcslen ( const wchar_t *  wstr)
extern

◆ 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.0.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.0.0.

◆ SDL_wcsnlen()

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

◆ SDL_wcsnstr()

wchar_t * SDL_wcsnstr ( const wchar_t *  haystack,
const wchar_t *  needle,
size_t  maxlen 
)
extern

◆ SDL_wcsstr()

wchar_t * SDL_wcsstr ( const wchar_t *  haystack,
const wchar_t *  needle 
)
extern

◆ SDL_wcstol()

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

Variable Documentation

◆ size

size_t size

Definition at line 535 of file SDL_stdinc.h.