lib: move strstr()
authorJan Beulich <jbeulich@suse.com>
Thu, 22 Apr 2021 12:50:54 +0000 (14:50 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 22 Apr 2021 12:50:54 +0000 (14:50 +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/strstr.c [new file with mode: 0644]

index 7c4edc17e32a905c0855129de5c2f8ec642ba821..abb1689edd9fe32e88fd34a79e3721345353a6fe 100644 (file)
@@ -131,27 +131,6 @@ char * strsep(char **s, const char *ct)
 }
 #endif
 
-#ifndef __HAVE_ARCH_STRSTR
-/**
- * strstr - Find the first substring in a %NUL terminated string
- * @s1: The string to be searched
- * @s2: The string to search for
- */
-char *(strstr)(const char *s1, const char *s2)
-{
-       size_t l1, l2 = strlen(s2);
-
-       if (!l2)
-               return (char *)s1;
-
-       for (l1 = strlen(s1); l1 >= l2; --l1, ++s1)
-               if (!memcmp(s1, s2, l2))
-                       return (char *)s1;
-
-       return NULL;
-}
-#endif
-
 /*
  * Local variables:
  * mode: C
index e531e2dfb37dfc2b3a55d486691fdd624823149e..57a7095ffac51637c0346d4acd210126e1bb7121 100644 (file)
@@ -22,6 +22,7 @@ lib-y += strlen.o
 lib-y += strncmp.o
 lib-y += strnlen.o
 lib-y += strrchr.o
+lib-y += strstr.o
 lib-$(CONFIG_X86) += xxhash32.o
 lib-$(CONFIG_X86) += xxhash64.o
 
diff --git a/xen/lib/strstr.c b/xen/lib/strstr.c
new file mode 100644 (file)
index 0000000..c305f5a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ */
+
+#include <xen/string.h>
+
+/**
+ * strstr - Find the first substring in a %NUL terminated string
+ * @s1: The string to be searched
+ * @s2: The string to search for
+ */
+char *(strstr)(const char *s1, const char *s2)
+{
+       size_t l1, l2 = strlen(s2);
+
+       if (!l2)
+               return (char *)s1;
+
+       for (l1 = strlen(s1); l1 >= l2; --l1, ++s1)
+               if (!memcmp(s1, s2, l2))
+                       return (char *)s1;
+
+       return NULL;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ */