cctools
Functions
xxmalloc.h File Reference

Brittle memory allocation routines. More...

#include <sys/types.h>

Go to the source code of this file.

Functions

void * xxmalloc (size_t nbytes)
 Allocate memory, or abort on failure. More...
 
char * xxstrdup (const char *str)
 Duplicate string, or abort on failure. More...
 

Detailed Description

Brittle memory allocation routines.

These routines may be used in place of malloc and strdup. If they fail due to the (rare) possibility of heap exhaustion, they will abort by calling fatal with an appropriate error message. Thus, the caller of these routines need not continually check for a null pointer return.

Function Documentation

void* xxmalloc ( size_t  nbytes)

Allocate memory, or abort on failure.

Parameters
nbytesThe amount of memory to allocate.
Returns
On success, returns a valid pointer. On failure, aborts by calling fatal.
char* xxstrdup ( const char *  str)

Duplicate string, or abort on failure.

Parameters
strThe string to duplicate.
Returns
On success, returns a valid pointer. On failure, aborts by calling fatal.