Skip to content

Commit 395a77f

Browse files
authored
Merge pull request #260 from apple/eng/PR-duplicate-as-release/1.6.0
[1.6] Fix: FileDescriptor.duplicate(as:) returns an invalid file descriptor on Windows
2 parents 890830f + b161847 commit 395a77f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/System/Internals/WindowsSyscallAdapters.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ internal func dup(_ fd: Int32) -> Int32 {
135135

136136
@inline(__always)
137137
internal func dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
138-
_dup2(fd, fd2)
138+
// _dup2 returns 0 to indicate success.
139+
if _dup2(fd, fd2) == 0 {
140+
return fd2
141+
}
142+
return -1
139143
}
140144

141145
@inline(__always)

0 commit comments

Comments
 (0)