Unicode support on Win32.

Win32 API calls that are Unicode aware require wide character
strings, but LLDB uses UTF8 everywhere.  This patch does conversions
wherever necessary when passing strings into and out of Win32 API
calls.

Patch by Cameron
Differential Revision: http://reviews.llvm.org/D17107
Reviewed By: zturner, amccarth

llvm-svn: 264074
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index 5b38920..adf04cc 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -14,7 +14,6 @@
 #include <limits.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <sys/stat.h>
 
 #ifdef _WIN32
 #include "lldb/Host/windows/windows.h"
@@ -22,6 +21,7 @@
 #include <sys/ioctl.h>
 #endif
 
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Process.h" // for llvm::sys::Process::FileDescriptorHasColors()
 
 #include "lldb/Core/DataBufferHeap.h"
@@ -29,6 +29,7 @@
 #include "lldb/Core/Log.h"
 #include "lldb/Host/Config.h"
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Host/FileSystem.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -267,7 +268,18 @@
 
     do
     {
+#ifdef _WIN32
+        std::wstring wpath;
+        if (!llvm::ConvertUTF8toWide(path, wpath))
+        {
+            m_descriptor = -1;
+            error.SetErrorString("Error converting path to UTF-16");
+            return error;
+        }
+        ::_wsopen_s(&m_descriptor, wpath.c_str(), oflag, _SH_DENYNO, mode);
+#else
         m_descriptor = ::open(path, oflag, mode);
+#endif
     } while (m_descriptor < 0 && errno == EINTR);
 
     if (!DescriptorIsValid())
@@ -287,7 +299,8 @@
     if (file_spec)
     {
         struct stat file_stats;
-        if (::stat(file_spec.GetCString(), &file_stats) == -1)
+        int stat_result = FileSystem::Stat(file_spec.GetCString(), &file_stats);
+        if (stat_result == -1)
             error.SetErrorToErrno();
         else
         {