From 355466e0bf6c8920fd4a2d0cdaf73042171418b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 23 Aug 2021 12:57:31 +0200 Subject: [PATCH] fix fs_is_dir with unicode on windows --- src/base/system.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index 29c80ccf4..55c6b4e9f 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -2257,25 +2257,22 @@ int fs_is_dir(const char *path) { #if defined(CONF_FAMILY_WINDOWS) /* TODO: do this smarter */ - WIN32_FIND_DATA finddata; + WIN32_FIND_DATAW finddata; HANDLE handle; - char buffer[1024 * 2]; + char buffer[IO_MAX_PATH_LENGTH]; + WCHAR wBuffer[IO_MAX_PATH_LENGTH]; str_format(buffer, sizeof(buffer), "%s/*", path); + MultiByteToWideChar(CP_UTF8, 0, buffer, IO_MAX_PATH_LENGTH, wBuffer, IO_MAX_PATH_LENGTH); - if((handle = FindFirstFileA(buffer, &finddata)) == INVALID_HANDLE_VALUE) + if((handle = FindFirstFileW(wBuffer, &finddata)) == INVALID_HANDLE_VALUE) return 0; - FindClose(handle); return 1; #else struct stat sb; if(stat(path, &sb) == -1) return 0; - - if(S_ISDIR(sb.st_mode)) - return 1; - else - return 0; + return S_ISDIR(sb.st_mode) ? 1 : 0; #endif }