1 /*
2  *  R : A Computer Language for Statistical Data Analysis
3  *  Copyright (C) 2002   The R Core Team.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, a copy is available at
17  *  https://www.R-project.org/Licenses/
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include <ctype.h>
25 #include <sys/types.h>
26 
27 /* This version uses locale-specific case folding */
28 
strncasecmp(const char * s1,const char * s2,size_t n)29 int strncasecmp(const char *s1, const char *s2, size_t n)
30 {
31     char c1, c2;
32     int i;
33 
34     for (i = 0; i < n; i++) {
35 	c1 = s1[i]; c2 = s2[i];
36 	c1 = isupper(c1) ? tolower(c1) : c1;
37 	c2 = isupper(c2) ? tolower(c2) : c2;
38 	if (c1 == '\0') return ((c2 == '\0') ? 0 : -1);
39 	if (c2 == '\0') return 1;
40 	if (c1 < c2) return -1;
41 	if (c1 > c2) return 1;
42     }
43     return 0;
44 }
45