Skip to content

Commit bb2201f

Browse files
committed
try to fix open call on windows
1 parent c132fab commit bb2201f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/swsh/FDWrapperCommand.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ internal class FDWrapperCommand: Command {
2929

3030
convenience init(inner: Command, opening path: String, toHandle dstFd: FileDescriptor, oflag: Int32) {
3131
self.init(inner: inner) { command in
32-
printOSCall("open", path, oflag, 0o666)
33-
let fd = open(path, oflag, 0o666)
32+
#if os(Windows)
33+
let pmode: Int32 = _S_IREAD | _S_IWRITE
34+
#else
35+
let pmode: mode_t = 0o666
36+
#endif
37+
printOSCall("open", path, oflag, pmode)
38+
let fd = open(path, oflag, pmode)
3439
guard fd >= 0 else {
3540
return .failure(SyscallError(name: "open(\"\(path)\", ...)", command: command, errno: errno))
3641
}
@@ -170,7 +175,7 @@ extension Command {
170175
#else
171176
let pipe = FDPipe()
172177
let dispatchData = data.withUnsafeBytes { DispatchData(bytes: $0) }
173-
178+
174179
printOSCall("DispatchIO.write", pipe.fileHandleForWriting.fileDescriptor.rawValue, data, "DispatchQueue.global()")
175180
DispatchIO.write(
176181
toFileDescriptor: pipe.fileHandleForWriting.fileDescriptor.rawValue,

0 commit comments

Comments
 (0)