shithub: scc

Download patch

ref: d1475c2e8a729ae33f2f8fd94ad0b54b519ce8c3
parent: 84f02dfac20a8cf49239e9eb1a9a9e9422c05686
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Feb 16 16:24:06 EST 2017

[libc] Add strrchr()

--- a/libc/src/Makefile
+++ b/libc/src/Makefile
@@ -1,7 +1,8 @@
 # See LICENSE file for copyright and license details.
 .POSIX:
 
-LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o
+LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
+          strrchr.o
 
 all: libc.a
 
--- /dev/null
+++ b/libc/src/strrchr.c
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+char *
+strrchr(const char *s, int c)
+{
+	char *t;
+
+	for (t = (char *) s; *t; ++t)
+		/* nothing */;
+	while (t > s && *t != c)
+		--t;
+	return (*t == c) ? t : NULL;
+}