1 /* 2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved. 3 ** Distributed under the terms of the NewOS License. 4 */ 5 /* 6 * Copyright (c) 2008 Travis Geiselbrecht 7 * 8 * Use of this source code is governed by a MIT-style 9 * license that can be found in the LICENSE file or at 10 * https://opensource.org/licenses/MIT 11 */ 12 #include <string.h> 13 #include <ctype.h> 14 #include <sys/types.h> 15 16 int strnicmp(char const * s1,char const * s2,size_t len)17strnicmp(char const *s1, char const *s2, size_t len) { 18 unsigned char c1 = '\0'; 19 unsigned char c2 = '\0'; 20 21 if (len > 0) { 22 do { 23 c1 = *s1; 24 c2 = *s2; 25 s1++; 26 s2++; 27 if (!c1) 28 break; 29 if (!c2) 30 break; 31 if (c1 == c2) 32 continue; 33 c1 = tolower(c1); 34 c2 = tolower(c2); 35 if (c1 != c2) 36 break; 37 } while (--len); 38 } 39 return (int)c1 - (int)c2; 40 } 41 #pragma weak strncasecmp=strnicmp 42