]> Pileus Git - ~andy/fetchmail/blob - xmalloc.c
481f818091f0254a0278b956f3d613c8b13325ed
[~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  * i18n by Arnaldo Carvalho de Melo <acme@conectiva.com.br> 7-Nov-1998
7  */
8
9 #include "config.h"
10 #include <stdio.h>
11 #include <errno.h>
12 #include <string.h>
13 #if defined(STDC_HEADERS)
14 #include  <stdlib.h>
15 #endif
16 #include "fetchmail.h"
17 #include "i18n.h"
18
19 #if defined(HAVE_VOIDPOINTER)
20 #define XMALLOCTYPE void
21 #else
22 #define XMALLOCTYPE char
23 #endif
24
25 XMALLOCTYPE *
26 xmalloc (int n)
27 {
28     XMALLOCTYPE *p;
29
30     p = (XMALLOCTYPE *) malloc(n);
31     if (p == (XMALLOCTYPE *) 0)
32         error(PS_UNDEFINED, errno, _("malloc failed"));
33     return(p);
34 }
35
36 XMALLOCTYPE *
37 xrealloc (XMALLOCTYPE *p, int n)
38 {
39     if (p == 0)
40         return xmalloc (n);
41     p = (XMALLOCTYPE *) realloc(p, n);
42     if (p == (XMALLOCTYPE *) 0)
43         error(PS_UNDEFINED, errno, _("realloc failed"));
44     return p;
45 }
46
47 char *xstrdup(const char *s)
48 {
49     char *p;
50     p = (char *) xmalloc(strlen(s)+1);
51     strcpy(p,s);
52     return p;
53 }
54
55 /* xmalloc.c ends here */