-
Notifications
You must be signed in to change notification settings - Fork 654
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
call pipe2 directly on Linux #427
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
//! Standard symbolic constants and types | ||
//! | ||
use {Errno, Error, Result, NixPath}; | ||
use fcntl::{fcntl, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; | ||
use fcntl::FcntlArg::{F_SETFD, F_SETFL}; | ||
use fcntl::{fcntl, OFlag, O_CLOEXEC, FD_CLOEXEC}; | ||
use fcntl::FcntlArg::F_SETFD; | ||
use libc::{self, c_char, c_void, c_int, c_uint, size_t, pid_t, off_t, uid_t, gid_t, mode_t}; | ||
use std::mem; | ||
use std::ffi::{CString, CStr, OsString}; | ||
|
@@ -360,6 +360,25 @@ pub fn pipe() -> Result<(RawFd, RawFd)> { | |
} | ||
} | ||
|
||
// libc only defines `pipe2` in `libc::notbsd`. | ||
#[cfg(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 res = libc::pipe2(fds.as_mut_ptr(), flags.bits()); | ||
|
||
try!(Errno::result(res)); | ||
|
||
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(); | ||
|
@@ -374,7 +393,13 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> { | |
} | ||
} | ||
|
||
#[cfg(not(any(target_os = "linux", | ||
target_os = "android", | ||
target_os = "emscripten")))] | ||
fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> { | ||
use fcntl::O_NONBLOCK; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you pull these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is the only function that uses these imports, and it's no longer building on Linux, we get "unused import" warnings if we leave these at the top. Is there another good way to avoid those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. |
||
use fcntl::FcntlArg::F_SETFL; | ||
|
||
let mut res = Ok(0); | ||
|
||
if flags.contains(O_CLOEXEC) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use
unsafe
as finegrained as possible, even if you need more instances.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b28005f. I notice GitHub's fancy new review system doesn't automatically collapse comments in the same way though.