mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Set errno in strtol family of functions (#110)
This commit is contained in:
parent
b16b332539
commit
f5da4efcaf
6 changed files with 57 additions and 13 deletions
|
@ -17,12 +17,19 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
|
||||
long long strtoll(const char *s, char **endptr, int optional_base) {
|
||||
long long res;
|
||||
intmax_t res;
|
||||
res = strtoimax(s, endptr, optional_base);
|
||||
if (res < LONG_LONG_MIN) return LONG_LONG_MIN;
|
||||
if (res > LONG_LONG_MAX) return LONG_LONG_MAX;
|
||||
if (res < LONG_LONG_MIN) {
|
||||
errno = ERANGE;
|
||||
return LONG_LONG_MIN;
|
||||
}
|
||||
if (res > LONG_LONG_MAX) {
|
||||
errno = ERANGE;
|
||||
return LONG_LONG_MAX;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue