Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lldb/source/Host/common/File.cpp
Show All 33 Lines | |||||
#include "lldb/Utility/DataBufferHeap.h" | #include "lldb/Utility/DataBufferHeap.h" | ||||
#include "lldb/Utility/FileSpec.h" | #include "lldb/Utility/FileSpec.h" | ||||
#include "lldb/Utility/Log.h" | #include "lldb/Utility/Log.h" | ||||
using namespace lldb; | using namespace lldb; | ||||
using namespace lldb_private; | using namespace lldb_private; | ||||
using llvm::Expected; | using llvm::Expected; | ||||
static Expected<const char *> GetStreamOpenModeFromOptions(uint32_t options) { | Expected<const char *> | ||||
File::GetStreamOpenModeFromOptions(File::OpenOptions options) { | |||||
if (options & File::eOpenOptionAppend) { | if (options & File::eOpenOptionAppend) { | ||||
if (options & File::eOpenOptionRead) { | if (options & File::eOpenOptionRead) { | ||||
if (options & File::eOpenOptionCanCreateNewOnly) | if (options & File::eOpenOptionCanCreateNewOnly) | ||||
return "a+x"; | return "a+x"; | ||||
else | else | ||||
return "a+"; | return "a+"; | ||||
} else if (options & File::eOpenOptionWrite) { | } else if (options & File::eOpenOptionWrite) { | ||||
if (options & File::eOpenOptionCanCreateNewOnly) | if (options & File::eOpenOptionCanCreateNewOnly) | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | if (result > 0) { | ||||
Write(s, s_len); | Write(s, s_len); | ||||
result = s_len; | result = s_len; | ||||
} | } | ||||
free(s); | free(s); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
Expected<File::OpenOptions> File::GetOptions() const { | |||||
return llvm::createStringError( | |||||
llvm::inconvertibleErrorCode(), | |||||
"GetOptions() not implemented for this File class"); | |||||
} | |||||
uint32_t File::GetPermissions(Status &error) const { | uint32_t File::GetPermissions(Status &error) const { | ||||
int fd = GetDescriptor(); | int fd = GetDescriptor(); | ||||
if (!DescriptorIsValid(fd)) { | if (!DescriptorIsValid(fd)) { | ||||
error = std::error_code(ENOTSUP, std::system_category()); | error = std::error_code(ENOTSUP, std::system_category()); | ||||
return 0; | return 0; | ||||
} | } | ||||
struct stat file_stats; | struct stat file_stats; | ||||
if (::fstat(fd, &file_stats) == -1) { | if (::fstat(fd, &file_stats) == -1) { | ||||
error.SetErrorToErrno(); | error.SetErrorToErrno(); | ||||
return 0; | return 0; | ||||
} | } | ||||
error.Clear(); | error.Clear(); | ||||
return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); | return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); | ||||
} | } | ||||
Expected<File::OpenOptions> NativeFile::GetOptions() const { return m_options; } | |||||
int NativeFile::GetDescriptor() const { | int NativeFile::GetDescriptor() const { | ||||
if (DescriptorIsValid()) | if (DescriptorIsValid()) | ||||
return m_descriptor; | return m_descriptor; | ||||
// Don't open the file descriptor if we don't need to, just get it from the | // Don't open the file descriptor if we don't need to, just get it from the | ||||
// stream if we have one. | // stream if we have one. | ||||
if (StreamIsValid()) { | if (StreamIsValid()) { | ||||
#if defined(_WIN32) | #if defined(_WIN32) | ||||
▲ Show 20 Lines • Show All 501 Lines • ▼ Show 20 Lines | mode_t File::ConvertOpenOptionsForPOSIXOpen(OpenOptions open_options) { | ||||
if (open_options & eOpenOptionCanCreateNewOnly) | if (open_options & eOpenOptionCanCreateNewOnly) | ||||
mode |= O_CREAT | O_EXCL; | mode |= O_CREAT | O_EXCL; | ||||
else if (open_options & eOpenOptionCanCreate) | else if (open_options & eOpenOptionCanCreate) | ||||
mode |= O_CREAT; | mode |= O_CREAT; | ||||
return mode; | return mode; | ||||
} | } | ||||
char File::ID = 0; | |||||
char NativeFile::ID = 0; |