From b8eda812a008ec5d505ac7efda5660399bf20725 Mon Sep 17 00:00:00 2001 From: paulpr0 Date: Thu, 3 Aug 2017 02:34:34 +0100 Subject: [PATCH] Upgrade nix to 0.9 (map nix::Error to io::Error) --- Cargo.toml | 4 ++-- src/unix.rs | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42350ff..553adfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "os_pipe" -version = "0.5.1" +version = "0.5.2" authors = ["Jack O'Connor"] description = "a cross-platform library for opening OS pipes" repository = "https://github.com/oconnor663/os_pipe.rs" @@ -8,7 +8,7 @@ documentation = "https://docs.rs/os_pipe" license = "MIT" [target.'cfg(not(windows))'.dependencies] -nix = "^0.8.0" +nix = "^0.9.0" [target.'cfg(windows)'.dependencies] winapi = "^0.2.8" diff --git a/src/unix.rs b/src/unix.rs index 413d529..dc14d4a 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -2,9 +2,12 @@ extern crate nix; use std::fs::File; use std::io; +use std::io::ErrorKind; use std::os::unix::prelude::*; use std::process::Stdio; +use sys::nix::Error::Sys; + use PipeReader; use PipeWriter; use IntoStdio; @@ -13,7 +16,7 @@ pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> { // O_CLOEXEC prevents children from inheriting these pipes. Nix's pipe2() will make a best // effort to make that atomic on platforms that support it, to avoid the case where another // thread forks right after the pipes are created but before O_CLOEXEC is set. - let (read_fd, write_fd) = nix::unistd::pipe2(nix::fcntl::O_CLOEXEC)?; + let (read_fd, write_fd) = nix::unistd::pipe2(nix::fcntl::O_CLOEXEC).map_err(nix_err_to_io_err)?; unsafe { Ok(( @@ -42,6 +45,17 @@ fn dup_fd(fd: RawFd) -> io::Result { dup_result.map(File::into_stdio) } +fn nix_err_to_io_err(err: nix::Error) -> io::Error { + match err { + Sys(err_no) => { + io::Error::from(err_no) + } + _ => { + io::Error::new(ErrorKind::InvalidData, err) + } + } +} + impl IntoStdio for T { fn into_stdio(self) -> Stdio { let fd = self.into_raw_fd();