lib: move memchr_inv()
authorJan Beulich <jbeulich@suse.com>
Thu, 22 Apr 2021 12:45:33 +0000 (14:45 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 22 Apr 2021 12:45:33 +0000 (14:45 +0200)
Allow the function to be individually linkable, discardable, and
overridable.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/common/string.c
xen/lib/Makefile
xen/lib/memchr_inv.c [new file with mode: 0644]

index ba282637f1d7e5fa8059f3aaaefe36598eebed61..eae5e2a314b095f4738f0edb4dd5e52ffdb756f2 100644 (file)
@@ -311,26 +311,6 @@ char *(strstr)(const char *s1, const char *s2)
 }
 #endif
 
-/**
- * memchr_inv - Find an unmatching character in an area of memory.
- * @s: The memory area
- * @c: The byte that is expected
- * @n: The size of the area.
- *
- * returns the address of the first occurrence of a character other than @c,
- * or %NULL if the whole buffer contains just @c.
- */
-void *memchr_inv(const void *s, int c, size_t n)
-{
-       const unsigned char *p = s;
-
-       while (n--)
-               if ((unsigned char)c != *p++)
-                       return (void *)(p - 1);
-
-       return NULL;
-}
-
 /*
  * Local variables:
  * mode: C
index acdd0a4a12432d52a479435b57d678fee26bf387..ce61fbe3cdb877037d423604ef245dbea5e3a6aa 100644 (file)
@@ -5,6 +5,7 @@ lib-y += ctors.o
 lib-y += ctype.o
 lib-y += list-sort.o
 lib-y += memchr.o
+lib-y += memchr_inv.o
 lib-y += memcmp.o
 lib-y += memcpy.o
 lib-y += memmove.o
diff --git a/xen/lib/memchr_inv.c b/xen/lib/memchr_inv.c
new file mode 100644 (file)
index 0000000..1bf6cb6
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ */
+
+#include <xen/string.h>
+
+/**
+ * memchr_inv - Find an unmatching character in an area of memory.
+ * @s: The memory area
+ * @c: The byte that is expected
+ * @n: The size of the area.
+ *
+ * returns the address of the first occurrence of a character other than @c,
+ * or %NULL if the whole buffer contains just @c.
+ */
+void *memchr_inv(const void *s, int c, size_t n)
+{
+       const unsigned char *p = s;
+
+       while (n--)
+               if ((unsigned char)c != *p++)
+                       return (void *)(p - 1);
+
+       return NULL;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ */