X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb2.h;h=fa5787c3779acd424e7f3cbde6a4c5e6746eb45d;hb=66711021849dd07cd29383c9ed40ab4b9f3d1e07;hp=0940be1ceac40797435eaaa6241cbdd0e787484f;hpb=8d8de08d9079f503256e1682dfa93bb22dcd4ad0;p=ccan diff --git a/ccan/tdb2/tdb2.h b/ccan/tdb2/tdb2.h index 0940be1c..fa5787c3 100644 --- a/ccan/tdb2/tdb2.h +++ b/ccan/tdb2/tdb2.h @@ -45,6 +45,7 @@ extern "C" { #endif #include #include +#include union tdb_attribute; struct tdb_context; @@ -221,6 +222,24 @@ static inline bool tdb_deq(struct tdb_data a, struct tdb_data b) return a.dsize == b.dsize && memcmp(a.dptr, b.dptr, a.dsize) == 0; } +/** + * tdb_mkdata - make a struct tdb_data from const data + * @p: the constant pointer + * @len: the length + * + * As the dptr member of struct tdb_data is not constant, you need to + * cast it. This function keeps thost casts in one place, as well as + * suppressing the warning some compilers give when casting away a + * qualifier (eg. gcc with -Wcast-qual) + */ +static inline struct tdb_data tdb_mkdata(const void *p, size_t len) +{ + struct tdb_data d; + d.dptr = cast_const(void *, p); + d.dsize = len; + return d; +} + /** * tdb_transaction_start - start a transaction * @tdb: the tdb context returned from tdb_open() @@ -430,6 +449,17 @@ enum TDB_ERROR tdb_check_(struct tdb_context *tdb, void *private), void *private); +/** + * tdb_error - get the last error (not threadsafe) + * @tdb: the tdb context returned from tdb_open() + * + * Returns the last error returned by a TDB function. + * + * This makes porting from TDB1 easier, but note that the last error is not + * reliable in threaded programs. + */ +enum TDB_ERROR tdb_error(struct tdb_context *tdb); + /** * enum tdb_summary_flags - flags for tdb_summary. */