/*
 *			s t r n c m . c
 */

/*)LIBRARY
*/

#ifdef	DOCUMENTATION


title	strncmp	String Compare With Count
index		String compare with count

synopsis
	.s.nf
	int
	strncmp(s1, s2, count);
	char		*s1;
	char		*s2;
	unsigned int	count;
	.s.f
Description

	Compare at most count bytes between two strings, returning:

	  -1 if s1  < s2
	   0 if s1 == s2
	  +1 if s1  > s2

Bugs

#endif

#define	EOS	0

int
strncmp(s1, s2, count)
register char		*s1;
register char		*s2;
register unsigned int	count;
/*
 * Compare strings, at most count bytes.
 */
{
	if (count == 0)
	    return (0);
	else {
	    while (*s1++ == *s2) {
		if (*s2++ == EOS || --count <= 0)
		    return (0);
	    }
	    return ((s1[-1] < *s2) ? -1 : 1);		/* Unequal	*/
	}
}
