Skip to contentSkip to conversation

powerpc: boot: add strrchr function

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: boot: add strrchr function

libfdt gained a new dependency on strrchr, so copy the implementation from lib/string.c. Most of the string functions are in assembly, but stdio.c already has strnlen, so add strrchr there.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>

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

 arch/powerpc/boot/stdio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/boot/stdio.c +10 -0
index a701261b1781..98042eff7b26 100644
@@ -21,6 +21,16 @@ size_t strnlen(const char * s, size_t count)
 	return sc - s;
 }
 
+char *strrchr(const char *s, int c)
+{
+	const char *last = NULL;
+	do {
+		if (*s == (char)c)
+			last = s;
+	} while (*s++);
+	return (char *)last;
+}
+
 #ifdef __powerpc64__
 
 # define do_div(n, base) ({						\
Signature · 1 line
2.14.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rob Herring

libfdt gained a new dependency on strrchr, so copy the implementation from lib/string.c. Most of the string functions are in assembly, but stdio.c already has strnlen, so add strrchr there.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>

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

Yeah seems fine. At some point we should try and duplicate less code in boot, but now is not that time.

cheers

Quoted 23 lines
arch/powerpc/boot/stdio.c +10 -0
index a701261b1781..98042eff7b26 100644
@@ -21,6 +21,16 @@ size_t strnlen(const char * s, size_t count)
 	return sc - s;
 }
 
+char *strrchr(const char *s, int c)
+{
+	const char *last = NULL;
+	do {
+		if (*s == (char)c)
+			last = s;
+	} while (*s++);
+	return (char *)last;
+}
+
 #ifdef __powerpc64__
 
 # define do_div(n, base) ({						\
Signature · 1 line
2.14.1