forked from mischief/9pfs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.c
52 lines (41 loc) · 705 Bytes
/
util.c
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
47
48
49
50
51
52
#include <sys/types.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <err.h>
#include <errno.h>
void*
emalloc(size_t size)
{
void *v;
if((v = malloc(size)) == NULL)
err(1, "emalloc: out of memory");
memset(v, 0, size);
return v;
}
void*
erealloc(void *p, size_t size)
{
void *v;
if((v = realloc(p, size)) == NULL)
err(1, "emalloc: out of memory");
return v;
}
void*
ecalloc(size_t nmemb, size_t size)
{
void *v;
if((v = calloc(nmemb, size)) == NULL)
err(1, "ecalloc: out of memory");
return v;
}
char*
estrdup(const char *s)
{
char *r;
if((r = strdup(s)) == NULL)
err(1, "estrdup: out of memory");
return r;
}