.TH "libwget-xalloc" 3 "Mon Aug 7 2017" "Version 1.0.0" "wget2" \" -*- nroff -*- .ad l .nh .SH NAME libwget-xalloc .SH SYNOPSIS .br .PP .SS "Functions" .in +1c .ti -1c .RI "void \fBwget_set_oomfunc\fP (void(*oom_callback)(void))" .br .ti -1c .RI "void * \fBwget_malloc\fP (size_t size)" .br .ti -1c .RI "void * \fBwget_calloc\fP (size_t nmemb, size_t size)" .br .ti -1c .RI "void * \fBwget_realloc\fP (void *ptr, size_t size)" .br .ti -1c .RI "void \fBwget_free\fP (void *ptr)" .br .in -1c .SH "Detailed Description" .PP 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\&. .PP You can provide a out-of-memory function that will be called before exit(), e\&.g\&. to print out a 'No memory' message\&. .PP To work around this behavior, provide your own allocation routines, namely malloc(), calloc(), realloc()\&. .SH "Function Documentation" .PP .SS "void wget_set_oomfunc (void(*)(void) oom_callback)" .PP \fBParameters:\fP .RS 4 \fIoom_callback\fP Pointer to your custom out-of-memory function .RE .PP Set a custom out-of-memory function\&. .SS "void* wget_malloc (size_t size)" .PP \fBParameters:\fP .RS 4 \fIsize\fP Number of bytes to allocate .RE .PP \fBReturns:\fP .RS 4 A pointer to the allocated (uninitialized) memory .RE .PP 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); .SS "void* wget_calloc (size_t nmemb, size_t size)" .PP \fBParameters:\fP .RS 4 \fInmemb\fP Number of elements (each of size \fCsize\fP) to allocate .br \fIsize\fP Size of element .RE .PP \fBReturns:\fP .RS 4 A pointer to the allocated (initialized) memory .RE .PP 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); .SS "void* wget_realloc (void * ptr, size_t size)" .PP \fBParameters:\fP .RS 4 \fIptr\fP Pointer to old memory area .br \fIsize\fP Number of bytes to allocate for the new memory area .RE .PP \fBReturns:\fP .RS 4 A pointer to the new memory area .RE .PP Like the standard realloc(), except that it doesn't return NULL values\&. If an out-of-memory condition occurs \fIor\fP size is 0, the oom callback function is called (if set)\&. Thereafter the application is terminated by exit(EXIT_FAILURE); .SS "void wget_free (void * ptr)" .PP \fBParameters:\fP .RS 4 \fIptr\fP Pointer to memory-pointer to be freed .RE .PP This function is like free()\&. .PP It is basically needed on systems where the library malloc heap is different from the caller's malloc heap, which happens on Windows when the library is a separate DLL\&. .PP To prevent typical use-after-free issues, use the macro wget_xfree()\&. .SH "Author" .PP Generated automatically by Doxygen for wget2 from the source code\&.