From b2566f207ed858604747bf306dfdd993bda517aa Mon Sep 17 00:00:00 2001 From: Philipp Hug Date: Mon, 11 Feb 2019 20:50:31 +0100 Subject: libpayload: add memchr to libc libfdt requires memchr. Add missing function to libc. Change-Id: I872026559d16a352f350147c9d7c4be97456a99f Signed-off-by: Philipp Hug Reviewed-on: https://review.coreboot.org/c/31354 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- payloads/libpayload/include/string.h | 1 + payloads/libpayload/libc/memory.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'payloads') diff --git a/payloads/libpayload/include/string.h b/payloads/libpayload/include/string.h index ca5d5131e2..4aff0e8994 100644 --- a/payloads/libpayload/include/string.h +++ b/payloads/libpayload/include/string.h @@ -39,6 +39,7 @@ void *memset(void *s, int c, size_t n); void *memcpy(void *dst, const void *src, size_t n); void *memmove(void *dst, const void *src, size_t n); +void *memchr(const void *s, int c, size_t n); int memcmp(const void *s1, const void *s2, size_t len); /** @} */ diff --git a/payloads/libpayload/libc/memory.c b/payloads/libpayload/libc/memory.c index 25c2b3af4f..8ee3eed9da 100644 --- a/payloads/libpayload/libc/memory.c +++ b/payloads/libpayload/libc/memory.c @@ -145,3 +145,15 @@ static int default_memcmp(const void *s1, const void *s2, size_t n) int memcmp(const void *s1, const void *s2, size_t n) __attribute__((weak, alias("default_memcmp"))); + + +void *memchr(const void *s, int c, size_t n) +{ + unsigned char *p = (unsigned char *)s; + while (n--) + if (*p != (unsigned char)c) + p++; + else + return p; + return 0; +} -- cgit v1.2.3