mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 18:28:30 +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"
|
||||
|
||||
unsigned long strtoul(const char *s, char **endptr, int optional_base) {
|
||||
unsigned long long res;
|
||||
intmax_t res;
|
||||
res = strtoimax(s, endptr, optional_base);
|
||||
if (res < ULONG_MIN) return ULONG_MIN;
|
||||
if (res > ULONG_MAX) return ULONG_MAX;
|
||||
if (res < ULONG_MIN) {
|
||||
errno = ERANGE;
|
||||
return ULONG_MIN;
|
||||
}
|
||||
if (res > ULONG_MAX) {
|
||||
errno = ERANGE;
|
||||
return ULONG_MAX;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue