diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_file.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 8bfa0bcd97..b954fe7ebc 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -123,6 +123,7 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
123 | 123 | ||
124 | #if defined(_WIN32) && defined(CP_UTF8) | 124 | #if defined(_WIN32) && defined(CP_UTF8) |
125 | int sz, len_0 = (int)strlen(filename)+1; | 125 | int sz, len_0 = (int)strlen(filename)+1; |
126 | DWORD flags; | ||
126 | 127 | ||
127 | /* | 128 | /* |
128 | * Basically there are three cases to cover: a) filename is | 129 | * Basically there are three cases to cover: a) filename is |
@@ -136,17 +137,22 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
136 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall | 137 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall |
137 | * back to fopen... | 138 | * back to fopen... |
138 | */ | 139 | */ |
139 | if ((sz=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS, | 140 | if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS), |
141 | filename,len_0,NULL,0))>0 || | ||
142 | (GetLastError()==ERROR_INVALID_FLAGS && | ||
143 | (sz=MultiByteToWideChar(CP_UTF8,(flags=0), | ||
140 | filename,len_0,NULL,0))>0) | 144 | filename,len_0,NULL,0))>0) |
145 | ) | ||
141 | { | 146 | { |
142 | WCHAR wmode[8]; | 147 | WCHAR wmode[8]; |
143 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); | 148 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); |
144 | 149 | ||
145 | if (MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS, | 150 | if (MultiByteToWideChar(CP_UTF8,flags, |
146 | filename,len_0,wfilename,sz) && | 151 | filename,len_0,wfilename,sz) && |
147 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, | 152 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, |
148 | wmode,sizeof(wmode)/sizeof(wmode[0])) && | 153 | wmode,sizeof(wmode)/sizeof(wmode[0])) && |
149 | (file=_wfopen(wfilename,wmode))==NULL && errno==ENOENT | 154 | (file=_wfopen(wfilename,wmode))==NULL && |
155 | (errno==ENOENT || errno==EBADF) | ||
150 | ) /* UTF-8 decode succeeded, but no file, filename | 156 | ) /* UTF-8 decode succeeded, but no file, filename |
151 | * could still have been locale-ized... */ | 157 | * could still have been locale-ized... */ |
152 | file = fopen(filename,mode); | 158 | file = fopen(filename,mode); |