Index: include/llvm/Support/FileSystem.h
===================================================================
--- include/llvm/Support/FileSystem.h	(revision 141071)
+++ include/llvm/Support/FileSystem.h	(working copy)
@@ -436,6 +436,32 @@
 error_code GetMainExecutable(const char *argv0, void *MainAddr,
                              SmallVectorImpl<char> &result);
 
+/// @brief Convert argv to vector of UTF8 strings.
+///
+/// @param argc Number of arguments in argv.
+/// @param argv Array of command line arguments to convert (parameter is ignored
+///             on Windows and a call to GetCommandLine is used instead).
+/// @results vector of UTF8 command line arguments.
+std::vector<std::string> GetArgvAsUTF8(int argc, const char** argv);
+
+/// @brief Open a file.
+///
+/// @param path Input path.
+/// @param flags File access modes.
+/// @results File descriptor if the file has been successfully opened, 
+///          -1 otherwise.
+int Open(const char* path, int flags);
+
+/// @brief Get status information on a file.
+///
+/// @param path Input path.
+/// @param StatBuf Pointer to structure that stores results.
+/// @results 0 if the file-status information has been successfully obtained,
+///          -1 otherwise.
+int Stat(const char* path, struct stat *StatBuf);
+
+
+
 /// @}
 /// @name Iterators
 /// @{
Index: lib/Support/MemoryBuffer.cpp
===================================================================
--- lib/Support/MemoryBuffer.cpp	(revision 141071)
+++ lib/Support/MemoryBuffer.cpp	(working copy)
@@ -16,6 +16,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Errno.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
@@ -220,7 +221,7 @@
 #ifdef O_BINARY
   OpenFlags |= O_BINARY;  // Open input file in binary mode on win32.
 #endif
-  int FD = ::open(Filename, OpenFlags);
+  int FD = llvm::sys::fs::Open(Filename, OpenFlags);
   if (FD == -1)
     return error_code(errno, posix_category());
 
Index: lib/Support/Unix/PathV2.inc
===================================================================
--- lib/Support/Unix/PathV2.inc	(revision 141071)
+++ lib/Support/Unix/PathV2.inc	(working copy)
@@ -508,6 +508,25 @@
   return success;
 }
 
+std::vector<std::string> GetArgvAsUTF8(int argc, const char** argv)
+{
+  std::vector<std::string> utf8_argv;
+  for (int i = 0; i != argc; ++i)
+    utf8_argv.push_back(argv[i]);
+
+  return utf8_argv;
+}
+
+int Open(const char* path, int flags)
+{
+  return ::open(path, flags);
+}
+
+int Stat(const char* path, struct stat *StatBuf)
+{
+  return ::stat(path, StatBuf);
+}
+
 } // end namespace fs
 } // end namespace sys
 } // end namespace llvm
Index: lib/Support/Windows/PathV2.inc
===================================================================
--- lib/Support/Windows/PathV2.inc	(revision 141071)
+++ lib/Support/Windows/PathV2.inc	(working copy)
@@ -17,6 +17,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Windows.h"
+#include <ShellAPI.h>
 #include <wincrypt.h>
 #include <fcntl.h>
 #include <io.h>
@@ -777,6 +778,55 @@
   return success;
 }
 
+std::vector<std::string> GetArgvAsUTF8(int argc, const char**)
+{
+  wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
+
+  std::vector<std::string> utf8_argv;
+
+  for (int i = 0; i != argc; ++i)
+  {
+    // check length
+    int len = ::WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,
+                                    NULL, 0, NULL, NULL);
+    assert(len != 0);
+
+    // allocate enough space to use it as a buffer
+    std::string arg(len, ' ');
+
+    // do the conversion
+    len = ::WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,
+                                &arg[0], len, NULL, NULL);
+    assert(len != 0);
+
+    utf8_argv.push_back(arg);
+  }
+
+  ::LocalFree(wargv);
+
+  return utf8_argv;
+}
+
+int Open(const char* path, int flags)
+{
+  SmallVector<wchar_t, 128> utf16;
+  error_code ec = UTF8ToUTF16(path, utf16);
+  assert(ec == success);
+  return ::_wopen(utf16.begin(), flags);
+}
+
+int Stat(const char* path, struct stat *StatBuf)
+{
+  // unfortunately ::_wstat uses _stat64i32 instead of stat, 
+  // but these two structures should be identical
+  assert(sizeof(struct stat) == sizeof(struct _stat64i32));
+
+  SmallVector<wchar_t, 128> utf16;
+  error_code ec = UTF8ToUTF16(path, utf16);
+  assert(ec == success);
+  return ::_wstat(utf16.begin(), reinterpret_cast<struct _stat64i32*>(StatBuf));
+}
+
 } // end namespace fs
 } // end namespace sys
 } // end namespace llvm
