diff --git a/lib/atoi/strtou_noneg.c b/lib/atoi/strtou_noneg.c index 14602a9b..ec8773d7 100644 --- a/lib/atoi/strtou_noneg.c +++ b/lib/atoi/strtou_noneg.c @@ -6,6 +6,11 @@ #include "atoi/strtou_noneg.h" +#include + + +extern inline uintmax_t strtou_noneg(const char *s, char **restrict endp, + int base, uintmax_t min, uintmax_t max, int *restrict status); extern inline unsigned long strtoul_noneg(const char *s, char **restrict endp, int base); diff --git a/lib/atoi/strtou_noneg.h b/lib/atoi/strtou_noneg.h index 5670dc9b..a1d15569 100644 --- a/lib/atoi/strtou_noneg.h +++ b/lib/atoi/strtou_noneg.h @@ -9,11 +9,17 @@ #include #include +#include #include +#include "atoi/strtoi.h" #include "attr.h" +ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6) +inline uintmax_t strtou_noneg(const char *s, char **restrict endp, + int base, uintmax_t min, uintmax_t max, int *restrict status); + ATTR_STRING(1) ATTR_ACCESS(write_only, 2) inline unsigned long strtoul_noneg(const char *s, char **restrict endp, int base); @@ -22,6 +28,21 @@ inline unsigned long long strtoull_noneg(const char *s, char **restrict endp, int base); +inline uintmax_t +strtou_noneg(const char *s, char **restrict endp, int base, + uintmax_t min, uintmax_t max, int *restrict status) +{ + int st; + + if (status == NULL) + status = &st; + if (strtoi_(s, endp, base, 0, 1, status) == 0 && *status == ERANGE) + return min; + + return strtou_(s, endp, base, min, max, status); +} + + inline unsigned long strtoul_noneg(const char *s, char **restrict endp, int base) {