Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
tmpbuf.c File Reference

Implementation of temporary buffers with round-robin usage pattern. More...

Go to the source code of this file.

Description

Implementation of temporary buffers with round-robin usage pattern.

Warning
this is the restored old version from bc989dab7a97fc69c (July 2010) (the improved version is still buggy as of 5/2011)

Definition in file tmpbuf.c.

#include "lib/safeclib.h"
#include "lib/tmpbuf.h"
#include <string.h>
#include <pthread.h>
#include <stdint.h>
#include <stdarg.h>
#include <nobug.h>

Classes

struct  lumiera_tmpbuf_struct
 

Functions

void lumiera_tmpbuf_freeall (void)
 free all buffers associated with this thread.
 
static void lumiera_tmpbuf_destroy (void *buf)
 
static void lumiera_tmpbuf_init (void)
 
void * lumiera_tmpbuf_provide (size_t size)
 Query a thread local tmpbuf.
 
char * lumiera_tmpbuf_strndup (const char *src, size_t size)
 Duplicate string to a tmpbuf.
 
char * lumiera_tmpbuf_snprintf (size_t size, const char *fmt,...)
 Construct a string in a tmpbuf.
 
char * lumiera_tmpbuf_strcat3 (const char *str1, size_t str1_len, const char *str2, size_t str2_len, const char *str3, size_t str3_len)
 Concat up to 3 strings in a tmpbuf.
 
char * lumiera_tmpbuf_tr (const char *in, const char *from, const char *to, const char *def)
 Translates characters in a string, similar to the shell 'tr' utility.
 

Variables

static pthread_once_t lumiera_tmpbuf_tls_once = PTHREAD_ONCE_INIT
 
static pthread_key_t lumiera_tmpbuf_tls_key
 

Class Documentation

◆ lumiera_tmpbuf_struct

struct lumiera_tmpbuf_struct
Class Members
void * buffers[64]
size_t sizes[64]
unsigned idx
+ Collaboration diagram for lumiera_tmpbuf_struct:

Function Documentation

◆ lumiera_tmpbuf_freeall()

void lumiera_tmpbuf_freeall ( void  )

free all buffers associated with this thread.

This function is called automatically, usually one doesnt need to call it.

Definition at line 64 of file tmpbuf.c.

References lumiera_tmpbuf_struct::buffers, lumiera_tmpbuf_struct::idx, lumiera_free(), lumiera_tmpbuf_init(), LUMIERA_TMPBUF_NUM, lumiera_tmpbuf_tls_key, lumiera_tmpbuf_tls_once, and NULL.

Referenced by lumiera_tmpbuf_destroy(), lumiera_tmpbuf_init(), and main().

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

◆ lumiera_tmpbuf_destroy()

static void lumiera_tmpbuf_destroy ( void *  buf)
static

Definition at line 49 of file tmpbuf.c.

References lumiera_tmpbuf_freeall().

Referenced by lumiera_tmpbuf_init().

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

◆ lumiera_tmpbuf_init()

static void lumiera_tmpbuf_init ( void  )
static

Definition at line 56 of file tmpbuf.c.

References lumiera_tmpbuf_destroy(), lumiera_tmpbuf_freeall(), and lumiera_tmpbuf_tls_key.

Referenced by lumiera_tmpbuf_freeall(), and lumiera_tmpbuf_provide().

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

◆ lumiera_tmpbuf_provide()

void * lumiera_tmpbuf_provide ( size_t  size)

Query a thread local tmpbuf.

Parameters
sizeminimal needed size for the tmpbuf
Returns
the tmpbuf

Definition at line 80 of file tmpbuf.c.

References lumiera_tmpbuf_struct::buffers, lumiera_tmpbuf_struct::idx, lumiera_calloc(), lumiera_free(), lumiera_malloc(), lumiera_tmpbuf_init(), lumiera_tmpbuf_tls_key, lumiera_tmpbuf_tls_once, and lumiera_tmpbuf_struct::sizes.

