# \[SYS-0007\] System: Add wrappers for \`dup3\` and \`pipe2\`

**URL:** <https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789>\
**Category:** Pitches\
**Tags:** swift-system\
**Created:** [May 18, 2026, 9:04pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789 "2026-05-18T21:04:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrflat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrflat/32/31407_2.png) [@jrflat](https://forums.swift.org/u/jrflat)\
**Post date:** [May 18, 2026, 9:04pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/1 "2026-05-18T21:04:42Z")

</div>

Hi Swift System community,

**SYS-0007: Add support for `dup3` and `pipe2` POSIX API to `FileDescriptor`** is ready for review, and we would love your feedback! The review period will run through May 25.

Original pitch: [[Pitch] SwiftSystem: dup3 and pipe2 cover APIs](https://forums.swift.org/t/pitch-swiftsystem-dup3-and-pipe2-cover-apis/82486)  
Proposal: [apple/swift-system#274](https://github.com/apple/swift-system/pull/274) ([Markdown](https://github.com/glessard/swift-system/blob/e65f5a6cadcd6b025855f32e8e9d9f0675c29591/Proposals/0007-FileDescriptor-dup3-pipe2.md))  
Implementation: [apple/swift-system#266](https://github.com/apple/swift-system/pull/266)

Please provide your feedback by:

- Responding to this forums post, or
- Sending me a private email or forums message, which will be communicated anonymously to the proposal authors

Thank you so much for participating in the evolution of Swift System!

---

<div class="post-metadata">

**Author:** ![rhx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rhx/32/14647_2.png) [@rhx](https://forums.swift.org/u/rhx)\
**Post date:** [May 19, 2026, 8:03pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/2 "2026-05-19T20:03:41Z")

</div>

+1  
Makes perfect sense.

---

<div class="post-metadata">

**Author:** ![fclout](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fclout/32/36155_2.png) [@fclout](https://forums.swift.org/u/fclout)\
**Post date:** [May 19, 2026, 11:24pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/3 "2026-05-19T23:24:05Z")

</div>

Is this intentionally in under the pitches topic?

---

<div class="post-metadata">

**Author:** ![jrflat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrflat/32/31407_2.png) [@jrflat](https://forums.swift.org/u/jrflat)\
**Post date:** [May 19, 2026, 11:47pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/4 "2026-05-19T23:47:32Z")

</div>

I didn't select the `Proposal Reviews` topic since it's not an official Swift Evolution proposal, but `Related Projects > System` is probably a better place to host this moving forward.

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [May 20, 2026, 2:26pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/5 "2026-05-20T14:26:18Z")

</div>

+1 to the proposal and +1 to the idea of `Related Projects > System` for such pitches and proposals.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [May 20, 2026, 2:49pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/6 "2026-05-20T14:49:45Z")

</div>

Absolutely! 🚢

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [May 20, 2026, 5:22pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/7 "2026-05-20T17:22:42Z")

</div>

Oh, it occurs to me that Windows' [`_pipe()`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/pipe?view=msvc-170), which takes a flags argument (named, confusingly, `textmode`), is basically the same as `pipe2()`, and we ought to consider supporting it. The set of flags it supports isn't the same as POSIX.

---

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [May 20, 2026, 5:46pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/8 "2026-05-20T17:46:13Z")

</div>

That is already what we call for the no-options version of `FileDescriptor.pipe()`. It's not clear to me what the guarantees of Windows's `_pipe()` happed to be regarding when options are set with regard to file descriptor binding. Are they similar enough to those of POSIX's `pipe2`?

We can amend this proposal later if we find that we can use the existing call for pipe2 on Windows.

---

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [May 20, 2026, 8:47pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/9 "2026-05-20T20:47:48Z")

</div>

As far as I can tell, we've always passed `_O_NOINHERIT` to Windows's `_pipe()` call, probably making it more similar in behaviour to a `pipe2()` with a default value of `O_CLOEXEC`. I'm not entirely sure how to square that with this proposal.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [May 21, 2026, 9:22pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/10 "2026-05-21T21:22:36Z")

</div>

> [@glessard](#):
>
> As far as I can tell, we've always passed `_O_NOINHERIT` to Windows's `_pipe()` call, probably making it more similar in behaviour to a `pipe2()` with a default value of `O_CLOEXEC`. I'm not

That seems like the wrong default (or rather, I would expect that we'd apply `_O_NOINHERIT` in the same contexts as `O_CLOEXEC`). There are some subtle differences between the flags and how you manage handle inheritance vs. file descriptor inheritance, but in broad strokes they represent the same concept.

---

<div class="post-metadata">

**Author:** ![jrflat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrflat/32/31407_2.png) [@jrflat](https://forums.swift.org/u/jrflat)\
**Post date:** [May 26, 2026, 8:18pm UTC](https://forums.swift.org/t/sys-0007-system-add-wrappers-for-dup3-and-pipe2/86789/11 "2026-05-26T20:18:34Z")

</div>

The review period has concluded, thank you all for your feedback! Given the support, we accept this proposal and will work to land it in `swift-system`, adding a note for future directions of `pipe2` on Windows.

As a reminder, future `swift-system` pitches and proposal reviews will be hosted in `Related Projects > System`. Thank you all!
