_info 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * enum TDB_ERROR error;
  27. *
  28. * if (argc < 4)
  29. * usage(argv[0]);
  30. *
  31. * tdb = tdb_open(argv[2], TDB_DEFAULT, O_CREAT|O_RDWR,0600, NULL);
  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(argv[0]);
  41. * error = tdb_fetch(tdb, key, &value);
  42. * if (error)
  43. * errx(1, "fetch %s: %s",
  44. * argv[3], tdb_errorstr(error));
  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(argv[0]);
  50. * value.dptr = (void *)argv[4];
  51. * value.dsize = strlen(argv[4]);
  52. * error = tdb_store(tdb, key, value, 0);
  53. * if (error)
  54. * errx(1, "store %s: %s",
  55. * argv[3], tdb_errorstr(error));
  56. * } else
  57. * usage(argv[0]);
  58. *
  59. * return 0;
  60. * }
  61. *
  62. * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
  63. *
  64. * Author: Rusty Russell
  65. *
  66. * License: LGPLv3 (or later)
  67. *
  68. * Ccanlint:
  69. * // hash fails because it accesses data in 4 byte quantities for speed.
  70. * tests_pass_valgrind --partial-loads-ok=yes
  71. */
  72. int main(int argc, char *argv[])
  73. {
  74. if (argc != 2)
  75. return 1;
  76. if (strcmp(argv[1], "depends") == 0) {
  77. printf("ccan/hash\n");
  78. printf("ccan/likely\n");
  79. printf("ccan/asearch\n");
  80. printf("ccan/compiler\n");
  81. printf("ccan/build_assert\n");
  82. printf("ccan/ilog\n");
  83. printf("ccan/failtest\n");
  84. printf("ccan/tally\n");
  85. return 0;
  86. }
  87. return 1;
  88. }