1 /* $Id: xmalloc.c,v 1.4 2002/03/02 20:35:52 sverrehu Exp $ */
2 /*------------------------------------------------------------------------
3  |  FILE            xmalloc.c
4  |  MODULE OF       xalloc - memory allocation with error checking
5  |
6  |  DESCRIPTION     malloc-matching routine. Aborts program or calls a
7  |                  user supplied function if no more memory left.
8  |
9  |  WRITTEN BY      Sverre H. Huseby <shh@thathost.com>
10  +----------------------------------------------------------------------*/
11 
12 #include <stdlib.h>
13 
14 #include "xalloc.h"
15 
16 extern void _xaOutOfMem(void);
17 
18 /*-----------------------------------------------------------------------+
19 |  PUBLIC FUNCTIONS                                                      |
20 +-----------------------------------------------------------------------*/
21 
22 /*------------------------------------------------------------------------
23  |  NAME          xmalloc
24  |
25  |  FUNCTION      Do as malloc(3), but with error handling.
26  |
27  |  SYNOPSIS      #include "xalloc.h"
28  |                void *xmalloc(size_t size);
29  |
30  |  INPUT         size    number of bytes to allocate.
31  |
32  |  RETURNS       Pointer to buffer allocated. Never returns in case
33  |                of error.
34  */
35 void *
xmalloc(size_t size)36 xmalloc(size_t size)
37 {
38     void *ret;
39 
40     if ((ret = malloc(size)) == NULL)
41 	_xaOutOfMem();
42     return ret;
43 }
44