feat(vars): vars
This commit is contained in:
parent
b7b6a6a8d5
commit
d377b80803
2 changed files with 63 additions and 0 deletions
32
src/utils/vars/vars.c
Normal file
32
src/utils/vars/vars.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#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));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue