Skip to content

Commit bcd0559

Browse files
committed
[flang][msvc] Define access flags under Windows. NFC.
The flags F_OK, R_OK and W_OK are defined in unistd.h, which does not exist under the Windows platform. Windows still defines the `access` function. Its access flags are documented at https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess. For compatibility, define the flags F_OK, R_OK and W_OK using these constants. This patch is part of the series to make flang compilable with MS Visual Studio <http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html>. Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D88508
1 parent b554306 commit bcd0559

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

flang/runtime/file.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@ int OpenFile::PendingResult(const Terminator &terminator, int iostat) {
397397

398398
bool IsATerminal(int fd) { return ::isatty(fd); }
399399

400+
#ifdef WIN32
401+
// Access flags are normally defined in unistd.h, which unavailable under
402+
// Windows. Instead, define the flags as documented at
403+
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess
404+
#define F_OK 00
405+
#define W_OK 02
406+
#define R_OK 04
407+
#endif
408+
400409
bool IsExtant(const char *path) { return ::access(path, F_OK) == 0; }
401410
bool MayRead(const char *path) { return ::access(path, R_OK) == 0; }
402411
bool MayWrite(const char *path) { return ::access(path, W_OK) == 0; }

0 commit comments

Comments
 (0)