Arax -8d09c51940345c86062e8ef2427c705ae66e5926
A Runtime Framework for Decoupling Applications from Heterogeneous Accelerators
Loading...
Searching...
No Matches
config.h File Reference
#include <stddef.h>
+ Include dependency graph for config.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  utils_config_source { CONFIG_FILE , CONFIG_ENV }
 

Functions

char * utils_config_alloc_path (const char *path)
 
void utils_config_free_path (char *path)
 
int utils_config_get_str (char *path, const char *key, char *value, size_t value_size, const char *def_val)
 
int utils_config_get_bool (char *path, const char *key, int *value, int def_val)
 
int utils_config_get_int (char *path, const char *key, int *value, int def_val)
 
int utils_config_get_long (char *path, const char *key, long *value, long def_val)
 
int utils_config_get_size (char *path, const char *key, size_t *value, size_t def_val)
 
enum utils_config_source utils_config_get_source ()
 

Detailed Description

Persistent configuration utility functions.

Configuration file format: Each line(terminated with a newline character
) contains a single key value pair in the following format:

KEY VALUE
The key value can have any printable character except white space, it should not be larger than 32 characters. The value begins after KEY and any whites-pace after it. Value ends at the first newline character.

Definition in file config.h.

Enumeration Type Documentation

◆ utils_config_source

Enumerator
CONFIG_FILE 
CONFIG_ENV 

Definition at line 141 of file config.h.

Function Documentation

◆ utils_config_alloc_path()

char * utils_config_alloc_path ( const char * path)

Create configuration based on path

NOTE: free returned value with utils_config_free_path().

path is scanned for the following characters and replaced: ~:Gets replaced with users home path (e.g. /home/user)

Parameters
path
Returns
NULL on failure

Definition at line 94 of file config.c.

References arax_assert, and system_home_path().

Referenced by _arax_init(), arax_clean(), async_meta_init_always(), and async_meta_init_once().

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

◆ utils_config_free_path()

void utils_config_free_path ( char * path)

Free path allocated with utils_config_alloc_path.

Parameters
pathReturn value of a utils_config_alloc_path invocation.

Definition at line 128 of file config.c.

Referenced by arax_clean(), arax_exit(), async_meta_init_always(), and async_meta_init_once().

+ Here is the caller graph for this function:

◆ utils_config_get_bool()

int utils_config_get_bool ( char * path,
const char * key,
int * value,
int def_val )

Get value corresponding to key as a boolean (0,1)

Will search the path file for a key/value pair matching the key. If the value is not found 0 will be returned. If during the search any error occurs, 0 will be returned and a message will be printed on stderr. If the value is found and the value equals to 1 then *value will be assigned 1, otherwise *value will be set to 0.

Note
This is a very slow function, use it only during initialization.
Parameters
pathConfig path.
keyc style string, with the key of interest.
valuepointer to allocated array of size value_size.
def_valDefault value in case the key is not found.
Returns
Zero on failure.

Definition at line 178 of file config.c.

References utils_config_get_int().

Referenced by _arax_init(), and async_meta_init_once().

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

◆ utils_config_get_int()

int utils_config_get_int ( char * path,
const char * key,
int * value,
int def_val )

Get value corresponding to key as an integer

Will search the path file for a key/value pair matching the key. If during the search any error occurs, 0 will be returned and a message will be printed on stderr. If the value is found it will be converted to an integer using atoi() and the result will be assigned to val. If no value is found val will be assigned def_val and 0 will be returned.

Note
This is a very slow function, use it only during initialization.
Parameters
pathConfig path.
keyc style string string, with the key of interest.
valuepointer to allocated array of size value_size.
def_valDefault value in case the key is not found.
Returns
Zero on failure.

Definition at line 190 of file config.c.

References utils_config_get_long().

Referenced by utils_config_get_bool().

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

◆ utils_config_get_long()

int utils_config_get_long ( char * path,
const char * key,
long * value,
long def_val )

Get value corresponding to key as a long

Will search the path file for a key/value pair matching the key. If during the search any error occurs, 0 will be returned and a message will be printed on stderr. If the value is found it will be converted to a long using strtol() and the result will be assigned to val. If no value is found val will be assigned def_val and 0 will be returned.

Note
This is a very slow function, use it only during initialization.
Parameters
pathConfig path.
keyc style string string, with the key of interest.
valuepointer to allocated array of size value_size.
def_valDefault value in case the key is not found.
Returns
Zero on failure.

Definition at line 206 of file config.c.

References _utils_config_get_str(), and utils_config_write_long().

Referenced by utils_config_get_int(), and utils_config_get_size().

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

◆ utils_config_get_size()

int utils_config_get_size ( char * path,
const char * key,
size_t * value,
size_t def_val )

Get value corresponding to key as a size_t

Value is retrieved with utils_config_get_long(). If acquired value value is in [SIZE_MAX,0] it is assigned to val and 1 is returned.

Otherwise 0 is returned and val is assigned def_val.

Note
This function only works for numbers <= 2^63.
Parameters
pathConfig path.
keyc style string string, with the key of interest.
valuepointer to allocated array of size value_size.
def_valDefault value in case value was not found/appropriate.
Returns
Zero on failure.

Definition at line 226 of file config.c.

References utils_config_get_long().

Referenced by _arax_init().

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

◆ utils_config_get_source()

enum utils_config_source utils_config_get_source ( )

Return the current configuration source.

See also
utils_config_source

Definition at line 242 of file config.c.

References CONFIG_ENV, CONFIG_FILE, and system_env_var().

Referenced by _arax_init(), conf_get(), and conf_set().

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

◆ utils_config_get_str()

int utils_config_get_str ( char * path,
const char * key,
char * value,
size_t value_size,
const char * def_val )

Get value corresponding to key as a string

Will search the path file for a key/value pair matching the key. If the value is not found 0 will be returned. If during the search any error occurs, 0 will be returned and a message will be printed on stderr.

Note
This is a very slow function, use it only during initialization.
Parameters
pathConfig path, returned by utils_config_alloc_path.
keyc style string string, with the key of interest.
valuepointer to allocated array of size value_size.
value_sizeSize of value array, in bytes.
def_valDefault value in case the key is not found.
Returns
Zero on failure.

Definition at line 164 of file config.c.

References _utils_config_get_str(), and utils_config_write_str().

Referenced by _arax_init(), arax_clean(), and async_meta_init_always().

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