Referenced by lumiera_tmpbuf_snprintf(), lumiera_tmpbuf_strndup(), main(), and TEST().

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

◆ lumiera_tmpbuf_strndup()

char * lumiera_tmpbuf_strndup ( const char *  src,
size_t  size 
)

Duplicate string to a tmpbuf.

Parameters
srcstring to be duplicated
sizemaximal length to be copied
Returns
temporary buffer containing a copy of the string

Definition at line 102 of file tmpbuf.c.

References lumiera_tmpbuf_provide().

Referenced by lumiera_config_setdefault(), lumiera_config_wordlist_get_nth(), lumiera_tmpbuf_tr(), scan_string(), and scan_word().

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

◆ lumiera_tmpbuf_snprintf()

char * lumiera_tmpbuf_snprintf ( size_t  size,
const char *  fmt,
  ... 
)

Construct a string in a tmpbuf.

Parameters
sizemaximal length for the string
fmtprintf like formatstring
...parameters
Returns
temporary buffer containing the constructed of the string

Definition at line 116 of file tmpbuf.c.

References lumiera_tmpbuf_provide(), and NULL.

Referenced by lumiera_config_get(), lumiera_config_init(), lumiera_config_lookup_insert_default(), lumiera_config_number_get(), lumiera_config_number_set(), lumiera_config_set(), lumiera_config_string_set(), lumiera_config_word_set(), lumiera_config_wordlist_add(), lumiera_config_wordlist_replace(), lumiera_config_wordlist_set(), lumiera_configitem_set_value(), lumiera_plugin_discover(), lumiera_plugin_load_DYNLIB(), lumiera_tmpbuf_strcat3(), main(), main(), TEST(), TEST(), and TEST().

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

◆ lumiera_tmpbuf_strcat3()

char * lumiera_tmpbuf_strcat3 ( const char *  str1,
size_t  str1_len,
const char *  str2,
size_t  str2_len,
const char *  str3,
size_t  str3_len 
)

Concat up to 3 strings in a tmpbuf.

Parameters
str1first string to concat or NULL
str1_lenhow much of the first string shall be used
str2second string to concat or NULL
str2_lenhow much of the second string shall be used
str3third string to concat or NULL
str3_lenhow much of the third string shall be used
Returns
temporary buffer containing the constructed of the string

Definition at line 135 of file tmpbuf.c.

References lumiera_tmpbuf_snprintf().

Referenced by lumiera_config_lookup_insert().

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

◆ lumiera_tmpbuf_tr()

char * lumiera_tmpbuf_tr ( const char *  in,
const char *  from,
const char *  to,
const char *  def 
)

Translates characters in a string, similar to the shell 'tr' utility.

Parameters
ininput string to be translated
fromsource character set
todestination character set
defdefault destination character when a character is not in the source set, when NULL then translation will abort on unknown characters and return NULL, when "" then unknown characters will be removed when set to a single character string, unknown characters will be replaced with this character
Returns
temporary buffer containing the constructed of the string

Definition at line 147 of file tmpbuf.c.

References lumiera_tmpbuf_strndup(), and NULL.

Referenced by lumiera_config_get(), TEST(), TEST(), and TEST().

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

Variable Documentation

◆ lumiera_tmpbuf_tls_once

pthread_once_t lumiera_tmpbuf_tls_once = PTHREAD_ONCE_INIT
static

Definition at line 42 of file tmpbuf.c.

Referenced by lumiera_tmpbuf_freeall(), and lumiera_tmpbuf_provide().

◆ lumiera_tmpbuf_tls_key

pthread_key_t lumiera_tmpbuf_tls_key
static

Definition at line 43 of file tmpbuf.c.

Referenced by lumiera_tmpbuf_freeall(), lumiera_tmpbuf_init(), and lumiera_tmpbuf_provide().