Module stdinc

Available on crate feature dep_sdl3 only.
Expand description

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

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

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

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

Structs§

SDL_Environment
A thread-safe set of environment variables
SDL_iconv_data_t

Constants§

SDL_FLT_EPSILON
SDL_ICONV_E2BIG
Output buffer was too small.
SDL_ICONV_EILSEQ
Invalid input sequence was encountered.
SDL_ICONV_EINVAL
Incomplete input sequence was encountered.
SDL_ICONV_ERROR
Generic error. Check [SDL_GetError()]?
SDL_INVALID_UNICODE_CODEPOINT
The Unicode REPLACEMENT CHARACTER codepoint.
SDL_MAX_SINT8
SDL_MAX_SINT16
SDL_MAX_SINT32
SDL_MAX_SINT64
SDL_MAX_TIME
SDL_MAX_UINT8
SDL_MAX_UINT16
SDL_MAX_UINT32
SDL_MAX_UINT64
SDL_MIN_SINT8
SDL_MIN_SINT16
SDL_MIN_SINT32
SDL_MIN_SINT64
SDL_MIN_TIME
SDL_MIN_UINT8
SDL_MIN_UINT16
SDL_MIN_UINT32
SDL_MIN_UINT64
SDL_PI_D
The value of Pi, as a double-precision floating point literal.
SDL_PI_F
The value of Pi, as a single-precision floating point literal.
SDL_PRILLX
SDL_PRILL_PREFIX
SDL_PRILLd
SDL_PRILLu
SDL_PRILLx
SDL_PRIX32
SDL_PRIX64
SDL_PRIs32
SDL_PRIs64
SDL_PRIu32
SDL_PRIu64
SDL_PRIx32
SDL_PRIx64
SDL_SIZE_MAX

Functions§

