51static struct rbnode *config_section_create(
config_t *config,
const char *name);
52static void config_section_destroy(
struct rbnode *node);
54static const char *config_section_set(
55 struct rbnode *node,
const char *
key,
const char *value);
57static void config_section_foreach(
69 const char *
key,
const char *value);
70static void config_entry_destroy(
struct rbnode *node);
75 void *ptr = malloc(
sizeof(
struct __config));
84__config_free(
void *ptr)
90__config_init(
struct __config *config,
int flags)
97 if (!config_section_create(config,
""))
104__config_fini(
struct __config *config)
110 config_section_destroy(node);
119 config_t *config = __config_alloc();
122 goto error_alloc_config;
125 if (!__config_init(config, flags)) {
127 goto error_init_config;
133 __config_free(config);
143 __config_fini(config);
144 __config_free(config);
158 for (
size_t i = 0; node && i < n; node =
rbnode_next(node), i++)
159 sections[i] = node->
key;
185 for (
size_t i = 0; node && i < n; node =
rbnode_next(node), i++)
232 node = config_section_create(config, section);
234 return node ? config_section_set(node,
key, value) : NULL;
245 config_section_foreach(node, func, data);
248 const char *section = node->
key;
250 if (!section || !*section)
252 config_section_foreach(node, func, data);
257config_section_create(
config_t *config,
const char *name)
269 goto error_alloc_section;
274 node->
key = malloc(strlen(name) + 1);
279 goto error_alloc_key;
281 strcpy((
char *)node->
key, name);
297config_section_destroy(
struct rbnode *node)
307 config_entry_destroy(
node);
314config_section_set(
struct rbnode *
node,
const char *key,
const char *value)
324 config_entry_destroy(
node);
329 node = config_entry_create(section, key, value);
334config_section_foreach(
363 goto error_alloc_entry;
368 node->
key = malloc(strlen(
key) + 1);
373 goto error_alloc_key;
375 strcpy((
char *)node->
key,
key);
377 entry->
value = malloc(strlen(value) + 1);
382 goto error_alloc_value;
384 strcpy(entry->
value, value);
392 free((
char *)node->
key);
401config_entry_destroy(
struct rbnode *node)
This header file is part of the utilities library; it contains the comparison function definitions.
const char * config_set(config_t *config, const char *section, const char *key, const char *value)
Sets a key in or removes a key from a configuration struct.
void config_foreach(const config_t *config, config_foreach_func_t *func, void *data)
Invokes a function for each key in a configuration struct.
size_t config_get_sections(const config_t *config, size_t n, const char **sections)
Retrieves a list of section names from a configuration struct.
config_t * config_create(int flags)
Creates a new configuration struct with an unnamed empty root section.
size_t config_get_keys(const config_t *config, const char *section, size_t n, const char **keys)
Retrieves a list of key names from a section in a configuration struct.
const char * config_get(const config_t *config, const char *section, const char *key)
Retrieves a key from a configuration struct.
void config_destroy(config_t *config)
Destroys a configuration struct.
This header file is part of the utilities library; it contains the configuration functions.
void config_foreach_func_t(const char *section, const char *key, const char *value, void *data)
The type of a function called by config_foreach() for each key in a configuration struct.
@ CONFIG_CASE
Section and key names are case-insensitive.
This header file is part of the utilities library; it contains the native and platform-independent er...
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
This header file is part of the utilities library; it contains the red-black tree declarations.
void rbtree_insert(struct rbtree *tree, struct rbnode *node)
Inserts a node into a red-black tree.
struct rbnode * rbtree_find(const struct rbtree *tree, const void *key)
Finds a node in a red-black tree.
struct rbnode * rbtree_first(const struct rbtree *tree)
Returns a pointer to the first (leftmost) node in a red-black tree.
struct rbnode * rbnode_next(const struct rbnode *node)
Returns a pointer to the next (in-order) node in a red-black tree with respect to node.
void rbtree_init(struct rbtree *tree, rbtree_cmp_t *cmp)
Initializes a red-black tree.
size_t rbtree_size(const struct rbtree *tree)
Returns the size (in number of nodes) of a red-black tree.
void rbtree_remove(struct rbtree *tree, struct rbnode *node)
Removes a node from a red-black tree.
#define rbtree_foreach(tree, node)
Iterates over each node in a red-black tree in ascending order.
This is the internal header file of the utilities library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
This header file is part of the C11 and POSIX compatibility library; it includes <string....
struct rbtree tree
The tree containing the sections.
An entry in a configuration section.
char * value
The value of the entry.
struct rbnode node
The node of this entry in the tree of entries.
A section in a configuration struct.
struct rbnode node
The node of this section in the tree of sections.
struct rbtree tree
The tree containing the entries.
A node in a red-black tree.
const void * key
A pointer to the key for this node.
rbtree_cmp_t * cmp
A pointer to the function used to compare two keys.