From 082adfe732db95083b238e6eb787a68a4141f593 Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Tue, 14 May 2024 14:42:57 +0100 Subject: [PATCH] [Windows] Add a comment to explain the O_RDONLY/O_WRONLY/O_RDWR logic. The values of these flags on Windows do not overlap, and more particularly, `O_RDONLY` is actually zero on Windows, which means we cannot test for it by AND-ing. --- Sources/System/Internals/WindowsSyscallAdapters.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/System/Internals/WindowsSyscallAdapters.swift b/Sources/System/Internals/WindowsSyscallAdapters.swift index 1e35ee9..048377b 100644 --- a/Sources/System/Internals/WindowsSyscallAdapters.swift +++ b/Sources/System/Internals/WindowsSyscallAdapters.swift @@ -620,6 +620,9 @@ fileprivate struct DecodedOpenFlags { dwCreationDisposition = DWORD(OPEN_EXISTING) } + // The _O_RDONLY, _O_WRONLY and _O_RDWR flags are non-overlapping + // on Windows; in particular, _O_RDONLY is zero, which means we can't + // test for it by AND-ing. dwDesiredAccess = 0 switch (oflag & (_O_RDONLY|_O_WRONLY|_O_RDWR)) { case _O_RDONLY: