chiark / gitweb /
@@@ tty mess
[mLib] / struct / buf.3.in
index f3c2e7f569b717f8a3d08c17fbfaca3fb4eb0700..6a3a68ca850b72b53eafa24ac857a861fddfd414 100644 (file)
 .\" @dbuf_put
 .\" @dbuf_fill
 .
+.\" @buf_align
 .\" @buf_alignskip
 .\" @buf_alignfill
+.\" @dbuf_align
 .\" @dbuf_alignskip
 .\" @dbuf_alignfill
 .
@@ -545,6 +547,7 @@ and taking a first argument of type
 .BI "int buf_put(buf *" b ", const void *" p ", size_t " sz );
 .BI "int buf_fill(buf *" b ", int " ch ", size_t " sz );
 .PP
+.BI "int buf_align(buf *" b ", size_t " m ", size_t " a ", size_t *" sz_out );
 .BI "int buf_alignskip(buf *" b ", size_t " m ", size_t " a );
 .BI "int buf_alignfill(buf *" b ", int " ch ", size_t " m ", size_t " a );
 .PP
@@ -850,16 +853,33 @@ to the buffer, as if by calling
 If it succeeds, it returns 0; otherwise it returns \-1.
 .PP
 The
-.B buf_alignskip
-function advances the buffer's position as little as possible,
+.B buf_align
+function tries to advance the buffer's position as little as possible,
 so as to cause the position to be
 .I a
 bytes more than a multiple of
-.IR m .
-If
+.IR m ;
+if
 .I m
-is zero then nothing is done.
-The buffer contents are not altered.
+is zero then no change is needed.
+If the buffer is broken, then
+.B buf_align
+immediately returns null.
+Otherwise, it sets
+.BI * sz_out
+to the number of bytes \(en possibly zero \(en
+by which the position would have to advance
+in order to achieve the requested alignment.
+If there is sufficient space remaining in the buffer,
+then the current position is advanced,
+and the old position is returned;
+otherwise, the buffer is broken and a null pointer is returned.
+The
+.B buf_alignskip
+function
+simply advances the buffer position
+until the designed alignment is achieved:
+the buffer contents are not altered.
 The related
 .B buf_alignfill
 function is similar, except that it advances the buffer position by writing
@@ -867,11 +887,17 @@ copies of the byte
 .IR ch ,
 as if by calling
 .BR memset (3).
-Use
+These functions return zero on success,
+or \-1 if the buffer lacked enough space
+or was already broken.
+Usually, it's best to use
 .B buf_alignskip
 for input and
 .B buf_alignfill
 for output.
+The primitive
+.B buf_align
+function can be used for either.
 .
 .SS "Formatted buffer access"
 The function