xref: /titanic_52/usr/src/lib/libbc/libc/gen/common/stricmp.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"  /* from UCB 1.3 8/3/87 */
7 
8 /*
9  * Copyright (c) 1987 Regents of the University of California.
10  * All rights reserved.  The Berkeley software License Agreement
11  * specifies the terms and conditions for redistribution.
12  */
13 
14 /*
15  * This array is designed for mapping upper and lower case letter
16  * together for a case independent comparison.  The mappings are
17  * based upon ascii character sequences.
18  */
19 static char charmap[] = {
20 	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
21 	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
22 	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
23 	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
24 	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
25 	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
26 	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
27 	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
28 	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
29 	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
30 	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
31 	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
32 	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
33 	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
34 	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
35 	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
36 	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
37 	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
38 	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
39 	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
40 	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
41 	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
42 	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
43 	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
44 	'\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
45 	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
46 	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
47 	'\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
48 	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
49 	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
50 	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
51 	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
52 };
53 
54 strcasecmp(s1, s2)
55 	register char *s1, *s2;
56 {
57 	register char *cm = charmap;
58 
59 	while (cm[*s1] == cm[*s2++])
60 		if (*s1++ == '\0')
61 			return(0);
62 	return(cm[*s1] - cm[*--s2]);
63 }
64 
65 strncasecmp(s1, s2, n)
66 	register char *s1, *s2;
67 	register int n;
68 {
69 	register char *cm = charmap;
70 
71 	while (--n >= 0 && cm[*s1] == cm[*s2++])
72 		if (*s1++ == '\0')
73 			return(0);
74 	return(n < 0 ? 0 : cm[*s1] - cm[*--s2]);
75 }
76 
77 /*
78  *  For 4.0 compatibility
79  */
80 stricmp(s1, s2)
81 	register char *s1, *s2;
82 {
83 	return(strcasecmp(s1, s2));
84 }
85 
86 strnicmp(s1, s2, n)
87 	register char *s1, *s2;
88 	register int n;
89 {
90 	return(strncasecmp(s1, s2, n));
91 }
92 
93