Lumiera  0.pre.03
»edit your freedom«
safeclib.h File Reference

Go to the source code of this file.

Description

Portable and safe wrappers around some C-Lib functions.

Definition in file safeclib.h.

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

Functions

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

Function Documentation

◆ lumiera_safeclib_set_resourcecollector()

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 initialised and removed from it before shut down. Without resourcecollector failed allocations will abort().

Parameters
hookpointer to the resourcecollector_run function, must be of type lumiera_resourcecollector_run_fn but we don't want a dependency on vault in this header

◆ lumiera_malloc()

void* lumiera_malloc ( size_t  sz)

Allocate memory.

always succeeds or dies

Parameters
sizememory to be allocated
Returns
pointer to the allocated memory

Definition at line 122 of file safeclib.c.

References LUMIERA_RESOURCE_ONE.

Referenced by lumiera_plugin_new().

+ Here is the caller graph for this function:

◆ lumiera_calloc()

void* lumiera_calloc ( size_t  n,
size_t  size 
)

Allocate cleared memory for an array.

always succeeds or dies

Parameters
nnumber of elements
sizememory to be allocated
Returns
pointer to the allocated memory

Definition at line 139 of file safeclib.c.

References LUMIERA_RESOURCE_ONE.

◆ lumiera_realloc()

void* lumiera_realloc ( void *  ptr,
size_t  size 
)

Change the size of a memory block.

Parameters
ptrpointer to the old memory block obtained by lumiera_malloc or lumiera_calloc
sizenew size of the block
Returns
address of new block

Definition at line 158 of file safeclib.c.

References LUMIERA_RESOURCE_ONE.

◆ lumiera_free()

static void lumiera_free ( void *  mem)
inlinestatic

Free previously allocated memory.

Parameters
mempointer to the memory block obtained by lumiera_malloc or lumiera_calloc

Definition at line 82 of file safeclib.h.

References lumiera_streq(), lumiera_strncmp(), and lumiera_strndup().

+ Here is the call graph for this function:

◆ lumiera_strndup()

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

Duplicate a C string.

always succeeds or dies

Parameters
strstring to be copied
lenmaximal length to be copied
Returns
pointer to the new string, "" if NULL was passed as str

Definition at line 175 of file safeclib.c.

References LUMIERA_RESOURCE_ONE.

Referenced by lumiera_free(), and lumiera_plugin_new().

+ Here is the caller graph for this function:

◆ lumiera_strncmp()

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
afirst string for comparsion
bsecond string for comparsion
lenmaximal length for the comparsion
Returns
0 if the strings are identical, -1 if smaller 1 if bigger.

Definition at line 193 of file safeclib.c.

Referenced by lumiera_free(), and lumiera_streq().

+ Here is the caller graph for this function:

◆ lumiera_streq()

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

check 2 strings for identity.

Parameters
afirst string for comparsion
bsecond string for comparsion
Returns
1 when the strings are the the same, 0 if not.

Definition at line 200 of file safeclib.c.

References lumiera_strncmp().

Referenced by lumiera_free().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: