/usr/share/doc/libelektra-dev/examples/keyset.c is in libelektra-dev 0.8.7-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 55 56 57 58 59 60 61 62 63 64 65 | #include <kdb.h>
#include <stdio.h>
void f (const Key * source)
{
Key * dup = keyDup (source);
printf ("\tin f\n");
keyDel (dup);
}
void g (const Key * source, KeySet * ks)
{
Key * dup = keyDup (source);
printf ("\tin g\n");
ksAppendKey (ks, dup);
}
void h (Key *k)
{
Key * c = keyNew("user/from/h", KEY_END);
printf ("\tin h\n");
keyCopy (k, c);
keyDel (c);
/* the caller will see the changed key k */
}
int main()
{
Key * origKey;
KeySet * ks = ksNew(0);
Key * key = keyNew ("user/test/name",
KEY_VALUE, "myvalue",
KEY_END);
printf ("Created key %s with value %s\n",
keyName(key), keyString(key));
f(key);
printf ("Key is unchanged with value %s\n",
keyString(key));
g(key, ks);
printf ("A duplication was appended in keyset with name %s\n",
keyName(ksHead(ks)));
h(key);
printf ("Key has changed to name %s with value %s\n",
keyName(key), keyString(key));
/* key is yet independent */
keyDel (key);
ksRewind (ks);
origKey = ksNext (ks);
key = keyDup (origKey);
printf ("A duplication of the key %s with value %s\n",
keyName(key), keyString(key));
keyDel (key);
ksDel (ks);
return 0;
}
|