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 : Key * k;
16 : Key * c;
17 : const Key * meta;
18 0 : k = keyNew ("user/metakey", KEY_END);
19 0 : c = keyNew ("user/metacopy", KEY_END);
20 :
21 0 : keySetMeta (k, "hello", "hello_world");
22 :
23 0 : keySetMeta (k, "mode", "0644");
24 0 : keySetMeta (k, "time", "1271234264");
25 0 : keySetMeta (k, "empty", "");
26 :
27 0 : meta = keyGetMeta (k, "hello");
28 0 : printf ("Metadata %s has the value %s with the value size %zd\n", keyName (meta), (const char *) keyValue (meta),
29 : keyGetValueSize (meta));
30 0 : printf ("Metadata mode has the value %s\n", (const char *) keyValue (keyGetMeta (k, "mode")));
31 0 : printf ("Metadata time has the value %s\n", (const char *) keyValue (keyGetMeta (k, "time")));
32 0 : printf ("Metadata empty has the value %s\n", (const char *) keyValue (keyGetMeta (k, "empty")));
33 :
34 0 : if (!keyGetMeta (k, "nonexist")) printf ("Check if a metadata exist\n");
35 :
36 0 : keySetMeta (k, "hello", "between");
37 0 : keyCopyMeta (c, k, "hello");
38 :
39 0 : if (keyGetMeta (k, "hello") == keyGetMeta (c, "hello")) printf ("Check if they point to the same metadata after a copy\n");
40 :
41 0 : printf ("Metadata hello now has the value %s\n", (const char *) keyValue (keyGetMeta (k, "hello")));
42 :
43 0 : keySetMeta (k, "hello", 0);
44 :
45 0 : printf ("Metadata hello now has the value %s (after dropping)\n", (const char *) keyValue (keyGetMeta (k, "hello")));
46 :
47 0 : keySetMeta (k, "hello", "goodbye");
48 :
49 0 : printf ("Metadata hello now has the value %s\n", (const char *) keyValue (keyGetMeta (k, "hello")));
50 :
51 0 : printf ("Now we will output all metadata of the key:\n");
52 0 : keyRewindMeta (k);
53 0 : while ((meta = keyNextMeta (k)) != 0)
54 : {
55 0 : printf ("%s=%s\n", keyName (meta), (const char *) keyValue (meta));
56 : }
57 :
58 0 : keyDel (k);
59 :
60 : return 0;
61 : }
|