aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarcel Raad <Marcel.Raad@teamviewer.com>2020-01-02 22:47:33 +0100
committerMarcel Raad <Marcel.Raad@teamviewer.com>2020-05-14 18:13:37 +0200
commitffdddb45d9dc87b3a2f67dcdbdcc11f4a4e029d2 (patch)
tree0c19793ff9ad4afbbda7296e948f300f4e749684 /lib
parent9e5669f3880674de262000e772ef21ec0cc874be (diff)
curl_setup: support Unicode functions to open files on Windows
Use them only if `_UNICODE` is defined, in which case command-line arguments have been converted to UTF-8. Closes https://github.com/curl/curl/pull/3784
Diffstat (limited to 'lib')
-rw-r--r--lib/curl_multibyte.c51
-rw-r--r--lib/curl_setup.h10
2 files changed, 59 insertions, 2 deletions
diff --git a/lib/curl_multibyte.c b/lib/curl_multibyte.c
index 2cf70e325..5345d7b36 100644
--- a/lib/curl_multibyte.c
+++ b/lib/curl_multibyte.c
@@ -79,3 +79,54 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
}
#endif /* WIN32 */
+
+#if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES)
+
+FILE *curlx_win32_fopen(const char *filename, const char *mode)
+{
+#ifdef _UNICODE
+ FILE *result = NULL;
+ wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
+ wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode);
+ if(filename_w && mode_w)
+ result = _wfopen(filename_w, mode_w);
+ free(filename_w);
+ free(mode_w);
+ if(result)
+ return result;
+#endif
+
+ return (fopen)(filename, mode);
+}
+
+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 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)
+ result = _wstati64(path_w, buffer);
+ else
+#endif /* _UNICODE */
+ result = _stati64(path, buffer);
+#endif /* USE_WIN32_SMALL_FILES */
+
+#ifdef _UNICODE
+ free(path_w);
+#endif
+
+ return result;
+}
+
+#endif /* USE_WIN32_LARGE_FILES || USE_WIN32_SMALL_FILES */
diff --git a/lib/curl_setup.h b/lib/curl_setup.h
index 56e6db83c..a86a235b3 100644
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -331,9 +331,12 @@
# undef fstat
# define fstat(fdes,stp) _fstati64(fdes, stp)
# undef stat
-# define stat(fname,stp) _stati64(fname, stp)
+# define stat(fname,stp) curlx_win32_stat(fname, stp)
# define struct_stat struct _stati64
# define LSEEK_ERROR (__int64)-1
+# define fopen(fname,mode) curlx_win32_fopen(fname, mode)
+ int curlx_win32_stat(const char *path, struct_stat *buffer);
+ FILE *curlx_win32_fopen(const char *filename, const char *mode);
#endif
/*
@@ -348,8 +351,11 @@
# undef lseek
# define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
# define fstat(fdes,stp) _fstat(fdes, stp)
-# define stat(fname,stp) _stat(fname, stp)
+# define stat(fname,stp) curlx_win32_stat(fname, stp)
# define struct_stat struct _stat
+# define fopen(fname,mode) curlx_win32_fopen(fname, mode)
+ int curlx_win32_stat(const char *path, struct_stat *buffer);
+ FILE *curlx_win32_fopen(const char *filename, const char *mode);
# endif
# define LSEEK_ERROR (long)-1
#endif