9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 8e03e0ea337ea4eca6c8d905062bbacb6dffb9c3
parent 6c9f8d77183b91462388bc44572c858b642ea19b
Author: Roberto Vargas <roberto.vargas@arm.com>
Date:   Thu,  9 May 2019 13:39:00 +0100

[libc] Add memrchr function

Change-Id: Ic61a133b66888896711a326f17d6adec2076c478

Diffstat:
Msrc/libc/string/Makefile | 1+
Asrc/libc/string/memrchr.c | 13+++++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/libc/string/Makefile b/src/libc/string/Makefile @@ -4,6 +4,7 @@ include $(PROJECTDIR)/scripts/rules.mk include ../rules.mk OBJS = memchr.o\ + memrchr.o \ memcmp.o\ memcpy.o\ memmove.o\ diff --git a/src/libc/string/memrchr.c b/src/libc/string/memrchr.c @@ -0,0 +1,13 @@ +#include <string.h> + +#undef memrchr + +void * +memrchr(const void *s, int c, size_t n) +{ + unsigned char *p = s; + + for (p += n-1; n > 0 && *p != c; --p) + n--; + return (n == 0) ? NULL : p; +}