-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproperty.c
More file actions
54 lines (47 loc) · 1.13 KB
/
property.c
File metadata and controls
54 lines (47 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <aul/hashtable.h>
#include <kernel.h>
#include <kernel-priv.h>
extern hashtable_t properties;
void property_set(const char * name, const char * value)
{
hashentry_t * entry = hashtable_get(&properties, name);
if (entry == NULL)
{
property_t * prop = malloc(sizeof(property_t));
memset(prop, 0, sizeof(property_t));
prop->name = strdup(name);
prop->value = strdup(value);
hashtable_put(&properties, prop->name, &prop->entry);
}
else
{
property_t * prop = hashtable_entry(entry, property_t, entry);
free(prop->value);
prop->value = strdup(value);
}
}
void property_clear(const char * name)
{
hashentry_t * entry = hashtable_get(&properties, name);
if (entry != NULL)
{
hashtable_remove(entry);
property_t * prop = hashtable_entry(entry, property_t, entry);
free(prop->name);
free(prop->value);
free(prop);
}
}
const char * property_get(const char * name)
{
hashentry_t * entry = hashtable_get(&properties, name);
if (entry == NULL)
{
return NULL;
}
return hashtable_entry(entry, property_t, entry)->value;
}
bool property_isset(const char * name)
{
return hashtable_get(&properties, name) != NULL;
}