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

index f433b15afdbc2b0ecb9cf35922a75476046623ff..7c4edc17e32a905c0855129de5c2f8ec642ba821 100644 (file)
@@ -56,24 +56,6 @@ int (strcasecmp)(const char *s1, const char *s2)
 }
 #endif
 
-#ifndef __HAVE_ARCH_STRRCHR
-/**
- * strrchr - Find the last occurrence of a character in a string
- * @s: The string to be searched
- * @c: The character to search for
- */
-char *(strrchr)(const char *s, int c)
-{
-       const char *p = s + strlen(s);
-
-       for (; *p != (char)c; --p)
-               if (p == s)
-                       return NULL;
-
-       return (char *)p;
-}
-#endif
-
 #ifndef __HAVE_ARCH_STRSPN
 /**
  * strspn - Calculate the length of the initial substring of @s which only
index b69b5163691bfd4d3d6e1c09b275d4549e831947..e531e2dfb37dfc2b3a55d486691fdd624823149e 100644 (file)
@@ -21,6 +21,7 @@ lib-y += strlcpy.o
 lib-y += strlen.o
 lib-y += strncmp.o
 lib-y += strnlen.o
+lib-y += strrchr.o
 lib-$(CONFIG_X86) += xxhash32.o
 lib-$(CONFIG_X86) += xxhash64.o
 
diff --git a/xen/lib/strrchr.c b/xen/lib/strrchr.c
new file mode 100644 (file)
index 0000000..0d53dd9
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ */
+
+#include <xen/string.h>
+
+/**
+ * strrchr - Find the last occurrence of a character in a string
+ * @s: The string to be searched
+ * @c: The character to search for
+ */
+char *(strrchr)(const char *s, int c)
+{
+       const char *p = s + strlen(s);
+
+       for (; *p != (char)c; --p)
+               if (p == s)
+                       return NULL;
+
+       return (char *)p;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ */