mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 16:58: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,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
|
||||
/**
|
||||
|
@ -25,5 +26,15 @@
|
|||
* @param optional_base is recommended as 0 for flexidecimal
|
||||
*/
|
||||
long strtol(const char *s, char **opt_out_end, int optional_base) {
|
||||
return strtoimax(s, opt_out_end, optional_base);
|
||||
intmax_t res;
|
||||
res = strtoimax(s, opt_out_end, optional_base);
|
||||
if (res < LONG_MIN) {
|
||||
errno = ERANGE;
|
||||
return LONG_MIN;
|
||||
}
|
||||
if (res > LONG_MAX) {
|
||||
errno = ERANGE;
|
||||
return LONG_MAX;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -17,12 +17,19 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
|
||||
unsigned long long strtoull(const char *s, char **endptr, int optional_base) {
|
||||
unsigned long long res;
|
||||
intmax_t res;
|
||||
res = strtoimax(s, endptr, optional_base);
|
||||
if (res < ULONG_LONG_MIN) return ULONG_LONG_MIN;
|
||||
if (res > ULONG_LONG_MAX) return ULONG_LONG_MAX;
|
||||
if (res < ULONG_LONG_MIN) {
|
||||
errno = ERANGE;
|
||||
return ULONG_LONG_MIN;
|
||||
}
|
||||
if (res > ULONG_LONG_MAX) {
|
||||
errno = ERANGE;
|
||||
return ULONG_LONG_MAX;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue