]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: Add b_set_data().
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 28 Jun 2018 17:10:25 +0000 (19:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:39 +0000 (16:23 +0200)
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.

include/common/buf.h

index 294deb79454b9236b6f1875f914979a463cd4f96..6d1a8c0bea613fc3ead29f14d82d3a7131184008 100644 (file)
@@ -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 */