diff options
author | Andy Polyakov <appro@openssl.org> | 2010-04-21 20:38:21 +0000 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2010-04-21 20:38:21 +0000 |
commit | d183244b432f4e16fc1576341878905e39fbc945 (patch) | |
tree | 90da32c28cf725dc7e8d991ea0faa0e433feffa0 /crypto/bio/bss_file.c | |
parent | 5e60dba84f9e30454d67f456bf071d0a334ade54 (diff) | |
download | openssl-d183244b432f4e16fc1576341878905e39fbc945.tar.gz |
bss_file.c: reserve for option to encode file name with UTF-8.
Diffstat (limited to 'crypto/bio/bss_file.c')
-rw-r--r-- | crypto/bio/bss_file.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c index ba4f8e9940..3f458a0c7c 100644 --- a/crypto/bio/bss_file.c +++ b/crypto/bio/bss_file.c @@ -121,7 +121,27 @@ BIO *BIO_new_file(const char *filename, const char *mode) BIO *ret; FILE *file; - if ((file=fopen(filename,mode)) == NULL) + file=fopen(filename,mode); +#if defined(_WIN32) && defined(CP_UTF8) + if (file==NULL && errno==ENOENT) /* see if filename is UTF-8 encoded */ + { + int sz,len_0 = (int)strlen(filename)+1; + if ((sz=MultiByteToWideChar(CP_UTF8,0,filename,len_0, + NULL,0))>0) + { + WCHAR wmode[8]; + WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); + + if (MultiByteToWideChar(CP_UTF8,0,filename,len_0, + wfilename,sz) && + MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, + wmode,sizeof(wmode)/sizeof(wmode[0])) + ) + file = _wfopen(wfilename,wmode); + } + } +#endif + if (file == NULL) { SYSerr(SYS_F_FOPEN,get_last_sys_error()); ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); |