summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nxt_string.c')
-rw-r--r--src/nxt_string.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/nxt_string.c b/src/nxt_string.c
index ed4ff955..3a3fd5bf 100644
--- a/src/nxt_string.c
+++ b/src/nxt_string.c
@@ -8,8 +8,13 @@
#include <nxt_main.h>
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <nxt_unit_cdefs.h>
+
+#include "nxt_string.h"
+
static inline unsigned long nxt_strtoul_noneg(const char *nptr,
char **restrict endptr, int base);
@@ -852,6 +857,39 @@ nxt_base64_decode(u_char *dst, u_char *src, size_t length)
}
+unsigned long
+nxt_atoul(const nxt_str_t *s)
+{
+ int e;
+ char *endptr;
+ unsigned long ul;
+ char buf[BUFSIZ];
+
+ if (s == NULL || s->length >= nxt_nitems(buf)) {
+ errno = ECANCELED;
+ return 0;
+ }
+
+ stpcpy(nxt_cpymem(buf, s->start, s->length), "");
+
+ e = errno;
+ errno = 0;
+ ul = nxt_strtoul_noneg(buf, &endptr, 0);
+
+ if (endptr == buf) {
+ errno = ECANCELED;
+ } else if (errno == ERANGE) {
+ errno = ERANGE;
+ } else if (*endptr == '\0') {
+ errno = ENOTSUP;
+ } else {
+ errno = e;
+ }
+
+ return ul;
+}
+
+
static inline unsigned long
nxt_strtoul_noneg(const char *nptr, char **restrict endptr, int base)
{