-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathutil.c
More file actions
47 lines (39 loc) · 764 Bytes
/
util.c
File metadata and controls
47 lines (39 loc) · 764 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
46
#include "binflow.h"
void xfree(void *p)
{
if (p != NULL)
free(p);
}
char * _strdupa(const char *s)
{
char *p = alloca(strlen(s) + 1);
strcpy(p, s);
return p;
}
void * heapAlloc(unsigned int len)
{
uint8_t *mem = malloc(len);
if (!mem) {
perror("malloc");
exit(-1);
}
return mem;
}
char * xstrdup(const char *s)
{
char *p = strdup(s);
if (p == NULL) {
perror("strdup");
exit(-1);
}
return p;
}
char * xfmtstrdup(char *fmt, ...)
{
char *s, buf[512];
va_list va;
va_start (va, fmt);
vsnprintf (buf, sizeof(buf), fmt, va);
s = xstrdup(buf);
return s;
}