wget2  1.0.0
Memory allocation functions

Functions

void wget_set_oomfunc (void(*oom_callback)(void))
 
void * wget_malloc (size_t size)
 
void * wget_calloc (size_t nmemb, size_t size)
 
void * wget_realloc (void *ptr, size_t size)
 

Detailed Description

The provided memory allocation functions are used by explicit libwget memory allocations. They differ from the standard ones in that they exit the program in an out-of-memory situation with EXIT_FAILURE. That means, you don't have to check the returned value against NULL.

You can provide a out-of-memory function that will be called before exit(), e.g. to print out a "No memory" message.

To work around this behavior, provide your own allocation routines, namely malloc(), calloc(), realloc().

Function Documentation

◆ wget_set_oomfunc()

void wget_set_oomfunc ( void(*)(void)  oom_callback)
Parameters
[in]oom_callbackPointer to your custom out-of-memory function

Set a custom out-of-memory function.

◆ wget_malloc()

void* wget_malloc ( size_t  size)
Parameters
[in]sizeNumber of bytes to allocate
Returns
A pointer to the allocated (uninitialized) memory

Like the standard malloc(), except that it doesn't return NULL values. If an out-of-memory condition occurs the oom callback function is called (if set). Thereafter the application is terminated by exit(EXIT_FAILURE);

◆ wget_calloc()

void* wget_calloc ( size_t  nmemb,
size_t  size 
)
Parameters
[in]nmembNumber of elements (each of size size) to allocate
[in]sizeSize of element
Returns
A pointer to the allocated (initialized) memory

Like the standard calloc(), except that it doesn't return NULL values. If an out-of-memory condition occurs the oom callback function is called (if set). Thereafter the application is terminated by exit(EXIT_FAILURE);

◆ wget_realloc()

void* wget_realloc ( void *  ptr,
size_t  size 
)
Parameters
[in]ptrPointer to old memory area
[in]sizeNumber of bytes to allocate for the new memory area
Returns
A pointer to the new memory area

Like the standard realloc(), except that it doesn't return NULL values. If an out-of-memory condition occurs or size is 0, the oom callback function is called (if set). Thereafter the application is terminated by exit(EXIT_FAILURE);