stdlib: Rewrite SDL_wcstol impl

SDL_wcstol should now fully adhere to the libc spec.
This commit is contained in:
Carl Åstholm
2024-09-10 21:50:48 +02:00
committed by Sam Lantinga
parent 5d30980df4
commit fd53b3e112
2 changed files with 69 additions and 50 deletions

View File

@@ -1499,21 +1499,18 @@ extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar
/**
* Parse a `long` from a wide string.
*
* This function makes fewer guarantees than the C runtime `wcstol`:
* 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 a `long`.
* If the parsed number does not fit inside a `long`, the result is clamped to the minimum and maximum representable `long` values.
*
* \param str The null-terminated wide string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid wide character
* (i.e. the next character after the parsed number) will be
* written to this pointer.
* \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.
* \returns The parsed `long`.
* \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 `long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
@@ -1826,7 +1823,7 @@ extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp,
* - 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 a `long long`.
* not fit inside an `unsigned long long`.
*
* \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.