From e07a9397654e79d979c0e2fd63a030bf6b51960f Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 13 Aug 2025 15:28:40 +0200 Subject: [PATCH] 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 --- dix/rpcbuf_priv.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dix/rpcbuf_priv.h b/dix/rpcbuf_priv.h index cb795a7875..0914ddd317 100644 --- a/dix/rpcbuf_priv.h +++ b/dix/rpcbuf_priv.h @@ -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 */