Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flang-rt/include/flang-rt/runtime/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class OpenFile {
public:
using FileOffset = std::int64_t;

int fd() const { return fd_; }
const char *path() const { return path_.get(); }
std::size_t pathLength() const { return pathLength_; }
void set_path(OwningPtr<char> &&, std::size_t bytes);
Expand Down
9 changes: 9 additions & 0 deletions flang-rt/lib/runtime/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ std::int64_t RTNAME(Ftell)(int unitNumber) {
return -1;
}
}

std::int32_t FORTRAN_PROCEDURE_NAME(fnum)(const int &unitNumber) {
if (ExternalFileUnit * unit{ExternalFileUnit::LookUp(unitNumber)}) {
return unit->fd();
} else {
return -1;
}
}

} // namespace io

} // extern "C"
Expand Down
1 change: 1 addition & 0 deletions flang-rt/lib/runtime/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class PseudoOpenFile {
public:
using FileOffset = std::int64_t;

RT_API_ATTRS int fd() const { return 1 /*stdout*/; }
RT_API_ATTRS const char *path() const { return nullptr; }
RT_API_ATTRS std::size_t pathLength() const { return 0; }
RT_API_ATTRS void set_path(OwningPtr<char> &&, std::size_t bytes) {}
Expand Down
2 changes: 2 additions & 0 deletions flang/docs/Intrinsics.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ CALL BACKTRACE()
CALL FDATE(TIME)
CALL GETLOG(USRNAME)
CALL GETENV(NAME [, VALUE, LENGTH, STATUS, TRIM_NAME, ERRMSG ])
unixFD = FNUM(FORTRAN_UNIT)
```

## Intrinsic Procedure Name Resolution
Expand Down Expand Up @@ -778,6 +779,7 @@ This phase currently supports all the intrinsic procedures listed above but the
| Atomic intrinsic subroutines | ATOMIC_ADD |
| Collective intrinsic subroutines | CO_REDUCE |
| Library subroutines | BACKTRACE, FDATE, GETLOG, GETENV |
| Library functions | FNUM |


### Intrinsic Function Folding
Expand Down
3 changes: 3 additions & 0 deletions flang/include/flang/Runtime/extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ std::int32_t RTNAME(Fseek)(int unit, std::int64_t zeroBasedPos, int whence,
const char *sourceFileName, int lineNumber);
std::int64_t RTNAME(Ftell)(int unit);

// FNUM maps a Fortran unit number to its UNIX file descriptor
std::int32_t FORTRAN_PROCEDURE_NAME(fnum)(const int &unitNumber);

// GNU Fortran 77 compatibility function IARGC.
std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();

Expand Down