lib/tdb2: Do not include config.h in (to-be) public library, use replace.
authorAmitay Isaacs <amitay@gmail.com>
Tue, 21 Feb 2012 04:59:17 +0000 (15:29 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 21 Feb 2012 04:59:17 +0000 (15:29 +1030)
Like tdb1, it's the caller's responsibility to set up various config
options (eg. by #include "config.h") before including the public
header.

We use HAVE_CCAN for including the (private) CCAN headers, otherwise
dummy macros are used.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/tdb2/private.h
lib/tdb2/tdb2.h

index 91d3ca09333d80d8f5b07644ca15c1f27030d73b..31790bc3351cbb51e5f26b8b6d2b13a3c3976700 100644 (file)
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "config.h"
+#ifndef HAVE_CCAN
+#error You need ccan to build tdb2!
+#endif
 #include "tdb2.h"
+#include <ccan/compiler/compiler.h>
 #include <ccan/likely/likely.h>
 #include <ccan/endian/endian.h>
 
index 44e7897993fa0389a88bcc3b6c78d9ef58c0b842..4782117e9751a0dff2e99e2597e4945855998052 100644 (file)
@@ -29,9 +29,8 @@
 extern "C" {
 #endif
 
-#include "config.h"
 #ifdef HAVE_LIBREPLACE
-#include "replace.h"
+#include <replace.h>
 #else
 #if HAVE_FILE_OFFSET_BITS
 #define _FILE_OFFSET_BITS 64
@@ -49,9 +48,25 @@ extern "C" {
 /* For memcmp */
 #include <string.h>
 #endif
+
+#if HAVE_CCAN
 #include <ccan/compiler/compiler.h>
 #include <ccan/typesafe_cb/typesafe_cb.h>
 #include <ccan/cast/cast.h>
+#else
+#ifndef typesafe_cb_preargs
+/* Failing to have CCAN just mean less typesafe protection, etc. */
+#define typesafe_cb_preargs(rtype, atype, fn, arg, ...)        \
+       ((rtype (*)(__VA_ARGS__, atype))(fn))
+#endif
+#ifndef cast_const
+#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
+#define cast_const(type, expr) ((type)((intptr_t)(expr)))
+#else
+#define cast_const(type, expr) ((type *)(expr))
+#endif
+#endif
+#endif /* !HAVE_CCAN */
 
 union tdb_attribute;
 struct tdb_context;