]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/test/helper.h
tal/str: use tal/talloc backend #ifdef TAL_USE_TALLOC.
[ccan] / ccan / tal / str / test / helper.h
diff --git a/ccan/tal/str/test/helper.h b/ccan/tal/str/test/helper.h
new file mode 100644 (file)
index 0000000..c1bc9cc
--- /dev/null
@@ -0,0 +1,22 @@
+/* tal/talloc can't implement tal_first/tal_next. */
+#ifdef TAL_USE_TALLOC
+static inline bool no_children(const void *ctx)
+{
+       return talloc_total_blocks(ctx) == 1;
+}
+
+static inline bool single_child(const void *ctx, const void *child)
+{
+       return talloc_total_blocks(ctx) == 2 && tal_parent(child) == ctx;
+}
+#else
+static inline bool no_children(const void *ctx)
+{
+       return !tal_first(ctx);
+}
+
+static inline bool single_child(const void *ctx, const void *child)
+{
+       return tal_first(ctx) == child && !tal_next(ctx, child);
+}
+#endif