lib/safeclib.h File Reference


Detailed Description

Portable and safe wrappers around some clib functions and some tools.

Definition in file safeclib.h.

#include "error.h"
#include <stdlib.h>

Include dependency graph for safeclib.h:

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

Go to the source code of this file.

Functions

void * lumiera_calloc (size_t n, size_t size)
 Allocate cleared memory for an array.
 LUMIERA_ERROR_DECLARE (NO_MEMORY)
static void lumiera_free (void *mem)
 Free previously allocated memory.
void * lumiera_malloc (size_t sz)
 Allocate memory.
void * lumiera_realloc (void *ptr, size_t size)
 Change the size of a memory block.
void lumiera_safeclib_set_resourcecollector (void *hook)
 Install the resourcecollector run hook.
int lumiera_streq (const char *a, const char *b)
 check 2 strings for identity.
int lumiera_strncmp (const char *a, const char *b, size_t len)
 Compare two C strings.
char * lumiera_strndup (const char *str, size_t len)
 Duplicate a C string.


Function Documentation

void lumiera_safeclib_set_resourcecollector ( void *  hook  ) 

Install the resourcecollector run hook.

The resourcecollectr must be hooked into the safeclib at bootup after it got initialized and removed from it before shut down. Without resourcecollector failed allocations will abort().

Parameters:
hook pointer to the resourcecollector_run function, must be of type lumiera_resourcecollector_run_fn but we dont want a dependency on backend in this header

Definition at line 49 of file safeclib.c.

void* lumiera_malloc ( size_t  sz  ) 

Allocate memory.

always succeeds or dies

Parameters:
size memory to be allocated
Returns:
pointer to the allocated memory

Definition at line 59 of file safeclib.c.

void* lumiera_calloc ( size_t  n,
size_t  size 
)

Allocate cleared memory for an array.

always succeeds or dies

Parameters:
n number of elements
size memory to be allocated
Returns:
pointer to the allocated memory

Definition at line 74 of file safeclib.c.

void* lumiera_realloc ( void *  ptr,
size_t  size 
)

Change the size of a memory block.

Parameters:
ptr pointer to the old memory block obtained by lumiera_malloc or lumiera_calloc
size new size of the block
Returns:
address of new block

Definition at line 91 of file safeclib.c.

static void lumiera_free ( void *  mem  )  [inline, static]

Free previously allocated memory.

Parameters:
mem pointer to the memory block obtained by lumiera_malloc or lumiera_calloc

Definition at line 80 of file safeclib.h.

Referenced by lumiera_config_destroy(), lumiera_file_delete(), lumiera_file_delete_unlink(), lumiera_file_destroy(), lumiera_file_new(), lumiera_filedescriptor_delete(), lumiera_filehandlecache_delete(), lumiera_mrucache_age(), lumiera_mrucache_destroy(), lumiera_thread_delete(), and lumiera_tmpbuf_provide().

Here is the caller graph for this function:

char* lumiera_strndup ( const char *  str,
size_t  len 
)

Duplicate a C string.

always succeeds or dies

Parameters:
str string to be copied
len maximal length to be copied
Returns:
pointer to the new string, "" if NULL was passed as str

Definition at line 106 of file safeclib.c.

int lumiera_strncmp ( const char *  a,
const char *  b,
size_t  len 
)

Compare two C strings.

Handles NULL pointers as "", shortcut for same addresses

Parameters:
a first string for comparsion
b second string for comparsion
len maximal length for the comparsion
Returns:
0 if the strings are identical, -1 if smaller 1 if bigger.

Definition at line 123 of file safeclib.c.

int lumiera_streq ( const char *  a,
const char *  b 
)

check 2 strings for identity.

Parameters:
a first string for comparsion
b second string for comparsion
Returns:
1 when the strings are the the same, 0 if not.

Definition at line 130 of file safeclib.c.


Generated on Sun Aug 1 21:31:31 2010 for Lumiera by  doxygen 1.5.6