dix: rpcbuf: add x_rpcbuf_pad() for padding the buffer

New function for padding the buffer to full protocol units granularity:
If the current write position isn't at 4-byte granularity, it reserves
the remaining number of bytes (ie. writing zeros), in order to make the
next write align to 4-byte granularity again.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2025-08-13 15:28:40 +02:00
committed by Enrico Weigelt
parent 02737a1cd4
commit e07a939765

View File

@@ -244,4 +244,15 @@ static inline CARD32 x_rpcbuf_wsize_units(x_rpcbuf_t *rpcbuf) {
return (CARD32)((rpcbuf->wpos + 3) / 4);
}
/*
* pad the buffer to 4-byte-units (ie. write extra zeros if necessary)
*
* @param rpcbuf pointer to x_rpcbuf_t to operate on
*/
static inline void x_rpcbuf_pad(x_rpcbuf_t *rpcbuf) {
x_rpcbuf_reserve0(
rpcbuf,
(((rpcbuf->wpos + 3) / 4) * 4) - rpcbuf->wpos);
}
#endif /* _XSERVER_DIX_RPCBUF_PRIV_H */