1 |
|
|
/* $OpenBSD: xmalloc.c,v 1.2 2016/10/16 20:26:56 natano Exp $ */ |
2 |
|
|
|
3 |
|
|
#include <err.h> |
4 |
|
|
#include <stdlib.h> |
5 |
|
|
#include <string.h> |
6 |
|
|
|
7 |
|
|
void * |
8 |
|
|
emalloc(size_t size) |
9 |
|
|
{ |
10 |
|
|
void *v; |
11 |
|
|
|
12 |
|
|
if ((v = malloc(size)) == NULL) |
13 |
|
|
err(1, "malloc"); |
14 |
|
|
return v; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
void * |
18 |
|
|
ecalloc(size_t nmemb, size_t size) |
19 |
|
|
{ |
20 |
|
|
void *v; |
21 |
|
|
|
22 |
|
|
if ((v = calloc(nmemb, size)) == NULL) |
23 |
|
|
err(1, "calloc"); |
24 |
|
|
return v; |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
void * |
28 |
|
|
erealloc(void *ptr, size_t size) |
29 |
|
|
{ |
30 |
|
|
void *v; |
31 |
|
|
|
32 |
|
|
if ((v = realloc(ptr, size)) == NULL) |
33 |
|
|
err(1, "realloc"); |
34 |
|
|
return v; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
char * |
38 |
|
|
estrdup(const char *s) |
39 |
|
|
{ |
40 |
|
|
char *s2; |
41 |
|
|
|
42 |
|
|
if ((s2 = strdup(s)) == NULL) |
43 |
|
|
err(1, "strdup"); |
44 |
|
|
return s2; |
45 |
|
|
} |