xalloc, xrealloc - memory allocation with simple error check
# include <begemot.h>
void * xalloc(size_t size);
void * xrealloc(void *ptr, size_t size);
void xfree(void *ptr);
These functions are a layer above the malloc(3C) and realloc(3C)
functions. They call these basic functions and check whether the returned
pointer is NULL. In this case panic(l) is called with the
message 'Out of memory: param' , where param are the parameters
to the allocation function.
See malloc(3C) and realloc(3C) for a description of
the arguments.
These functions have the following additional features:
- -
- xalloc(0) returns a unique pointer for each call.
- -
- xfree(NULL) is legal.
- -
- xrealloc(NULL, 0) behaves like xalloc(0).
- -
- xrealloc(NULL, s) will behave like xalloc(s).
- -
- xrealloc(p, 0) behaves like a sequence of free(p) and
xalloc(0).
See malloc(3C) and realloc(3C) for a description of the return
values. Note that these functions never return NULL.
malloc(3C), realloc(3C), panic(l)