From 297bdc842c71d35a74e6d17f490053ab0738557e Mon Sep 17 00:00:00 2001
From: Clinton Stimpson <clinton@elemtech.com>
Date: Fri, 26 Sep 2014 21:20:24 -0600
Subject: [PATCH 1/2] Fix to accept UTF-8 encoded file:// URLs on Windows.

---
 lib/file.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/file.c b/lib/file.c
index 73df42e..8f36ec0 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -195,6 +195,8 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
 #ifdef DOS_FILESYSTEM
   int i;
   char *actual_path;
+  int num_char;
+  wchar_t* wpath;
 #endif
 
   real_path = curl_easy_unescape(data, data->state.path, 0, NULL);
@@ -229,8 +231,12 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
     if(actual_path[i] == '/')
       actual_path[i] = '\\';
 
-  fd = open_readonly(actual_path, O_RDONLY|O_BINARY);
+  num_char = MultiByteToWideChar(CP_UTF8, 0, actual_path, -1, NULL, 0);
+  wpath = malloc((num_char+1) * sizeof(wchar_t));
+  MultiByteToWideChar(CP_UTF8, 0, actual_path, -1, wpath, num_char+1);
+  fd = _wopen(wpath, O_RDONLY|O_BINARY);
   file->path = actual_path;
+  free(wpath);
 #else
   fd = open_readonly(real_path, O_RDONLY);
   file->path = real_path;
@@ -304,6 +310,10 @@ static CURLcode file_upload(struct connectdata *conn)
   struct timeval now = Curl_tvnow();
   struct_stat file_stat;
   const char* buf2;
+#if defined(WIN32) || defined(MSDOS)
+  wchar_t *wpath;
+  int num_chars;
+#endif
 
   /*
    * Since FILE: doesn't do the full init, we need to provide some extra
@@ -330,7 +340,15 @@ static CURLcode file_upload(struct connectdata *conn)
   else
     mode = MODE_DEFAULT|O_TRUNC;
 
+#if defined(WIN32) || defined(MSDOS)
+  num_chars = MultiByteToWideChar(CP_UTF8, 0, file->path, -1, NULL, 0);
+  wpath = malloc((num_chars+1) * sizeof(wchar_t));
+  MultiByteToWideChar(CP_UTF8, 0, file->path, -1, wpath, num_chars+1);
+  fd = _wopen(wpath, mode, conn->data->set.new_file_perms);
+  free(wpath);
+#else
   fd = open(file->path, mode, conn->data->set.new_file_perms);
+#endif
   if(fd < 0) {
     failf(data, "Can't open %s for writing", file->path);
     return CURLE_WRITE_ERROR;
-- 
1.9.4.msysgit.0

