[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
This commit is contained in:
Jonas Devlieghere 2018-11-02 17:34:16 +00:00
parent 0eb5008352
commit d7c2b798be
4 changed files with 20 additions and 12 deletions

View 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;

View 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) {

View 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);
}

View 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;
}