+/**
+ * Copy data to write head of a buffer pool and feed it to all children nodes.
+ *
+ * \param src The source buffer.
+ * \param n The size of the source buffer in bytes.
+ * \param btrp The destination buffer pool.
+ * \param btrn Add the data as output of this node.
+ *
+ * This is expensive. The caller must make sure the data fits into the buffer
+ * pool area.
+ */
+void btr_copy(const void *src, size_t n, struct btr_pool *btrp,
+ struct btr_node *btrn)
+{
+ char *buf;
+ size_t sz, copy;
+
+ if (n == 0)
+ return;
+ assert(n <= btr_pool_unused(btrp));
+ sz = btr_pool_get_buffer(btrp, &buf);
+ copy = PARA_MIN(sz, n);
+ memcpy(buf, src, copy);
+ btr_add_output_pool(btrp, copy, btrn);
+ if (copy == n)
+ return;
+ sz = btr_pool_get_buffer(btrp, &buf);
+ assert(sz >= n - copy);
+ memcpy(buf, src + copy, n - copy);
+ btr_add_output_pool(btrp, n - copy, btrn);
+}
+