Last change
on this file since abd4109 was f40a309, checked in by Thomas Lopatic <thomas@…>, 7 years ago |
Unix line breaks.
|
-
Property mode
set to
100644
|
File size:
514 bytes
|
Rev | Line | |
---|
[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | strncmp.c -- compare strings
|
---|
| 4 | Version 2 -- 1987-06-15
|
---|
| 5 |
|
---|
| 6 | Compare strings (at most n bytes)
|
---|
| 7 | Returns: s1>s2; >0 s1==s2; 0 s1<s2; <0
|
---|
| 8 | =============================================================================
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | int
|
---|
| 12 | strncmp(s1, s2, n)
|
---|
| 13 | register char *s1, *s2;
|
---|
| 14 | register int n;
|
---|
| 15 | {
|
---|
| 16 | if (s1 == s2)
|
---|
| 17 | return(0);
|
---|
| 18 |
|
---|
| 19 | while ((--n >= 0) && (*s1 == *s2++))
|
---|
| 20 | if(*s1++ == '\0')
|
---|
| 21 | return(0);
|
---|
| 22 |
|
---|
| 23 | return((n < 0) ? 0 : (int)(*s1 - *--s2));
|
---|
| 24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.