]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: add b_end() and b_to_end()
authorWilly Tarreau <w@1wt.eu>
Tue, 19 Sep 2017 19:14:08 +0000 (21:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2017 09:27:31 +0000 (11:27 +0200)
These ones return respectively the pointer to the end of the buffer and
the distance between b->p and the end. These will simplify a bit some
new code needed to parse directly from a wrapping buffer.

include/common/buffer.h

index 8043e29292c67948f8ce271b014ca2e40d13a3cb..b29946673ef4a5a935827453679387c4353b1a9a 100644 (file)
@@ -79,6 +79,18 @@ void buffer_slow_realign(struct buffer *buf);
                __ret;                                          \
        })
 
+/* Returns the pointer to the buffer's end (data+size) */
+static inline const char *b_end(const struct buffer *b)
+{
+       return b->data + b->size;
+}
+
+/* Returns the distance between <p> and the buffer's end (data+size) */
+static inline unsigned int b_to_end(const struct buffer *b)
+{
+       return b->data + b->size - b->p;
+}
+
 /* Skips <del> bytes in a one-way buffer <b> : <p> advances by <del>, <i>
  * shrinks by <del> as well, and <o> is left untouched (supposed to be zero).
  * The caller is responsible for ensuring that <del> is always smaller than or