Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #include <kdb.h>
10 :
11 : #include <stdio.h>
12 :
13 0 : int main (void)
14 : {
15 0 : KeySet * config = ksNew (0, KS_END);
16 0 : Key * root = keyNew ("user/test", KEY_END);
17 :
18 0 : printf ("Open key database\n");
19 0 : KDB * handle = kdbOpen (root);
20 :
21 0 : printf ("Retrieve key set\n");
22 0 : kdbGet (handle, config, root);
23 :
24 0 : printf ("Number of key-value pairs: %zd\n", ksGetSize (config));
25 :
26 0 : Key * key = keyNew ("user/test/hello", KEY_VALUE, "elektra", KEY_END);
27 0 : printf ("Add key %s\n", keyName (key));
28 0 : ksAppendKey (config, key);
29 0 : printf ("Number of key-value pairs: %zd\n", ksGetSize (config));
30 0 : printf ("\n%s, %s\n\n", keyBaseName (key), keyString (key));
31 :
32 : // If you want to store the key database on disk, then please uncomment the following two lines
33 : // printf ("Write key set to disk\n");
34 : // kdbSet (handle, config, root);
35 :
36 0 : printf ("Delete key-value pairs inside memory\n");
37 0 : ksDel (config);
38 0 : printf ("Close key database\n");
39 0 : kdbClose (handle, 0);
40 :
41 : return 0;
42 : }
|