MINOR: buffers: provide simple pointer normalization functions
Add buffer_wrap_sub() and buffer_wrap_add() to normalize buffer pointers
after an addition or subtract.
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index bb2dd45..ec8eaab 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -87,6 +87,22 @@
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