[flang-commits] [PATCH] D127014: [flang][runtime] INQUIRE(FILE="...", SIZE=nbytes)

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jun 3 18:05:47 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9878facfd01c: [flang][runtime] INQUIRE(FILE="...",SIZE=nbytes) (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127014

Files:
  flang/runtime/file.cpp
  flang/runtime/file.h
  flang/runtime/io-stmt.cpp


Index: flang/runtime/io-stmt.cpp
===================================================================
--- flang/runtime/io-stmt.cpp
+++ flang/runtime/io-stmt.cpp
@@ -1483,9 +1483,11 @@
   case HashInquiryKeyword("NUMBER"):
   case HashInquiryKeyword("POS"):
   case HashInquiryKeyword("RECL"):
-  case HashInquiryKeyword("SIZE"):
     result = -1;
     return true;
+  case HashInquiryKeyword("SIZE"):
+    result = SizeInBytes(path_.get());
+    return true;
   default:
     BadInquiryKeywordHashCrash(inquiry);
     return false;
Index: flang/runtime/file.h
===================================================================
--- flang/runtime/file.h
+++ flang/runtime/file.h
@@ -109,5 +109,6 @@
 bool MayRead(const char *path);
 bool MayWrite(const char *path);
 bool MayReadAndWrite(const char *path);
+std::int64_t SizeInBytes(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
@@ -434,4 +434,17 @@
 bool MayReadAndWrite(const char *path) {
   return ::access(path, R_OK | W_OK) == 0;
 }
+
+std::int64_t SizeInBytes(const char *path) {
+#ifndef _WIN32
+  struct stat buf;
+  if (::stat(path, &buf) == 0) {
+    return buf.st_size;
+  }
+#else // TODO: _WIN32
+#endif
+  // No Fortran compiler signals an error
+  return -1;
+}
+
 } // namespace Fortran::runtime::io


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127014.434225.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220604/ae38f4c3/attachment.bin>


More information about the flang-commits mailing list