forked from OSchip/llvm-project
[flang][runtime] OPEN write-only files
If a file being opened with no ACTION= is write-only then cope with it rather than defaulting prematurely to treating it as read-only. Differential Revision: https://reviews.llvm.org/D127015
This commit is contained in:
parent
cc3bd43533
commit
e5a4f730da
|
@ -97,12 +97,18 @@ void OpenFile::Open(OpenStatus status, std::optional<Action> action,
|
||||||
flags |= O_TRUNC;
|
flags |= O_TRUNC;
|
||||||
}
|
}
|
||||||
if (!action) {
|
if (!action) {
|
||||||
// Try to open read/write, back off to read-only on failure
|
// Try to open read/write, back off to read-only or even write-only
|
||||||
|
// on failure
|
||||||
fd_ = ::open(path_.get(), flags | O_RDWR, 0600);
|
fd_ = ::open(path_.get(), flags | O_RDWR, 0600);
|
||||||
if (fd_ >= 0) {
|
if (fd_ >= 0) {
|
||||||
action = Action::ReadWrite;
|
action = Action::ReadWrite;
|
||||||
} else {
|
} else {
|
||||||
|
fd_ = ::open(path_.get(), flags | O_RDONLY, 0600);
|
||||||
|
if (fd_ >= 0) {
|
||||||
action = Action::Read;
|
action = Action::Read;
|
||||||
|
} else {
|
||||||
|
action = Action::Write;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fd_ < 0) {
|
if (fd_ < 0) {
|
||||||
|
|
Loading…
Reference in New Issue