Commit | Line | Data |
---|---|---|
7db9433a | 1 | /* |
6c685f97 | 2 | * Copyright (c) 1989 The Regents of the University of California. |
7291c5cf KB |
3 | * All rights reserved. |
4 | * | |
019bea33 | 5 | * %sccs.include.redist.c% |
7db9433a BJ |
6 | */ |
7 | ||
7291c5cf | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
a64329b4 | 9 | static char sccsid[] = "@(#)strncmp.c 5.6 (Berkeley) %G%"; |
7291c5cf | 10 | #endif /* LIBC_SCCS and not lint */ |
7db9433a | 11 | |
a64329b4 | 12 | #include <sys/cdefs.h> |
6c685f97 KB |
13 | #include <string.h> |
14 | ||
15 | int | |
16 | strncmp(s1, s2, n) | |
17 | register const char *s1, *s2; | |
18 | register size_t n; | |
7291c5cf | 19 | { |
6c685f97 KB |
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); | |
7db9433a | 30 | } |