1 /* 2 * Copyright (c) 2018 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <stdlib.h> 8 #include <ctype.h> 9 10 int strncasecmp(const char * s1,const char * s2,size_t n)11strncasecmp(const char *s1, const char *s2, size_t n) 12 { 13 unsigned char c = 1U; 14 15 for (; c && n != 0; n--) { 16 unsigned char lower1, lower2; 17 18 c = *s1++; 19 lower1 = tolower(c); 20 lower2 = tolower((unsigned char)*s2++); 21 22 if (lower1 != lower2) { 23 return (lower1 > lower2) - (lower1 < lower2); 24 } 25 } 26 27 return 0; 28 } 29