mirror of
https://github.com/apple/swift-system
synced 2026-11-25 04:47:55 +00:00
Add option-taking pipe() implementation for Windows
This commit is contained in:
1 parent
ebbbc31709
commit
e59002fa14
6 files changed
+30
-7
No files matched your search
@@ -7,5 +7,8 @@
|
||||
See https://swift.org/LICENSE.txt for license information
|
||||
*/
|
||||
|
||||
#if !defined(_WIN32)
|
||||
extern int csystem_posix_pipe2(int fildes[2], int flag);
|
||||
#endif
|
||||
|
||||
extern int csystem_posix_dup3(int fildes, int fildes2, int flag);
|
||||
@@ -28,6 +28,8 @@
|
||||
#endif
|
||||
|
||||
// Wrappers are required because _GNU_SOURCE causes a conflict with other imports when defined in CSystemLinux.h
|
||||
|
||||
#if !defined(_WIN32)
|
||||
extern int csystem_posix_pipe2(int fildes[2], int flag) {
|
||||
#ifdef HAVE_PIPE2_DUP3
|
||||
return pipe2(fildes, flag);
|
||||
@@ -36,6 +38,8 @@ extern int csystem_posix_pipe2(int fildes[2], int flag) {
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
#endif // !defined(_WIN32)
|
||||
|
||||
extern int csystem_posix_dup3(int fildes, int fildes2, int flag) {
|
||||
#ifdef HAVE_PIPE2_DUP3
|
||||
return dup3(fildes, fildes2, flag);
|
||||
|
||||
@@ -324,7 +324,6 @@ extension FileDescriptor {
|
||||
|
||||
/// Options that specify behavior for a newly-created pipe.
|
||||
@frozen
|
||||
@available(Windows, unavailable)
|
||||
@available(macOS, unavailable)
|
||||
@available(iOS, unavailable)
|
||||
@available(tvOS, unavailable)
|
||||
@@ -350,6 +349,7 @@ extension FileDescriptor {
|
||||
@_alwaysEmitIntoClient
|
||||
@available(*, unavailable, renamed: "nonBlocking")
|
||||
public static var O_NONBLOCK: PipeOptions { nonBlocking }
|
||||
#endif // !os(Windows)
|
||||
|
||||
/// Indicates that executing a program closes the file.
|
||||
///
|
||||
@@ -369,7 +369,13 @@ extension FileDescriptor {
|
||||
@available(*, unavailable, renamed: "closeOnExec")
|
||||
public static var O_CLOEXEC: PipeOptions { closeOnExec }
|
||||
|
||||
#if !os(WASI) && !os(Linux) && !os(Android)
|
||||
#if os(Windows)
|
||||
@_alwaysEmitIntoClient
|
||||
@available(*, unavailable, renamed: "closeOnExec")
|
||||
public static var O_NOINHERIT: PipeOptions { closeOnExec }
|
||||
#endif
|
||||
|
||||
#if !os(Windows) && !os(WASI) && !os(Linux) && !os(Android)
|
||||
/// Indicates that forking a program closes the file.
|
||||
///
|
||||
/// Normally, file descriptors remain open
|
||||
@@ -387,7 +393,6 @@ extension FileDescriptor {
|
||||
@_alwaysEmitIntoClient
|
||||
@available(*, unavailable, renamed: "closeOnFork")
|
||||
public static var O_CLOFORK: PipeOptions { closeOnFork }
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -524,7 +524,6 @@ extension FileDescriptor {
|
||||
///
|
||||
/// The corresponding C function is `pipe2`.
|
||||
@_alwaysEmitIntoClient
|
||||
@available(Windows, unavailable)
|
||||
@available(macOS, unavailable)
|
||||
@available(iOS, unavailable)
|
||||
@available(tvOS, unavailable)
|
||||
@@ -550,7 +549,6 @@ extension FileDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
@available(Windows, unavailable)
|
||||
@available(macOS, unavailable)
|
||||
@available(iOS, unavailable)
|
||||
@available(tvOS, unavailable)
|
||||
|
||||
@@ -619,10 +619,16 @@ internal var _O_DIRECTORY: CInt {
|
||||
internal var _O_SYMLINK: CInt { O_SYMLINK }
|
||||
#endif
|
||||
|
||||
#if !os(Windows)
|
||||
@_alwaysEmitIntoClient
|
||||
internal var _O_CLOEXEC: CInt { O_CLOEXEC }
|
||||
internal var _O_CLOEXEC: CInt {
|
||||
#if os(Windows)
|
||||
O_NOINHERIT
|
||||
#else
|
||||
O_CLOEXEC
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !os(Windows)
|
||||
@_alwaysEmitIntoClient
|
||||
internal var _O_CLOFORK: CInt {
|
||||
#if !os(WASI) && !os(Linux) && !os(Android) && !canImport(Darwin)
|
||||
|
||||
@@ -206,6 +206,13 @@ internal func pipe(
|
||||
return _pipe(fds, bytesReserved, _O_BINARY | _O_NOINHERIT);
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
internal func csystem_posix_pipe2(
|
||||
_ fds: UnsafeMutablePointer<Int32>, bytesReserved: UInt32 = 0, _ oflag: Int32
|
||||
) -> CInt {
|
||||
return _pipe(fds, bytesReserved, _O_BINARY | oflag)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
internal func ftruncate(_ fd: Int32, _ length: off_t) -> Int32 {
|
||||
let handle: intptr_t = _get_osfhandle(fd)
|
||||
|
||||
Reference in new issue
Block a user