From: Willy Tarreau Date: Fri, 15 Jun 2018 15:50:15 +0000 (+0200) Subject: MINOR: buffer: introduce b_realign_if_empty() X-Git-Tag: v1.9-dev1~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f17f19f1a796ea9bbb4e31e7bdd0589f08a64e7e;p=thirdparty%2Fhaproxy.git MINOR: buffer: introduce b_realign_if_empty() Many places deal with buffer realignment after data removal. The method is always the same : if the buffer is empty, set its pointer to the origin. Let's have a function for this so that we have less code to change with the new API. --- diff --git a/include/common/buf.h b/include/common/buf.h index 6d1a8c0bea..564e0ebad3 100644 --- a/include/common/buf.h +++ b/include/common/buf.h @@ -322,6 +322,13 @@ static inline void b_set_data(struct buffer *b, size_t len) } } +/* b_realign_if_empty() : realigns a buffer if it's empty */ +static inline void b_realign_if_empty(struct buffer *b) +{ + if (!b_data(b)) + b->p = b->data; +} + #endif /* _COMMON_BUF_H */