From: Baptiste Assmann Date: Sun, 29 Mar 2020 06:10:16 +0000 (+0200) Subject: MINOR: ist: add istadv() function X-Git-Tag: v2.2-dev7~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ef1967af73f66c0e302cae84576fc78b4826637;p=thirdparty%2Fhaproxy.git MINOR: ist: add istadv() function The purpose of istadv() function is to move forward <.ptr> by characters. It is very useful when parsing a payload. --- diff --git a/include/common/ist.h b/include/common/ist.h index 2b5178f8c0..2b647a22a7 100644 --- a/include/common/ist.h +++ b/include/common/ist.h @@ -740,6 +740,17 @@ static inline struct ist iststop(const struct ist ist, char chr) return ist2(ist.ptr, len - 1); } +/* + * advance <.ptr> by characters. + * If 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 bytes and returns an `ist` pointing to * the allocated area with size `0`.