diff options
| author | Michael Jones <michaelrj@google.com> | 2022-09-01 15:19:35 -0700 |
|---|---|---|
| committer | Michael Jones <michaelrj@google.com> | 2022-12-09 14:35:47 -0800 |
| commit | 74da5e6c082edff19981892328d724a8e02ffcd9 (patch) | |
| tree | 6a17bc318ebd6ef9956dcc93e7b35cc62cefa9ec /libc/src/stdlib/strtoll.cpp | |
| parent | 142e38007d956c20c94d4c379f8c66152c99d437 (diff) | |
[libc] add result class to strtointeger
This is a class intended to improve errno handling for internal
functions by allowing functions to return their result and error status
instead of setting errno. This specific class will be used for
strtointeger and (in a followup patch) strtofloat.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D133163
Diffstat (limited to 'libc/src/stdlib/strtoll.cpp')
| -rw-r--r-- | libc/src/stdlib/strtoll.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libc/src/stdlib/strtoll.cpp b/libc/src/stdlib/strtoll.cpp index e2f0aac54668..c1aa94e54123 100644 --- a/libc/src/stdlib/strtoll.cpp +++ b/libc/src/stdlib/strtoll.cpp @@ -15,7 +15,14 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, strtoll, (const char *__restrict str, char **__restrict str_end, int base)) { - return internal::strtointeger<long long>(str, str_end, base); + auto result = internal::strtointeger<long long>(str, base); + if (result.has_error()) + errno = result.error; + + if (str_end != nullptr) + *str_end = const_cast<char *>(str + result.parsed_len); + + return result; } } // namespace __llvm_libc |
