From 6106ba08b6ab2fec248c96c9b4afa33a721c40db Mon Sep 17 00:00:00 2001
From: Clinton Stimpson <clinton@elemtech.com>
Date: Fri, 26 Sep 2014 21:44:35 -0600
Subject: [PATCH 2/2] Fix curl tool to encode URL as UTF-8 before calling API.

---
 src/tool_operate.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/tool_operate.c b/src/tool_operate.c
index fd2fd6d..c57d979 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -476,6 +476,11 @@ static CURLcode operate_do(struct GlobalConfig *global,
         long retry_sleep_default;
         long retry_sleep;
         char *this_url = NULL;
+#if defined(WIN32)
+        int convert_num;
+        wchar_t * this_url_wide;
+        char *this_url_utf8;
+#endif
         int metalink_next_res = 0;
 
         outfile = NULL;
@@ -839,7 +844,23 @@ static CURLcode operate_do(struct GlobalConfig *global,
         /* size of uploaded file: */
         if(uploadfilesize != -1)
           my_setopt(curl, CURLOPT_INFILESIZE_LARGE, uploadfilesize);
+#if defined(WIN32)
+        /* convert tool encoding to UTF-8 for urls*/
+        convert_num = MultiByteToWideChar(GetACP(), 0, this_url, -1,
+          NULL, 0);
+        this_url_wide = malloc((convert_num+1) * sizeof(wchar_t));
+        MultiByteToWideChar(GetACP(), 0, this_url, -1, this_url_wide, convert_num+1);
+        convert_num = WideCharToMultiByte(CP_UTF8, 0, this_url_wide, -1,
+          NULL, 0, NULL, NULL);
+        this_url_utf8 = malloc(convert_num+1);
+        WideCharToMultiByte(CP_UTF8, 0, this_url_wide, -1, this_url_utf8,
+          convert_num+1, NULL, NULL);
+        my_setopt_str(curl, CURLOPT_URL, this_url_utf8);     /* what to fetch */
+        free(this_url_utf8);
+        free(this_url_wide);
+#else
         my_setopt_str(curl, CURLOPT_URL, this_url);     /* what to fetch */
+#endif
         my_setopt(curl, CURLOPT_NOPROGRESS, global->noprogress?1L:0L);
         if(config->no_body) {
           my_setopt(curl, CURLOPT_NOBODY, 1L);
-- 
1.9.4.msysgit.0

