467
|
1 /* Copyright (C) 1992 Free Software Foundation, Inc. |
|
2 This file is part of the GNU C Library. |
|
3 |
|
4 The GNU C Library is free software; you can redistribute it and/or |
829
|
5 modify it under the terms of the GNU General Public License as |
467
|
6 published by the Free Software Foundation; either version 2 of the |
|
7 License, or (at your option) any later version. |
|
8 |
|
9 The GNU C Library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
829
|
12 General Public License for more details. |
467
|
13 |
829
|
14 You should have received a copy of the GNU General Public |
|
15 License along with the GNU C Library; see the file COPYING. If |
5307
|
16 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
|
17 Fifth Floor, Boston, MA 02110-1301, USA. */ |
467
|
18 |
|
19 #ifdef HAVE_CONFIG_H |
1243
|
20 #include <config.h> |
467
|
21 #endif |
|
22 |
|
23 #ifndef HAVE_STRNCASECMP |
|
24 |
1351
|
25 #include <ctype.h> |
467
|
26 #include <string.h> |
|
27 |
|
28 /* Compare no more than N characters of S1 and S2, |
|
29 ignoring case, returning less than, equal to or |
|
30 greater than zero if S1 is lexicographically less |
|
31 than, equal to or greater than S2. */ |
|
32 int |
|
33 strncasecmp (const char *s1, const char *s2, size_t n) |
|
34 { |
|
35 register const unsigned char *p1 = (const unsigned char *) s1; |
|
36 register const unsigned char *p2 = (const unsigned char *) s2; |
|
37 unsigned char c1, c2; |
|
38 |
|
39 if (p1 == p2 || n == 0) |
|
40 return 0; |
|
41 |
|
42 do |
|
43 { |
|
44 c1 = tolower (*p1++); |
|
45 c2 = tolower (*p2++); |
|
46 if (c1 == '\0' || c1 != c2) |
|
47 return c1 - c2; |
|
48 } while (--n > 0); |
|
49 |
|
50 return c1 - c2; |
|
51 } |
|
52 |
|
53 #endif |