1*e0ac190eSjoerg /* $NetBSD: wcscasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $ */
2a2480880Schristos
3a2480880Schristos /*
4a2480880Schristos * Copyright (C) 2006 Aleksey Cheusov
5a2480880Schristos *
6a2480880Schristos * This material is provided "as is", with absolutely no warranty expressed
7a2480880Schristos * or implied. Any use is at your own risk.
8a2480880Schristos *
9a2480880Schristos * Permission to use or copy this software for any purpose is hereby granted
10a2480880Schristos * without fee. Permission to modify the code and to distribute modified
11a2480880Schristos * code is also granted without any restrictions.
12a2480880Schristos */
1354097ce7Schristos
1454097ce7Schristos #include <sys/cdefs.h>
1554097ce7Schristos #if defined(LIBC_SCCS) && !defined(lint)
16*e0ac190eSjoerg __RCSID("$NetBSD: wcscasecmp.c,v 1.4 2013/05/17 12:55:57 joerg Exp $");
1754097ce7Schristos #endif /* LIBC_SCCS and not lint */
1854097ce7Schristos
1954097ce7Schristos #include "namespace.h"
2054097ce7Schristos #include <assert.h>
2154097ce7Schristos #include <wchar.h>
2254097ce7Schristos #include <wctype.h>
2310e0e4a0Sjoerg #include <locale.h>
2410e0e4a0Sjoerg #include "setlocale_local.h"
2554097ce7Schristos
__weak_alias(wcscasecmp,_wcscasecmp)2654097ce7Schristos __weak_alias(wcscasecmp,_wcscasecmp)
2710e0e4a0Sjoerg __weak_alias(wcscasecmp_l,_wcscasecmp_l)
2854097ce7Schristos
2954097ce7Schristos int
3010e0e4a0Sjoerg wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t loc)
3154097ce7Schristos {
3254097ce7Schristos int lc1 = 0;
3354097ce7Schristos int lc2 = 0;
3454097ce7Schristos int diff = 0;
3554097ce7Schristos
3654097ce7Schristos _DIAGASSERT(s1);
3754097ce7Schristos _DIAGASSERT(s2);
3854097ce7Schristos
3954097ce7Schristos for (;;) {
4010e0e4a0Sjoerg lc1 = towlower_l(*s1, loc);
4110e0e4a0Sjoerg lc2 = towlower_l(*s2, loc);
4254097ce7Schristos
4354097ce7Schristos diff = lc1 - lc2;
4454097ce7Schristos if (diff)
4554097ce7Schristos return diff;
4654097ce7Schristos
4754097ce7Schristos if (!lc1)
4854097ce7Schristos return 0;
4954097ce7Schristos
5054097ce7Schristos ++s1;
5154097ce7Schristos ++s2;
5254097ce7Schristos }
5354097ce7Schristos }
5410e0e4a0Sjoerg
5510e0e4a0Sjoerg int
wcscasecmp(const wchar_t * s1,const wchar_t * s2)5610e0e4a0Sjoerg wcscasecmp(const wchar_t *s1, const wchar_t *s2)
5710e0e4a0Sjoerg {
58*e0ac190eSjoerg return wcscasecmp_l(s1, s2, _current_locale());
5910e0e4a0Sjoerg }
60