Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
safeclib.h File Reference

Portable and safe wrappers around some C-Lib functions. More...

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

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

Function Documentation

◆ LUMIERA_ERROR_DECLARE()

LUMIERA_ERROR_DECLARE ( NO_MEMORY  )

◆ 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 113 of file safeclib.c.

References die_no_mem(), LUMIERA_RESOURCE_MEMORY, LUMIERA_RESOURCE_ONE, and NULL.

Referenced by init_exts_globs(), lumiera_config_init(), lumiera_config_lookupentry_new(), lumiera_configentry_new(), lumiera_configitem_new(), lumiera_interfacenode_new(), lumiera_plugin_new(), lumiera_tmpbuf_provide(), TEST(), TEST(), and TEST().

+ Here is the call graph for this function:
+ 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 130 of file safeclib.c.

References die_no_mem(), LUMIERA_RESOURCE_MEMORY, LUMIERA_RESOURCE_ONE, and NULL.

Referenced by lumiera_tmpbuf_provide(), and push_dependency().

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

◆ 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 149 of file safeclib.c.

References die_no_mem(), LUMIERA_RESOURCE_MEMORY, LUMIERA_RESOURCE_ONE, and NULL.

Referenced by push_dependency().

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

◆ 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 73 of file safeclib.h.

Referenced by lumiera_config_destroy(), lumiera_config_lookupentry_delete(), lumiera_config_lookupentry_destroy(), lumiera_configitem_delete(), lumiera_configitem_destroy(), lumiera_configitem_parse(), lumiera_interfacenode_delete(), lumiera_tmpbuf_freeall(), and lumiera_tmpbuf_provide().

+ Here is the caller 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 166 of file safeclib.c.

References die_no_mem(), LUMIERA_RESOURCE_MEMORY, LUMIERA_RESOURCE_ONE, and NULL.

Referenced by lumiera_config_lookupentry_init(), lumiera_configitem_parse(), and lumiera_plugin_new().

+ Here is the call graph for this function:
+ 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 184 of file safeclib.c.

Referenced by 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 191 of file safeclib.c.

References lumiera_strncmp().

Referenced by TEST().

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