libgslutil
1.2.3
|
Functions | |
void * | safe_malloc (size_t amt) |
Allocate memory. More... | |
void * | safe_realloc (void *p, size_t amt) |
Dynamically resize allocated memory. More... | |
char * | safe_strdup (const char *str) |
Copy a string. More... | |
This module contains a set of functions for safely allocating memory. This may involve zeroing the memory before it is returned and aborting if the allocation fails.
void* safe_malloc | ( | size_t | amt | ) |
Allocate memory.
amt | Amount (in bytes) to allocate. |
This function will allocate amt bytes of memory, returning a pointer to the new block. Should the allocation fail, it is logged to syslog and the program aborted with abort()
. The newly allocated block is zeroed with memset()
. Returns a unique pointer even if amt is zero.
void* safe_realloc | ( | void * | p, |
size_t | amt | ||
) |
Dynamically resize allocated memory.
p | Existing pointer (may be 0). |
amt | New size to allocate. |
This function will allocate amt bytes of memory, possibly by resizing the block at p (if it is not null), but in any case keeping any existing contents of p. Should the allocation fail, it is logged to syslog and the program aborted with abort()
. Returns a unique pointer even if amt is zero.
char* safe_strdup | ( | const char * | str | ) |
Copy a string.
str | Existing string (may not be 0). |
This function will copy str (which may not be 0), allocating the required amount of memory for it. Should the allocation fail, it is logged to syslog and the program aborted with abort()
.