]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
file: Support unicode urls on windows
authorStephan Szabo <stephan.szabo@sony.com>
Wed, 20 Jan 2021 18:08:49 +0000 (10:08 -0800)
committerJay Satiro <raysatiro@yahoo.com>
Tue, 9 Feb 2021 07:45:51 +0000 (02:45 -0500)
Closes https://github.com/curl/curl/pull/6501

lib/curl_multibyte.c
lib/curl_setup.h
tests/FILEFORMAT.md
tests/data/Makefile.inc
tests/data/test1703 [new file with mode: 0644]
tests/runtests.pl

index d327c8ba771e940ef58c58c4c0fbeeed93976321..571f1d38a6f058939401a7f1e46e33821694290b 100644 (file)
@@ -82,6 +82,32 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
 
 #if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES)
 
+int curlx_win32_open(const char *filename, int oflag, ...)
+{
+  int pmode = 0;
+
+#ifdef _UNICODE
+  int result = -1;
+  wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
+#endif
+
+  va_list param;
+  va_start(param, oflag);
+  if(oflag & O_CREAT)
+    pmode = va_arg(param, int);
+  va_end(param);
+
+#ifdef _UNICODE
+  if(filename_w)
+    result = _wopen(filename_w, oflag, pmode);
+  free(filename_w);
+  if(result != -1)
+    return result;
+#endif
+
+  return (_open)(filename, oflag, pmode);
+}
+
 FILE *curlx_win32_fopen(const char *filename, const char *mode)
 {
 #ifdef _UNICODE
index 22def2defac89f3a75cef3a5c1ed41998d1defa0..9cef5f7d0fa76e7a538f84677cb10ff06cea26b9 100644 (file)
 #  define stat(fname,stp)            curlx_win32_stat(fname, stp)
 #  define struct_stat                struct _stati64
 #  define LSEEK_ERROR                (__int64)-1
+#  define open                       curlx_win32_open
 #  define fopen(fname,mode)          curlx_win32_fopen(fname, mode)
 #  define access(fname,mode)         curlx_win32_access(fname, mode)
+   int curlx_win32_open(const char *filename, int oflag, ...);
    int curlx_win32_stat(const char *path, struct_stat *buffer);
    FILE *curlx_win32_fopen(const char *filename, const char *mode);
    int curlx_win32_access(const char *path, int mode);
 #    define fstat(fdes,stp)            _fstat(fdes, stp)
 #    define stat(fname,stp)            curlx_win32_stat(fname, stp)
 #    define struct_stat                struct _stat
+#    define open                       curlx_win32_open
 #    define fopen(fname,mode)          curlx_win32_fopen(fname, mode)
 #    define access(fname,mode)         curlx_win32_access(fname, mode)
      int curlx_win32_stat(const char *path, struct_stat *buffer);
+     int curlx_win32_open(const char *filename, int oflag, ...);
      FILE *curlx_win32_fopen(const char *filename, const char *mode);
      int curlx_win32_access(const char *path, int mode);
 #  endif
index ec0dc4815a35daf8f757209ce92bf1ca92407a8d..b75a02a51a37f29f3ab8f848ad6db6a392cdac5d 100644 (file)
@@ -406,6 +406,7 @@ Features testable here are:
 - `TLS-SRP`
 - `TrackMemory`
 - `typecheck`
+- `Unicode`
 - `unittest`
 - `unix-sockets`
 - `verbose-strings`
index 464eab2a9b9f897dfb917bbf375d161593828d9e..6762c8dcc133b39b3db5097d203a99ddb32550a0 100644 (file)
@@ -201,7 +201,7 @@ test1630 test1631 test1632 test1633 test1634 \
 test1650 test1651 test1652 test1653 test1654 test1655 \
 test1660 \
 \
-test1700 test1701 test1702 \
+test1700 test1701 test1702 test1703 \
 \
 test1800 test1801 \
 \
diff --git a/tests/data/test1703 b/tests/data/test1703
new file mode 100644 (file)
index 0000000..ab4f028
--- /dev/null
@@ -0,0 +1,45 @@
+<testcase>
+<info>
+<keywords>
+FILE
+</keywords>
+</info>
+
+<reply>
+<data>
+foo
+   bar
+bar
+   foo
+moo
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+file
+</server>
+<features>
+Unicode
+win32
+</features>
+<name>
+basic file:// file with UTF-8 characters
+</name>
+<command option="no-include">
+file://localhost%FILE_PWD/log/%E3%83%86%E3%82%B9%E3%83%881703.txt
+</command>
+<file name="log/ใƒ†ใ‚นใƒˆ1703.txt">
+foo
+   bar
+bar
+   foo
+moo
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+</verify>
+</testcase>
index e7ed435bc5bbf7dc320f03b65c49934ade8b6a03..ddee02ad36ea403c1628ed60aeb82baf0f40a517 100755 (executable)
@@ -268,6 +268,7 @@ my $has_manual;     # set if built with built-in manual
 my $has_win32;      # set if built for Windows
 my $has_mingw;      # set if built with MinGW (as opposed to MinGW-w64)
 my $has_hyper = 0;  # set if built with Hyper
+my $has_unicode;    # set if libcurl is built with Unicode support
 
 # this version is decided by the particular nghttp2 library that is being used
 my $h2cver = "h2c";
@@ -2826,6 +2827,7 @@ sub setupfeatures {
     $feature{"threaded-resolver"} = $has_threadedres;
     $feature{"TLS-SRP"} = $has_tls_srp;
     $feature{"TrackMemory"} = $has_memory_tracking;
+    $feature{"Unicode"} = $has_unicode;
     $feature{"unittest"} = $debug_build;
     $feature{"unix-sockets"} = $has_unix;
     $feature{"win32"} = $has_win32;
@@ -3093,6 +3095,9 @@ sub checksystem {
                 # 'https-proxy' is used as "server" so consider it a protocol
                 push @protocols, 'https-proxy';
             }
+            if($feat =~ /Unicode/i) {
+                $has_unicode = 1;
+            }
         }
         #
         # Test harness currently uses a non-stunnel server in order to