forked from Chuyu-Team/VC-LTL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocale_thunks.cpp
More file actions
100 lines (79 loc) · 2.09 KB
/
Copy pathlocale_thunks.cpp
File metadata and controls
100 lines (79 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
用于实现各种 _l 后缀的函数
*/
#include <corecrt_internal.h>
#include <locale.h>
#include <corecrt_wstdlib.h>
#include <time.h>
#include <mbctype.h>
#ifndef _ATL_XP_TARGETING
class LocaleAutoUpdate
{
public:
__acrt_ptd* ptd;
__crt_locale_pointers Backup;
int _own_locale;
LocaleAutoUpdate(_locale_t _Locale)
:ptd(nullptr)
{
if (_Locale)
{
ptd = __acrt_getptd();
_own_locale = ptd->VistaOrLater_msvcrt._own_locale;
//强制启用线程区域信息
ptd->VistaOrLater_msvcrt._own_locale |= _PER_THREAD_LOCALE_BIT;
//备份当前区域信息
Backup.locinfo = ptd->VistaOrLater_msvcrt._locale_info;
Backup.mbcinfo = ptd->VistaOrLater_msvcrt._multibyte_info;
//替换当前区域信息
ptd->VistaOrLater_msvcrt._locale_info = _Locale->locinfo;
ptd->VistaOrLater_msvcrt._multibyte_info = _Locale->mbcinfo;
}
}
~LocaleAutoUpdate()
{
if (ptd)
{
//恢复当前区域信息
ptd->VistaOrLater_msvcrt._locale_info = Backup.locinfo;
ptd->VistaOrLater_msvcrt._multibyte_info = Backup.mbcinfo;
//回滚区域线程状态
ptd->VistaOrLater_msvcrt._own_locale = _own_locale;
}
}
};
#endif
#ifndef _ATL_XP_TARGETING
EXTERN_C double __cdecl _wcstod_l(
_In_z_ wchar_t const* _String,
_Out_opt_ _Deref_post_z_ wchar_t** _EndPtr,
_In_opt_ _locale_t _Locale
)
{
LocaleAutoUpdate Tmp(_Locale);
return wcstod(_String, _EndPtr);
}
#endif
#ifndef _ATL_XP_TARGETING
EXTERN_C float __cdecl _wcstof_l(
_In_z_ wchar_t const* _String,
_Out_opt_ _Deref_post_z_ wchar_t** _EndPtr,
_In_opt_ _locale_t _Locale
)
{
return _wcstod_l(_String, _EndPtr, _Locale);
}
#endif
#ifndef _ATL_XP_TARGETING
EXTERN_C size_t __cdecl _strftime_l(
_Out_writes_z_(_MaxSize) char* _Buffer,
_In_ size_t _MaxSize,
_In_z_ _Printf_format_string_ char const* _Format,
_In_ struct tm const* _Tm,
_In_opt_ _locale_t _Locale
)
{
LocaleAutoUpdate Tmp(_Locale);
return strftime(_Buffer, _MaxSize, _Format, _Tm);
}
#endif