@@ -855,10 +855,22 @@ pub fn pipe() -> Result<(RawFd, RawFd)> {
855
855
}
856
856
}
857
857
858
- // libc only defines `pipe2` in `libc::notbsd`.
859
- #[ cfg( any( target_os = "linux" ,
860
- target_os = "android" ,
861
- target_os = "emscripten" ) ) ]
858
+ /// Like `pipe`, but allows setting certain file descriptor flags.
859
+ ///
860
+ /// The following flags are supported, and will be set atomically as the pipe is
861
+ /// created:
862
+ ///
863
+ /// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
864
+ /// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
865
+ ///
866
+ /// See also [pipe(2)](http://man7.org/linux/man-pages/man2/pipe.2.html)
867
+ #[ cfg( any( target_os = "android" ,
868
+ target_os = "dragonfly" ,
869
+ target_os = "emscripten" ,
870
+ target_os = "freebsd" ,
871
+ target_os = "linux" ,
872
+ target_os = "netbsd" ,
873
+ target_os = "openbsd" ) ) ]
862
874
pub fn pipe2 ( flags : OFlag ) -> Result < ( RawFd , RawFd ) > {
863
875
let mut fds: [ c_int ; 2 ] = unsafe { mem:: uninitialized ( ) } ;
864
876
@@ -869,9 +881,19 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
869
881
Ok ( ( fds[ 0 ] , fds[ 1 ] ) )
870
882
}
871
883
872
- #[ cfg( not( any( target_os = "linux" ,
873
- target_os = "android" ,
874
- target_os = "emscripten" ) ) ) ]
884
+ /// Like `pipe`, but allows setting certain file descriptor flags.
885
+ ///
886
+ /// The following flags are supported, and will be set after the pipe is
887
+ /// created:
888
+ ///
889
+ /// `O_CLOEXEC`: Set the close-on-exec flag for the new file descriptors.
890
+ /// `O_NONBLOCK`: Set the non-blocking flag for the ends of the pipe.
891
+ #[ cfg( any( target_os = "ios" ,
892
+ target_os = "macos" ) ) ]
893
+ #[ deprecated(
894
+ since="0.10.0" ,
895
+ note="pipe2(2) is not actually atomic on these platforms. Use pipe(2) and fcntl(2) instead"
896
+ ) ]
875
897
pub fn pipe2 ( flags : OFlag ) -> Result < ( RawFd , RawFd ) > {
876
898
let mut fds: [ c_int ; 2 ] = unsafe { mem:: uninitialized ( ) } ;
877
899
@@ -884,9 +906,8 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
884
906
Ok ( ( fds[ 0 ] , fds[ 1 ] ) )
885
907
}
886
908
887
- #[ cfg( not( any( target_os = "linux" ,
888
- target_os = "android" ,
889
- target_os = "emscripten" ) ) ) ]
909
+ #[ cfg( any( target_os = "ios" ,
910
+ target_os = "macos" ) ) ]
890
911
fn pipe2_setflags ( fd1 : RawFd , fd2 : RawFd , flags : OFlag ) -> Result < ( ) > {
891
912
use fcntl:: O_NONBLOCK ;
892
913
use fcntl:: FcntlArg :: F_SETFL ;
0 commit comments