From 9f0487945164a4a5921f7b7bcc13d01d5fdc2e94 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 5 Aug 2024 10:43:34 -0700 Subject: [PATCH] libfrog: add memchr_inv Signed-off-by: Darrick J. Wong [hch: split from a larger patch] Signed-off-by: Christoph Hellwig --- libfrog/util.c | 14 ++++++++++++++ libfrog/util.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/libfrog/util.c b/libfrog/util.c index 8fb10cf82..46047571a 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 5df95e69c..8b4ee7c13 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__ */ -- 2.50.1