From: Olivier Houchard Date: Thu, 28 Jun 2018 17:10:25 +0000 (+0200) Subject: MINOR: buffer: Add b_set_data(). X-Git-Tag: v1.9-dev1~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a04e40d5788fde49924f11a68e59fc33a4cb8dfe;p=thirdparty%2Fhaproxy.git MINOR: buffer: Add b_set_data(). Add a new function that lets you set the amount of input in a buffer. For now it extends/truncates b->i except if the total length is below b->o in which case it clears i and adjusts o. --- diff --git a/include/common/buf.h b/include/common/buf.h index 294deb7945..6d1a8c0bea 100644 --- a/include/common/buf.h +++ b/include/common/buf.h @@ -311,6 +311,17 @@ static inline void bo_add(struct buffer *b, size_t count) b->o += count; } +/* b_set_data() : sets the buffer's length */ +static inline void b_set_data(struct buffer *b, size_t len) +{ + if (len >= b->o) + b->i = len - b->o; + else { + b->o = len; + b->i = 0; + } +} + #endif /* _COMMON_BUF_H */