Skip to content

Commit

Permalink
make unsafe code more fine-grained in pipe2
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Sep 15, 2016
1 parent 71688a0 commit b28005f
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,32 +365,28 @@ pub fn pipe() -> Result<(RawFd, RawFd)> {
target_os = "android",
target_os = "emscripten"))]
pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
unsafe {
let mut fds: [c_int; 2] = mem::uninitialized();
let mut fds: [c_int; 2] = unsafe { mem::uninitialized() };

let res = libc::pipe2(fds.as_mut_ptr(), flags.bits());
let res = unsafe { libc::pipe2(fds.as_mut_ptr(), flags.bits()) };

try!(Errno::result(res));
try!(Errno::result(res));

Ok((fds[0], fds[1]))
}
Ok((fds[0], fds[1]))
}

#[cfg(not(any(target_os = "linux",
target_os = "android",
target_os = "emscripten")))]
pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
unsafe {
let mut fds: [c_int; 2] = mem::uninitialized();
let mut fds: [c_int; 2] = unsafe { mem::uninitialized() };

let res = libc::pipe(fds.as_mut_ptr());
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };

try!(Errno::result(res));
try!(Errno::result(res));

try!(pipe2_setflags(fds[0], fds[1], flags));
try!(pipe2_setflags(fds[0], fds[1], flags));

Ok((fds[0], fds[1]))
}
Ok((fds[0], fds[1]))
}

#[cfg(not(any(target_os = "linux",
Expand Down

0 comments on commit b28005f

Please sign in to comment.