tdb2: change API to return the error value.
[ccan] / ccan / tdb2 / _info
index 661fb7d2db285bc8f9efba41da78d1f68933883c..114b60b2182c7daefbaf585b15c9d9f3a2cc2033 100644 (file)
  *     #include <err.h>
  *     #include <stdio.h>
  *     
- *     static void usage(void)
+ *     static void usage(const char *argv0)
  *     {
  *             errx(1, "Usage: %s fetch <dbfile> <key>\n"
- *                  "OR %s store <dbfile> <key> <data>");
+ *                  "OR %s store <dbfile> <key> <data>", argv0, argv0);
  *     }
  *     
  *     int main(int argc, char *argv[])
  *     {
  *             struct tdb_context *tdb;
  *             TDB_DATA key, value;
- *     
+ *             enum TDB_ERROR error;
+ *
  *             if (argc < 4)
- *                     usage();
+ *                     usage(argv[0]);
  *     
- *             tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
- *                             0600);
+ *             tdb = tdb_open(argv[2], TDB_DEFAULT, O_CREAT|O_RDWR,0600, NULL);
  *             if (!tdb)
  *                     err(1, "Opening %s", argv[2]);
  *     
  *     
  *             if (streq(argv[1], "fetch")) {
  *                     if (argc != 4)
- *                             usage();
- *                     value = tdb_fetch(tdb, key);
- *                     if (!value.dptr)
+ *                             usage(argv[0]);
+ *                     error = tdb_fetch(tdb, key, &value);
+ *                     if (error)
  *                             errx(1, "fetch %s: %s",
- *                                  argv[3], tdb_errorstr(tdb));
+ *                                  argv[3], tdb_errorstr(error));
  *                     printf("%.*s\n", value.dsize, (char *)value.dptr);
  *                     free(value.dptr);
  *             } else if (streq(argv[1], "store")) {
  *                     if (argc != 5)
- *                             usage();
+ *                             usage(argv[0]);
  *                     value.dptr = (void *)argv[4];
  *                     value.dsize = strlen(argv[4]);
- *                     if (tdb_store(tdb, key, value, 0) != 0)
+ *                     error = tdb_store(tdb, key, value, 0);
+ *                     if (error)
  *                             errx(1, "store %s: %s",
- *                                  argv[3], tdb_errorstr(tdb));
+ *                                  argv[3], tdb_errorstr(error));
  *             } else
- *                     usage();
+ *                     usage(argv[0]);
  *     
  *             return 0;
  *     }
  *
  * Author: Rusty Russell
  *
- * Licence: LGPLv3 (or later)
+ * License: LGPLv3 (or later)
  *
- * Fails:
- *     valgrind-tests // hash needs --partial-loads-ok=yes.
+ * Ccanlint:
+ *     // hash fails because it accesses data in 4 byte quantities for speed.
+ *     tests_pass_valgrind --partial-loads-ok=yes
  */
 int main(int argc, char *argv[])
 {
@@ -77,7 +79,10 @@ int main(int argc, char *argv[])
                printf("ccan/hash\n");
                printf("ccan/likely\n");
                printf("ccan/asearch\n");
+               printf("ccan/compiler\n");
                printf("ccan/build_assert\n");
+               printf("ccan/ilog\n");
+               printf("ccan/failtest\n");
                printf("ccan/tally\n");
                return 0;
        }