1: /* 2: * Copyright (c) 1987 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: */ 6: 7: #if defined(LIBC_SCCS) && !defined(lint) 8: static char sccsid[] = "@(#)strcasecmp.c 1.3 (Berkeley) 8/3/87"; 9: #endif LIBC_SCCS and not lint 10: 11: /* 12: * This array is designed for mapping upper and lower case letter 13: * together for a case independent comparison. The mappings are 14: * based upon ascii character sequences. 15: */ 16: static char charmap[] = { 17: '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 18: '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 19: '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 20: '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 21: '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 22: '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 23: '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 24: '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 25: '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 26: '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 27: '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 28: '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 29: '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 30: '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 31: '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 32: '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 33: '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 34: '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 35: '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 36: '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 37: '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 38: '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 39: '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 40: '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 41: '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 42: '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 43: '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 44: '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 45: '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 46: '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 47: '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 48: '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 49: }; 50: 51: strcasecmp(s1, s2) 52: register char *s1, *s2; 53: { 54: register char *cm = charmap; 55: 56: while (cm[*s1] == cm[*s2++]) 57: if (*s1++ == '\0') 58: return(0); 59: return(cm[*s1] - cm[*--s2]); 60: } 61: 62: strncasecmp(s1, s2, n) 63: register char *s1, *s2; 64: register int n; 65: { 66: register char *cm = charmap; 67: 68: while (--n >= 0 && cm[*s1] == cm[*s2++]) 69: if (*s1++ == '\0') 70: return(0); 71: return(n < 0 ? 0 : cm[*s1] - cm[*--s2]); 72: }