133965Sjdp/* 233965Sjdp * Copyright (c) 1987 Regents of the University of California. 333965Sjdp * All rights reserved. 433965Sjdp * 533965Sjdp * Redistribution and use in source and binary forms are permitted 633965Sjdp * provided that this notice is preserved and that due credit is given 733965Sjdp * to the University of California at Berkeley. The name of the University 833965Sjdp * may not be used to endorse or promote products derived from this 933965Sjdp * software without specific written prior permission. This software 1033965Sjdp * is provided ``as is'' without express or implied warranty. 1133965Sjdp */ 1233965Sjdp 1389857Sobrien/* 1489857Sobrien 1589857Sobrien@deftypefn Supplemental int strncasecmp (const char *@var{s1}, const char *@var{s2}) 1689857Sobrien 1789857SobrienA case-insensitive @code{strncmp}. 1889857Sobrien 1989857Sobrien@end deftypefn 2089857Sobrien 2189857Sobrien*/ 2289857Sobrien 2333965Sjdp#if defined(LIBC_SCCS) && !defined(lint) 2433965Sjdpstatic char sccsid[] = "@(#)strcasecmp.c 5.5 (Berkeley) 11/24/87"; 2533965Sjdp#endif /* LIBC_SCCS and not lint */ 2633965Sjdp 2733965Sjdp#include <ansidecl.h> 2833965Sjdp#include <stddef.h> 2933965Sjdp 3033965Sjdp/* 3133965Sjdp * This array is designed for mapping upper and lower case letter 3233965Sjdp * together for a case independent comparison. The mappings are 3333965Sjdp * based upon ascii character sequences. 3433965Sjdp */ 3589857Sobrienstatic const unsigned char charmap[] = { 3633965Sjdp '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 3733965Sjdp '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 3833965Sjdp '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 3933965Sjdp '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 4033965Sjdp '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 4133965Sjdp '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 4233965Sjdp '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 4333965Sjdp '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 4433965Sjdp '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 4533965Sjdp '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 4633965Sjdp '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 4733965Sjdp '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 4833965Sjdp '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 4933965Sjdp '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 5033965Sjdp '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 5133965Sjdp '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 5233965Sjdp '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 5333965Sjdp '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 5433965Sjdp '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 5533965Sjdp '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 5633965Sjdp '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 5733965Sjdp '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 5833965Sjdp '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 5933965Sjdp '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 6033965Sjdp '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 6133965Sjdp '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 6233965Sjdp '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 6333965Sjdp '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 6433965Sjdp '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 6533965Sjdp '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 6633965Sjdp '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 6733965Sjdp '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 6833965Sjdp}; 6933965Sjdp 7033965Sjdpint 71218822Sdimstrncasecmp(const char *s1, const char *s2, register size_t n) 7233965Sjdp{ 7333965Sjdp register unsigned char u1, u2; 7433965Sjdp 7533965Sjdp for (; n != 0; --n) { 7633965Sjdp u1 = (unsigned char) *s1++; 7733965Sjdp u2 = (unsigned char) *s2++; 7833965Sjdp if (charmap[u1] != charmap[u2]) { 7933965Sjdp return charmap[u1] - charmap[u2]; 8033965Sjdp } 8133965Sjdp if (u1 == '\0') { 8233965Sjdp return 0; 8333965Sjdp } 8433965Sjdp } 8533965Sjdp return 0; 8633965Sjdp} 87