171671b9obrien/* strncmp -- compare two strings, stop after n bytes.
271671b9obrien   This function is in the public domain.  */
371671b9obrien
471671b9obrien/*
571671b9obrien
671671b9obrien@deftypefn Supplemental int strncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
771671b9obrien
871671b9obrienCompares the first @var{n} bytes of two strings, returning a value as
971671b9obrien@code{strcmp}.
1071671b9obrien
1171671b9obrien@end deftypefn
1271671b9obrien
1371671b9obrien*/
1471671b9obrien
1571671b9obrien#include <ansidecl.h>
1671671b9obrien#include <stddef.h>
1771671b9obrien
1871671b9obrienint
190acbbeedimstrncmp(const char *s1, const char *s2, register size_t n)
2071671b9obrien{
2171671b9obrien  register unsigned char u1, u2;
2271671b9obrien
2371671b9obrien  while (n-- > 0)
2471671b9obrien    {
2571671b9obrien      u1 = (unsigned char) *s1++;
2671671b9obrien      u2 = (unsigned char) *s2++;
2771671b9obrien      if (u1 != u2)
2871671b9obrien	return u1 - u2;
2971671b9obrien      if (u1 == '\0')
3071671b9obrien	return 0;
3171671b9obrien    }
3271671b9obrien  return 0;
3371671b9obrien}
34