]>
Commit | Line | Data |
---|---|---|
18c8241a MM |
1 | /* |
2 | * BIRD Library -- malloc() With Checking | |
3 | * | |
7722938d | 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> |
18c8241a MM |
5 | * |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #include <stdlib.h> | |
10 | ||
11 | #include "nest/bird.h" | |
12 | #include "lib/resource.h" | |
13 | ||
7a2105be MM |
14 | #ifndef HAVE_LIBDMALLOC |
15 | ||
7722938d MM |
16 | /** |
17 | * xmalloc - malloc with checking | |
18 | * @size: block size | |
19 | * | |
20 | * This function is equivalent to malloc() except that in case of | |
21 | * failure it calls die() to quit the program instead of returning | |
22 | * a %NULL pointer. | |
23 | * | |
2e9b2421 | 24 | * Wherever possible, please use the memory resources instead. |
7722938d | 25 | */ |
18c8241a MM |
26 | void * |
27 | xmalloc(unsigned size) | |
28 | { | |
29 | void *p = malloc(size); | |
30 | if (p) | |
31 | return p; | |
32 | die("Unable to allocate %d bytes of memory", size); | |
33 | } | |
7a2105be | 34 | |
3d15dcdb OZ |
35 | /** |
36 | * xrealloc - realloc with checking | |
37 | * @ptr: original memory block | |
38 | * @size: block size | |
39 | * | |
40 | * This function is equivalent to realloc() except that in case of | |
41 | * failure it calls die() to quit the program instead of returning | |
42 | * a %NULL pointer. | |
43 | * | |
44 | * Wherever possible, please use the memory resources instead. | |
45 | */ | |
46 | void * | |
47 | xrealloc(void *ptr, unsigned size) | |
48 | { | |
49 | void *p = realloc(ptr, size); | |
50 | if (p) | |
51 | return p; | |
52 | die("Unable to allocate %d bytes of memory", size); | |
53 | } | |
54 | ||
7a2105be | 55 | #endif |