xref: /titanic_41/usr/src/lib/libbc/libc/gen/common/stricmp.c (revision c138f478d2bc94e73ab8f6a084e323bec25e62f5)
1 /*
2  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1987 Regents of the University of California.
8  * All rights reserved.  The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
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 int
55 strcasecmp(char *s1, char *s2)
56 {
57 	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 int
66 strncasecmp(char *s1, char *s2, int n)
67 {
68 	char *cm = charmap;
69 
70 	while (--n >= 0 && cm[*s1] == cm[*s2++])
71 		if (*s1++ == '\0')
72 			return (0);
73 	return(n < 0 ? 0 : cm[*s1] - cm[*--s2]);
74 }
75 
76 /*
77  *  For 4.0 compatibility
78  */
79 int
80 stricmp(char *s1, char *s2)
81 {
82 	return (strcasecmp(s1, s2));
83 }
84 
85 int
86 strnicmp(char *s1, char *s2, int n)
87 {
88 	return (strncasecmp(s1, s2, n));
89 }
90