Skip to contentSkip to conversation

efi/libstub: add strrchr function

PATCH In review Rob Herring 2 participants 2 messages Mar 1, 2018 EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi/libstub: add strrchr function

libfdt gained a new dependency on strrchr, so copy the implementation from lib/string.c.

Cc Ard Biesheuvel <[email protected]>

---
Please ack. This is a dependency for dtc/libfdt sync with upstream.

 drivers/firmware/efi/libstub/string.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/firmware/efi/libstub/string.c +17 -0
index ed10e3f602c5..c1a7e58a5af7 100644
@@ -56,3 +56,20 @@ int strncmp(const char *cs, const char *ct, size_t count)
 	return 0;
 }
 #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 *last = NULL;
+	do {
+		if (*s == (char)c)
+			last = s;
+	} while (*s++);
+	return (char *)last;
+}
+#endif
Signature · 1 line
2.14.1
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Rob Herring

libfdt gained a new dependency on strrchr, so copy the implementation from lib/string.c.

Cc Ard Biesheuvel <[email protected]>

---
Please ack. This is a dependency for dtc/libfdt sync with upstream.

 drivers/firmware/efi/libstub/string.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/firmware/efi/libstub/string.c +0 -0
index ed10e3f602c5..c1a7e58a5af7 100644

drivers/firmware/efi/libstub/string.c int strncmp(const char *cs, const char *ct, size_t count) · line 60

Quoted 5 lines
drivers/firmware/efi/libstub/string.c +2 -0
@@ -56,3 +56,20 @@ int strncmp(const char *cs, const char *ct, size_t count)
        return 0;
 }
 #endif
+
+#ifndef __HAVE_ARCH_STRRCHR

As discussed over IRC, this #ifndef needs to be dropped.

Quoted 18 lines
drivers/firmware/efi/libstub/string.c +15 -1
+/**
+ * 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 *last = NULL;
+       do {
+               if (*s == (char)c)
+                       last = s;
+       } while (*s++);
+       return (char *)last;
+}
+#endif
--

2.14.1