Skip to content
Snippets Groups Projects
Commit abea1c38 authored by Daniel Campora's avatar Daniel Campora
Browse files

lib/libc: Add memchr. We already have strchr, but memchr is useful too.

parent 9fbc265e
No related branches found
No related tags found
No related merge requests found
...@@ -114,6 +114,18 @@ int memcmp(const void *s1, const void *s2, size_t n) { ...@@ -114,6 +114,18 @@ int memcmp(const void *s1, const void *s2, size_t n) {
return 0; return 0;
} }
void *memchr(const void *s, int c, size_t n) {
if (n != 0) {
const unsigned char *p = s;
do {
if (*p++ == c)
return ((void *)(p - 1));
} while (--n != 0);
}
return 0;
}
size_t strlen(const char *str) { size_t strlen(const char *str) {
int len = 0; int len = 0;
for (const char *s = str; *s; s++) { for (const char *s = str; *s; s++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment