]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb2.h
licence->license: US English is the standard for code.
[ccan] / ccan / tdb2 / tdb2.h
index 48c5ba65d0b316cb34a5a23a390a1559ca3dd565..343264d588f0a04db188556f6f1f1f542cd4cd2b 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
 /* For uint64_t */
 #include <stdint.h>
 #endif
+#include <ccan/compiler/compiler.h>
 
 /* flags to tdb_store() */
 #define TDB_REPLACE 1          /* Unused */
@@ -52,19 +53,19 @@ extern "C" {
 #define TDB_INTERNAL 2 /* don't store on disk */
 #define TDB_NOLOCK   4 /* don't do any locking */
 #define TDB_NOMMAP   8 /* don't use mmap */
-#define TDB_CONVERT 16 /* convert endian (internal use) */
-#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
+#define TDB_CONVERT 16 /* convert endian */
 #define TDB_NOSYNC   64 /* don't use synchronous transactions */
 #define TDB_SEQNUM   128 /* maintain a sequence number */
 #define TDB_VOLATILE   256 /* Activate the per-hashchain freelist, default 5 */
 #define TDB_ALLOW_NESTING 512 /* Allow transactions to nest */
-#define TDB_DISALLOW_NESTING 1024 /* Disallow transactions to nest */
 
 /* error codes */
 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, 
-               TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
-               TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY,
-               TDB_ERR_NESTING};
+               TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST,
+               TDB_ERR_EINVAL, TDB_ERR_RDONLY, TDB_ERR_NESTING };
+
+/* flags for tdb_summary. Logical or to combine. */
+enum tdb_summary_flags { TDB_SUMMARY_HISTOGRAMS = 1 };
 
 /* debugging uses one of the following levels */
 enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, 
@@ -75,21 +76,10 @@ typedef struct tdb_data {
        size_t dsize;
 } TDB_DATA;
 
-#ifndef PRINTF_ATTRIBUTE
-#if (__GNUC__ >= 3)
-/** Use gcc attribute to check printf fns.  a1 is the 1-based index of
- * the parameter containing the format, and a2 the index of the first
- * argument. Note that some gcc 2.x versions don't handle this
- * properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-#endif
-
 struct tdb_context;
 
 /* FIXME: Make typesafe */
+typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
 typedef void (*tdb_logfn_t)(struct tdb_context *, enum tdb_debug_level, void *priv, const char *, ...) PRINTF_ATTRIBUTE(4, 5);
 typedef uint64_t (*tdb_hashfn_t)(const void *key, size_t len, uint64_t seed,
                                 void *priv);
@@ -129,11 +119,24 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 struct tdb_data tdb_fetch(struct tdb_context *tdb, struct tdb_data key);
 int tdb_delete(struct tdb_context *tdb, struct tdb_data key);
 int tdb_store(struct tdb_context *tdb, struct tdb_data key, struct tdb_data dbuf, int flag);
+int tdb_append(struct tdb_context *tdb, struct tdb_data key, struct tdb_data dbuf);
+int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
+int64_t tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *p);
+int64_t tdb_traverse_read(struct tdb_context *tdb,
+                         tdb_traverse_func fn, void *p);
+TDB_DATA tdb_firstkey(struct tdb_context *tdb);
+TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key);
 int tdb_close(struct tdb_context *tdb);
 int tdb_check(struct tdb_context *tdb,
              int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
              void *private_data);
 
+enum TDB_ERROR tdb_error(struct tdb_context *tdb);
+const char *tdb_errorstr(struct tdb_context *tdb);
+
+char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags);
+
 extern struct tdb_data tdb_null;
 
 #ifdef  __cplusplus