[flang-commits] [PATCH] D127015: [flang][runtime] OPEN write-only files

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jun 3 15:45:55 PDT 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D127015

Files:
  flang/runtime/file.cpp


Index: flang/runtime/file.cpp
===================================================================
--- flang/runtime/file.cpp
+++ flang/runtime/file.cpp
@@ -97,12 +97,18 @@
       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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127015.434174.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220603/19b5b0e7/attachment.bin>


More information about the flang-commits mailing list