struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / asxxsrc / strcmpi.c
blob53cdc5a8fd096f55dbdbbac76e54d76b5ce4a236
1 /* strcmpi.c */
3 /*
4 * Compare two strings ignoring case.
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 *
12 #include <ctype.h>
13 #include <stddef.h>
15 int as_strcmpi (const char *s1, const char *s2)
17 const unsigned char *p1 = (const unsigned char *) s1;
18 const unsigned char *p2 = (const unsigned char *) s2;
19 unsigned char c1, c2;
21 if (p1 == p2)
22 return 0;
26 c1 = tolower (*p1++);
27 c2 = tolower (*p2++);
28 if (c1 == '\0')
29 break;
31 while (c1 == c2);
33 return c1 - c2;
36 int as_strncmpi (const char *s1, const char *s2, size_t n)
38 const unsigned char *p1 = (const unsigned char *) s1;
39 const unsigned char *p2 = (const unsigned char *) s2;
40 unsigned char c1, c2;
42 if ((p1 == p2) || (n == 0))
43 return 0;
47 c1 = tolower (*p1++);
48 c2 = tolower (*p2++);
49 if (c1 == '\0')
50 break;
52 while ((c1 == c2) && --n);
54 return c1 - c2;