summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/mem.c9
-rw-r--r--src/shared/mem.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/src/shared/mem.c b/src/shared/mem.c
index 35b2f14..3075963 100644
--- a/src/shared/mem.c
+++ b/src/shared/mem.c
@@ -1,6 +1,15 @@
#include <shared/mem.h>
#include <stdint.h>
+void *memchr(const void *s, int c, size_t n) {
+ const unsigned char *s2 = s;
+ for (size_t i = 0; i < n; i++) {
+ if (s2[i] == (unsigned char)c)
+ return &s2[i];
+ }
+ return NULL;
+}
+
int memcmp(const void *s1, const void *s2, size_t n) {
const unsigned char *c1 = s1, *c2 = s2;
for (size_t i = 0; i < n; i++) {
diff --git a/src/shared/mem.h b/src/shared/mem.h
index 7036381..8eb091f 100644
--- a/src/shared/mem.h
+++ b/src/shared/mem.h
@@ -1,6 +1,7 @@
#pragma once
#include <stddef.h>
+void *memchr(const void *s, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *dest, const void *src, size_t n);