Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency with _dup2 on Windows #192

Open
jakepetroules opened this issue Aug 1, 2024 · 1 comment
Open

Inconsistency with _dup2 on Windows #192

jakepetroules opened this issue Aug 1, 2024 · 1 comment

Comments

@jakepetroules
Copy link
Member

jakepetroules commented Aug 1, 2024

On Windows, _dup2 is documented to return 0 to indicate success, in contrast to POSIX's dup2, which returns the new file descriptor.

Should we change the Windows syscall adapter to something like:

@inline(__always)
internal func dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
  _dup2(fd, fd2)
  return fd2 // dup2 is documented on windows to return 0 on success while POSIX expects fd2, 
             // so always return fd2 for consistency
}

I understand the general spirit of swift-system is to match the platform behavior, but this one stands out as potentially quite surprising, so I wonder if we should at least call it out in the documentation comments for this function?

@glessard
Copy link
Contributor

glessard commented Oct 17, 2024

The current state of FileDescriptor on Windows is that it's become a questionable POSIX-emulation layer, and it shouldn't be this way. We should have the thinnest possible wrappers over the platform calls, with the translation limited to adapting language differences. Cross-platform behaviour should be implemented by swift-foundation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants