summaryrefslogtreecommitdiff
path: root/lib/libc/string/memchr.c
blob: f13a2a2c04d241b529bca073b14387697f67f34a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stddef.h> // for NULL
#include <string.h> // for memchr, size_t

void *memchr(const void *s, int c, size_t n)
{
	const unsigned char *p = s;
	while (n--) {
		if (*p == (unsigned char)c)
			return (void *)p;
		p++;
	}
	return NULL;
}