stdinc topic
CategoryStdinc
SDL provides its own implementation of some of the most important C runtime functions.
Using these functions allows an app to have access to common C functionality without depending on a specific C runtime (or a C runtime at all). More importantly, the SDL implementations work identically across platforms, so apps can avoid surprises like snprintf() behaving differently between Windows and Linux builds, or itoa() only existing on some platforms.
For many of the most common functions, like SDL_memcpy, SDL might just call through to the usual C runtime behind the scenes, if it makes sense to do so (if it's faster and always available/reliable on a given platform), reducing library size and offering the most optimized option.
SDL also offers other C-runtime-adjacent functionality in this header that either isn't, strictly speaking, part of any C runtime standards, like SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better options, like SDL_strlcpy(), which functions as a safer form of strcpy().
Functions
-
sdlAbs(
int x) → int stdinc -
Compute the absolute value of
x
. -
sdlAcos(
double x) → double stdinc -
Compute the arc cosine of
x
. -
sdlAcosf(
double x) → double stdinc -
Compute the arc cosine of
x
. -
sdlAlignedAlloc(
int alignment, int size) → Pointer< stdincNativeType> - Allocate memory aligned to a specific alignment.
-
sdlAlignedFree(
Pointer< stdincNativeType> mem) → void - Free memory allocated by SDL_aligned_alloc().
-
sdlAsin(
double x) → double stdinc -
Compute the arc sine of
x
. -
sdlAsinf(
double x) → double stdinc -
Compute the arc sine of
x
. -
sdlAsprintf(
Pointer< stdincPointer< strp, String? fmt) → intInt8> > - This works exactly like asprintf() but doesn't require access to a C runtime.
-
sdlAtan(
double x) → double stdinc -
Compute the arc tangent of
x
. -
sdlAtan2(
double y, double x) → double stdinc -
Compute the arc tangent of
y / x
, using the signs of x and y to adjust the result's quadrant. -
sdlAtan2f(
double y, double x) → double stdinc -
Compute the arc tangent of
y / x
, using the signs of x and y to adjust the result's quadrant. -
sdlAtanf(
double x) → double stdinc -
Compute the arc tangent of
x
. -
sdlAtof(
String? str) → double stdinc -
Parse a
double
from a string. -
sdlAtoi(
String? str) → int stdinc -
Parse an
int
from a string. -
sdlBsearch(
Pointer< stdincNativeType> key, Pointer<NativeType> base, int nmemb, int size, Pointer<NativeFunction< compare) → Pointer<SdlCompareCallback> >NativeType> - Perform a binary search on a previously sorted array.
-
sdlBsearchR(
Pointer< stdincNativeType> key, Pointer<NativeType> base, int nmemb, int size, Pointer<NativeFunction< compare, Pointer<SdlCompareCallbackR> >NativeType> userdata) → Pointer<NativeType> - Perform a binary search on a previously sorted array, passing a userdata pointer to the compare function.
-
sdlCeil(
double x) → double stdinc -
Compute the ceiling of
x
. -
sdlCeilf(
double x) → double stdinc -
Compute the ceiling of
x
. -
sdlCopysign(
double x, double y) → double stdinc - Copy the sign of one floating-point value to another.
-
sdlCopysignf(
double x, double y) → double stdinc - Copy the sign of one floating-point value to another.
-
sdlCos(
double x) → double stdinc -
Compute the cosine of
x
. -
sdlCosf(
double x) → double stdinc -
Compute the cosine of
x
. -
sdlCrc16(
int crc, Pointer< stdincNativeType> data, int len) → int - Calculate a CRC-16 value.
-
sdlCrc32(
int crc, Pointer< stdincNativeType> data, int len) → int - Calculate a CRC-32 value.
-
sdlCreateEnvironment(
bool populated) → Pointer< stdincSdlEnvironment> - Create a set of environment variables
-
sdlDestroyEnvironment(
Pointer< stdincSdlEnvironment> env) → void - Destroy a set of environment variables.
-
sdlExp(
double x) → double stdinc -
Compute the exponential of
x
. -
sdlExpf(
double x) → double stdinc -
Compute the exponential of
x
. -
sdlFabs(
double x) → double stdinc -
Compute the absolute value of
x
-
sdlFabsf(
double x) → double stdinc -
Compute the absolute value of
x
-
sdlFloor(
double x) → double stdinc -
Compute the floor of
x
. -
sdlFloorf(
double x) → double stdinc -
Compute the floor of
x
. -
sdlFmod(
double x, double y) → double stdinc -
Return the floating-point remainder of
x / y
-
sdlFmodf(
double x, double y) → double stdinc -
Return the floating-point remainder of
x / y
-
sdlFree(
Pointer< stdincNativeType> mem) → void - Free allocated memory.
-
sdlGetenv(
String? name) → String? stdinc - Get the value of a variable in the environment.
-
sdlGetEnvironment(
) → Pointer< stdincSdlEnvironment> - Get the process environment.
-
sdlGetEnvironmentVariable(
Pointer< stdincSdlEnvironment> env, String? name) → String? - Get the value of a variable in the environment.
-
sdlGetEnvironmentVariables(
Pointer< stdincSdlEnvironment> env) → Pointer<Pointer< Int8> > - Get all variables in the environment.
-
sdlGetenvUnsafe(
String? name) → String? stdinc - Get the value of a variable in the environment.
-
sdlGetMemoryFunctions(
Pointer< stdincPointer< mallocFunc, Pointer<NativeFunction< >SdlMallocFunc> >Pointer< callocFunc, Pointer<NativeFunction< >SdlCallocFunc> >Pointer< reallocFunc, Pointer<NativeFunction< >SdlReallocFunc> >Pointer< freeFunc) → voidNativeFunction< >SdlFreeFunc> > - Get the current set of SDL memory functions.
-
sdlGetNumAllocations(
) → int stdinc - Get the number of outstanding (unfreed) allocations.
-
sdlGetOriginalMemoryFunctions(
Pointer< stdincPointer< mallocFunc, Pointer<NativeFunction< >SdlMallocFunc> >Pointer< callocFunc, Pointer<NativeFunction< >SdlCallocFunc> >Pointer< reallocFunc, Pointer<NativeFunction< >SdlReallocFunc> >Pointer< freeFunc) → voidNativeFunction< >SdlFreeFunc> > - Get the original set of SDL memory functions.
-
sdlIconv(
Pointer< stdincSdlIconvT> cd, Pointer<Pointer< inbuf, Pointer<Int8> >Uint32> inbytesleft, Pointer<Pointer< outbuf, Pointer<Int8> >Uint32> outbytesleft) → int - This function converts text between encodings, reading from and writing to a buffer.
-
sdlIconvClose(
Pointer< stdincSdlIconvT> cd) → int - This function frees a context used for character set conversion.
-
sdlIconvOpen(
String? tocode, String? fromcode) → Pointer< stdincSdlIconvT> - This function allocates a context for the specified character set conversion.
-
sdlIconvString(
String? tocode, String? fromcode, String? inbuf, int inbytesleft) → Pointer< stdincInt8> - Helper function to convert a string's encoding in one call.
-
sdlIsalnum(
int x) → int stdinc - Query if a character is alphabetic (a letter) or a number.
-
sdlIsalpha(
int x) → int stdinc - Query if a character is alphabetic (a letter).
-
sdlIsblank(
int x) → int stdinc - Report if a character is blank (a space or tab).
-
sdlIscntrl(
int x) → int stdinc - Report if a character is a control character.
-
sdlIsdigit(
int x) → int stdinc - Report if a character is a numeric digit.
-
sdlIsgraph(
int x) → int stdinc - Report if a character is any "printable" except space.
-
sdlIsinf(
double x) → int stdinc - Return whether the value is infinity.
-
sdlIsinff(
double x) → int stdinc - Return whether the value is infinity.
-
sdlIslower(
int x) → int stdinc - Report if a character is lower case.
-
sdlIsnan(
double x) → int stdinc - Return whether the value is NaN.
-
sdlIsnanf(
double x) → int stdinc - Return whether the value is NaN.
-
sdlIsprint(
int x) → int stdinc - Report if a character is "printable".
-
sdlIspunct(
int x) → int stdinc - Report if a character is a punctuation mark.
-
sdlIsspace(
int x) → int stdinc - Report if a character is whitespace.
-
sdlIsupper(
int x) → int stdinc - Report if a character is upper case.
-
sdlIsxdigit(
int x) → int stdinc - Report if a character is a hexadecimal digit.
-
sdlItoa(
int value, Pointer< stdincInt8> str, int radix) → Pointer<Int8> - Convert an integer into a string.
-
sdlLltoa(
Pointer< stdincNativeType> value, Pointer<Int8> str, int radix) → Pointer<Int8> - Convert a long long integer into a string.
-
sdlLog10(
double x) → double stdinc -
Compute the base-10 logarithm of
x
. -
sdlLog10f(
double x) → double stdinc -
Compute the base-10 logarithm of
x
. -
sdlLogf(
double x) → double stdinc -
Compute the natural logarithm of
x
. -
sdlLround(
double x) → int stdinc -
Round
x
to the nearest integer representable as a long -
sdlLroundf(
double x) → int stdinc -
Round
x
to the nearest integer representable as a long -
sdlLtoa(
int value, Pointer< stdincInt8> str, int radix) → Pointer<Int8> - Convert a long integer into a string.
-
sdlMalloc(
int size) → Pointer< stdincNativeType> - Allocate uninitialized memory.
-
sdlMemcmp(
Pointer< stdincNativeType> s1, Pointer<NativeType> s2, int len) → int - Compare two buffers of memory.
-
sdlMemcpy(
Pointer< stdincNativeType> arg0, Pointer<NativeType> arg1, int len) → Pointer<NativeType> - Copy non-overlapping memory.
-
sdlMemmove(
Pointer< stdincNativeType> arg0, Pointer<NativeType> arg1, int len) → Pointer<NativeType> - Copy memory ranges that might overlap.
-
sdlMemset(
Pointer< stdincNativeType> arg0, int c, int len) → Pointer<NativeType> - Initialize all bytes of buffer of memory to a specific value.
-
sdlMemset4(
Pointer< stdincNativeType> dst, int val, int dwords) → Pointer<NativeType> - Initialize all 32-bit words of buffer of memory to a specific value.
-
sdlModf(
double x, Pointer< stdincDouble> y) → double -
Split
x
into integer and fractional parts -
sdlModff(
double x, Pointer< stdincFloat> y) → double -
Split
x
into integer and fractional parts -
sdlMurmur332(
Pointer< stdincNativeType> data, int len, int seed) → int - Calculate a 32-bit MurmurHash3 value for a block of data.
-
sdlPow(
double x, double y) → double stdinc -
Raise
x
to the powery
-
sdlPowf(
double x, double y) → double stdinc -
Raise
x
to the powery
-
sdlQsort(
Pointer< stdincNativeType> base, int nmemb, int size, Pointer<NativeFunction< compare) → voidSdlCompareCallback> > - Sort an array.
-
sdlQsortR(
Pointer< stdincNativeType> base, int nmemb, int size, Pointer<NativeFunction< compare, Pointer<SdlCompareCallbackR> >NativeType> userdata) → void - Sort an array, passing a userdata pointer to the compare function.
-
sdlRand(
int n) → int stdinc - Generate a pseudo-random number less than n for positive n
-
sdlRandBits(
) → int stdinc - Generate 32 pseudo-random bits.
-
sdlRandBitsR(
Pointer< stdincUint64> state) → int - Generate 32 pseudo-random bits.
-
sdlRandf(
) → double stdinc - Generate a uniform pseudo-random floating point number less than 1.0
-
sdlRandfR(
Pointer< stdincUint64> state) → double - Generate a uniform pseudo-random floating point number less than 1.0
-
sdlRandR(
Pointer< stdincUint64> state, int n) → int - Generate a pseudo-random number less than n for positive n
-
sdlRound(
double x) → double stdinc -
Round
x
to the nearest integer. -
sdlRoundf(
double x) → double stdinc -
Round
x
to the nearest integer. -
sdlScalbn(
double x, int n) → double stdinc -
Scale
x
by an integer power of two. -
sdlScalbnf(
double x, int n) → double stdinc -
Scale
x
by an integer power of two. -
sdlSetEnvironmentVariable(
Pointer< stdincSdlEnvironment> env, String? name, String? value, bool overwrite) → bool - Set the value of a variable in the environment.
-
sdlSetenvUnsafe(
String? name, String? value, int overwrite) → int stdinc - Set the value of a variable in the environment.
-
sdlSetMemoryFunctions(
Pointer< stdincNativeFunction< mallocFunc, Pointer<SdlMallocFunc> >NativeFunction< callocFunc, Pointer<SdlCallocFunc> >NativeFunction< reallocFunc, Pointer<SdlReallocFunc> >NativeFunction< freeFunc) → boolSdlFreeFunc> > - Replace SDL's memory allocation functions with a custom set.
-
sdlSin(
double x) → double stdinc -
Compute the sine of
x
. -
sdlSinf(
double x) → double stdinc -
Compute the sine of
x
. -
sdlSnprintf(
Pointer< stdincInt8> text, int maxlen, String? fmt) → int - This works exactly like snprintf() but doesn't require access to a C runtime.
-
sdlSqrt(
double x) → double stdinc -
Compute the square root of
x
. -
sdlSqrtf(
double x) → double stdinc -
Compute the square root of
x
. -
sdlSrand(
int seed) → void stdinc - Seeds the pseudo-random number generator.
-
sdlSscanf(
String? text, String? fmt) → int stdinc - This works exactly like sscanf() but doesn't require access to a C runtime.
-
sdlStepBackUtf8(
String? start, Pointer< stdincPointer< pstr) → intInt8> > - Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
-
sdlStepUtf8(
Pointer< stdincPointer< pstr, Pointer<Int8> >Uint32> pslen) → int - Decode a UTF-8 string, one Unicode codepoint at a time.
-
sdlStrcasecmp(
String? str1, String? str2) → int stdinc - Compare two null-terminated UTF-8 strings, case-insensitively.
-
sdlStrcasestr(
String? haystack, String? needle) → Pointer< stdincInt8> - Search a UTF-8 string for the first instance of a specific substring, case-insensitively.
-
sdlStrchr(
String? str, int c) → Pointer< stdincInt8> - Search a string for the first instance of a specific byte.
-
sdlStrcmp(
String? str1, String? str2) → int stdinc - Compare two null-terminated UTF-8 strings.
-
sdlStrdup(
String? str) → Pointer< stdincInt8> - Allocate a copy of a string.
-
sdlStrlcat(
Pointer< stdincNativeType> arg0, String? src, int maxlen) → int - Concatenate strings.
-
sdlStrlcpy(
Pointer< stdincInt8> dst, String? src, int maxlen) → int - Copy a string.
-
sdlStrlen(
String? str) → int stdinc - This works exactly like strlen() but doesn't require access to a C runtime.
-
sdlStrlwr(
Pointer< stdincInt8> str) → Pointer<Int8> - Convert a string to lowercase.
-
sdlStrncasecmp(
String? str1, String? str2, int maxlen) → int stdinc - Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
-
sdlStrncmp(
String? str1, String? str2, int maxlen) → int stdinc - Compare two UTF-8 strings up to a number of bytes.
-
sdlStrndup(
String? str, int maxlen) → Pointer< stdincInt8> - Allocate a copy of a string, up to n characters.
-
sdlStrnlen(
String? str, int maxlen) → int stdinc - This works exactly like strnlen() but doesn't require access to a C runtime.
-
sdlStrnstr(
String? haystack, String? needle, int maxlen) → Pointer< stdincInt8> - Search a string, up to n bytes, for the first instance of a specific substring.
-
sdlStrpbrk(
String? str, String? breakset) → Pointer< stdincInt8> - Searches a string for the first occurrence of any character contained in a breakset, and returns a pointer from the string to that character.
-
sdlStrrchr(
String? str, int c) → Pointer< stdincInt8> - Search a string for the last instance of a specific byte.
-
sdlStrrev(
Pointer< stdincInt8> str) → Pointer<Int8> - Reverse a string's contents.
-
sdlStrstr(
String? haystack, String? needle) → Pointer< stdincInt8> - Search a string for the first instance of a specific substring.
-
sdlStrtod(
String? str, Pointer< stdincPointer< endp) → doubleInt8> > -
Parse a
double
from a string. -
sdlStrtokR(
Pointer< stdincInt8> str, String? delim, Pointer<Pointer< saveptr) → Pointer<Int8> >Int8> - This works exactly like strtok_r() but doesn't require access to a C runtime.
-
sdlStrtol(
String? str, Pointer< stdincPointer< endp, int base) → intInt8> > -
Parse a
long
from a string. -
sdlStrtoll(
String? str, Pointer< stdincPointer< endp, int base) → Pointer<Int8> >NativeType> -
Parse a
long long
from a string. -
sdlStrtoul(
String? str, Pointer< stdincPointer< endp, int base) → intInt8> > -
Parse an
unsigned long
from a string. -
sdlStrtoull(
String? str, Pointer< stdincPointer< endp, int base) → Pointer<Int8> >NativeType> -
Parse an
unsigned long long
from a string. -
sdlStrupr(
Pointer< stdincInt8> str) → Pointer<Int8> - Convert a string to uppercase.
-
sdlSwprintf(
Pointer< stdincInt16> text, int maxlen, Pointer<Int16> fmt) → int - This works exactly like swprintf() but doesn't require access to a C runtime.
-
sdlTan(
double x) → double stdinc -
Compute the tangent of
x
. -
sdlTanf(
double x) → double stdinc -
Compute the tangent of
x
. -
sdlTolower(
int x) → int stdinc - Convert low-ASCII English letters to lowercase.
-
sdlToupper(
int x) → int stdinc - Convert low-ASCII English letters to uppercase.
-
sdlTrunc(
double x) → double stdinc -
Truncate
x
to an integer. -
sdlTruncf(
double x) → double stdinc -
Truncate
x
to an integer. -
sdlUcs4ToUtf8(
int codepoint, Pointer< stdincInt8> dst) → Pointer<Int8> - Convert a single Unicode codepoint to UTF-8.
-
sdlUitoa(
int value, Pointer< stdincInt8> str, int radix) → Pointer<Int8> - Convert an unsigned integer into a string.
-
sdlUlltoa(
Pointer< stdincNativeType> value, Pointer<Int8> str, int radix) → Pointer<Int8> - Convert an unsigned long long integer into a string.
-
sdlUltoa(
int value, Pointer< stdincInt8> str, int radix) → Pointer<Int8> - Convert an unsigned long integer into a string.
-
sdlUnsetEnvironmentVariable(
Pointer< stdincSdlEnvironment> env, String? name) → bool - Clear a variable from the environment.
-
sdlUnsetenvUnsafe(
String? name) → int stdinc - Clear a variable from the environment.
-
sdlUtf8strlcpy(
Pointer< stdincInt8> dst, String? src, int dstBytes) → int - Copy an UTF-8 string.
-
sdlUtf8strlen(
String? str) → int stdinc - Count the number of codepoints in a UTF-8 string.
-
sdlUtf8strnlen(
String? str, int bytes) → int stdinc - Count the number of codepoints in a UTF-8 string, up to n bytes.
-
sdlVasprintf(
Pointer< stdincPointer< strp, String? fmt) → intInt8> > - This works exactly like vasprintf() but doesn't require access to a C runtime.
-
sdlVsnprintf(
Pointer< stdincInt8> text, int maxlen, String? fmt) → int - This works exactly like vsnprintf() but doesn't require access to a C runtime.
-
sdlVsscanf(
String? text, String? fmt) → int stdinc - This works exactly like vsscanf() but doesn't require access to a C runtime.
-
sdlVswprintf(
Pointer< stdincInt16> text, int maxlen, Pointer<Int16> fmt) → int - This works exactly like vswprintf() but doesn't require access to a C runtime.
-
sdlWcscasecmp(
Pointer< stdincInt16> str1, Pointer<Int16> str2) → int - Compare two null-terminated wide strings, case-insensitively.
-
sdlWcscmp(
Pointer< stdincInt16> str1, Pointer<Int16> str2) → int - Compare two null-terminated wide strings.
-
sdlWcsdup(
Pointer< stdincInt16> wstr) → Pointer<Int16> - Allocate a copy of a wide string.
-
sdlWcslcat(
Pointer< stdincNativeType> arg0, Pointer<Int16> src, int maxlen) → int - Concatenate wide strings.
-
sdlWcslcpy(
Pointer< stdincInt16> dst, Pointer<Int16> src, int maxlen) → int - Copy a wide string.
-
sdlWcslen(
Pointer< stdincInt16> wstr) → int - This works exactly like wcslen() but doesn't require access to a C runtime.
-
sdlWcsncasecmp(
Pointer< stdincInt16> str1, Pointer<Int16> str2, int maxlen) → int - Compare two wide strings, case-insensitively, up to a number of wchar_t.
-
sdlWcsncmp(
Pointer< stdincInt16> str1, Pointer<Int16> str2, int maxlen) → int - Compare two wide strings up to a number of wchar_t values.
-
sdlWcsnlen(
Pointer< stdincInt16> wstr, int maxlen) → int - This works exactly like wcsnlen() but doesn't require access to a C runtime.
-
sdlWcsnstr(
Pointer< stdincInt16> haystack, Pointer<Int16> needle, int maxlen) → Pointer<Int16> - Search a wide string, up to n wide chars, for the first instance of a specific substring.
-
sdlWcsstr(
Pointer< stdincInt16> haystack, Pointer<Int16> needle) → Pointer<Int16> - Search a wide string for the first instance of a specific substring.
-
sdlWcstol(
Pointer< stdincInt16> str, Pointer<Pointer< endp, int base) → intInt16> > -
Parse a
long
from a wide string.