commit 008332b425b189c60ecff4e8a2d9096e3b7aa62b parent c7de2f7e79a025d87a47e0835f57d8091752b27e Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Thu, 16 Feb 2017 21:24:06 +0100 [libc] Add strrchr() Diffstat:
M | libc/src/Makefile | | | 3 | ++- |
A | libc/src/strrchr.c | | | 15 | +++++++++++++++ |
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git 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 diff --git a/libc/src/strrchr.c b/libc/src/strrchr.c @@ -0,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; +}