summaryrefslogtreecommitdiff
path: root/na/lib/string/strncmp.c
blob: b98473bb764c0a9126dcd06852fe49ccd44eb1d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
/* SPDX-License-Identifier: MIT */
/* Derived from musl libc (Copyright © 2005-2020 Rich Felker, et al.) */

#include <string.h>

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