summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/string.h1
-rw-r--r--src/lib/Makefile.inc2
-rw-r--r--src/lib/memchr.c11
3 files changed, 14 insertions, 0 deletions
diff --git a/src/include/string.h b/src/include/string.h
index 21689473ce..708961b635 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -8,6 +8,7 @@ void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
+void *memchr(const void *s, int c, size_t n);
#if !defined(__PRE_RAM__)
int sprintf(char * buf, const char *fmt, ...);
#endif
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 432e24e780..a31033cf5c 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -1,6 +1,7 @@
romstage-y += memset.c
+romstage-y += memchr.c
romstage-y += memcpy.c
romstage-y += memcmp.c
romstage-y += cbfs.c
@@ -15,6 +16,7 @@ romstage-$(CONFIG_CONSOLE_NE2K) += compute_ip_checksum.c
romstage-$(CONFIG_USBDEBUG) += usbdebug.c
ramstage-y += memset.c
+ramstage-y += memchr.c
ramstage-y += memcpy.c
ramstage-y += memcmp.c
ramstage-y += memmove.c
diff --git a/src/lib/memchr.c b/src/lib/memchr.c
new file mode 100644
index 0000000000..a890dceada
--- /dev/null
+++ b/src/lib/memchr.c
@@ -0,0 +1,11 @@
+#include <string.h>
+void *memchr(const void *s, int c, size_t n)
+{
+ const unsigned char *sc = s;
+ while (n--) {
+ if (*sc == (unsigned char)c)
+ return (void *)sc;
+ sc++;
+ }
+ return NULL;
+}