1 /* This file is part of GNU Mailutils
2    Copyright (C) 2009-2021 Free Software Foundation, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 3 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General
15    Public License along with this library.  If not, see
16    <http://www.gnu.org/licenses/>. */
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stddef.h>
22 #include <mailutils/cctype.h>
23 
24 int
mu_c_strcasecmp(const char * a,const char * b)25 mu_c_strcasecmp (const char *a, const char *b)
26 {
27   int d = 0;
28   for (; d == 0; a++, b++)
29     {
30       int ac = (int) *a;
31       int bc = (int) *b;
32       if (ac == 0 || bc == 0)
33 	return ac - bc;
34       if (mu_isascii (ac) && mu_isascii (bc))
35 	d = mu_toupper (ac) - mu_toupper (bc);
36       else
37 	d = ac - bc;
38     }
39   return d;
40 }
41 
42 int
mu_c_strncasecmp(const char * a,const char * b,size_t n)43 mu_c_strncasecmp (const char *a, const char *b, size_t n)
44 {
45   int d = 0;
46   for (; d == 0 && n > 0; a++, b++, n--)
47     {
48       int ac = (int) *a;
49       int bc = (int) *b;
50       if (ac == 0 || bc == 0)
51 	return ac - bc;
52       if (mu_isascii (ac) && mu_isascii (bc))
53 	d = mu_toupper (ac) - mu_toupper (bc);
54       else
55 	d = ac - bc;
56     }
57   return d;
58 }
59