1 // Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com
2 // Copyright 2002 Albert Cahalan
3 //
4 // This file is placed under the conditions of the GNU Library
5 // General Public License, version 2, or any later version.
6 // See file COPYING for information on distribution conditions.
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "alloc.h"
11
xcalloc(void * pointer,int size)12 void *xcalloc(void *pointer, int size)
13 {
14 void *ret;
15 free(pointer);
16 if (!(ret = calloc(1, size))) {
17 fprintf(stderr, "xcalloc: allocation error, size = %d\n", size);
18 exit(1);
19 }
20 return ret;
21 }
22
xmalloc(unsigned int size)23 void *xmalloc(unsigned int size)
24 {
25 void *p;
26
27 if (size == 0)
28 ++size;
29 p = malloc(size);
30 if (!p) {
31 fprintf(stderr, "xmalloc: malloc(%d) failed", size);
32 perror(NULL);
33 exit(1);
34 }
35 return (p);
36 }
37
xrealloc(void * oldp,unsigned int size)38 void *xrealloc(void *oldp, unsigned int size)
39 {
40 void *p;
41
42 if (size == 0)
43 ++size;
44 p = realloc(oldp, size);
45 if (!p) {
46 fprintf(stderr, "xrealloc: realloc(%d) failed", size);
47 perror(NULL);
48 exit(1);
49 }
50 return (p);
51 }
52