提交 46ea8e61 编写于 作者: A Andy Polyakov

crypto/LPdir_win.c: harmonize with o_fopen.c.

Reviewed-by: NRich Salz <rsalz@openssl.org>
Reviewed-by: NRichard Levitte <levitte@openssl.org>
上级 878f4225
...@@ -55,6 +55,12 @@ ...@@ -55,6 +55,12 @@
# define NAME_MAX 255 # define NAME_MAX 255
#endif #endif
#ifdef CP_UTF8
# define CP_DEFAULT CP_UTF8
#else
# define CP_DEFAULT CP_ACP
#endif
struct LP_dir_context_st { struct LP_dir_context_st {
WIN32_FIND_DATA ctx; WIN32_FIND_DATA ctx;
HANDLE handle; HANDLE handle;
...@@ -104,27 +110,41 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) ...@@ -104,27 +110,41 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
TCHAR *wdir = NULL; TCHAR *wdir = NULL;
/* len_0 denotes string length *with* trailing 0 */ /* len_0 denotes string length *with* trailing 0 */
size_t index = 0, len_0 = strlen(extdir) + 1; size_t index = 0, len_0 = strlen(extdir) + 1;
#ifdef LP_MULTIBYTE_AVAILABLE
wdir = (TCHAR *)calloc(len_0, sizeof(TCHAR)); int sz = 0;
if (wdir == NULL) { UINT cp;
do {
# ifdef CP_UTF8
if ((sz = MultiByteToWideChar((cp = CP_UTF8), 0, extdir, len_0,
NULL, 0)) > 0 ||
GetLastError() != ERROR_NO_UNICODE_TRANSLATION)
break;
# endif
sz = MultiByteToWideChar((cp = CP_ACP), 0, extdir, len_0,
NULL, 0);
} while (0);
if (sz > 0) {
wdir = _alloca(sz * sizeof(TCHAR));
if (!MultiByteToWideChar(cp, 0, extdir, len_0, wdir, sz)) {
if (extdirbuf != NULL) { if (extdirbuf != NULL) {
free(extdirbuf); free(extdirbuf);
} }
free(*ctx); free(*ctx);
*ctx = NULL; *ctx = NULL;
errno = ENOMEM; errno = EINVAL;
return 0; return 0;
} }
#ifdef LP_MULTIBYTE_AVAILABLE } else
if (!MultiByteToWideChar
(CP_ACP, 0, extdir, len_0, (WCHAR *)wdir, len_0))
#endif #endif
{
wdir = _alloca(len_0 * sizeof(TCHAR));
for (index = 0; index < len_0; index++) for (index = 0; index < len_0; index++)
wdir[index] = (TCHAR)extdir[index]; wdir[index] = (TCHAR)extdir[index];
}
(*ctx)->handle = FindFirstFile(wdir, &(*ctx)->ctx); (*ctx)->handle = FindFirstFile(wdir, &(*ctx)->ctx);
free(wdir);
} else { } else {
(*ctx)->handle = FindFirstFile((TCHAR *)extdir, &(*ctx)->ctx); (*ctx)->handle = FindFirstFile((TCHAR *)extdir, &(*ctx)->ctx);
} }
...@@ -152,8 +172,8 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) ...@@ -152,8 +172,8 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
len_0++; len_0++;
#ifdef LP_MULTIBYTE_AVAILABLE #ifdef LP_MULTIBYTE_AVAILABLE
if (!WideCharToMultiByte if (!WideCharToMultiByte(CP_DEFAULT, 0, (WCHAR *)wdir, len_0,
(CP_ACP, 0, (WCHAR *)wdir, len_0, (*ctx)->entry_name, (*ctx)->entry_name,
sizeof((*ctx)->entry_name), NULL, 0)) sizeof((*ctx)->entry_name), NULL, 0))
#endif #endif
for (index = 0; index < len_0; index++) for (index = 0; index < len_0; index++)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册