1f9f848faSopenharmony_ci/* 2f9f848faSopenharmony_ci * Copyright (c) 1987 Regents of the University of California. 3f9f848faSopenharmony_ci * All rights reserved. 4f9f848faSopenharmony_ci * 5f9f848faSopenharmony_ci * Redistribution and use in source and binary forms are permitted 6f9f848faSopenharmony_ci * provided that the above copyright notice and this paragraph are 7f9f848faSopenharmony_ci * duplicated in all such forms and that any documentation, 8f9f848faSopenharmony_ci * advertising materials, and other materials related to such 9f9f848faSopenharmony_ci * distribution and use acknowledge that the software was developed 10f9f848faSopenharmony_ci * by the University of California, Berkeley. The name of the 11f9f848faSopenharmony_ci * University may not be used to endorse or promote products derived 12f9f848faSopenharmony_ci * from this software without specific prior written permission. 13f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14f9f848faSopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15f9f848faSopenharmony_ci * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16f9f848faSopenharmony_ci */ 17f9f848faSopenharmony_ci 18f9f848faSopenharmony_ci#if defined(LIBC_SCCS) && !defined(lint) 19f9f848faSopenharmony_cistatic char sccsid[] = "@(#)strcasecmp.c 5.6 (Berkeley) 6/27/88"; 20f9f848faSopenharmony_ci#endif /* LIBC_SCCS and not lint */ 21f9f848faSopenharmony_ci 22f9f848faSopenharmony_ci/* Some environments don't define u_char -- WZV */ 23f9f848faSopenharmony_ci#if 0 24f9f848faSopenharmony_ci#include <sys/types.h> 25f9f848faSopenharmony_ci#else 26f9f848faSopenharmony_citypedef unsigned char u_char; 27f9f848faSopenharmony_ci#endif 28f9f848faSopenharmony_ci 29f9f848faSopenharmony_ci/* 30f9f848faSopenharmony_ci * This array is designed for mapping upper and lower case letter 31f9f848faSopenharmony_ci * together for a case independent comparison. The mappings are 32f9f848faSopenharmony_ci * based upon ascii character sequences. 33f9f848faSopenharmony_ci */ 34f9f848faSopenharmony_cistatic u_char charmap[] = { 35f9f848faSopenharmony_ci '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 36f9f848faSopenharmony_ci '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 37f9f848faSopenharmony_ci '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 38f9f848faSopenharmony_ci '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 39f9f848faSopenharmony_ci '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 40f9f848faSopenharmony_ci '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 41f9f848faSopenharmony_ci '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 42f9f848faSopenharmony_ci '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 43f9f848faSopenharmony_ci '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 44f9f848faSopenharmony_ci '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 45f9f848faSopenharmony_ci '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 46f9f848faSopenharmony_ci '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 47f9f848faSopenharmony_ci '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 48f9f848faSopenharmony_ci '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 49f9f848faSopenharmony_ci '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 50f9f848faSopenharmony_ci '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 51f9f848faSopenharmony_ci '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 52f9f848faSopenharmony_ci '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 53f9f848faSopenharmony_ci '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 54f9f848faSopenharmony_ci '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 55f9f848faSopenharmony_ci '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 56f9f848faSopenharmony_ci '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 57f9f848faSopenharmony_ci '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 58f9f848faSopenharmony_ci '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 59f9f848faSopenharmony_ci '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 60f9f848faSopenharmony_ci '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 61f9f848faSopenharmony_ci '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 62f9f848faSopenharmony_ci '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 63f9f848faSopenharmony_ci '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 64f9f848faSopenharmony_ci '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 65f9f848faSopenharmony_ci '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 66f9f848faSopenharmony_ci '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 67f9f848faSopenharmony_ci}; 68f9f848faSopenharmony_ci 69f9f848faSopenharmony_ciint strcasecmp(char *s1, char *s2) 70f9f848faSopenharmony_ci{ 71f9f848faSopenharmony_ci register u_char *cm = charmap, 72f9f848faSopenharmony_ci *us1 = (u_char *)s1, 73f9f848faSopenharmony_ci *us2 = (u_char *)s2; 74f9f848faSopenharmony_ci 75f9f848faSopenharmony_ci while (cm[*us1] == cm[*us2++]) 76f9f848faSopenharmony_ci if (*us1++ == '\0') 77f9f848faSopenharmony_ci return(0); 78f9f848faSopenharmony_ci return(cm[*us1] - cm[*--us2]); 79f9f848faSopenharmony_ci} 80f9f848faSopenharmony_ci 81f9f848faSopenharmony_ciint strncasecmp(char *s1, char *s2, register int n) 82f9f848faSopenharmony_ci{ 83f9f848faSopenharmony_ci register u_char *cm = charmap, 84f9f848faSopenharmony_ci *us1 = (u_char *)s1, 85f9f848faSopenharmony_ci *us2 = (u_char *)s2; 86f9f848faSopenharmony_ci 87f9f848faSopenharmony_ci while (--n >= 0 && cm[*us1] == cm[*us2++]) 88f9f848faSopenharmony_ci if (*us1++ == '\0') 89f9f848faSopenharmony_ci return(0); 90f9f848faSopenharmony_ci return(n < 0 ? 0 : cm[*us1] - cm[*--us2]); 91f9f848faSopenharmony_ci} 92