5 * tdb - The trivial (transactional) database
7 * The tdb module provides an efficient keyword data mapping (usually
8 * within a file). It supports transactions, so the contents of the
9 * database is reliable even across crashes.
12 * #include <ccan/tdb/tdb.h>
13 * #include <ccan/str/str.h>
17 * static void usage(const char *argv0)
19 * errx(1, "Usage: %s fetch <dbfile> <key>\n"
20 * "OR %s store <dbfile> <key> <data>", argv0, argv0);
23 * int main(int argc, char *argv[])
25 * struct tdb_context *tdb;
26 * TDB_DATA key, value;
31 * tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
34 * err(1, "Opening %s", argv[2]);
36 * key.dptr = (void *)argv[3];
37 * key.dsize = strlen(argv[3]);
39 * if (streq(argv[1], "fetch")) {
42 * value = tdb_fetch(tdb, key);
44 * errx(1, "fetch %s: %s",
45 * argv[3], tdb_errorstr(tdb));
46 * printf("%.*s\n", value.dsize, (char *)value.dptr);
48 * } else if (streq(argv[1], "store")) {
51 * value.dptr = (void *)argv[4];
52 * value.dsize = strlen(argv[4]);
53 * if (tdb_store(tdb, key, value, 0) != 0)
54 * errx(1, "store %s: %s",
55 * argv[3], tdb_errorstr(tdb));
62 * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
64 * Author: Andrew Tridgell, Jeremy Allison, Rusty Russell
66 * License: LGPLv3 (or later)
69 * // valgrind breaks fcntl locks.
70 * tests_pass_valgrind FAIL
72 int main(int argc, char *argv[])
77 if (strcmp(argv[1], "depends") == 0) {
78 printf("ccan/compiler\n");