1 |
lefcha |
1.1 |
#include <stdlib.h> |
2 |
|
|
#include <string.h> |
3 |
|
|
#include <errno.h> |
4 |
|
|
|
5 |
|
|
#include "imapfilter.h" |
6 |
|
|
|
7 |
lefcha |
1.4 |
|
8 |
lefcha |
1.1 |
/* |
9 |
lefcha |
1.3 |
* A malloc() that checks the results and dies in case of error. |
10 |
lefcha |
1.1 |
*/ |
11 |
|
|
void *xmalloc(size_t size) |
12 |
|
|
{ |
13 |
|
|
void *ptr; |
14 |
lefcha |
1.2 |
|
15 |
lefcha |
1.1 |
ptr = (void *) malloc(size); |
16 |
lefcha |
1.2 |
|
17 |
lefcha |
1.1 |
if (!ptr) |
18 |
|
|
fatal(ERROR_MEMORY_ALLOCATION, |
19 |
|
|
"imapfilter: allocating memory; %s\n", strerror(errno)); |
20 |
lefcha |
1.2 |
|
21 |
lefcha |
1.1 |
return ptr; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* |
26 |
lefcha |
1.3 |
* A realloc() that checks the results and dies in case of error. |
27 |
|
|
*/ |
28 |
|
|
void *xrealloc(void *ptr, size_t size) |
29 |
|
|
{ |
30 |
|
|
ptr = (void *) realloc(ptr, size); |
31 |
|
|
|
32 |
|
|
if (!ptr) |
33 |
|
|
fatal(ERROR_MEMORY_ALLOCATION, |
34 |
|
|
"imapfilter: allocating memory; %s\n", strerror(errno)); |
35 |
|
|
|
36 |
|
|
return ptr; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/* |
41 |
|
|
* A strdup() that checks the results and dies in case of error. |
42 |
lefcha |
1.1 |
*/ |
43 |
|
|
char *xstrdup(const char *s) |
44 |
|
|
{ |
45 |
|
|
char *cp; |
46 |
lefcha |
1.2 |
|
47 |
lefcha |
1.1 |
cp = strdup(s); |
48 |
lefcha |
1.2 |
|
49 |
lefcha |
1.1 |
if (!cp) |
50 |
|
|
fatal(ERROR_MEMORY_ALLOCATION, |
51 |
|
|
"imapfilter: allocating memory; %s\n", strerror(errno)); |
52 |
lefcha |
1.2 |
|
53 |
lefcha |
1.1 |
return cp; |
54 |
lefcha |
1.2 |
} |