]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/_info
ccanlint: fix dependencies on tests_pass_without_features.
[ccan] / ccan / tdb2 / _info
1 #include <string.h>
2 #include <stdio.h>
3
4 /**
5  * tdb2 - [[WORK IN PROGRESS!]] The trivial (64bit transactional) database
6  *
7  * The tdb2 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.
10  *
11  * Example:
12  *      #include <ccan/tdb2/tdb2.h>
13  *      #include <ccan/str/str.h>
14  *      #include <err.h>
15  *      #include <stdio.h>
16  *      
17  *      static void usage(const char *argv0)
18  *      {
19  *              errx(1, "Usage: %s fetch <dbfile> <key>\n"
20  *                   "OR %s store <dbfile> <key> <data>", argv0, argv0);
21  *      }
22  *      
23  *      int main(int argc, char *argv[])
24  *      {
25  *              struct tdb_context *tdb;
26  *              TDB_DATA key, value;
27  *              enum TDB_ERROR error;
28  *
29  *              if (argc < 4)
30  *                      usage(argv[0]);
31  *      
32  *              tdb = tdb_open(argv[2], TDB_DEFAULT, O_CREAT|O_RDWR,0600, NULL);
33  *              if (!tdb)
34  *                      err(1, "Opening %s", argv[2]);
35  *      
36  *              key.dptr = (void *)argv[3];
37  *              key.dsize = strlen(argv[3]);
38  *      
39  *              if (streq(argv[1], "fetch")) {
40  *                      if (argc != 4)
41  *                              usage(argv[0]);
42  *                      error = tdb_fetch(tdb, key, &value);
43  *                      if (error)
44  *                              errx(1, "fetch %s: %s",
45  *                                   argv[3], tdb_errorstr(error));
46  *                      printf("%.*s\n", value.dsize, (char *)value.dptr);
47  *                      free(value.dptr);
48  *              } else if (streq(argv[1], "store")) {
49  *                      if (argc != 5)
50  *                              usage(argv[0]);
51  *                      value.dptr = (void *)argv[4];
52  *                      value.dsize = strlen(argv[4]);
53  *                      error = tdb_store(tdb, key, value, 0);
54  *                      if (error)
55  *                              errx(1, "store %s: %s",
56  *                                   argv[3], tdb_errorstr(error));
57  *              } else
58  *                      usage(argv[0]);
59  *      
60  *              return 0;
61  *      }
62  *
63  * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
64  *
65  * Author: Rusty Russell
66  *
67  * License: LGPL (v3 or any later version)
68  */
69 int main(int argc, char *argv[])
70 {
71         if (argc != 2)
72                 return 1;
73
74         if (strcmp(argv[1], "depends") == 0) {
75                 printf("ccan/asprintf\n");
76                 printf("ccan/hash\n");
77                 printf("ccan/likely\n");
78                 printf("ccan/asearch\n");
79                 printf("ccan/compiler\n");
80                 printf("ccan/build_assert\n");
81                 printf("ccan/ilog\n");
82                 printf("ccan/failtest\n");
83                 printf("ccan/tally\n");
84                 printf("ccan/typesafe_cb\n");
85                 printf("ccan/cast\n");
86                 printf("ccan/endian\n");
87                 return 0;
88         }
89
90         return 1;
91 }