From 38744ee151e4527cd150241c3648c8f0101b6288 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Mon, 23 Oct 2023 23:58:18 -0700 Subject: [PATCH] Check for opening a directory on Linux Linux also allows the `open` syscall to open a directory, at least when opening with `O_RDONLY`. --- libbutl/fdstream.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx index 07cb9f2..b4661c5 100644 --- a/libbutl/fdstream.cxx +++ b/libbutl/fdstream.cxx @@ -1074,12 +1074,12 @@ namespace butl of |= O_LARGEFILE; #endif - // Unlike other platforms, *BSD allows opening a directory as a file which - // will cause all kinds of problems upstream (e.g., cpfile()). So we - // detect and diagnose this. Note: not certain this is the case for NetBSD - // and OpenBSD. + // Unlike other platforms, *BSD and Linux allow opening a directory as a + // file which will cause all kinds of problems upstream (e.g., cpfile()). + // So we detect and diagnose this. Note: not certain this is the case for + // NetBSD and OpenBSD. // -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) { struct stat s; if (stat (f, &s) == 0 && S_ISDIR (s.st_mode))