_info 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <string.h>
  2. #include <stdio.h>
  3. /**
  4. * tdb2 - [[WORK IN PROGRESS!]] The trivial (64bit transactional) database
  5. *
  6. * The tdb2 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/tdb2/tdb2.h>
  12. * #include <ccan/str/str.h>
  13. * #include <err.h>
  14. * #include <stdio.h>
  15. *
  16. * static void usage(const char *argv0)
  17. * {
  18. * errx(1, "Usage: %s fetch <dbfile> <key>\n"
  19. * "OR %s store <dbfile> <key> <data>", argv0, argv0);
  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(argv[0]);
  29. *
  30. * tdb = tdb_open(argv[2], TDB_DEFAULT, O_CREAT|O_RDWR,0600, NULL);
  31. * if (!tdb)
  32. * err(1, "Opening %s", argv[2]);
  33. *
  34. * key.dptr = (void *)argv[3];
  35. * key.dsize = strlen(argv[3]);
  36. *
  37. * if (streq(argv[1], "fetch")) {
  38. * if (argc != 4)
  39. * usage(argv[0]);
  40. * value = tdb_fetch(tdb, key);
  41. * if (!value.dptr)
  42. * errx(1, "fetch %s: %s",
  43. * argv[3], tdb_errorstr(tdb));
  44. * printf("%.*s\n", value.dsize, (char *)value.dptr);
  45. * free(value.dptr);
  46. * } else if (streq(argv[1], "store")) {
  47. * if (argc != 5)
  48. * usage(argv[0]);
  49. * value.dptr = (void *)argv[4];
  50. * value.dsize = strlen(argv[4]);
  51. * if (tdb_store(tdb, key, value, 0) != 0)
  52. * errx(1, "store %s: %s",
  53. * argv[3], tdb_errorstr(tdb));
  54. * } else
  55. * usage(argv[0]);
  56. *
  57. * return 0;
  58. * }
  59. *
  60. * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
  61. *
  62. * Author: Rusty Russell
  63. *
  64. * Licence: LGPLv3 (or later)
  65. *
  66. * Fails:
  67. * valgrind-tests // hash needs --partial-loads-ok=yes.
  68. */
  69. int main(int argc, char *argv[])
  70. {
  71. if (argc != 2)
  72. return 1;
  73. if (strcmp(argv[1], "depends") == 0) {
  74. printf("ccan/hash\n");
  75. printf("ccan/likely\n");
  76. printf("ccan/asearch\n");
  77. printf("ccan/compiler\n");
  78. printf("ccan/build_assert\n");
  79. printf("ccan/tally\n");
  80. return 0;
  81. }
  82. return 1;
  83. }