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

void *memccpy(void *restrict s1, const void *restrict s2, int c, size_t n)
{
	const unsigned char *p2 = s2;
	unsigned char *p1 = s1;
	while (n--) {
		if (*p2 == (unsigned char)c)
			return p1 + 1;
		*p1++ = *p2++;
	}
	return NULL;
}