summaryrefslogtreecommitdiff
path: root/flang/runtime/file.h
diff options
context:
space:
mode:
Diffstat (limited to 'flang/runtime/file.h')
-rw-r--r--flang/runtime/file.h38
1 files changed, 25 insertions, 13 deletions
diff --git a/flang/runtime/file.h b/flang/runtime/file.h
index d5e521756653..9ed1c250364a 100644
--- a/flang/runtime/file.h
+++ b/flang/runtime/file.h
@@ -19,25 +19,33 @@
namespace Fortran::runtime::io {
+enum class OpenStatus { Old, New, Scratch, Replace, Unknown };
+enum class CloseStatus { Keep, Delete };
+enum class Position { AsIs, Rewind, Append };
+
class OpenFile {
public:
using FileOffset = std::int64_t;
- FileOffset position() const { return position_; }
-
- void Open(const char *path, std::size_t pathLength, const char *status,
- std::size_t statusLength, const char *action, std::size_t actionLength,
- IoErrorHandler &);
- void Predefine(int fd);
- void Close(const char *action, std::size_t actionLength, IoErrorHandler &);
-
- int fd() const { return fd_; }
+ Lock &lock() { return lock_; }
+ const char *path() const { return path_.get(); }
+ void set_path(OwningPtr<char> &&, std::size_t bytes);
+ std::size_t pathLength() const { return pathLength_; }
bool mayRead() const { return mayRead_; }
- bool mayWrite() const { return mayWrite_; }
- bool mayPosition() const { return mayPosition_; }
void set_mayRead(bool yes) { mayRead_ = yes; }
+ bool mayWrite() const { return mayWrite_; }
void set_mayWrite(bool yes) { mayWrite_ = yes; }
+ bool mayAsynchronous() const { return mayAsynchronous_; }
+ void set_mayAsynchronous(bool yes) { mayAsynchronous_ = yes; }
+ bool mayPosition() const { return mayPosition_; }
void set_mayPosition(bool yes) { mayPosition_ = yes; }
+ FileOffset position() const { return position_; }
+ bool isTerminal() const { return isTerminal_; }
+
+ bool IsOpen() const { return fd_ >= 0; }
+ void Open(OpenStatus, Position, IoErrorHandler &);
+ void Predefine(int fd);
+ void Close(CloseStatus, IoErrorHandler &);
// Reads data into memory; returns amount acquired. Synchronous.
// Partial reads (less than minBytes) signify end-of-file. If the
@@ -69,10 +77,11 @@ private:
};
// lock_ must be held for these
- void CheckOpen(Terminator &);
+ void CheckOpen(const Terminator &);
bool Seek(FileOffset, IoErrorHandler &);
bool RawSeek(FileOffset);
- int PendingResult(Terminator &, int);
+ bool RawSeekToEnd();
+ int PendingResult(const Terminator &, int);
Lock lock_;
int fd_{-1};
@@ -81,8 +90,11 @@ private:
bool mayRead_{false};
bool mayWrite_{false};
bool mayPosition_{false};
+ bool mayAsynchronous_{false};
FileOffset position_{0};
std::optional<FileOffset> knownSize_;
+ bool isTerminal_{false};
+
int nextId_;
OwningPtr<Pending> pending_;
};