]> git.ozlabs.org Git - ccan/blob - ccan/tdb/_info
75f20b455c1a414f18622e17648a57301e1630c6
[ccan] / ccan / tdb / _info
1 #include <string.h>
2
3 /**
4  * tdb - The trivial (transactional) database
5  *
6  * The tdb module provides an efficient keyword data mapping (usually
7  * within a file).  It supports transactions, so the contents of the
8  * database is reliable even across crashes.
9  *
10  * Example:
11  *      #include <ccan/tdb/tdb.h>
12  *      #include <ccan/str/str.h>
13  *      #include <err.h>
14  *      #include <stdio.h>
15  *      
16  *      static void usage(void)
17  *      {
18  *              errx(1, "Usage: %s fetch <dbfile> <key>\n"
19  *                   "OR %s store <dbfile> <key> <data>");
20  *      }
21  *      
22  *      int main(int argc, char *argv[])
23  *      {
24  *              struct tdb_context *tdb;
25  *              TDB_DATA key, value;
26  *      
27  *              if (argc < 4)
28  *                      usage();
29  *      
30  *              tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
31  *                              0600);
32  *              if (!tdb)
33  *                      err(1, "Opening %s", argv[2]);
34  *      
35  *              key.dptr = (void *)argv[3];
36  *              key.dsize = strlen(argv[3]);
37  *      
38  *              if (streq(argv[1], "fetch")) {
39  *                      if (argc != 4)
40  *                              usage();
41  *                      value = tdb_fetch(tdb, key);
42  *                      if (!value.dptr)
43  *                              errx(1, "fetch %s: %s",
44  *                                   argv[3], tdb_errorstr(tdb));
45  *                      printf("%.*s\n", value.dsize, (char *)value.dptr);
46  *                      free(value.dptr);
47  *              } else if (streq(argv[1], "store")) {
48  *                      if (argc != 5)
49  *                              usage();
50  *                      value.dptr = (void *)argv[4];
51  *                      value.dsize = strlen(argv[4]);
52  *                      if (tdb_store(tdb, key, value, 0) != 0)
53  *                              errx(1, "store %s: %s",
54  *                                   argv[3], tdb_errorstr(tdb));
55  *              } else
56  *                      usage();
57  *      
58  *              return 0;
59  *      }
60  *
61  * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
62  *
63  * Author: Andrew Tridgell, Jeremy Allison, Rusty Russell
64  *
65  * Licence: LGPLv3 (or later)
66  */
67 int main(int argc, char *argv[])
68 {
69         if (argc != 2)
70                 return 1;
71
72         if (strcmp(argv[1], "depends") == 0)
73                 return 0;
74
75         return 1;
76 }