17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright 1990 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* 77c478bd9Sstevel@tonic-gate * Copyright (c) 1987 Regents of the University of California. 87c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 97c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 107c478bd9Sstevel@tonic-gate */ 117c478bd9Sstevel@tonic-gate 12*5d54f3d8Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 13*5d54f3d8Smuffin 147c478bd9Sstevel@tonic-gate /* 157c478bd9Sstevel@tonic-gate * This array is designed for mapping upper and lower case letter 167c478bd9Sstevel@tonic-gate * together for a case independent comparison. The mappings are 177c478bd9Sstevel@tonic-gate * based upon ascii character sequences. 187c478bd9Sstevel@tonic-gate */ 197c478bd9Sstevel@tonic-gate static char charmap[] = { 207c478bd9Sstevel@tonic-gate '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 217c478bd9Sstevel@tonic-gate '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 227c478bd9Sstevel@tonic-gate '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 237c478bd9Sstevel@tonic-gate '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 247c478bd9Sstevel@tonic-gate '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 257c478bd9Sstevel@tonic-gate '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 267c478bd9Sstevel@tonic-gate '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 277c478bd9Sstevel@tonic-gate '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 287c478bd9Sstevel@tonic-gate '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 297c478bd9Sstevel@tonic-gate '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 307c478bd9Sstevel@tonic-gate '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 317c478bd9Sstevel@tonic-gate '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 327c478bd9Sstevel@tonic-gate '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 337c478bd9Sstevel@tonic-gate '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 347c478bd9Sstevel@tonic-gate '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 357c478bd9Sstevel@tonic-gate '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 367c478bd9Sstevel@tonic-gate '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 377c478bd9Sstevel@tonic-gate '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 387c478bd9Sstevel@tonic-gate '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 397c478bd9Sstevel@tonic-gate '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 407c478bd9Sstevel@tonic-gate '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 417c478bd9Sstevel@tonic-gate '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 427c478bd9Sstevel@tonic-gate '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 437c478bd9Sstevel@tonic-gate '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 447c478bd9Sstevel@tonic-gate '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 457c478bd9Sstevel@tonic-gate '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 467c478bd9Sstevel@tonic-gate '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 477c478bd9Sstevel@tonic-gate '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', 487c478bd9Sstevel@tonic-gate '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 497c478bd9Sstevel@tonic-gate '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 507c478bd9Sstevel@tonic-gate '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 517c478bd9Sstevel@tonic-gate '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 527c478bd9Sstevel@tonic-gate }; 537c478bd9Sstevel@tonic-gate 54*5d54f3d8Smuffin int 55*5d54f3d8Smuffin strcasecmp(char *s1, char *s2) 567c478bd9Sstevel@tonic-gate { 57*5d54f3d8Smuffin char *cm = charmap; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate while (cm[*s1] == cm[*s2++]) 607c478bd9Sstevel@tonic-gate if (*s1++ == '\0') 617c478bd9Sstevel@tonic-gate return (0); 627c478bd9Sstevel@tonic-gate return(cm[*s1] - cm[*--s2]); 637c478bd9Sstevel@tonic-gate } 647c478bd9Sstevel@tonic-gate 65*5d54f3d8Smuffin int 66*5d54f3d8Smuffin strncasecmp(char *s1, char *s2, int n) 677c478bd9Sstevel@tonic-gate { 68*5d54f3d8Smuffin char *cm = charmap; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate while (--n >= 0 && cm[*s1] == cm[*s2++]) 717c478bd9Sstevel@tonic-gate if (*s1++ == '\0') 727c478bd9Sstevel@tonic-gate return (0); 737c478bd9Sstevel@tonic-gate return(n < 0 ? 0 : cm[*s1] - cm[*--s2]); 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * For 4.0 compatibility 787c478bd9Sstevel@tonic-gate */ 79*5d54f3d8Smuffin int 80*5d54f3d8Smuffin stricmp(char *s1, char *s2) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate return (strcasecmp(s1, s2)); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 85*5d54f3d8Smuffin int 86*5d54f3d8Smuffin strnicmp(char *s1, char *s2, int n) 877c478bd9Sstevel@tonic-gate { 887c478bd9Sstevel@tonic-gate return (strncasecmp(s1, s2, n)); 897c478bd9Sstevel@tonic-gate } 90