1*84d9c625SLionel Sambuc /* $NetBSD: wcscasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $ */
22fe8fb19SBen Gras
32fe8fb19SBen Gras /*
42fe8fb19SBen Gras * Copyright (C) 2006 Aleksey Cheusov
52fe8fb19SBen Gras *
62fe8fb19SBen Gras * This material is provided "as is", with absolutely no warranty expressed
72fe8fb19SBen Gras * or implied. Any use is at your own risk.
82fe8fb19SBen Gras *
92fe8fb19SBen Gras * Permission to use or copy this software for any purpose is hereby granted
102fe8fb19SBen Gras * without fee. Permission to modify the code and to distribute modified
112fe8fb19SBen Gras * code is also granted without any restrictions.
122fe8fb19SBen Gras */
132fe8fb19SBen Gras
142fe8fb19SBen Gras #include <sys/cdefs.h>
152fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
16*84d9c625SLionel Sambuc __RCSID("$NetBSD: wcscasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $");
172fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
182fe8fb19SBen Gras
192fe8fb19SBen Gras #include "namespace.h"
202fe8fb19SBen Gras #include <assert.h>
212fe8fb19SBen Gras #include <wchar.h>
222fe8fb19SBen Gras #include <wctype.h>
23*84d9c625SLionel Sambuc #include <locale.h>
24*84d9c625SLionel Sambuc #include "setlocale_local.h"
252fe8fb19SBen Gras
__weak_alias(wcscasecmp,_wcscasecmp)262fe8fb19SBen Gras __weak_alias(wcscasecmp,_wcscasecmp)
27*84d9c625SLionel Sambuc __weak_alias(wcscasecmp_l,_wcscasecmp_l)
282fe8fb19SBen Gras
292fe8fb19SBen Gras int
30*84d9c625SLionel Sambuc wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t loc)
312fe8fb19SBen Gras {
322fe8fb19SBen Gras int lc1 = 0;
332fe8fb19SBen Gras int lc2 = 0;
342fe8fb19SBen Gras int diff = 0;
352fe8fb19SBen Gras
362fe8fb19SBen Gras _DIAGASSERT(s1);
372fe8fb19SBen Gras _DIAGASSERT(s2);
382fe8fb19SBen Gras
392fe8fb19SBen Gras for (;;) {
40*84d9c625SLionel Sambuc lc1 = towlower_l(*s1, loc);
41*84d9c625SLionel Sambuc lc2 = towlower_l(*s2, loc);
422fe8fb19SBen Gras
432fe8fb19SBen Gras diff = lc1 - lc2;
442fe8fb19SBen Gras if (diff)
452fe8fb19SBen Gras return diff;
462fe8fb19SBen Gras
472fe8fb19SBen Gras if (!lc1)
482fe8fb19SBen Gras return 0;
492fe8fb19SBen Gras
502fe8fb19SBen Gras ++s1;
512fe8fb19SBen Gras ++s2;
522fe8fb19SBen Gras }
532fe8fb19SBen Gras }
54*84d9c625SLionel Sambuc
55*84d9c625SLionel Sambuc int
wcscasecmp(const wchar_t * s1,const wchar_t * s2)56*84d9c625SLionel Sambuc wcscasecmp(const wchar_t *s1, const wchar_t *s2)
57*84d9c625SLionel Sambuc {
58*84d9c625SLionel Sambuc return wcscasecmp_l(s1, s2, _current_locale());
59*84d9c625SLionel Sambuc }
60