summary refs log tree commit diff
path: root/warteraum/http_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'warteraum/http_string.c')
-rw-r--r--warteraum/http_string.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/warteraum/http_string.c b/warteraum/http_string.c
new file mode 100644
index 0000000..bf93c77
--- /dev/null
+++ b/warteraum/http_string.c
@@ -0,0 +1,29 @@
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "http_string.h"
+
+unsigned long long http_string_to_uint(struct http_string_s s) {
+  char *zero_terminated = malloc(s.len + 1);
+  char *end = NULL;
+
+  if(zero_terminated == NULL) {
+    errno = ENOMEM;
+    return ULONG_MAX;
+  }
+
+  memcpy(zero_terminated, s.buf, s.len);
+  zero_terminated[s.len] = '\0';
+
+  unsigned long long int l = strtoull(zero_terminated, &end, 10);
+
+  if(*end != '\0') {
+    errno = EINVAL;
+  }
+
+  free(zero_terminated);
+
+  return l;
+}