@@ -876,10 +876,22 @@ pub fn pipe() -> Result<(RawFd, RawFd)> {
876
876
}
877
877
}
878
878
879
- // libc only defines `pipe2` in `libc::notbsd`.
880
- #[ cfg( any( target_os = "linux" ,
881
- target_os = "android" ,
882
- target_os = "emscripten" ) ) ]
879
+ /// Like `pipe`, but allows setting certain file descriptor flags.
880
+ ///
881
+ /// The following flags are supported, and will be set atomically as the pipe is
882
+ /// created:
883
+ ///
884
+ /// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
885
+ /// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
886
+ ///
887
+ /// See also [pipe(2)](http://man7.org/linux/man-pages/man2/pipe.2.html)
888
+ #[ cfg( any( target_os = "android" ,
889
+ target_os = "dragonfly" ,
890
+ target_os = "emscripten" ,
891
+ target_os = "freebsd" ,
892
+ target_os = "linux" ,
893
+ target_os = "netbsd" ,
894
+ target_os = "openbsd" ) ) ]
883
895
pub fn pipe2 ( flags : OFlag ) -> Result < ( RawFd , RawFd ) > {
884
896
let mut fds: [ c_int ; 2 ] = unsafe { mem:: uninitialized ( ) } ;
885
897
@@ -890,9 +902,18 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
890
902
Ok ( ( fds[ 0 ] , fds[ 1 ] ) )
891
903
}
892
904
893
- #[ cfg( not( any( target_os = "linux" ,
894
- target_os = "android" ,
895
- target_os = "emscripten" ) ) ) ]
905
+ /// Like `pipe`, but allows setting certain file descriptor flags.
906
+ ///
907
+ /// The following flags are supported, and will be set after the pipe is
908
+ /// created:
909
+ ///
910
+ /// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
911
+ /// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
912
+ #[ cfg( any( target_os = "ios" , target_os = "macos" ) ) ]
913
+ #[ deprecated(
914
+ since="0.10.0" ,
915
+ note="pipe2(2) is not actually atomic on these platforms. Use pipe(2) and fcntl(2) instead"
916
+ ) ]
896
917
pub fn pipe2 ( flags : OFlag ) -> Result < ( RawFd , RawFd ) > {
897
918
let mut fds: [ c_int ; 2 ] = unsafe { mem:: uninitialized ( ) } ;
898
919
@@ -905,9 +926,7 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
905
926
Ok ( ( fds[ 0 ] , fds[ 1 ] ) )
906
927
}
907
928
908
- #[ cfg( not( any( target_os = "linux" ,
909
- target_os = "android" ,
910
- target_os = "emscripten" ) ) ) ]
929
+ #[ cfg( any( target_os = "ios" , target_os = "macos" ) ) ]
911
930
fn pipe2_setflags ( fd1 : RawFd , fd2 : RawFd , flags : OFlag ) -> Result < ( ) > {
912
931
use fcntl:: FdFlag ;
913
932
use fcntl:: FcntlArg :: F_SETFL ;
0 commit comments