From 23798b52a0aa4bf556b06f15fb9f5923db3cc46f Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 23 Nov 2020 17:09:28 +0100 Subject: Ported sxml library --- libc/inc/mem.h | 1 + libc/mem.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'libc') diff --git a/libc/inc/mem.h b/libc/inc/mem.h index 8977a48..964b24b 100644 --- a/libc/inc/mem.h +++ b/libc/inc/mem.h @@ -22,6 +22,7 @@ void free(void *ptr); void *memcpy(void *dest, const void *src, u32 n); void *memset(void *dest, int val, u32 n); +void *memchr(void *src, int c, u32 n); int memcmp(const void *s1, const void *s2, u32 n); #endif diff --git a/libc/mem.c b/libc/mem.c index 2fde00b..c81a13f 100644 --- a/libc/mem.c +++ b/libc/mem.c @@ -43,6 +43,18 @@ void *memset(void *dest, int val, u32 n) return dest; } +void *memchr(void *src, int c, u32 n) +{ + const u8 *s = (const u8 *)src; + + while (n-- > 0) { + if (*s == c) + return (void *)s; + s++; + } + return NULL; +} + int memcmp(const void *s1, const void *s2, u32 n) { const u8 *a = (const u8 *)s1; -- cgit v1.2.3