summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2021-01-24 18:22:05 -0500
committerJay Satiro <raysatiro@yahoo.com>2021-02-09 02:47:05 -0500
commitb48db908e08cf6dca67ef12f29738e7188702299 (patch)
treef168f23e517cba837b87b64b1c73bf16204c8643
parent1269c80af1dc45c3cee1dbbc76270ac7c7d6f1c3 (diff)
downloadcurl-b48db908e08cf6dca67ef12f29738e7188702299.tar.gz
curl_multibyte: fall back to local code page stat/access on Windows
If libcurl is built with Unicode support for Windows then it is assumed the filename string is Unicode in UTF-8 encoding and it is converted to UTF-16 to be passed to the wide character version of the respective function (eg wstat). However the filename string may actually be in the local encoding so, even if it successfully converted to UTF-16, if it could not be stat/accessed then try again using the local code page version of the function (eg wstat fails try stat). We already do this with fopen (ie wfopen fails try fopen), so I think it makes sense to extend it to stat and access functions. Closes https://github.com/curl/curl/pull/6514
-rw-r--r--lib/curl_multibyte.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/lib/curl_multibyte.c b/lib/curl_multibyte.c
index 571f1d38a..39b2c587c 100644
--- a/lib/curl_multibyte.c
+++ b/lib/curl_multibyte.c
@@ -130,50 +130,38 @@ int curlx_win32_stat(const char *path, struct_stat *buffer)
int result = -1;
#ifdef _UNICODE
wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
-#endif /* _UNICODE */
-
+ if(path_w) {
#if defined(USE_WIN32_SMALL_FILES)
-#if defined(_UNICODE)
- if(path_w)
result = _wstat(path_w, buffer);
- else
-#endif /* _UNICODE */
- result = _stat(path, buffer);
-#else /* USE_WIN32_SMALL_FILES */
-#if defined(_UNICODE)
- if(path_w)
+#else
result = _wstati64(path_w, buffer);
- else
+#endif
+ free(path_w);
+ if(result != -1)
+ return result;
+ }
#endif /* _UNICODE */
- result = _stati64(path, buffer);
-#endif /* USE_WIN32_SMALL_FILES */
-#ifdef _UNICODE
- free(path_w);
+#if defined(USE_WIN32_SMALL_FILES)
+ result = _stat(path, buffer);
+#else
+ result = _stati64(path, buffer);
#endif
-
return result;
}
int curlx_win32_access(const char *path, int mode)
{
- int result = -1;
-#ifdef _UNICODE
- wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
-#endif /* _UNICODE */
-
#if defined(_UNICODE)
- if(path_w)
- result = _waccess(path_w, mode);
- else
-#endif /* _UNICODE */
- result = _access(path, mode);
-
-#ifdef _UNICODE
+ wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
+ if(path_w) {
+ int result = _waccess(path_w, mode);
free(path_w);
-#endif
-
- return result;
+ if(result != -1)
+ return result;
+ }
+#endif /* _UNICODE */
+ return _access(path, mode);
}
#endif /* USE_WIN32_LARGE_FILES || USE_WIN32_SMALL_FILES */