1 /***
2 *mbsicoll.c - Collate MBCS strings, ignoring case
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 * Collate MBCS strings, ignoring case
8 *
9 *******************************************************************************/
10 #ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12 #endif
13
14 #include <corecrt_internal.h>
15 #include <corecrt_internal_mbstring.h>
16 #include <locale.h>
17
18 /***
19 * _mbsicoll - Collate MBCS strings, ignoring case
20 *
21 *Purpose:
22 * Collates two strings for lexical order (ignoring case).
23 * Strings are collated on a character basis, not a byte basis.
24 *
25 *Entry:
26 * char *s1, *s2 = strings to collate
27 *
28 *Exit:
29 * Returns <0 if s1 < s2
30 * Returns 0 if s1 == s2
31 * Returns >0 if s1 > s2
32 * Returns _NLSCMPERROR is something went wrong
33 *
34 *Exceptions:
35 * Input parameters are validated. Refer to the validation section of the function.
36 *
37 *******************************************************************************/
38
_mbsicoll_l(const unsigned char * s1,const unsigned char * s2,_locale_t plocinfo)39 extern "C" int __cdecl _mbsicoll_l(
40 const unsigned char *s1,
41 const unsigned char *s2,
42 _locale_t plocinfo
43 )
44 {
45 int ret;
46 _LocaleUpdate _loc_update(plocinfo);
47
48 /* validation section */
49 _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR);
50 _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR);
51
52 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
53 return _stricoll_l((const char *)s1, (const char *)s2, plocinfo);
54
55 if ( 0 == (ret = __acrt_CompareStringA(
56 _loc_update.GetLocaleT(),
57 _loc_update.GetLocaleT()->mbcinfo->mblocalename,
58 SORT_STRINGSORT | NORM_IGNORECASE,
59 (LPCSTR)s1,
60 -1,
61 (LPSTR)s2,
62 -1,
63 _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) )
64 {
65 errno = EINVAL;
66 return _NLSCMPERROR;
67 }
68
69 return ret - 2;
70
71 }
72
73 extern "C" int (__cdecl _mbsicoll)(
74 const unsigned char *s1,
75 const unsigned char *s2
76 )
77 {
78 return _mbsicoll_l(s1, s2, nullptr);
79 }
80