BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionLibC / blob / ad9b6af63f1fdfcf3556c9b2fc670f72cdc60ab4 / string / strcmp.c

// Related

OrionLibC

Barry Importing existing Orion LibC 03048a9 (2 years, 2 months ago)
#include <stddef.h>

/* Compare two strings */
int
strcmp(char *s1, char *s2)
{
	for (; *s1 == *s2 && *s1 && *s2; s1++, s2++);
	return *(unsigned char *) s1 - *(unsigned char *) s2;
}

/* Compare two limited strings */
int
strncmp(char *s1, char *s2, size_t n)
{
	if (!n--) return 0;
	for (; *s1 == *s2 && *s1 && *s2 && n; s1++, s2++, n--);
	return *(unsigned char *) s1 - *(unsigned char *) s2;
}