[flang-commits] [flang] bcd0559 - [flang][msvc] Define access flags under Windows. NFC.

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Tue Sep 29 15:01:45 PDT 2020


Author: Michael Kruse
Date: 2020-09-29T17:01:36-05:00
New Revision: bcd05599d0e53977a963799d6ee4f6e0bc21331b

URL: https://github.com/llvm/llvm-project/commit/bcd05599d0e53977a963799d6ee4f6e0bc21331b
DIFF: https://github.com/llvm/llvm-project/commit/bcd05599d0e53977a963799d6ee4f6e0bc21331b.diff

LOG: [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

Added: 
    

Modified: 
    flang/runtime/file.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index 8fc81efe6c93..fa59567f6c10 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -397,6 +397,15 @@ int OpenFile::PendingResult(const Terminator &terminator, int iostat) {
 
 bool IsATerminal(int fd) { return ::isatty(fd); }
 
+#ifdef WIN32
+// Access flags are normally defined in unistd.h, which unavailable under
+// Windows. Instead, define the flags as documented at
+// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess
+#define F_OK 00
+#define W_OK 02
+#define R_OK 04
+#endif
+
 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; }


        


More information about the flang-commits mailing list