* patch #3967: Create a mh_xrealloc function to prevent mistakes when
[mmh] / sbr / utils.c
1
2 /*
3  * utils.c -- various utility routines
4  *
5  * $Id$
6  *
7  * This code is Copyright (c) 2006, by the authors of nmh.  See the
8  * COPYRIGHT file in the root directory of the nmh distribution for
9  * complete copyright information.
10  */
11
12 #include <h/nmh.h>
13 #include <h/utils.h>
14 #include <stdlib.h>
15
16 void *
17 mh_xmalloc(size_t size)
18 {
19     void *memory;
20
21     if (size == 0)
22         adios(NULL, "Tried to malloc 0 bytes");
23
24     memory = malloc(size);
25     if (!memory)
26         adios(NULL, "Malloc failed");
27
28     return memory;
29 }
30
31 void *
32 mh_xrealloc(void *ptr, size_t size)
33 {
34     void *memory;
35
36     if (size == 0)
37         adios(NULL, "Tried to realloc 0bytes");
38
39     memory = realloc(ptr, size);
40     if (!memory)
41         adios(NULL, "Realloc failed");
42
43     return memory;
44 }