[flang-commits] [PATCH] D85160: [flang] Acquire file accessibility, size, positioning

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Aug 3 16:43:23 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGd8334c43606a: [flang] Acquire file accessibility, size, positioning (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85160/new/

https://reviews.llvm.org/D85160

Files:
  flang/runtime/file.cpp
  flang/runtime/file.h


Index: flang/runtime/file.h
===================================================================
--- flang/runtime/file.h
+++ flang/runtime/file.h
@@ -95,5 +95,9 @@
 };
 
 bool IsATerminal(int fd);
+bool IsExtant(const char *path);
+bool MayRead(const char *path);
+bool MayWrite(const char *path);
+bool MayReadAndWrite(const char *path);
 } // namespace Fortran::runtime::io
 #endif // FORTRAN_RUNTIME_FILE_H_
Index: flang/runtime/file.cpp
===================================================================
--- flang/runtime/file.cpp
+++ flang/runtime/file.cpp
@@ -18,6 +18,7 @@
 #include <io.h>
 #include <windows.h>
 #else
+#include <sys/stat.h>
 #include <unistd.h>
 #endif
 
@@ -84,8 +85,7 @@
     fd_ = openfile_mkstemp(handler);
   } else {
     if (!path_.get()) {
-      handler.SignalError(
-          "FILE= is required unless STATUS='OLD' and unit is connected");
+      handler.SignalError("FILE= is required");
       return;
     }
     int flags{0};
@@ -134,8 +134,18 @@
   mayWrite_ = *action != Action::Read;
   if (status == OpenStatus::Old || status == OpenStatus::Unknown) {
     knownSize_.reset();
+#ifndef _WIN32
+    struct stat buf;
+    if (::fstat(fd_, &buf) == 0) {
+      mayPosition_ = S_ISREG(buf.st_mode);
+      knownSize_ = buf.st_size;
+    }
+#else // TODO: _WIN32
+    mayPosition_ = true;
+#endif
   } else {
     knownSize_ = 0;
+    mayPosition_ = true;
   }
 }
 
@@ -385,4 +395,11 @@
 }
 
 bool IsATerminal(int fd) { return ::isatty(fd); }
+
+bool IsExtant(const char *path) { return ::access(path, F_OK) == 0; }
+bool MayRead(const char *path) { return ::access(path, R_OK) == 0; }
+bool MayWrite(const char *path) { return ::access(path, W_OK) == 0; }
+bool MayReadAndWrite(const char *path) {
+  return ::access(path, R_OK | W_OK) == 0;
+}
 } // namespace Fortran::runtime::io


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85160.282768.patch
Type: text/x-patch
Size: 1823 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200803/1e5b064d/attachment-0001.bin>


More information about the flang-commits mailing list