forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloElektra.c
42 lines (32 loc) · 1.01 KB
/
helloElektra.c
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
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include <kdb.h>
#include <stdio.h>
int main (void)
{
KeySet * config = ksNew (0, KS_END);
Key * root = keyNew ("user:/test", KEY_END);
printf ("Open key database\n");
KDB * handle = kdbOpen (NULL, root);
printf ("Retrieve key set\n");
kdbGet (handle, config, root);
printf ("Number of key-value pairs: %zd\n", ksGetSize (config));
Key * key = keyNew ("user:/test/hello", KEY_VALUE, "elektra", KEY_END);
printf ("Add key %s\n", keyName (key));
ksAppendKey (config, key);
printf ("Number of key-value pairs: %zd\n", ksGetSize (config));
printf ("\n%s, %s\n\n", keyBaseName (key), keyString (key));
// If you want to store the key database on disk, then please uncomment the following two lines
// printf ("Write key set to disk\n");
// kdbSet (handle, config, root);
printf ("Delete key-value pairs inside memory\n");
ksDel (config);
printf ("Close key database\n");
kdbClose (handle, 0);
return 0;
}