|
Packit |
514978 |
|
|
Packit |
514978 |
|
|
Packit |
514978 |
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
|
Packit |
514978 |
*
|
|
Packit |
514978 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
514978 |
* software and its documentation for any purpose and without
|
|
Packit |
514978 |
* fee is hereby granted, provided that the above copyright
|
|
Packit |
514978 |
* notice appear in all copies and that both that copyright
|
|
Packit |
514978 |
* notice and this permission notice appear in supporting
|
|
Packit |
514978 |
* documentation, and that the name of M.I.T. not be used in
|
|
Packit |
514978 |
* advertising or publicity pertaining to distribution of the
|
|
Packit |
514978 |
* software without specific, written prior permission.
|
|
Packit |
514978 |
* M.I.T. makes no representations about the suitability of
|
|
Packit |
514978 |
* this software for any purpose. It is provided "as is"
|
|
Packit |
514978 |
* without express or implied warranty.
|
|
Packit |
514978 |
*/
|
|
Packit |
514978 |
|
|
Packit |
514978 |
#include "ares_setup.h"
|
|
Packit |
514978 |
#include "ares_strcasecmp.h"
|
|
Packit |
514978 |
|
|
Packit |
514978 |
#ifndef HAVE_STRCASECMP
|
|
Packit |
514978 |
int ares_strcasecmp(const char *a, const char *b)
|
|
Packit |
514978 |
{
|
|
Packit |
514978 |
#if defined(HAVE_STRCMPI)
|
|
Packit |
514978 |
return strcmpi(a, b);
|
|
Packit |
514978 |
#elif defined(HAVE_STRICMP)
|
|
Packit |
514978 |
return stricmp(a, b);
|
|
Packit |
514978 |
#else
|
|
Packit |
514978 |
size_t i;
|
|
Packit |
514978 |
|
|
Packit |
514978 |
for (i = 0; i < (size_t)-1; i++) {
|
|
Packit |
514978 |
int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
|
|
Packit |
514978 |
int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
|
|
Packit |
514978 |
if (c1 != c2)
|
|
Packit |
514978 |
return c1-c2;
|
|
Packit |
514978 |
if (!c1)
|
|
Packit |
514978 |
break;
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
return 0;
|
|
Packit |
514978 |
#endif
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
#endif
|
|
Packit |
514978 |
|
|
Packit |
514978 |
#ifndef HAVE_STRNCASECMP
|
|
Packit |
514978 |
int ares_strncasecmp(const char *a, const char *b, size_t n)
|
|
Packit |
514978 |
{
|
|
Packit |
514978 |
#if defined(HAVE_STRNCMPI)
|
|
Packit |
514978 |
return strncmpi(a, b, n);
|
|
Packit |
514978 |
#elif defined(HAVE_STRNICMP)
|
|
Packit |
514978 |
return strnicmp(a, b, n);
|
|
Packit |
514978 |
#else
|
|
Packit |
514978 |
size_t i;
|
|
Packit |
514978 |
|
|
Packit |
514978 |
for (i = 0; i < n; i++) {
|
|
Packit |
514978 |
int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
|
|
Packit |
514978 |
int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
|
|
Packit |
514978 |
if (c1 != c2)
|
|
Packit |
514978 |
return c1-c2;
|
|
Packit |
514978 |
if (!c1)
|
|
Packit |
514978 |
break;
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
return 0;
|
|
Packit |
514978 |
#endif
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
#endif
|
|
Packit |
514978 |
|