blob: bf93c77291b43548e03b2a95a6a3f7e30affe718 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}
|