stdlib: Rewrite SDL_strtoull impl

This commit is contained in:
Carl Åstholm
2024-09-11 22:32:45 +02:00
committed by Sam Lantinga
parent 5331f36789
commit fb82772fb3
2 changed files with 99 additions and 49 deletions

View File

@@ -1819,20 +1819,18 @@ extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp,
/**
* Parse an `unsigned long long` from a string.
*
* This function makes fewer guarantees than the C runtime `strtoull`:
* If `str` starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.
*
* - Only the bases 10 and 16 are guaranteed to be supported. The behavior for
* other bases is unspecified.
* - It is unspecified what this function returns when the parsed integer does
* not fit inside an `unsigned long long`.
* If the parsed number does not fit inside an `unsigned long long`,
* the result is clamped to the maximum representable `unsigned long long` value.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. The values 0, 10 and 16 are
* supported. If 0, the base will be inferred from the integer's
* prefix.
* \param base The base of the integer to read. Supported values are 0 and 2 to 36 inclusive.
* If 0, the base will be inferred from the number's
* prefix (0x for hexadecimal, 0 for octal, decimal otherwise).
* \returns The parsed `unsigned long long`.
*
* \threadsafety It is safe to call this function from any thread.