X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/beee81ec8fc4857080e809c759575c4267f7bd1f..3fec494b9a24b7835b3efb33e61b01146fc08201:/struct/buf.h diff --git a/struct/buf.h b/struct/buf.h index 212bd72..8201c49 100644 --- a/struct/buf.h +++ b/struct/buf.h @@ -289,6 +289,42 @@ extern int buf_fill(buf */*b*/, int /*ch*/, size_t /*sz*/); extern int dbuf_fill(dbuf */*db*/, int /*ch*/, size_t /*sz*/); #define dbuf_fill(db, ch, sz) (buf_fill(DBUF_BUF(db), (ch), (sz))) +/* --- @{,d}buf_alignskip@ --- * + * + * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block + * @size_t m, a@ = alignment multiple and offset + * + * Returns: Zero if it worked, nonzero if there wasn't enough space. + * + * Use: Advance the buffer position as little as possible such that + * it is @a@ greater than a multiple of @m@. This doesn't write + * anything to the buffer, so it's probably not suitable for + * output: use @buf_alignfill@ instead. + */ + +extern int buf_alignskip(buf */*b*/, size_t /*m*/, size_t /*a*/); +extern int dbuf_alignskip(dbuf */*db*/, size_t /*m*/, size_t /*a*/); +#define dbuf_alignskip(db, m, a) (buf_alignskip(DBUF_BUF(db), (m), (a))) + +/* --- @{,d}buf_alignfill@ --- * + * + * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block + * @int ch@ = fill character + * @size_t m, a@ = alignment multiple and offset + * + * Returns: Zero if it worked, nonzero if there wasn't enough space. + * + * Use: Fill the buffer with as few copies of @ch@ as possible, as if + * by @memset@, to advance the buffer position to a value @a@ + * greater than a multiple of @m@. + */ + +extern int buf_alignfill(buf */*b*/, int /*ch*/, size_t /*m*/, size_t /*a*/); +extern int (dbuf_alignfill)(dbuf */*db*/, int /*ch*/, + size_t /*m*/, size_t /*a*/); +#define dbuf_alignfill(db, ch, m, a) \ + (buf_alignfill(DBUF_BUF(db), (ch), (a), (m))) + /* --- @{,d}buf_getbyte@ --- * * * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block