]> Pileus Git - ~andy/fetchmail/blob - xmalloc.c
gcc -Wall cleanup.
[~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 #if defined(STDC_HEADERS)
12 #include  <stdlib.h>
13 #endif
14 #include "fetchmail.h"
15
16 #if defined(HAVE_VOIDPOINTER)
17 #define XMALLOCTYPE void
18 #else
19 #define XMALLOCTYPE char
20 #endif
21
22 XMALLOCTYPE *
23 xmalloc (n)
24 int n;
25 {
26   XMALLOCTYPE *p;
27
28   p = (XMALLOCTYPE *) malloc(n);
29   if (p == (XMALLOCTYPE *) 0) {
30     fputs("fetchmail: malloc failed\n",stderr);
31     exit(PS_UNDEFINED);
32   }
33   return(p);
34 }
35
36 char *xstrdup(s)
37 char *s;
38
39   char *p;
40   p = (char *) xmalloc(strlen(s)+1);
41   strcpy(p,s);
42   return p;
43 }
44
45 /* xmalloc.c ends here */