#include <io.h>
#include <windows.h>
#else
+#include <sys/stat.h>
#include <unistd.h>
#endif
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};
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;
}
}
}
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
};
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_