1 | /*
|
---|
2 | * Copyright (c) 1987 Regents of the University of California.
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms are permitted
|
---|
6 | * provided that the above copyright notice and this paragraph are
|
---|
7 | * duplicated in all such forms and that any documentation,
|
---|
8 | * advertising materials, and other materials related to such
|
---|
9 | * distribution and use acknowledge that the software was developed
|
---|
10 | * by the University of California, Berkeley. The name of the
|
---|
11 | * University may not be used to endorse or promote products derived
|
---|
12 | * from this software without specific prior written permission.
|
---|
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #if defined(LIBC_SCCS) && !defined(lint)
|
---|
19 | static char sccsid[] = "@(#)strcasecmp.c 5.6 (Berkeley) 6/27/88";
|
---|
20 | #endif /* LIBC_SCCS and not lint */
|
---|
21 |
|
---|
22 | #ifdef atarist
|
---|
23 | #include <sys/types.h>
|
---|
24 | #else
|
---|
25 | #define u_char unsigned char
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /* This rather ugly macro is for VMS C */
|
---|
29 | #ifdef C
|
---|
30 | #undef C
|
---|
31 | #endif
|
---|
32 | #define C(c) ((u_char)c)
|
---|
33 | /*
|
---|
34 | * This array is designed for mapping upper and lower case letter
|
---|
35 | * together for a case independent comparison. The mappings are
|
---|
36 | * based upon ascii character sequences.
|
---|
37 | */
|
---|
38 | static u_char charmap[] = {
|
---|
39 | '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
|
---|
40 | '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
|
---|
41 | '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
|
---|
42 | '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
|
---|
43 | '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
|
---|
44 | '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
|
---|
45 | '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
|
---|
46 | '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
|
---|
47 | '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
---|
48 | '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
---|
49 | '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
---|
50 | '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
|
---|
51 | '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
---|
52 | '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
---|
53 | '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
---|
54 | '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
|
---|
55 | C('\200'), C('\201'), C('\202'), C('\203'), C('\204'), C('\205'), C('\206'), C('\207'),
|
---|
56 | C('\210'), C('\211'), C('\212'), C('\213'), C('\214'), C('\215'), C('\216'), C('\217'),
|
---|
57 | C('\220'), C('\221'), C('\222'), C('\223'), C('\224'), C('\225'), C('\226'), C('\227'),
|
---|
58 | C('\230'), C('\231'), C('\232'), C('\233'), C('\234'), C('\235'), C('\236'), C('\237'),
|
---|
59 | C('\240'), C('\241'), C('\242'), C('\243'), C('\244'), C('\245'), C('\246'), C('\247'),
|
---|
60 | C('\250'), C('\251'), C('\252'), C('\253'), C('\254'), C('\255'), C('\256'), C('\257'),
|
---|
61 | C('\260'), C('\261'), C('\262'), C('\263'), C('\264'), C('\265'), C('\266'), C('\267'),
|
---|
62 | C('\270'), C('\271'), C('\272'), C('\273'), C('\274'), C('\275'), C('\276'), C('\277'),
|
---|
63 | C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'),
|
---|
64 | C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'),
|
---|
65 | C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\327'),
|
---|
66 | C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\337'),
|
---|
67 | C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'),
|
---|
68 | C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'),
|
---|
69 | C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\367'),
|
---|
70 | C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\377'),
|
---|
71 | };
|
---|
72 |
|
---|
73 | #undef C
|
---|
74 |
|
---|
75 | int
|
---|
76 | strcasecmp(s1, s2)
|
---|
77 | const char *s1, *s2;
|
---|
78 | {
|
---|
79 | register u_char *cm = charmap,
|
---|
80 | *us1 = (u_char *)s1,
|
---|
81 | *us2 = (u_char *)s2;
|
---|
82 |
|
---|
83 | while (cm[*us1] == cm[*us2++])
|
---|
84 | if (*us1++ == '\0')
|
---|
85 | return(0);
|
---|
86 | return(cm[*us1] - cm[*--us2]);
|
---|
87 | }
|
---|
88 |
|
---|
89 | int
|
---|
90 | strncasecmp(s1, s2, n)
|
---|
91 | const char *s1, *s2;
|
---|
92 | register size_t n;
|
---|
93 | {
|
---|
94 | register u_char *cm = charmap,
|
---|
95 | *us1 = (u_char *)s1,
|
---|
96 | *us2 = (u_char *)s2;
|
---|
97 |
|
---|
98 | while ((long)(--n) >= 0 && cm[*us1] == cm[*us2++])
|
---|
99 | if (*us1++ == '\0')
|
---|
100 | return(0);
|
---|
101 | return((long)n < 0 ? 0 : cm[*us1] - cm[*--us2]);
|
---|
102 | }
|
---|