]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: add memchr_inv
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:27 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:29 +0000 (18:01 -0800)
Add this kernel function so we can use it in userspace.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libfrog/util.c
libfrog/util.h

index 8fb10cf82f5ca4fa0f382df3a84a4c4c06624bce..46047571a5531f16f8832c64c6734dbb5e9ef45c 100644 (file)
@@ -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;
+}
index 5df95e69cd11da87b5c262e556148d6e9cf37572..8b4ee7c1333b6ba23dba0f6e868ff4ff91c96886 100644 (file)
@@ -6,6 +6,8 @@
 #ifndef __LIBFROG_UTIL_H__
 #define __LIBFROG_UTIL_H__
 
+#include <sys/types.h>
+
 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__ */