]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffers: provide simple pointer normalization functions
authorWilly Tarreau <w@1wt.eu>
Fri, 2 Mar 2012 09:38:01 +0000 (10:38 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 10:28:10 +0000 (12:28 +0200)
Add buffer_wrap_sub() and buffer_wrap_add() to normalize buffer pointers
after an addition or subtract.

include/proto/buffers.h

index bb2dd45ee46cfd4806d183b56d4fd89fa8685a34..ec8eaab2ba70ff12889aeb41c57c35edb182bd22 100644 (file)
@@ -87,6 +87,22 @@ static inline int buffer_empty(const struct buffer *buf)
        return !buffer_not_empty(buf);
 }
 
+/* Normalizes a pointer after a subtract */
+static inline char *buffer_wrap_sub(const struct buffer *buf, char *ptr)
+{
+       if (ptr < buf->data)
+               ptr += buf->size;
+       return ptr;
+}
+
+/* Normalizes a pointer after an addition */
+static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
+{
+       if (ptr - buf->size >= buf->data)
+               ptr -= buf->size;
+       return ptr;
+}
+
 /* Return the number of reserved bytes in the buffer, which ensures that once
  * all pending data are forwarded, the buffer still has global.tune.maxrewrite
  * bytes free. The result is between 0 and global.maxrewrite, which is itself