1 #if defined(LIBC_SCCS) && !defined(lint) 2 static const char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; 3 static const char rcsid[] = "$Id: strcasecmp.c,v 1.2 2005/04/27 04:56:12 sra Exp $"; 4 #endif /* LIBC_SCCS and not lint */ 5 6 /* 7 * Copyright (c) 1987, 1993 8 * The Regents of the University of California. All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #include "port_before.h" 40 41 #include <sys/param.h> 42 #include <sys/types.h> 43 #include <sys/cdefs.h> 44 45 #include <string.h> 46 47 #include "port_after.h" 48 49 #ifndef NEED_STRCASECMP 50 int __strcasecmp_unneeded__; 51 #else 52 53 /*% 54 * This array is designed for mapping upper and lower case letter 55 * together for a case independent comparison. The mappings are 56 * based upon ascii character sequences. 57 */ 58 static const u_char charmap[] = { 59 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007, 60 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017, 61 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027, 62 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037, 63 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047, 64 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057, 65 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, 66 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077, 67 0100, 0141, 0142, 0143, 0144, 0145, 0146, 0147, 68 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157, 69 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167, 70 0170, 0171, 0172, 0133, 0134, 0135, 0136, 0137, 71 0140, 0141, 0142, 0143, 0144, 0145, 0146, 0147, 72 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157, 73 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167, 74 0170, 0171, 0172, 0173, 0174, 0175, 0176, 0177, 75 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207, 76 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217, 77 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227, 78 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237, 79 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, 80 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257, 81 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, 82 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, 83 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307, 84 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317, 85 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327, 86 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, 87 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, 88 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357, 89 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, 90 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377 91 }; 92 93 int 94 strcasecmp(const char *s1, const char *s2) { 95 const u_char *cm = charmap, 96 *us1 = (const u_char *)s1, 97 *us2 = (const u_char *)s2; 98 99 while (cm[*us1] == cm[*us2++]) 100 if (*us1++ == '\0') 101 return (0); 102 return (cm[*us1] - cm[*--us2]); 103 } 104 105 int 106 strncasecmp(const char *s1, const char *s2, size_t n) { 107 if (n != 0) { 108 const u_char *cm = charmap, 109 *us1 = (const u_char *)s1, 110 *us2 = (const u_char *)s2; 111 112 do { 113 if (cm[*us1] != cm[*us2++]) 114 return (cm[*us1] - cm[*--us2]); 115 if (*us1++ == '\0') 116 break; 117 } while (--n != 0); 118 } 119 return (0); 120 } 121 122 #endif /*NEED_STRCASECMP*/ 123 124 /*! \file */ 125