ReactOS 0.4.16-dev-822-gbcedb53
mbscoll.cpp
Go to the documentation of this file.
1/***
2*mbscoll.c - Collate MBCS strings
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Collate MBCS strings
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
15#include <locale.h>
16#include <string.h>
17
18
19/***
20* _mbscoll - Collate MBCS strings
21*
22*Purpose:
23* Collates two strings for lexical order. Strings
24* are collated on a character basis, not a byte basis.
25*
26*Entry:
27* char *s1, *s2 = strings to collate
28*
29*Exit:
30* Returns <0 if s1 < s2
31* Returns 0 if s1 == s2
32* Returns >0 if s1 > s2
33* Returns _NLSCMPERROR is something went wrong
34*
35*Exceptions:
36* Input parameters are validated. Refer to the validation section of the function.
37*
38*******************************************************************************/
39
40extern "C" int __cdecl _mbscoll_l(
41 const unsigned char *s1,
42 const unsigned char *s2,
44 )
45{
46 int ret;
47 _LocaleUpdate _loc_update(plocinfo);
48
49 /* validation section */
52
53 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
54 return _strcoll_l((const char *)s1, (const char *)s2, plocinfo);
55
56 if (0 == (ret = __acrt_CompareStringA(
57 _loc_update.GetLocaleT(),
58 _loc_update.GetLocaleT()->mbcinfo->mblocalename,
60 (LPCSTR)s1,
61 -1,
62 (LPSTR)s2,
63 -1,
64 _loc_update.GetLocaleT()->mbcinfo->mbcodepage )))
65 {
66 errno = EINVAL;
67
68 return _NLSCMPERROR;
69 }
70
71 return ret - 2;
72
73}
74
75extern "C" int (__cdecl _mbscoll)(
76 const unsigned char *s1,
77 const unsigned char *s2
78 )
79{
80 return _mbscoll_l(s1, s2, nullptr);
81}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
int __cdecl __acrt_CompareStringA(_In_opt_ _locale_t _Plocinfo, _In_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, _In_CRT_NLS_string_(_CchCount1) PCCH _LpString1, _In_ int _CchCount1, _In_CRT_NLS_string_(_CchCount2) PCCH _LpString2, _In_ int _CchCount2, _In_ int _CodePage)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
_Check_return_ _CRTIMP int __cdecl _strcoll_l(_In_z_ const char *str1, _In_z_ const char *str2, _In_opt_ _locale_t locale)
Definition: stubs.c:472
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
_Check_return_ _CRTIMP int __cdecl _mbscoll(_In_z_ const unsigned char *_Str1, _In_z_ const unsigned char *_Str2)
_locale_t plocinfo
Definition: ismbbyte.cpp:75
int __cdecl _mbscoll_l(const unsigned char *s1, const unsigned char *s2, _locale_t plocinfo)
Definition: mbscoll.cpp:40
const unsigned char * s2
Definition: mbscoll.cpp:79
struct S1 s1
#define errno
Definition: errno.h:18
#define _NLSCMPERROR
Definition: string.h:19
int ret
#define SORT_STRINGSORT
Definition: winnls.h:185
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182