X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb2.h;h=fa5787c3779acd424e7f3cbde6a4c5e6746eb45d;hb=082d651ffd87f78f20d56aa477c3c75d7361c1e1;hp=4f5be81950d069fa9dbe5bb8492f0086ed50f708;hpb=f6067e4cbd7b7415571f12438aec00faec5657fb;p=ccan diff --git a/ccan/tdb2/tdb2.h b/ccan/tdb2/tdb2.h index 4f5be819..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()