From 159b6f7429a125be9414384c930730cce491b6ec Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Sun, 30 Jul 2017 22:13:13 +0200 Subject: [PATCH] [liba] Add strchr to string.h Change-Id: I6651daa030ad6dc5e567bb78f2f22d48f07524aa --- liba/Makefile | 1 + liba/include/string.h | 6 ++++-- liba/src/strchr.c | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 liba/src/strchr.c diff --git a/liba/Makefile b/liba/Makefile index 7b949d82f..c8e6f7031 100644 --- a/liba/Makefile +++ b/liba/Makefile @@ -16,6 +16,7 @@ objs += $(addprefix liba/src/, \ memmove.o \ memset.o \ strcmp.o \ + strchr.o \ strlcpy.o \ strlen.o \ external/sqlite/mem5.o \ diff --git a/liba/include/string.h b/liba/include/string.h index fedd91000..ff58e0c8a 100644 --- a/liba/include/string.h +++ b/liba/include/string.h @@ -10,9 +10,11 @@ int memcmp(const void * s1, const void * s2, size_t n); void * memcpy(void * dst, const void * src, size_t n); void * memmove(void * dst, const void * src, size_t n); void * memset(void * b, int c, size_t len); -size_t strlen(const char * s); -int strcmp(const char *s1, const char *s2); + +char * strchr(const char * s, int c); +int strcmp(const char * s1, const char * s2); size_t strlcpy(char * dst, const char * src, size_t len); +size_t strlen(const char * s); LIBA_END_DECLS diff --git a/liba/src/strchr.c b/liba/src/strchr.c new file mode 100644 index 000000000..b299d4c7a --- /dev/null +++ b/liba/src/strchr.c @@ -0,0 +1,11 @@ +#include + +char * strchr(const char * s, int c) { + while (*s != NULL && *s != c) { + s++; + } + if (*s == c) { + return (char *)s; + } + return NULL; +}