]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: add istadv() function
authorBaptiste Assmann <bedis9@gmail.com>
Sun, 29 Mar 2020 06:10:16 +0000 (08:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 May 2020 13:28:59 +0000 (15:28 +0200)
The purpose of istadv() function is to move forward <.ptr> by <nb>
characters. It is very useful when parsing a payload.

include/common/ist.h

index 2b5178f8c072324996feac25b33e5992c70859d8..2b647a22a7b6de44bf636c745660e92a2d478548 100644 (file)
@@ -740,6 +740,17 @@ static inline struct ist iststop(const struct ist ist, char chr)
        return ist2(ist.ptr, len - 1);
 }
 
+/*
+ * advance <.ptr> by <nb> characters.
+ * If <ist> is too short, (ist.end,0) is returned.
+ */
+static inline struct ist istadv(const struct ist ist, const size_t nb)
+{
+       if (ist.len < nb)
+               return ist2(ist.ptr + ist.len, 0);
+       return ist2(ist.ptr + nb, ist.len - nb);
+}
+
 #ifndef IST_FREESTANDING
 /* This function allocates <size> bytes and returns an `ist` pointing to
  * the allocated area with size `0`.