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

Annotation of /imapfilter/memory.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Tue Nov 6 17:42:34 2001 UTC (22 years, 4 months ago) by lefcha
Branch: MAIN
Changes since 1.2: +17 -2 lines
File MIME type: text/plain
Added xrealloc().

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26