Skip to content

Commit 2326a02

Browse files
authored
[flang] Support read-only access to an anonymous unit (#105859)
Don't require the "fort.123" file implicitly opened by READ(123, ... to be writable.
1 parent f099f76 commit 2326a02

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

flang/runtime/external-unit.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ ExternalFileUnit *ExternalFileUnit::LookUpOrCreateAnonymous(int unit,
6565
bool exists{false};
6666
ExternalFileUnit *result{GetUnitMap().LookUpOrCreate(unit, handler, exists)};
6767
if (result && !exists) {
68+
common::optional<Action> action;
69+
if (dir == Direction::Output) {
70+
action = Action::ReadWrite;
71+
}
6872
if (!result->OpenAnonymousUnit(
6973
dir == Direction::Input ? OpenStatus::Unknown : OpenStatus::Replace,
70-
Action::ReadWrite, Position::Rewind, Convert::Unknown, handler)) {
74+
action, Position::Rewind, Convert::Unknown, handler)) {
7175
// fort.N isn't a writable file
7276
if (ExternalFileUnit * closed{LookUpForClose(result->unitNumber())}) {
7377
closed->DestroyClosed();

0 commit comments

Comments
 (0)