xref: /csrg-svn/lib/libc/string/strncmp.c (revision 42166)
11988Swnj /*
2*42166Sbostic  * Copyright (c) 1989 The Regents of the University of California.
335096Sbostic  * All rights reserved.
435096Sbostic  *
535096Sbostic  * Redistribution and use in source and binary forms are permitted
635096Sbostic  * provided that the above copyright notice and this paragraph are
735096Sbostic  * duplicated in all such forms and that any documentation,
835096Sbostic  * advertising materials, and other materials related to such
935096Sbostic  * distribution and use acknowledge that the software was developed
1035096Sbostic  * by the University of California, Berkeley.  The name of the
1135096Sbostic  * University may not be used to endorse or promote products derived
1235096Sbostic  * from this software without specific prior written permission.
1335096Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1435096Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*42166Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
161988Swnj  */
171988Swnj 
1835096Sbostic #if defined(LIBC_SCCS) && !defined(lint)
19*42166Sbostic static char sccsid[] = "@(#)strncmp.c	5.4 (Berkeley) 05/17/90";
2035096Sbostic #endif /* LIBC_SCCS and not lint */
2135096Sbostic 
22*42166Sbostic #include <sys/stdc.h>
23*42166Sbostic #include <string.h>
24*42166Sbostic 
25*42166Sbostic int
26*42166Sbostic strncmp(s1, s2, n)
27*42166Sbostic 	register const char *s1, *s2;
28*42166Sbostic 	register size_t n;
291988Swnj {
30*42166Sbostic 
31*42166Sbostic 	if (n == 0)
32*42166Sbostic 		return (0);
33*42166Sbostic 	do {
34*42166Sbostic 		if (*s1 != *s2++)
35*42166Sbostic 			return (*(unsigned char *)s1 - *(unsigned char *)--s2);
36*42166Sbostic 		if (*s1++ == 0)
37*42166Sbostic 			break;
38*42166Sbostic 	} while (--n != 0);
39*42166Sbostic 	return (0);
401988Swnj }
41