[FileSystme] Move ::open abstraction into FileSystem.
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 2 Nov 2018 17:34:16 +0000 (17:34 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 2 Nov 2018 17:34:16 +0000 (17:34 +0000)
This moves the abstraction around ::open into the FileSystem, as is
already the case for ::fopen.

llvm-svn: 346002

lldb/include/lldb/Host/FileSystem.h
lldb/source/Host/common/File.cpp
lldb/source/Host/posix/FileSystem.cpp
lldb/source/Host/windows/FileSystem.cpp

index 60cdfdd..269df10 100644 (file)
@@ -43,10 +43,12 @@ public:
 
   Status ResolveSymbolicLink(const FileSpec &src, FileSpec &dst);
 
-  /// Wraps ::fopen in a platform-independent way. Once opened, FILEs can be
-  /// manipulated and closed with the normal ::fread, ::fclose, etc. functions.
+  /// Wraps ::fopen in a platform-independent way.
   FILE *Fopen(const char *path, const char *mode);
 
+  /// Wraps ::open in a platform-independent way.
+  int Open(const char *path, int flags, int mode);
+
   /// Returns the modification time of the given file.
   /// @{
   llvm::sys::TimePoint<> GetModificationTime(const FileSpec &file_spec) const;
index 4aae4d2..7639033 100644 (file)
@@ -30,6 +30,7 @@
 #include "llvm/Support/Process.h" // for llvm::sys::Process::FileDescriptorHasColors()
 
 #include "lldb/Host/Config.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/FileSpec.h"
@@ -160,16 +161,7 @@ void File::SetStream(FILE *fh, bool transfer_ownership) {
 }
 
 static int DoOpen(const char *path, int flags, int mode) {
-#ifdef _MSC_VER
-  std::wstring wpath;
-  if (!llvm::ConvertUTF8toWide(path, wpath))
-    return -1;
-  int result;
-  ::_wsopen_s(&result, wpath.c_str(), flags, _SH_DENYNO, mode);
-  return result;
-#else
-  return ::open(path, flags, mode);
-#endif
+  return FileSystem::Instance().Open(path, flags, mode);
 }
 
 Status File::Open(const char *path, uint32_t options, uint32_t permissions) {
index c4b203b..d7045ff 100644 (file)
@@ -11,6 +11,7 @@
 
 // C includes
 #include <dirent.h>
+#include <fcntl.h>
 #include <sys/mount.h>
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -73,3 +74,7 @@ Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
 FILE *FileSystem::Fopen(const char *path, const char *mode) {
   return ::fopen(path, mode);
 }
+
+int FileSystem::Open(const char *path, int flags, int mode) {
+  return ::open(path, flags, mode);
+}
index 3e9787d..3217cdc 100644 (file)
@@ -96,3 +96,12 @@ FILE *FileSystem::Fopen(const char *path, const char *mode) {
     return nullptr;
   return file;
 }
+
+int FileSystem::Open(const char *path, int flags, int mode) {
+  std::wstring wpath;
+  if (!llvm::ConvertUTF8toWide(path, wpath))
+    return -1;
+  int result;
+  ::_wsopen_s(&result, wpath.c_str(), flags, _SH_DENYNO, mode);
+  return result;
+}