4#define _POSIX_C_SOURCE 200809L
13#define CWIST_CONFIG_BUCKETS 64
19static size_t cwist_config_hash(
const char *key) {
31 if (!cfg)
return NULL;
67 if (!cfg || !key)
return;
85 if (!bucket->
key || !bucket->
value) {
103 if (!cfg || !key)
return NULL;
185 if (!cfg || !path)
return;
192 if (*
p ==
'#' || *
p ==
'\0')
continue;
197 char *value =
eq + 1;
200 while (
ke > key &&
isspace((
unsigned char)*
ke)) *
ke-- =
'\0';
202 while (
isspace((
unsigned char)*value)) value++;
203 char *
ve = value +
strlen(value) - 1;
204 while (
ve > value &&
isspace((
unsigned char)*
ve)) *
ve-- =
'\0';
206 if (value[0] ==
'"' &&
ve == value +
strlen(value) - 1 && *
ve ==
'"') {
Memory allocation wrappers backed by libttak.
void cwist_free(void *ptr)
Free memory obtained via cwist_alloc/cwist_strdup/etc.
char * cwist_strdup(const char *src)
Duplicate a string using libttak-backed storage.
#define CWIST_DEFER_FREE
Attach to a pointer variable's declaration to cwist_free() it automatically when that variable's encl...
void * cwist_alloc_array(size_t count, size_t elem_size)
Allocate zeroed memory for count elements.
void * cwist_alloc(size_t size)
Allocate zeroed memory tracked by libttak.
int cwist_config_get_int(cwist_config *cfg, const char *key, int default_val)
Get a config value parsed as an integer.
#define CWIST_CONFIG_BUCKETS
void cwist_config_load_file(cwist_config *cfg, const char *path)
Load key/value pairs from a simple properties-style file. Each non-blank, non-comment line must be ke...
void cwist_config_load_env(cwist_config *cfg, const char *prefix)
Load key/value pairs from the process environment into the config. Entries without '=' are skipped....
cwist_config * cwist_config_create(void)
Create an empty config store.
void cwist_config_destroy(cwist_config *cfg)
Free a config store and all of its key/value entries.
bool cwist_config_get_bool(cwist_config *cfg, const char *key, bool default_val)
Get a config value parsed as a boolean. Accepted true spellings (case-insensitive): "true",...
void cwist_config_set(cwist_config *cfg, const char *key, const char *value)
Set a config key to a value, replacing any existing entry.
const char * cwist_config_get(cwist_config *cfg, const char *key)
Look up the value for a key.
Application configuration management (.env, environment variables).
struct cwist_config_bucket * next
cwist_config_bucket ** buckets