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.
char * | xxstrdup (const char *str)
| Duplicate string, or abort on failure.

## 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

## xxmalloc()

void * xxmalloc | ( | size_t | nbytes | ) |

Allocate memory, or abort on failure.

Parameters

  nbytes | The amount of memory to allocate.

Returns
  On success, returns a valid pointer. On failure, aborts by calling fatal.

## xxstrdup()

char * xxstrdup | ( | const char * | str | ) |

Duplicate string, or abort on failure.

Parameters

  str | The string to duplicate.

Returns
  On success, returns a valid pointer. On failure, aborts by calling fatal.