xref: /onnv-gate/usr/src/lib/libbc/libc/gen/common/stricmp.c (revision 722:636b850d4ee9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate  * Copyright (c) 1987 Regents of the University of California.
80Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
90Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate  */
110Sstevel@tonic-gate 
12*722Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*722Smuffin 
140Sstevel@tonic-gate /*
150Sstevel@tonic-gate  * This array is designed for mapping upper and lower case letter
160Sstevel@tonic-gate  * together for a case independent comparison.  The mappings are
170Sstevel@tonic-gate  * based upon ascii character sequences.
180Sstevel@tonic-gate  */
190Sstevel@tonic-gate static char charmap[] = {
200Sstevel@tonic-gate 	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
210Sstevel@tonic-gate 	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
220Sstevel@tonic-gate 	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
230Sstevel@tonic-gate 	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
240Sstevel@tonic-gate 	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
250Sstevel@tonic-gate 	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
260Sstevel@tonic-gate 	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
270Sstevel@tonic-gate 	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
280Sstevel@tonic-gate 	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
290Sstevel@tonic-gate 	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
300Sstevel@tonic-gate 	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
310Sstevel@tonic-gate 	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
320Sstevel@tonic-gate 	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
330Sstevel@tonic-gate 	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
340Sstevel@tonic-gate 	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
350Sstevel@tonic-gate 	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
360Sstevel@tonic-gate 	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
370Sstevel@tonic-gate 	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
380Sstevel@tonic-gate 	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
390Sstevel@tonic-gate 	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
400Sstevel@tonic-gate 	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
410Sstevel@tonic-gate 	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
420Sstevel@tonic-gate 	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
430Sstevel@tonic-gate 	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
440Sstevel@tonic-gate 	'\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
450Sstevel@tonic-gate 	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
460Sstevel@tonic-gate 	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
470Sstevel@tonic-gate 	'\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
480Sstevel@tonic-gate 	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
490Sstevel@tonic-gate 	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
500Sstevel@tonic-gate 	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
510Sstevel@tonic-gate 	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
520Sstevel@tonic-gate };
530Sstevel@tonic-gate 
54*722Smuffin int
strcasecmp(char * s1,char * s2)55*722Smuffin strcasecmp(char *s1, char *s2)
560Sstevel@tonic-gate {
57*722Smuffin 	char *cm = charmap;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	while (cm[*s1] == cm[*s2++])
600Sstevel@tonic-gate 		if (*s1++ == '\0')
61*722Smuffin 			return (0);
620Sstevel@tonic-gate 	return(cm[*s1] - cm[*--s2]);
630Sstevel@tonic-gate }
640Sstevel@tonic-gate 
65*722Smuffin int
strncasecmp(char * s1,char * s2,int n)66*722Smuffin strncasecmp(char *s1, char *s2, int n)
670Sstevel@tonic-gate {
68*722Smuffin 	char *cm = charmap;
69*722Smuffin 
700Sstevel@tonic-gate 	while (--n >= 0 && cm[*s1] == cm[*s2++])
710Sstevel@tonic-gate 		if (*s1++ == '\0')
72*722Smuffin 			return (0);
730Sstevel@tonic-gate 	return(n < 0 ? 0 : cm[*s1] - cm[*--s2]);
740Sstevel@tonic-gate }
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  *  For 4.0 compatibility
780Sstevel@tonic-gate  */
79*722Smuffin int
stricmp(char * s1,char * s2)80*722Smuffin stricmp(char *s1, char *s2)
810Sstevel@tonic-gate {
82*722Smuffin 	return (strcasecmp(s1, s2));
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
85*722Smuffin int
strnicmp(char * s1,char * s2,int n)86*722Smuffin strnicmp(char *s1, char *s2, int n)
870Sstevel@tonic-gate {
88*722Smuffin 	return (strncasecmp(s1, s2, n));
890Sstevel@tonic-gate }
90