From: Willy Tarreau Date: Thu, 23 Feb 2023 08:52:58 +0000 (+0100) Subject: MINOR: buf: add b_rel_ofs() to turn an absolute offset into a relative one X-Git-Tag: v3.0-dev6~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5004ccb3680847cf0fc42a2fd7afc9df32c64d5;p=thirdparty%2Fhaproxy.git MINOR: buf: add b_rel_ofs() to turn an absolute offset into a relative one It basically does the opposite of b_peek_ofs(). If x=b_peek_ofs(y), then y=b_rel_ofs(x). --- diff --git a/include/haproxy/buf.h b/include/haproxy/buf.h index b24ec7902e..d9f3a7727e 100644 --- a/include/haproxy/buf.h +++ b/include/haproxy/buf.h @@ -103,6 +103,15 @@ static inline size_t b_add_ofs(const struct buffer *b, size_t ofs, size_t count) return ofs; } +/* b_rel_ofs() : take an absolute offset in the buffer, and return it relative + * to the buffer's head for use with b_peek(). + */ +static inline size_t b_rel_ofs(const struct buffer *b, size_t ofs) +{ + if (ofs < b->head) + ofs += b->size; + return ofs - b->head; +} /* 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