[Lldb-commits] [lldb] r346002 - [FileSystme] Move ::open abstraction into FileSystem.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 2 10:34:16 PDT 2018


Author: jdevlieghere
Date: Fri Nov  2 10:34:16 2018
New Revision: 346002

URL: http://llvm.org/viewvc/llvm-project?rev=346002&view=rev
Log:
[FileSystme] Move ::open abstraction into FileSystem.

This moves the abstraction around ::open into the FileSystem, as is
already the case for ::fopen.

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

Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=346002&r1=346001&r2=346002&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Fri Nov  2 10:34:16 2018
@@ -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;

Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=346002&r1=346001&r2=346002&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Fri Nov  2 10:34:16 2018
@@ -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 tran
 }
 
 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) {

Modified: lldb/trunk/source/Host/posix/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=346002&r1=346001&r2=346002&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/posix/FileSystem.cpp Fri Nov  2 10:34:16 2018
@@ -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(c
 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);
+}

Modified: lldb/trunk/source/Host/windows/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/FileSystem.cpp?rev=346002&r1=346001&r2=346002&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/windows/FileSystem.cpp Fri Nov  2 10:34:16 2018
@@ -96,3 +96,12 @@ FILE *FileSystem::Fopen(const char *path
     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;
+}




More information about the lldb-commits mailing list