else return ((a + m - BLEN(b)%m)%m);
}
+/* --- @{,d}buf_align@ --- *
+ *
+ * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block
+ * @size_t m, a@ = alignment multiple and offset
+ * @size_t *sz_out@ = where to put the length
+ *
+ * Returns: Pointer to previous buffer position, or null on error.
+ *
+ * Use: Advance the buffer position as little as possible such that
+ * it is @a@ greater than a multiple of @m@, returning the
+ * (possibly empty) portion of the buffer passed over.
+ */
+
+void *buf_align(buf *b, size_t m, size_t a, size_t *sz_out)
+{
+ size_t sz;
+
+ if (BBAD(b)) return (0);
+ sz = align_step(b, m, a); *sz_out = sz;
+ return (buf_get(b, sz));
+}
+void *(dbuf_align)(dbuf *db, size_t m, size_t a, size_t *sz_out)
+ { return (dbuf_align(db, m, a, sz_out)); }
+
/* --- @{,d}buf_alignskip@ --- *
*
* Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block