Skip to content

Commit ff677ad

Browse files
authored
(128068512) FoundationEssentials: correct the use of open on Windows (#607)
`open` is a variatic function and does not take the same permission modes on Windows. Prefer to use `_sopen_s` to allow us to have a non-variadic signature and repair the runtime on Windows.
1 parent d91433d commit ff677ad

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ private func openFileDescriptorProtected(path: UnsafePointer<CChar>, flags: Int3
3434
#if FOUNDATION_FRAMEWORK
3535
// Use file protection on this platform
3636
return _NSOpenFileDescriptor_Protected(path, Int(flags), options, 0o666)
37+
#elseif os(Windows)
38+
var fd: CInt = 0
39+
_ = _sopen_s(&fd, path, flags, _SH_DENYNO, _S_IREAD | _S_IWRITE)
40+
return fd
3741
#else
3842
return open(path, flags, 0o666)
3943
#endif

0 commit comments

Comments
 (0)