11cb0ef41Sopenharmony_ci/* MIT License
21cb0ef41Sopenharmony_ci *
31cb0ef41Sopenharmony_ci * Copyright (c) 1998 Massachusetts Institute of Technology
41cb0ef41Sopenharmony_ci * Copyright (c) The c-ares project and its contributors
51cb0ef41Sopenharmony_ci *
61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
71cb0ef41Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal
81cb0ef41Sopenharmony_ci * in the Software without restriction, including without limitation the rights
91cb0ef41Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
101cb0ef41Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is
111cb0ef41Sopenharmony_ci * furnished to do so, subject to the following conditions:
121cb0ef41Sopenharmony_ci *
131cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice (including the next
141cb0ef41Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
151cb0ef41Sopenharmony_ci * Software.
161cb0ef41Sopenharmony_ci *
171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
181cb0ef41Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191cb0ef41Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
201cb0ef41Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
211cb0ef41Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
221cb0ef41Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
231cb0ef41Sopenharmony_ci * SOFTWARE.
241cb0ef41Sopenharmony_ci *
251cb0ef41Sopenharmony_ci * SPDX-License-Identifier: MIT
261cb0ef41Sopenharmony_ci */
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci#include "ares_setup.h"
291cb0ef41Sopenharmony_ci#include "ares_strcasecmp.h"
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci#ifndef HAVE_STRCASECMP
321cb0ef41Sopenharmony_ciint ares_strcasecmp(const char *a, const char *b)
331cb0ef41Sopenharmony_ci{
341cb0ef41Sopenharmony_ci#  if defined(HAVE_STRCMPI)
351cb0ef41Sopenharmony_ci  return strcmpi(a, b);
361cb0ef41Sopenharmony_ci#  elif defined(HAVE_STRICMP)
371cb0ef41Sopenharmony_ci  return stricmp(a, b);
381cb0ef41Sopenharmony_ci#  else
391cb0ef41Sopenharmony_ci  size_t i;
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  for (i = 0; i < (size_t)-1; i++) {
421cb0ef41Sopenharmony_ci    int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
431cb0ef41Sopenharmony_ci    int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
441cb0ef41Sopenharmony_ci    if (c1 != c2) {
451cb0ef41Sopenharmony_ci      return c1 - c2;
461cb0ef41Sopenharmony_ci    }
471cb0ef41Sopenharmony_ci    if (!c1) {
481cb0ef41Sopenharmony_ci      break;
491cb0ef41Sopenharmony_ci    }
501cb0ef41Sopenharmony_ci  }
511cb0ef41Sopenharmony_ci  return 0;
521cb0ef41Sopenharmony_ci#  endif
531cb0ef41Sopenharmony_ci}
541cb0ef41Sopenharmony_ci#endif
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci#ifndef HAVE_STRNCASECMP
571cb0ef41Sopenharmony_ciint ares_strncasecmp(const char *a, const char *b, size_t n)
581cb0ef41Sopenharmony_ci{
591cb0ef41Sopenharmony_ci#  if defined(HAVE_STRNCMPI)
601cb0ef41Sopenharmony_ci  return strncmpi(a, b, n);
611cb0ef41Sopenharmony_ci#  elif defined(HAVE_STRNICMP)
621cb0ef41Sopenharmony_ci  return strnicmp(a, b, n);
631cb0ef41Sopenharmony_ci#  else
641cb0ef41Sopenharmony_ci  size_t i;
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  for (i = 0; i < n; i++) {
671cb0ef41Sopenharmony_ci    int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
681cb0ef41Sopenharmony_ci    int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
691cb0ef41Sopenharmony_ci    if (c1 != c2) {
701cb0ef41Sopenharmony_ci      return c1 - c2;
711cb0ef41Sopenharmony_ci    }
721cb0ef41Sopenharmony_ci    if (!c1) {
731cb0ef41Sopenharmony_ci      break;
741cb0ef41Sopenharmony_ci    }
751cb0ef41Sopenharmony_ci  }
761cb0ef41Sopenharmony_ci  return 0;
771cb0ef41Sopenharmony_ci#  endif
781cb0ef41Sopenharmony_ci}
791cb0ef41Sopenharmony_ci#endif
80