[flang-commits] [flang] e5a4f73 - [flang][runtime] OPEN write-only files
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Jun 3 18:09:50 PDT 2022
Author: Peter Klausler
Date: 2022-06-03T18:09:40-07:00
New Revision: e5a4f730dafd9a6dc2371d6e414540fa0fd15460
URL: https://github.com/llvm/llvm-project/commit/e5a4f730dafd9a6dc2371d6e414540fa0fd15460
DIFF: https://github.com/llvm/llvm-project/commit/e5a4f730dafd9a6dc2371d6e414540fa0fd15460.diff
LOG: [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
Added:
Modified:
flang/runtime/file.cpp
Removed:
################################################################################
diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index 6a86c9ddfc5d..fa040b417c31 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -97,12 +97,18 @@ void OpenFile::Open(OpenStatus status, std::optional<Action> action,
flags |= O_TRUNC;
}
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);
if (fd_ >= 0) {
action = Action::ReadWrite;
} else {
- action = Action::Read;
+ fd_ = ::open(path_.get(), flags | O_RDONLY, 0600);
+ if (fd_ >= 0) {
+ action = Action::Read;
+ } else {
+ action = Action::Write;
+ }
}
}
if (fd_ < 0) {
More information about the flang-commits
mailing list