strcasecmp.c revision 127668
1139826Simp/* 253541Sshin * Copyright (c) 1987 Regents of the University of California. 353541Sshin * All rights reserved. 453541Sshin * 553541Sshin * Redistribution and use in source and binary forms are permitted 653541Sshin * provided that this notice is preserved and that due credit is given 753541Sshin * to the University of California at Berkeley. The name of the University 853541Sshin * may not be used to endorse or promote products derived from this 953541Sshin * software without specific written prior permission. This software 1053541Sshin * is provided ``as is'' without express or implied warranty. 1153541Sshin */ 1253541Sshin 1353541Sshin#ifdef HAVE_CONFIG_H 1453541Sshin#include "config.h" 1553541Sshin#endif 1653541Sshin 1753541Sshin#ifndef lint 1853541Sshinstatic const char rcsid[] _U_ = 1953541Sshin "@(#) $Header: /tcpdump/master/tcpdump/strcasecmp.c,v 1.4.2.2 2003/11/16 08:51:57 guy Exp $"; 2053541Sshin#endif 2153541Sshin 2253541Sshin#include <tcpdump-stdinc.h> 2353541Sshin 2453541Sshin#include "interface.h" 2553541Sshin 2653541Sshin/* 2753541Sshin * This array is designed for mapping upper and lower case letter 28174510Sobrien * together for a case independent comparison. The mappings are 29174510Sobrien * based upon ascii character sequences. 3053541Sshin */ 3153541Sshinstatic u_char charmap[] = { 32174510Sobrien '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 33174510Sobrien '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 34174510Sobrien '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 3562587Sitojun '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 3662587Sitojun '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 37225044Sbz '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 3855009Sshin '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 39148921Ssuz '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 4053541Sshin '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 4153541Sshin '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 4253541Sshin '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 4378064Sume '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 4453541Sshin '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 4553541Sshin '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 4653541Sshin '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 4753541Sshin '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 4853541Sshin '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 4953541Sshin '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 5078064Sume '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 5153541Sshin '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 5253541Sshin '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 5353541Sshin '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 54225044Sbz '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 5553541Sshin '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 5684994Sdarrenr '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 5753541Sshin '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 5853541Sshin '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 5953541Sshin '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 6078064Sume '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 6178064Sume '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 6262587Sitojun '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 6378064Sume '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 6462587Sitojun}; 6553541Sshin 66148385Sumeint 6762587Sitojunstrcasecmp(s1, s2) 6853541Sshin const char *s1, *s2; 6953541Sshin{ 7078064Sume register u_char *cm = charmap, 7178064Sume *us1 = (u_char *)s1, 72171167Sgnn *us2 = (u_char *)s2; 73105199Ssam 74105199Ssam while (cm[*us1] == cm[*us2++]) 75105199Ssam if (*us1++ == '\0') 76171167Sgnn return(0); 77105199Ssam return(cm[*us1] - cm[*--us2]); 7884994Sdarrenr} 7984994Sdarrenr 8053541Sshinint 8153541Sshinstrncasecmp(s1, s2, n) 8253541Sshin const char *s1, *s2; 8353541Sshin register int n; 8453541Sshin{ 8553541Sshin register u_char *cm = charmap, 8653541Sshin *us1 = (u_char *)s1, 8753541Sshin *us2 = (u_char *)s2; 8853541Sshin 8953541Sshin while (--n >= 0 && cm[*us1] == cm[*us2++]) 9053541Sshin if (*us1++ == '\0') 9153541Sshin return(0); 9253541Sshin return(n < 0 ? 0 : cm[*us1] - cm[*--us2]); 93171259Sdelphij} 9453541Sshin