32 lines
702 B
C
32 lines
702 B
C
#define _POSIX_C_SOURCE 200809L
|
|
#include "vars.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
|
|
#include "../hash_map/hash_map.h"
|
|
|
|
#define VARS_INITIAL_SIZE 16
|
|
|
|
struct hash_map *vars_init(void)
|
|
{
|
|
return hash_map_init(VARS_INITIAL_SIZE);
|
|
}
|
|
|
|
char *get_var(const struct hash_map *vars, const char *key)
|
|
{
|
|
return (char *)hash_map_get(vars, key);
|
|
}
|
|
|
|
bool set_var(struct hash_map *vars, const char *key, const char *value)
|
|
{
|
|
if (key == NULL || value == NULL)
|
|
return false;
|
|
return hash_map_insert(vars, key, (void *)value, NULL);
|
|
}
|
|
|
|
bool set_var_copy(struct hash_map *vars, const char *key, const char *value)
|
|
{
|
|
return set_var(vars, strdup(key), strdup(value));
|
|
}
|