2 * UCW Library -- Generic Allocator Using Malloc
4 * (c) 2014 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/alloc.h>
15 /* Default allocator */
17 static void *ucw_std_alloc(struct ucw_allocator *a UNUSED, size_t size)
22 static void *ucw_std_realloc(struct ucw_allocator *a UNUSED, void *ptr, size_t old_size UNUSED, size_t new_size)
24 return xrealloc(ptr, new_size);
27 static void ucw_std_free(struct ucw_allocator *a UNUSED, void *ptr)
32 struct ucw_allocator ucw_allocator_std = {
33 .alloc = ucw_std_alloc,
34 .realloc = ucw_std_realloc,
38 /* Zeroing allocator */
40 static void *ucw_zeroed_alloc(struct ucw_allocator *a UNUSED, size_t size)
42 return xmalloc_zero(size);
45 static void *ucw_zeroed_realloc(struct ucw_allocator *a UNUSED, void *ptr, size_t old_size, size_t new_size)
47 ptr = xrealloc(ptr, new_size);
48 if (old_size < new_size)
49 bzero((byte *) ptr + old_size, new_size - old_size);
53 struct ucw_allocator ucw_allocator_zeroed = {
54 .alloc = ucw_zeroed_alloc,
55 .realloc = ucw_zeroed_realloc,