/[imapfilter]/imapfilter/memory.c
ViewVC logotype

Annotation of /imapfilter/memory.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Mon Jan 14 18:14:33 2002 UTC (22 years, 3 months ago) by lefcha
Branch: MAIN
Changes since 1.4: +12 -0 lines
File MIME type: text/plain
Added another verion of free().

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 lefcha 1.5 * A free() that dies if fed with NULL pointer.
42     */
43     void xfree(void *ptr)
44     {
45     if (!ptr)
46     fatal(ERROR_MEMORY_ALLOCATION,
47     "imapfilter: NULL pointer given as argument");
48     free(ptr);
49     }
50    
51    
52     /*
53 lefcha 1.3 * A strdup() that checks the results and dies in case of error.
54 lefcha 1.1 */
55     char *xstrdup(const char *s)
56     {
57     char *cp;
58 lefcha 1.2
59 lefcha 1.1 cp = strdup(s);
60 lefcha 1.2
61 lefcha 1.1 if (!cp)
62     fatal(ERROR_MEMORY_ALLOCATION,
63     "imapfilter: allocating memory; %s\n", strerror(errno));
64 lefcha 1.2
65 lefcha 1.1 return cp;
66 lefcha 1.2 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26