]> mj.ucw.cz Git - libucw.git/blob - lib/alloc.c
Added bit_array_assign(), replaced BIT_ARRAY_ALLOC by functions.
[libucw.git] / lib / alloc.c
1 /*
2  *      UCW Library -- Memory Allocation
3  *
4  *      (c) 2000 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11
12 #include <stdlib.h>
13 #include <string.h>
14
15 #ifndef DEBUG_DMALLOC
16
17 void *
18 xmalloc(uns size)
19 {
20   void *x = malloc(size);
21   if (!x)
22     die("Cannot allocate %d bytes of memory", size);
23   return x;
24 }
25
26 #endif
27
28 void *
29 xmalloc_zero(uns size)
30 {
31   void *x = xmalloc(size);
32   bzero(x, size);
33   return x;
34 }
35
36 void
37 xfree(void *ptr)
38 {
39   /*
40    * Maybe it is a little waste of resources to make this a function instead
41    * of a macro, but xmalloc() is not used for anything critical anyway,
42    * so let's prefer simplicity.
43    */
44   free(ptr);
45 }