]> Pileus Git - ~andy/fetchmail/blob - xmalloc.c
Fix copyrights.
[~andy/fetchmail] / xmalloc.c
1 /*
2  * xmalloc.c -- allocate space or die 
3  *
4  * Copyright 1998 by Eric S. Raymond.
5  * For license terms, see the file COPYING in this directory.
6  */
7
8 #include "config.h"
9 #include <stdio.h>
10 #include <errno.h>
11 #include <string.h>
12 #if defined(STDC_HEADERS)
13 #include  <stdlib.h>
14 #endif
15 #include "fetchmail.h"
16 #include "i18n.h"
17
18 #if defined(HAVE_VOIDPOINTER)
19 #define XMALLOCTYPE void
20 #else
21 #define XMALLOCTYPE char
22 #endif
23
24 XMALLOCTYPE *
25 xmalloc (int n)
26 {
27     XMALLOCTYPE *p;
28
29     p = (XMALLOCTYPE *) malloc(n);
30     if (p == (XMALLOCTYPE *) 0)
31         error(PS_UNDEFINED, errno, _("malloc failed"));
32     return(p);
33 }
34
35 XMALLOCTYPE *
36 xrealloc (XMALLOCTYPE *p, int n)
37 {
38     if (p == 0)
39         return xmalloc (n);
40     p = (XMALLOCTYPE *) realloc(p, n);
41     if (p == (XMALLOCTYPE *) 0)
42         error(PS_UNDEFINED, errno, _("realloc failed"));
43     return p;
44 }
45
46 char *xstrdup(const char *s)
47 {
48     char *p;
49     p = (char *) xmalloc(strlen(s)+1);
50     strcpy(p,s);
51     return p;
52 }
53
54 /* xmalloc.c ends here */