rearrange to allow internal/private use of ares_strcasecmp to any system that
[platform/upstream/c-ares.git] / ares_strcasecmp.c
1
2 /* $Id$ */
3
4 /* Copyright 1998 by the Massachusetts Institute of Technology.
5  *
6  * Permission to use, copy, modify, and distribute this
7  * software and its documentation for any purpose and without
8  * fee is hereby granted, provided that the above copyright
9  * notice appear in all copies and that both that copyright
10  * notice and this permission notice appear in supporting
11  * documentation, and that the name of M.I.T. not be used in
12  * advertising or publicity pertaining to distribution of the
13  * software without specific, written prior permission.
14  * M.I.T. makes no representations about the suitability of
15  * this software for any purpose.  It is provided "as is"
16  * without express or implied warranty.
17  */
18
19 #include "setup.h"
20 #include "ares_strcasecmp.h"
21
22 #ifndef HAVE_STRCASECMP
23 int ares_strcasecmp(const char *a, const char *b)
24 {
25 #if defined(HAVE_STRCMPI)
26   return strcmpi(a, b);
27 #elif defined(HAVE_STRICMP)
28   return stricmp(a, b);
29 #else
30   size_t i;
31
32   for (i = 0; i < (size_t)-1; i++) {
33     int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
34     int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
35     if (c1 != c2)
36       return c1-c2;
37     if (!c1)
38       break;
39   }
40   return 0;
41 #endif
42 }
43 #endif
44
45 #ifndef HAVE_STRNCASECMP
46 int ares_strncasecmp(const char *a, const char *b, size_t n)
47 {
48 #if defined(HAVE_STRNCMPI)
49   return strncmpi(a, b, n);
50 #elif defined(HAVE_STRNICMP)
51   return strnicmp(a, b, n);
52 #else
53   size_t i;
54
55   for (i = 0; i < n; i++) {
56     int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
57     int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
58     if (c1 != c2)
59       return c1-c2;
60     if (!c1)
61       break;
62   }
63   return 0;
64 #endif
65 }
66 #endif
67