xref: /csrg-svn/lib/libc/string/strncmp.c (revision 46144)
11988Swnj /*
242166Sbostic  * Copyright (c) 1989 The Regents of the University of California.
335096Sbostic  * All rights reserved.
435096Sbostic  *
542637Sbostic  * %sccs.include.redist.c%
61988Swnj  */
71988Swnj 
835096Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*46144Sbostic static char sccsid[] = "@(#)strncmp.c	5.6 (Berkeley) 01/26/91";
1035096Sbostic #endif /* LIBC_SCCS and not lint */
1135096Sbostic 
12*46144Sbostic #include <sys/cdefs.h>
1342166Sbostic #include <string.h>
1442166Sbostic 
1542166Sbostic int
1642166Sbostic strncmp(s1, s2, n)
1742166Sbostic 	register const char *s1, *s2;
1842166Sbostic 	register size_t n;
191988Swnj {
2042166Sbostic 
2142166Sbostic 	if (n == 0)
2242166Sbostic 		return (0);
2342166Sbostic 	do {
2442166Sbostic 		if (*s1 != *s2++)
2542166Sbostic 			return (*(unsigned char *)s1 - *(unsigned char *)--s2);
2642166Sbostic 		if (*s1++ == 0)
2742166Sbostic 			break;
2842166Sbostic 	} while (--n != 0);
2942166Sbostic 	return (0);
301988Swnj }
31