1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <ctype.h>
6 #include <strings.h>
7 
strcasecmp(const char * s1,const char * s2)8 int strcasecmp(const char* s1, const char* s2) {
9     while (1) {
10         int diff = tolower(*s1) - tolower(*s2);
11         if (diff != 0 || *s1 == '\0') {
12             return diff;
13         }
14         s1++;
15         s2++;
16     }
17 }
18 
strncasecmp(const char * s1,const char * s2,size_t len)19 int strncasecmp(const char* s1, const char* s2, size_t len) {
20     while (len-- > 0) {
21         int diff = tolower(*s1) - tolower(*s2);
22         if (diff != 0 || *s1 == '\0') {
23             return diff;
24         }
25         s1++;
26         s2++;
27     }
28     return 0;
29 }
30