comparison target-utils/libc/strcasecmp.c @ 87:7fb62fc724dc

target-utils/libc: beginning of newlib-ectomy
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 28 Oct 2016 22:20:26 +0000
parents
children
comparison
equal deleted inserted replaced
86:684eddecbc62 87:7fb62fc724dc
1 #include <sys/types.h>
2
3 /*
4 * This array is designed for mapping upper and lower case letter
5 * together for a case independent comparison. The mappings are
6 * based upon ascii character sequences.
7 */
8 static const u_char charmap[] = {
9 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
10 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
11 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
12 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
13 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
14 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
15 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
16 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
17 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
18 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
19 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
20 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
21 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
22 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
23 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
24 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
25 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
26 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
27 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
28 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
29 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
30 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
31 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
32 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
33 '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
34 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
35 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
36 '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
37 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
38 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
39 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
40 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
41 };
42
43 strcasecmp(s1, s2)
44 const char *s1, *s2;
45 {
46 register const u_char *us1 = (const u_char *)s1,
47 *us2 = (const u_char *)s2;
48
49 while (charmap[*us1] == charmap[*us2++])
50 if (*us1++ == '\0')
51 return(0);
52 return(charmap[*us1] - charmap[*--us2]);
53 }
54
55 strncasecmp(s1, s2, n)
56 const char *s1, *s2;
57 register int n;
58 {
59 register const u_char *us1 = (const u_char *)s1,
60 *us2 = (const u_char *)s2;
61
62 while (--n >= 0 && charmap[*us1] == charmap[*us2++])
63 if (*us1++ == '\0')
64 return(0);
65 return(n < 0 ? 0 : charmap[*us1] - charmap[*--us2]);
66 }