8
8
#include "common.h"
9
9
#include "utf-conv.h"
10
10
11
- GIT_INLINE (DWORD ) get_wc_flags (void )
12
- {
13
- static char inited = 0 ;
14
- static DWORD flags ;
15
-
16
- /* Invalid code point check supported on Vista+ only */
17
- if (!inited ) {
18
- flags = git_has_win32_version (6 , 0 , 0 ) ? WC_ERR_INVALID_CHARS : 0 ;
19
- inited = 1 ;
20
- }
21
-
22
- return flags ;
23
- }
24
-
25
11
GIT_INLINE (void ) git__set_errno (void )
26
12
{
27
13
if (GetLastError () == ERROR_INSUFFICIENT_BUFFER )
@@ -66,7 +52,7 @@ int git__utf16_to_8(char *dest, size_t dest_size, const wchar_t *src)
66
52
/* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to
67
53
* turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's
68
54
* length. WideCharToMultiByte never returns int's minvalue, so underflow is not possible */
69
- if ((len = WideCharToMultiByte (CP_UTF8 , get_wc_flags () , src , -1 , dest , (int )dest_size , NULL , NULL ) - 1 ) < 0 )
55
+ if ((len = WideCharToMultiByte (CP_UTF8 , WC_ERR_INVALID_CHARS , src , -1 , dest , (int )dest_size , NULL , NULL ) - 1 ) < 0 )
70
56
git__set_errno ();
71
57
72
58
return len ;
@@ -127,12 +113,11 @@ int git__utf8_to_16_alloc(wchar_t **dest, const char *src)
127
113
int git__utf16_to_8_alloc (char * * dest , const wchar_t * src )
128
114
{
129
115
int utf8_size ;
130
- DWORD dwFlags = get_wc_flags ();
131
116
132
117
* dest = NULL ;
133
118
134
119
/* Length of -1 indicates NULL termination of the input string */
135
- utf8_size = WideCharToMultiByte (CP_UTF8 , dwFlags , src , -1 , NULL , 0 , NULL , NULL );
120
+ utf8_size = WideCharToMultiByte (CP_UTF8 , WC_ERR_INVALID_CHARS , src , -1 , NULL , 0 , NULL , NULL );
136
121
137
122
if (!utf8_size ) {
138
123
git__set_errno ();
@@ -146,7 +131,7 @@ int git__utf16_to_8_alloc(char **dest, const wchar_t *src)
146
131
return -1 ;
147
132
}
148
133
149
- utf8_size = WideCharToMultiByte (CP_UTF8 , dwFlags , src , -1 , * dest , utf8_size , NULL , NULL );
134
+ utf8_size = WideCharToMultiByte (CP_UTF8 , WC_ERR_INVALID_CHARS , src , -1 , * dest , utf8_size , NULL , NULL );
150
135
151
136
if (!utf8_size ) {
152
137
git__set_errno ();
0 commit comments