[llvm] [Support] Report EISDIR when opening a directory (PR #79880)

Hubert Tong via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 15:51:10 PST 2024


================
@@ -1024,6 +1024,13 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
   auto Open = [&]() { return ::open(P.begin(), OpenFlags, Mode); };
   if ((ResultFD = sys::RetryAfterSignal(-1, Open)) < 0)
     return std::error_code(errno, std::generic_category());
+  if (Access == FA_Read) {
+    struct stat Status;
+    if (fstat(ResultFD, &Status) == -1)
+      return std::error_code(errno, std::generic_category());
+    if (S_ISDIR(Status.st_mode))
+      return make_error_code(errc::is_a_directory);
+  }
----------------
hubert-reinterpretcast wrote:

@azhan92, please add the `#ifdef` for `AIX` and `__MVS__` as requested by @MaskRay. We can add a comment that the underlying operation on these platforms allow opening directories for reading in more cases than other platforms.

https://github.com/llvm/llvm-project/pull/79880


More information about the llvm-commits mailing list