1 /* Copyright (C) 1991,1992,1995,1996,1997,2001,2002, 2004
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA */
19
20 /*
21 * August 2006. For Gawk: Borrowed from GLIBC to replace BSD licensed version.
22 * DON'T steal this for your own code, just go to the GLIBC sources.
23 * This version hacked unmercifully.
24 */
25
26
27 /* Compare S1 and S2, ignoring case, returning less than, equal to or
28 greater than zero if S1 is lexicographically less than,
29 equal to or greater than S2. */
30 int
31 strcasecmp (s1, s2)
32 const char *s1;
33 const char *s2;
34 {
35 const unsigned char *p1 = (const unsigned char *) s1;
36 const unsigned char *p2 = (const unsigned char *) s2;
37 int result;
38
39 if (p1 == p2)
40 return 0;
41
42 while ((result = tolower (*p1) - tolower (*p2++)) == 0)
43 if (*p1++ == '\0')
44 break;
45
46 return result;
47 }
48
49 /* Compare at most N characters of two strings without taking care for
50 the case.
51 Copyright (C) 1992, 1996, 1997, 2001, 2004 Free Software Foundation, Inc.
52 This file is part of the GNU C Library.
53
54 The GNU C Library is free software; you can redistribute it and/or
55 modify it under the terms of the GNU Lesser General Public
56 License as published by the Free Software Foundation; either
57 version 2.1 of the License, or (at your option) any later version.
58
59 The GNU C Library is distributed in the hope that it will be useful,
60 but WITHOUT ANY WARRANTY; without even the implied warranty of
61 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
62 Lesser General Public License for more details.
63
64 You should have received a copy of the GNU Lesser General Public
65 License along with the GNU C Library; if not, write to the Free
66 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
67 MA 02110-1335, USA
68 */
69
70 /*
71 * August 2006, for gawk, same comment applies. See strncase.c
72 * in the GLIBC sources.
73 */
74
75
76 /* Compare no more than N characters of S1 and S2,
77 ignoring case, returning less than, equal to or
78 greater than zero if S1 is lexicographically less
79 than, equal to or greater than S2. */
80 int
81 strncasecmp (s1, s2, n)
82 const char *s1;
83 const char *s2;
84 size_t n;
85 {
86 const unsigned char *p1 = (const unsigned char *) s1;
87 const unsigned char *p2 = (const unsigned char *) s2;
88 int result;
89
90 if (p1 == p2 || n == 0)
91 return 0;
92
93 while ((result = tolower (*p1) - tolower (*p2++)) == 0)
94 if (*p1++ == '\0' || --n == 0)
95 break;
96
97 return result;
98 }