From: Jonas Devlieghere Date: Fri, 2 Nov 2018 17:34:16 +0000 (+0000) Subject: [FileSystme] Move ::open abstraction into FileSystem. X-Git-Tag: llvmorg-8.0.0-rc1~5115 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d7c2b798be21004c628404711beedf315690539b;p=platform%2Fupstream%2Fllvm.git [FileSystme] Move ::open abstraction into FileSystem. This moves the abstraction around ::open into the FileSystem, as is already the case for ::fopen. llvm-svn: 346002 --- diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h index 60cdfdd7..269df10 100644 --- a/lldb/include/lldb/Host/FileSystem.h +++ b/lldb/include/lldb/Host/FileSystem.h @@ -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; diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index 4aae4d2..7639033 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -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) { diff --git a/lldb/source/Host/posix/FileSystem.cpp b/lldb/source/Host/posix/FileSystem.cpp index c4b203b..d7045ff 100644 --- a/lldb/source/Host/posix/FileSystem.cpp +++ b/lldb/source/Host/posix/FileSystem.cpp @@ -11,6 +11,7 @@ // C includes #include +#include #include #include #include @@ -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); +} diff --git a/lldb/source/Host/windows/FileSystem.cpp b/lldb/source/Host/windows/FileSystem.cpp index 3e9787d..3217cdc 100644 --- a/lldb/source/Host/windows/FileSystem.cpp +++ b/lldb/source/Host/windows/FileSystem.cpp @@ -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; +}