diff options
Diffstat (limited to 'src/stdlib/strtoul.c')
-rw-r--r-- | src/stdlib/strtoul.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/stdlib/strtoul.c b/src/stdlib/strtoul.c new file mode 100644 index 0000000..951d5e8 --- /dev/null +++ b/src/stdlib/strtoul.c @@ -0,0 +1,14 @@ +#include <stdlib.h> +#include <inttypes.h> +#include <errno.h> +#include <limits.h> + +unsigned long strtoul(const char *s, char **p, int base) +{ + uintmax_t x = strtoumax(s, p, base); + if (x > ULONG_MAX) { + errno = ERANGE; + return ULONG_MAX; + } + return x; +} |