-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
34 lines (27 loc) · 876 Bytes
/
Copy pathutils.c
File metadata and controls
34 lines (27 loc) · 876 Bytes
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
30
31
32
33
34
/**
* utils.c - Utility functions.
*
* Author: Thomas Cherryhomes <thom.cherryhomes@gmail.com>
* Version: 1.0
*/
#include <string.h>
#include "utils.h"
int has_prefix(const struct mg_str *uri, const struct mg_str *prefix) {
return uri->len > prefix->len && memcmp(uri->p, prefix->p, prefix->len) == 0;
}
int is_equal(const struct mg_str *s1, const struct mg_str *s2) {
return s1->len == s2->len && memcmp(s1->p, s2->p, s2->len) == 0;
}
char* get_query(const struct mg_str* query)
{
char* decoded_string = NULL;
int decoded_string_size = 0;
char* returned_string = NULL;
if (query==NULL)
return NULL;
decoded_string = malloc(query->len+1);
decoded_string_size = mg_url_decode(query->p,query->len,decoded_string,query->len+1,0);
returned_string = strndup(decoded_string,decoded_string_size);
free(decoded_string);
return returned_string;
}