wcscasecmp.c revision 1.3 1 1.3 joerg /* $NetBSD: wcscasecmp.c,v 1.3 2013/04/18 23:24:27 joerg Exp $ */
2 1.2 christos
3 1.2 christos /*
4 1.2 christos * Copyright (C) 2006 Aleksey Cheusov
5 1.2 christos *
6 1.2 christos * This material is provided "as is", with absolutely no warranty expressed
7 1.2 christos * or implied. Any use is at your own risk.
8 1.2 christos *
9 1.2 christos * Permission to use or copy this software for any purpose is hereby granted
10 1.2 christos * without fee. Permission to modify the code and to distribute modified
11 1.2 christos * code is also granted without any restrictions.
12 1.2 christos */
13 1.1 christos
14 1.1 christos #include <sys/cdefs.h>
15 1.1 christos #if defined(LIBC_SCCS) && !defined(lint)
16 1.3 joerg __RCSID("$NetBSD: wcscasecmp.c,v 1.3 2013/04/18 23:24:27 joerg Exp $");
17 1.1 christos #endif /* LIBC_SCCS and not lint */
18 1.1 christos
19 1.1 christos #include "namespace.h"
20 1.1 christos #include <assert.h>
21 1.1 christos #include <wchar.h>
22 1.1 christos #include <wctype.h>
23 1.3 joerg #include <locale.h>
24 1.3 joerg #include "setlocale_local.h"
25 1.1 christos
26 1.1 christos __weak_alias(wcscasecmp,_wcscasecmp)
27 1.3 joerg __weak_alias(wcscasecmp_l,_wcscasecmp_l)
28 1.1 christos
29 1.1 christos int
30 1.3 joerg wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t loc)
31 1.1 christos {
32 1.1 christos int lc1 = 0;
33 1.1 christos int lc2 = 0;
34 1.1 christos int diff = 0;
35 1.1 christos
36 1.3 joerg if (loc == NULL)
37 1.3 joerg loc = _C_locale;
38 1.3 joerg
39 1.1 christos _DIAGASSERT(s1);
40 1.1 christos _DIAGASSERT(s2);
41 1.1 christos
42 1.1 christos for (;;) {
43 1.3 joerg lc1 = towlower_l(*s1, loc);
44 1.3 joerg lc2 = towlower_l(*s2, loc);
45 1.1 christos
46 1.1 christos diff = lc1 - lc2;
47 1.1 christos if (diff)
48 1.1 christos return diff;
49 1.1 christos
50 1.1 christos if (!lc1)
51 1.1 christos return 0;
52 1.1 christos
53 1.1 christos ++s1;
54 1.1 christos ++s2;
55 1.1 christos }
56 1.1 christos }
57 1.3 joerg
58 1.3 joerg int
59 1.3 joerg wcscasecmp(const wchar_t *s1, const wchar_t *s2)
60 1.3 joerg {
61 1.3 joerg return wcscasecmp_l(s1, s2, *_current_locale());
62 1.3 joerg }
63