Git init
[pkgs/e/elektra.git] / examples / small.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <kdb.h>
4
5 void BailOut (char * msg)
6 {
7         fprintf (stderr, "%s\n", msg);
8         exit (1);
9 }
10
11 int main(void)
12 {
13         KDB * h;
14         KeySet * myConfig = ksNew(0);
15         Key    * myKey;
16         char   * myValue;
17
18         /* Open the Key Database */
19         if (!(h = kdbOpen()))
20                 BailOut ("Could not open Key Database");
21
22         /* Get the hello world keyset */
23         if (kdbGetByName(h, myConfig, "/", 0) == -1)
24                 BailOut ("Could not get Keys");
25
26         /* Find the key in the keyset */
27         if ((myKey = ksLookupByName (myConfig, "/hello", 0)) == NULL)
28                 BailOut ("Could not Lookup Key");
29
30         /* Get the value of the key */
31         if ((myValue = (char*) keyValue (myKey)) == NULL)
32                 BailOut ("Could not get Keyvalue");
33
34         /* Actually print the key */
35         printf ("%s\n", myValue);
36         /* Close and free KeySet */
37         ksDel(myConfig);
38         /* Close the Key database */
39         kdbClose(h);
40
41         return 0;
42 }
43