1 /* @(#)strncasecmp.c 1.1 11/11/24 Copyright 2011 J. Schilling */ 2 /* 3 * strcasecmp() to be used if missing in libc 4 * 5 * Copyright (c) 2011 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #include <schily/standard.h> 22 #include <schily/string.h> 23 #include <schily/types.h> /* For strncasecmp size_t */ 24 #include <schily/schily.h> 25 26 #ifndef HAVE_STRNCASECMP 27 28 EXPORT int strncasecmp __PR((const char *s1, const char *s2, 29 size_t len)); 30 31 EXPORT int strncasecmp(s1,s2,len)32strncasecmp(s1, s2, len) 33 register const char *s1; 34 register const char *s2; 35 register size_t len; 36 { 37 extern const char js_strcase_charmap[]; 38 register const char *chm = js_strcase_charmap; 39 40 if (s1 == s2) 41 return (0); 42 43 if (len == 0) 44 return (0); 45 46 do { 47 if (chm[* (const unsigned char *)s1] == 48 chm[* (const unsigned char *)s2++]) { 49 if (*s1++ == '\0') 50 return (0); 51 } else { 52 break; 53 } 54 } while (--len > 0); 55 56 return (len == 0 ? 0 : chm[*(unsigned char *)s1] - 57 chm[*(unsigned char *)(--s2)]); 58 } 59 #endif 60