]> Pileus Git - ~andy/fetchmail/blob - xmalloc.c
6fab5be1096d36966a65569c55041d5196c19eba
[~andy/fetchmail] / xmalloc.c
1 /*
2  * xmalloc.c -- allocate space or die 
3  *
4  * For license terms, see the file COPYING in this directory.
5  */
6
7 #include <config.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include "fetchmail.h"
12
13 #if defined(HAVE_VOIDPOINTER)
14 #define XMALLOCTYPE void
15 #else
16 #define XMALLOCTYPE char
17 #endif
18
19 XMALLOCTYPE *
20 xmalloc (n)
21 int n;
22 {
23   XMALLOCTYPE *p;
24
25   p = (XMALLOCTYPE *) malloc(n);
26   if (p == (XMALLOCTYPE *) 0) {
27     fputs("fetchmail: malloc failed\n",stderr);
28     exit(PS_UNDEFINED);
29   }
30   return(p);
31 }
32
33 char *xstrdup(s)
34 char *s;
35
36   char *p;
37   p = (char *) xmalloc(strlen(s)+1);
38   strcpy(p,s);
39   return p;
40 }
41
42 /* xmalloc.c ends here */