xref: /original-bsd/lib/libc/string/strncmp.c (revision 4ee49cc0)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)strncmp.c	8.1 (Berkeley) 06/04/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/cdefs.h>
13 #include <string.h>
14 
15 int
16 strncmp(s1, s2, n)
17 	register const char *s1, *s2;
18 	register size_t n;
19 {
20 
21 	if (n == 0)
22 		return (0);
23 	do {
24 		if (*s1 != *s2++)
25 			return (*(unsigned char *)s1 - *(unsigned char *)--s2);
26 		if (*s1++ == 0)
27 			break;
28 	} while (--n != 0);
29 	return (0);
30 }
31