-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathutils.cpp
More file actions
45 lines (42 loc) · 872 Bytes
/
utils.cpp
File metadata and controls
45 lines (42 loc) · 872 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
35
36
37
38
39
40
41
42
43
44
45
#include "common.h"
#include "utils.h"
char* filter_arg(char **param, int32_t *len) {
char *begptr = *param;
if (begptr == NULL) return NULL;
while (*begptr != '\0' && (*begptr == ' ' || *begptr == '\t')) {
++begptr;
}
char *endptr = begptr;
while (*endptr != '\0' && (*endptr != ' ' && *endptr != '\t')) {
++endptr;
}
if (begptr != endptr) {
if (*endptr != '\0') { /* don't reach the end */
*param = endptr + 1;
*endptr = '\0';
} else { /* reach the end */
*param = NULL;
}
if (len) {
*len = endptr - begptr;
}
return begptr;
} else { /* reach the end */
*param = NULL;
return NULL;
}
}
extern void* nl_memdup(const void* src, uint32_t len)
{
if (src) {
if (len != 0) {
void* temp = nl_malloc(len);
if (temp) {
return memcpy(temp, src, len);
}
} else {
return nl_malloc(1);
}
}
return NULL;
}