summaryrefslogtreecommitdiff
path: root/lib/strncmp.c
blob: e890517a68ce6344a0966c47bfada9f1ce582903 (plain)
1
2
3
4
5
6
7
8
9
10
11
#include <string.h>

int strncmp(const char *restrict lhs, const char *restrict rhs, size_t n)
{
	const unsigned char *l = (void *)lhs, *r = (void *)rhs;
	if (!n--)
		return 0;
	for (; *l && *r && n && *l == *r; l++, r++, n--)
		;
	return *l - *r;
}