aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/inc/mem.h1
-rw-r--r--libc/mem.c12
2 files changed, 13 insertions, 0 deletions
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;