1 /***
2 *wcscoll.c - Collate wide-character locale strings
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 * Compare two wchar_t strings using the locale LC_COLLATE information.
8 *
9 *******************************************************************************/
10 #include <corecrt_internal.h>
11 #include <ctype.h>
12 #include <locale.h>
13 #include <string.h>
14
15
16 /***
17 *int wcscoll() - Collate wide-character locale strings
18 *
19 *Purpose:
20 * Compare two wchar_t strings using the locale LC_COLLATE information.
21 * In the C locale, wcscmp() is used to make the comparison.
22 *
23 *Entry:
24 * const wchar_t *s1 = pointer to the first string
25 * const wchar_t *s2 = pointer to the second string
26 *
27 *Exit:
28 * -1 = first string less than second string
29 * 0 = strings are equal
30 * 1 = first string greater than second string
31 * Returns _NLSCMPERROR is something went wrong
32 * This range of return values may differ from other *cmp/*coll functions.
33 *
34 *Exceptions:
35 * Input parameters are validated. Refer to the validation section of the function.
36 *
37 *******************************************************************************/
38
_wcscoll_l(const wchar_t * _string1,const wchar_t * _string2,_locale_t plocinfo)39 extern "C" int __cdecl _wcscoll_l (
40 const wchar_t *_string1,
41 const wchar_t *_string2,
42 _locale_t plocinfo
43 )
44 {
45 int ret;
46 _LocaleUpdate _loc_update(plocinfo);
47
48 /* validation section */
49 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
50 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
51
52 if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr )
53 return (wcscmp(_string1, _string2));
54
55 if ( 0 == (ret = __acrt_CompareStringW(
56 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
57 SORT_STRINGSORT,
58 _string1,
59 -1,
60 _string2,
61 -1)) )
62 {
63 errno = EINVAL;
64 return _NLSCMPERROR;
65 }
66
67 return (ret - 2);
68
69 }
70
wcscoll(const wchar_t * _string1,const wchar_t * _string2)71 extern "C" int __cdecl wcscoll (
72 const wchar_t *_string1,
73 const wchar_t *_string2
74 )
75 {
76 if (!__acrt_locale_changed())
77 {
78 /* validation section */
79 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
80 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
81
82 return (wcscmp(_string1, _string2));
83 }
84 else
85 {
86 return _wcscoll_l(_string1, _string2, nullptr);
87 }
88 }
89