From: Willy Tarreau Date: Thu, 23 Feb 2023 08:52:42 +0000 (+0100) Subject: MINOR: buf: add b_add_ofs() to add a count to an absolute position X-Git-Tag: v3.0-dev6~52 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15e47b6a5970ad90f9e4ae53f157863aac0fa23a;p=thirdparty%2Fhaproxy.git MINOR: buf: add b_add_ofs() to add a count to an absolute position This function is used to compute a new absolute buffer offset by adding a length to an existing valid offset. It will check for wrapping. --- diff --git a/include/haproxy/buf.h b/include/haproxy/buf.h index 59484684a5..b24ec7902e 100644 --- a/include/haproxy/buf.h +++ b/include/haproxy/buf.h @@ -91,6 +91,18 @@ static inline size_t b_full(const struct buffer *b) return !b_room(b); } +/* b_add_ofs() : return new offset within buffer after applying wrapping. Only + * offsets resulting from initial positions added to counts within buffer size + * limits are handled. + */ +static inline size_t b_add_ofs(const struct buffer *b, size_t ofs, size_t count) +{ + ofs += count; + if (ofs >= b->size) + ofs -= b->size; + return ofs; +} + /* b_stop() : returns the pointer to the byte following the end of the buffer, * which may be out of the buffer if the buffer ends on the last byte of the