SDL_CreateEnvironment
Create a set of environment variables
SDL_DestroyEnvironment
Destroy a set of environment variables.
SDL_FOURCC
Define a four character code as a Uint32.
SDL_GetEnvironment
Get the process environment.
SDL_GetEnvironmentVariable
Get the value of a variable in the environment.
SDL_GetEnvironmentVariables
Get all variables in the environment.
SDL_GetMemoryFunctions
Get the current set of SDL memory functions.
SDL_GetNumAllocations
Get the number of outstanding (unfreed) allocations.
SDL_GetOriginalMemoryFunctions
Get the original set of SDL memory functions.
SDL_INIT_INTERFACE
A macro to initialize an SDL interface.
SDL_SetEnvironmentVariable
Set the value of a variable in the environment.
SDL_SetMemoryFunctions
Replace SDL’s memory allocation functions with a custom set.
SDL_StepBackUTF8
Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
SDL_StepUTF8
Decode a UTF-8 string, one Unicode codepoint at a time.
SDL_UCS4ToUTF8
Convert a single Unicode codepoint to UTF-8.
SDL_UnsetEnvironmentVariable
Clear a variable from the environment.
SDL_abs
Compute the absolute value of x.
SDL_acos
Compute the arc cosine of x.
SDL_acosf
Compute the arc cosine of x.
SDL_aligned_alloc
Allocate memory aligned to a specific alignment.
SDL_aligned_free
Free memory allocated by SDL_aligned_alloc().
SDL_asin
Compute the arc sine of x.
SDL_asinf
Compute the arc sine of x.
SDL_asprintf
This works exactly like asprintf() but doesn’t require access to a C runtime.
SDL_atan
Compute the arc tangent of x.
SDL_atan2
Compute the arc tangent of y / x, using the signs of x and y to adjust the result’s quadrant.
SDL_atan2f
Compute the arc tangent of y / x, using the signs of x and y to adjust the result’s quadrant.
SDL_atanf
Compute the arc tangent of x.
SDL_atof
Parse a double from a string.
SDL_atoi
Parse an int from a string.
SDL_bsearch
Perform a binary search on a previously sorted array.
SDL_bsearch_r
Perform a binary search on a previously sorted array, passing a userdata pointer to the compare function.
SDL_calloc
Allocate a zero-initialized array.
SDL_ceil
Compute the ceiling of x.
SDL_ceilf
Compute the ceiling of x.
SDL_clamp
SDL_copyp
A macro to copy memory between objects, with basic type checking.
SDL_copysign
Copy the sign of one floating-point value to another.
SDL_copysignf
Copy the sign of one floating-point value to another.
SDL_cos
Compute the cosine of x.
SDL_cosf
Compute the cosine of x.
SDL_crc16
Calculate a CRC-16 value.
SDL_crc32
Calculate a CRC-32 value.
SDL_exp
Compute the exponential of x.
SDL_expf
Compute the exponential of x.
SDL_fabs
Compute the absolute value of x
SDL_fabsf
Compute the absolute value of x
SDL_floor
Compute the floor of x.
SDL_floorf
Compute the floor of x.
SDL_fmod
Return the floating-point remainder of x / y
SDL_fmodf
Return the floating-point remainder of x / y
SDL_free
Free allocated memory.
SDL_getenv
Get the value of a variable in the environment.
SDL_getenv_unsafe
Get the value of a variable in the environment.
SDL_iconv
This function converts text between encodings, reading from and writing to a buffer.
SDL_iconv_close
This function frees a context used for character set conversion.
SDL_iconv_open
This function allocates a context for the specified character set conversion.
SDL_iconv_string
Helper function to convert a string’s encoding in one call.
SDL_iconv_utf8_locale
Convert a UTF-8 string to the current locale’s character encoding.
SDL_iconv_utf8_ucs2
Convert a UTF-8 string to UCS-2.
SDL_iconv_utf8_ucs4
Convert a UTF-8 string to UCS-4.
SDL_iconv_wchar_utf8
Convert a wchar_t string to UTF-8.
SDL_isalnum
Query if a character is alphabetic (a letter) or a number.
SDL_isalpha
Query if a character is alphabetic (a letter).
SDL_isblank
Report if a character is blank (a space or tab).
SDL_iscntrl
Report if a character is a control character.
SDL_isdigit
Report if a character is a numeric digit.
SDL_isgraph
Report if a character is any “printable” except space.
SDL_isinf
Return whether the value is infinity.
SDL_isinff
Return whether the value is infinity.
SDL_islower
Report if a character is lower case.
SDL_isnan
Return whether the value is NaN.
SDL_isnanf
Return whether the value is NaN.
SDL_isprint
Report if a character is “printable”.
SDL_ispunct
Report if a character is a punctuation mark.
SDL_isspace
Report if a character is whitespace.
SDL_isupper
Report if a character is upper case.
SDL_isxdigit
Report if a character is a hexadecimal digit.
SDL_itoa
Convert an integer into a string.
SDL_lltoa
Convert a long long integer into a string.
SDL_log
Compute the natural logarithm of x.
SDL_log10
Compute the base-10 logarithm of x.
SDL_log10f
Compute the base-10 logarithm of x.
SDL_logf
Compute the natural logarithm of x.
SDL_lround
Round x to the nearest integer representable as a long
SDL_lroundf
Round x to the nearest integer representable as a long
SDL_ltoa
Convert a long integer into a string.
SDL_malloc
Allocate uninitialized memory.
SDL_max
SDL_memcmp
Compare two buffers of memory.
SDL_memcpy
Copy non-overlapping memory.
SDL_memmove
Copy memory ranges that might overlap.
SDL_memset
Initialize all bytes of buffer of memory to a specific value.
SDL_memset4
Initialize all 32-bit words of buffer of memory to a specific value.
SDL_min
SDL_modf
Split x into integer and fractional parts
SDL_modff
Split x into integer and fractional parts
SDL_murmur3_32
Calculate a 32-bit MurmurHash3 value for a block of data.
SDL_pow
Raise x to the power y
SDL_powf
Raise x to the power y
SDL_qsort
Sort an array.
SDL_qsort_r
Sort an array, passing a userdata pointer to the compare function.
SDL_rand
Generate a pseudo-random number less than n for positive n
SDL_rand_bits
Generate 32 pseudo-random bits.
SDL_rand_bits_r
Generate 32 pseudo-random bits.
SDL_rand_r
Generate a pseudo-random number less than n for positive n
SDL_randf
Generate a uniform pseudo-random floating point number less than 1.0
SDL_randf_r
Generate a uniform pseudo-random floating point number less than 1.0
SDL_realloc
Change the size of allocated memory.
SDL_round
Round x to the nearest integer.
SDL_roundf
Round x to the nearest integer.
SDL_scalbn
Scale x by an integer power of two.
SDL_scalbnf
Scale x by an integer power of two.
SDL_setenv_unsafe
Set the value of a variable in the environment.
SDL_sin
Compute the sine of x.
SDL_sinf
Compute the sine of x.
SDL_size_add_check_overflow
Add two integers, checking for overflow.
SDL_size_mul_check_overflow
Multiply two integers, checking for overflow.
SDL_snprintf
This works exactly like snprintf() but doesn’t require access to a C runtime.
SDL_sqrt
Compute the square root of x.
SDL_sqrtf
Compute the square root of x.
SDL_srand
Seeds the pseudo-random number generator.
SDL_sscanf
This works exactly like sscanf() but doesn’t require access to a C runtime.
SDL_strcasecmp
Compare two null-terminated UTF-8 strings, case-insensitively.
SDL_strcasestr
Search a UTF-8 string for the first instance of a specific substring, case-insensitively.
SDL_strchr
Search a string for the first instance of a specific byte.
SDL_strcmp
Compare two null-terminated UTF-8 strings.
SDL_strdup
Allocate a copy of a string.
SDL_strlcat
Concatenate strings.
SDL_strlcpy
Copy a string.
SDL_strlen
This works exactly like strlen() but doesn’t require access to a C runtime.
SDL_strlwr
Convert a string to lowercase.
SDL_strncasecmp
Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
SDL_strncmp
Compare two UTF-8 strings up to a number of bytes.
SDL_strndup
Allocate a copy of a string, up to n characters.
SDL_strnlen
This works exactly like strnlen() but doesn’t require access to a C runtime.
SDL_strnstr
Search a string, up to n bytes, for the first instance of a specific substring.
SDL_strpbrk
Searches a string for the first occurence of any character contained in a breakset, and returns a pointer from the string to that character.
SDL_strrchr
Search a string for the last instance of a specific byte.
SDL_strrev
Reverse a string’s contents.
SDL_strstr
Search a string for the first instance of a specific substring.
SDL_strtod
Parse a double from a string.
SDL_strtok_r
This works exactly like strtok_r() but doesn’t require access to a C runtime.
SDL_strtol
Parse a long from a string.
SDL_strtoll
Parse a long long from a string.
SDL_strtoul
Parse an unsigned long from a string.
SDL_strtoull
Parse an unsigned long long from a string.
SDL_strupr
Convert a string to uppercase.
SDL_swprintf
This works exactly like swprintf() but doesn’t require access to a C runtime.
SDL_tan
Compute the tangent of x.
SDL_tanf
Compute the tangent of x.
SDL_tolower
Convert low-ASCII English letters to lowercase.
SDL_toupper
Convert low-ASCII English letters to uppercase.
SDL_trunc
Truncate x to an integer.
SDL_truncf
Truncate x to an integer.
SDL_uitoa
Convert an unsigned integer into a string.
SDL_ulltoa
Convert an unsigned long long integer into a string.
SDL_ultoa
Convert an unsigned long integer into a string.
SDL_unsetenv_unsafe
Clear a variable from the environment.
SDL_utf8strlcpy
Copy an UTF-8 string.
SDL_utf8strlen
Count the number of codepoints in a UTF-8 string.
SDL_utf8strnlen
Count the number of codepoints in a UTF-8 string, up to n bytes.
SDL_vasprintf
This works exactly like vasprintf() but doesn’t require access to a C runtime.
SDL_vsnprintf
This works exactly like vsnprintf() but doesn’t require access to a C runtime.
SDL_vsscanf
This works exactly like vsscanf() but doesn’t require access to a C runtime.
SDL_vswprintf
This works exactly like vswprintf() but doesn’t require access to a C runtime.
SDL_wcscasecmp
Compare two null-terminated wide strings, case-insensitively.
SDL_wcscmp
Compare two null-terminated wide strings.
SDL_wcsdup
Allocate a copy of a wide string.
SDL_wcslcat
Concatenate wide strings.
SDL_wcslcpy
Copy a wide string.
SDL_wcslen
This works exactly like wcslen() but doesn’t require access to a C runtime.
SDL_wcsncasecmp
Compare two wide strings, case-insensitively, up to a number of wchar_t.
SDL_wcsncmp
Compare two wide strings up to a number of wchar_t values.
SDL_wcsnlen
This works exactly like wcsnlen() but doesn’t require access to a C runtime.
SDL_wcsnstr
Search a wide string, up to n wide chars, for the first instance of a specific substring.
SDL_wcsstr
Search a wide string for the first instance of a specific substring.
SDL_wcstol
Parse a long from a wide string.
SDL_zerop
Clear an object’s memory to zero, using a pointer.

Type Aliases§

SDL_CompareCallback
A callback used with SDL sorting and binary search functions.
SDL_CompareCallback_r
A callback used with SDL sorting and binary search functions.
SDL_FunctionPointer
SDL_Time
SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970).
SDL_calloc_func
A callback used to implement SDL_calloc().
SDL_free_func
A callback used to implement SDL_free().
SDL_iconv_t
An opaque handle representing string encoding conversion state.
SDL_malloc_func
A callback used to implement SDL_malloc().
SDL_realloc_func
A callback used to implement SDL_realloc().
Sint8
A signed 8-bit integer type.
Sint16
A signed 16-bit integer type.
Sint32
A signed 32-bit integer type.
Sint64
A signed 64-bit integer type.
Uint8
An unsigned 8-bit integer type.
Uint16
An unsigned 16-bit integer type.
Uint32
An unsigned 32-bit integer type.
Uint64
An unsigned 64-bit integer type.