144743Smarkm/*
244743Smarkm * Copyright (c) 1987 Regents of the University of California.
344743Smarkm * All rights reserved.
444743Smarkm *
544743Smarkm * Redistribution and use in source and binary forms are permitted
644743Smarkm * provided that the above copyright notice and this paragraph are
744743Smarkm * duplicated in all such forms and that any documentation,
844743Smarkm * advertising materials, and other materials related to such
944743Smarkm * distribution and use acknowledge that the software was developed
1044743Smarkm * by the University of California, Berkeley.  The name of the
1144743Smarkm * University may not be used to endorse or promote products derived
1244743Smarkm * from this software without specific prior written permission.
1344743Smarkm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1444743Smarkm * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1544743Smarkm * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1644743Smarkm */
1744743Smarkm
1844743Smarkm#if defined(LIBC_SCCS) && !defined(lint)
1944743Smarkmstatic char sccsid[] = "@(#)strcasecmp.c	5.6 (Berkeley) 6/27/88";
2044743Smarkm#endif /* LIBC_SCCS and not lint */
2144743Smarkm
2244743Smarkm/* Some environments don't define u_char -- WZV */
2344743Smarkm#if 0
2444743Smarkm#include <sys/types.h>
2544743Smarkm#else
2644743Smarkmtypedef unsigned char u_char;
2744743Smarkm#endif
2844743Smarkm
2944743Smarkm/*
3044743Smarkm * This array is designed for mapping upper and lower case letter
3144743Smarkm * together for a case independent comparison.  The mappings are
3244743Smarkm * based upon ascii character sequences.
3344743Smarkm */
3444743Smarkmstatic u_char charmap[] = {
3544743Smarkm	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
3644743Smarkm	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
3744743Smarkm	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
3844743Smarkm	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
3944743Smarkm	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
4044743Smarkm	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
4144743Smarkm	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
4244743Smarkm	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
4344743Smarkm	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
4444743Smarkm	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
4544743Smarkm	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
4644743Smarkm	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
4744743Smarkm	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
4844743Smarkm	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
4944743Smarkm	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
5044743Smarkm	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
5144743Smarkm	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
5244743Smarkm	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
5344743Smarkm	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
5444743Smarkm	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
5544743Smarkm	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
5644743Smarkm	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
5744743Smarkm	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
5844743Smarkm	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
5944743Smarkm	'\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
6044743Smarkm	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
6144743Smarkm	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
6244743Smarkm	'\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
6344743Smarkm	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
6444743Smarkm	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
6544743Smarkm	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
6644743Smarkm	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
6744743Smarkm};
6844743Smarkm
6944743Smarkmstrcasecmp(s1, s2)
7044743Smarkm	char *s1, *s2;
7144743Smarkm{
7244743Smarkm	register u_char	*cm = charmap,
7344743Smarkm			*us1 = (u_char *)s1,
7444743Smarkm			*us2 = (u_char *)s2;
7544743Smarkm
7644743Smarkm	while (cm[*us1] == cm[*us2++])
7744743Smarkm		if (*us1++ == '\0')
7844743Smarkm			return(0);
7944743Smarkm	return(cm[*us1] - cm[*--us2]);
8044743Smarkm}
8144743Smarkm
8244743Smarkmstrncasecmp(s1, s2, n)
8344743Smarkm	char *s1, *s2;
8444743Smarkm	register int n;
8544743Smarkm{
8644743Smarkm	register u_char	*cm = charmap,
8744743Smarkm			*us1 = (u_char *)s1,
8844743Smarkm			*us2 = (u_char *)s2;
8944743Smarkm
9044743Smarkm	while (--n >= 0 && cm[*us1] == cm[*us2++])
9144743Smarkm		if (*us1++ == '\0')
9244743Smarkm			return(0);
9344743Smarkm	return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);
9444743Smarkm}
95