Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xmalloc.h File Reference

Convenient alternatives for malloc and friends. More...

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

void * xmalloc (size_t size)
 Reserve size bytes of memory on the heap.

void * xrealloc (void *ptr, size_t size)
 Change the size of a reserved memory block.

char * xstrdup (const char *str)
 Duplicate a string.


Detailed Description

Convenient alternatives for malloc and friends.

These functions work just like their standard counterparts without the 'x' prefix, but also check for out-of-memory conditions.

Definition in file xmalloc.h.


Function Documentation

void* xmalloc size_t    size
 

Reserve size bytes of memory on the heap.

If there is not enough free memory to reserve size bytes, an error message is sent to the system log, and the application exits with EXIT_FAILURE.

Parameters:
size  Number of bytes to reserve.
Returns:
A pointer to the reserved memory.

Definition at line 33 of file xmalloc.c.

void* xrealloc void *    ptr,
size_t    size
 

Change the size of a reserved memory block.

If there is not enough free memory to reserve size bytes, an error message is sent to the system log, and the application exits with EXIT_FAILURE.

Parameters:
ptr  Pointer to the memory block that will be resized. If NULL, this function works like a xmalloc.
size  New size of the memory block.
Returns:
A pointer to the resized memory block.

Definition at line 48 of file xmalloc.c.

char* xstrdup const char *    str
 

Duplicate a string.

This function attempt to reserve enough memory to hold a copy of the null-terminated string pointed to by str. If this fails, an error message is sent to the system log, and the application exits with EXIT_FAILURE.

Parameters:
str  Pointer to a null-terminated string.
Returns:
A pointer to a memory area that holds a copy of str.

Definition at line 67 of file xmalloc.c.


Generated on Sun Feb 16 23:40:04 2003 for FreeLCD by doxygen1.2.18