summaryrefslogtreecommitdiff
path: root/src/stdlib/strtoul.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/strtoul.c')
-rw-r--r--src/stdlib/strtoul.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/stdlib/strtoul.c b/src/stdlib/strtoul.c
new file mode 100644
index 00000000..951d5e8c
--- /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;
+}