Line | |
---|
1 | /*
|
---|
2 | strcasecmp.c
|
---|
3 |
|
---|
4 | Created Oct 14, 1991 by Philip Homburg
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <ctype.h>
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | #ifdef __STDC__
|
---|
11 | #define _CONST const
|
---|
12 | #else
|
---|
13 | #define _CONST
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | int
|
---|
17 | strcasecmp(s1, s2)
|
---|
18 | _CONST char *s1, *s2;
|
---|
19 | {
|
---|
20 | int c1, c2;
|
---|
21 | while (c1= toupper(*s1++), c2= toupper(*s2++), c1 == c2 && (c1 & c2))
|
---|
22 | ;
|
---|
23 | if (c1 & c2)
|
---|
24 | return c1 < c2 ? -1 : 1;
|
---|
25 | return c1 ? 1 : (c2 ? -1 : 0);
|
---|
26 | }
|
---|
27 |
|
---|
28 | int
|
---|
29 | strncasecmp(s1, s2, len)
|
---|
30 | _CONST char *s1, *s2;
|
---|
31 | size_t len;
|
---|
32 | {
|
---|
33 | int c1, c2;
|
---|
34 | do {
|
---|
35 | if (len == 0)
|
---|
36 | return 0;
|
---|
37 | len--;
|
---|
38 | } while (c1= toupper(*s1++), c2= toupper(*s2++), c1 == c2 && (c1 & c2))
|
---|
39 | ;
|
---|
40 | if (c1 & c2)
|
---|
41 | return c1 < c2 ? -1 : 1;
|
---|
42 | return c1 ? 1 : (c2 ? -1 : 0);
|
---|
43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.