From: Darrick J. Wong Date: Thu, 21 Nov 2024 00:24:27 +0000 (-0800) Subject: libfrog: add memchr_inv X-Git-Tag: v6.13.0~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=16ddcc41229c7af098e0083b4d0afd1b94715d06;p=thirdparty%2Fxfsprogs-dev.git libfrog: add memchr_inv Add this kernel function so we can use it in userspace. Signed-off-by: "Darrick J. Wong" [hch: split from a larger patch] Signed-off-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- diff --git a/libfrog/util.c b/libfrog/util.c index 8fb10cf8..46047571 100644 --- a/libfrog/util.c +++ b/libfrog/util.c @@ -22,3 +22,17 @@ log2_roundup(unsigned int i) } return rval; } + +void * +memchr_inv(const void *start, int c, size_t bytes) +{ + const unsigned char *p = start; + + while (bytes > 0) { + if (*p != (unsigned char)c) + return (void *)p; + bytes--; + } + + return NULL; +} diff --git a/libfrog/util.h b/libfrog/util.h index 5df95e69..8b4ee7c1 100644 --- a/libfrog/util.h +++ b/libfrog/util.h @@ -6,6 +6,8 @@ #ifndef __LIBFROG_UTIL_H__ #define __LIBFROG_UTIL_H__ +#include + unsigned int log2_roundup(unsigned int i); #define min_t(type,x,y) \ @@ -13,4 +15,6 @@ unsigned int log2_roundup(unsigned int i); #define max_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) +void *memchr_inv(const void *start, int c, size_t bytes); + #endif /* __LIBFROG_UTIL_H__ */