/* * */ #include "variables.h" #include "strmap.h" static strmap *map; bool init_variable_store(void) { map = strmap_create(hash_key); return map; } bool add_variable(const char *key, const char *val) { if (strmap_put(map, key, val) != STRMAP_OK) { return false; } return true; } const char *get_variable(const char *key) { key += (key[0] == '$'); const char *val; strmap_status stat = strmap_get(map, key, &val); switch (stat) { case STRMAP_OK: break; case STRMAP_NOTFOUND: val = getenv(key); break; default: val = NULL; break; } return (val) ? val : ""; } bool promote_variable_to_env(const char *key) { const char *val = get_variable(key); if (!val) { val = ""; } return !setenv(key, val, 1); } void destroy_variable_store() { strmap_destroy(map); }