Imported Upstream version 2.9.0
[debian/cc1111] / as / asxxsrc / strcmpi.c
1 /* strcmpi.c */
2
3 /*
4  * Compare two strings ignoring case.
5  *
6  * Taken from GLIBC 2.2.5. Original code is copyrighted "Free
7  * Software Foundation" and published under the GNU Lesser General
8  * Public License.
9  * 
10  */
11
12 #include <ctype.h>
13 #include <stddef.h>
14
15 int as_strcmpi (const char *s1, const char *s2)
16 {
17   const unsigned char *p1 = (const unsigned char *) s1;
18   const unsigned char *p2 = (const unsigned char *) s2;
19   unsigned char c1, c2;
20
21   if (p1 == p2)
22     return 0;
23
24   do
25     {
26       c1 = tolower (*p1++);
27       c2 = tolower (*p2++);
28       if (c1 == '\0')
29         break;
30     }
31   while (c1 == c2);
32   
33   return c1 - c2;
34 }
35
36 int as_strncmpi (const char *s1, const char *s2, size_t n)
37 {
38   const unsigned char *p1 = (const unsigned char *) s1;
39   const unsigned char *p2 = (const unsigned char *) s2;
40   unsigned char c1, c2;
41
42   if ((p1 == p2) || (n == 0))
43     return 0;
44
45   do
46     {
47       c1 = tolower (*p1++);
48       c2 = tolower (*p2++);
49       if (c1 == '\0')
50         break;
51     }
52   while ((c1 == c2) && --n);
53
54   return c1 - c2;
55 }