Skip to content

Commit

Permalink
Stop reexporting Errno and its variants
Browse files Browse the repository at this point in the history
cc #664 (unsure if this is everything needed)
  • Loading branch information
jonas-schievink committed Dec 4, 2017
1 parent 86ebf7b commit 512c351
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- The syscall module has been removed. This only exposed enough functionality for
`memfd_create()` and `pivot_root()`, which are still exposed as separate functions.
([#747](https://github.com/nix-rust/nix/pull/747))
- The `Errno` variants are no longer reexported from the `errno` module. `Errno` itself is no longer reexported from the
crate root and instead must be accessed using the `errno` module. ([#696](https://github.com/nix-rust/nix/pull/696))

## [0.9.0] 2017-07-23

Expand Down
4 changes: 2 additions & 2 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{fmt, io, error};
use {Error, Result};

pub use self::consts::*;
pub use self::consts::Errno::*;

cfg_if! {
if #[cfg(any(target_os = "freebsd",
Expand Down Expand Up @@ -113,6 +112,7 @@ fn last() -> Errno {
}

fn desc(errno: Errno) -> &'static str {
use self::Errno::*;
match errno {
UnknownErrno => "Unknown errno",
EPERM => "Operation not permitted",
Expand Down Expand Up @@ -1898,7 +1898,7 @@ mod consts {

#[cfg(test)]
mod test {
use super::*;
use super::Errno::*;
use nixtest::assert_const_eq;
use libc::c_int;

Expand Down
3 changes: 2 additions & 1 deletion src/fcntl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {Error, Errno, Result, NixPath};
use {Error, Result, NixPath};
use errno::Errno;
use libc::{self, c_int, c_uint, c_char, size_t, ssize_t};
use sys::stat::Mode;
use std::os::unix::io::RawFd;
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern crate nix_test as nixtest;

pub extern crate libc;

pub use errno::Errno;
use errno::Errno;

pub mod errno;
pub mod features;
Expand Down Expand Up @@ -96,24 +96,24 @@ pub enum Error {
impl Error {

/// Create a nix Error from a given errno
pub fn from_errno(errno: errno::Errno) -> Error {
pub fn from_errno(errno: Errno) -> Error {
Error::Sys(errno)
}

/// Get the current errno and convert it to a nix Error
pub fn last() -> Error {
Error::Sys(errno::Errno::last())
Error::Sys(Errno::last())
}

/// Create a new invalid argument error (`EINVAL`)
pub fn invalid_argument() -> Error {
Error::Sys(errno::EINVAL)
Error::Sys(Errno::EINVAL)
}

}

impl From<errno::Errno> for Error {
fn from(errno: errno::Errno) -> Error { Error::from_errno(errno) }
impl From<Errno> for Error {
fn from(errno: Errno) -> Error { Error::from_errno(errno) }
}

impl From<std::string::FromUtf8Error> for Error {
Expand Down
3 changes: 2 additions & 1 deletion src/mount.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc::{c_ulong, c_int};
use libc;
use {Errno, Result, NixPath};
use {Result, NixPath};
use errno::Errno;

bitflags!(
pub struct MsFlags: c_ulong {
Expand Down
3 changes: 2 additions & 1 deletion src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//!
//! [Further reading and details on the C API](http://man7.org/linux/man-pages/man7/mq_overview.7.html)
use {Errno, Result};
use Result;
use errno::Errno;

use libc::{self, c_char, c_long, mode_t, mqd_t, size_t};
use std::ffi::CString;
Expand Down
3 changes: 2 additions & 1 deletion src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use sys::signal::SigSet;
use std::os::unix::io::RawFd;

use libc;
use {Errno, Result};
use Result;
use errno::Errno;

/// This is a wrapper around `libc::pollfd`.
///
Expand Down
3 changes: 2 additions & 1 deletion src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use std::mem;
use std::os::unix::prelude::*;

use sys::termios::Termios;
use {Errno, Result, Error, fcntl};
use {Result, Error, fcntl};
use errno::Errno;

/// Representation of a master/slave pty pair
///
Expand Down
3 changes: 2 additions & 1 deletion src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::mem;
use std::os::unix::io::RawFd;
use std::option::Option;
use libc::{self, c_int, c_void};
use {Errno, Error, Result};
use {Error, Result};
use errno::Errno;
use ::unistd::Pid;

// For some functions taking with a parameter of type CloneFlags,
Expand Down
3 changes: 2 additions & 1 deletion src/sys/aio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {Error, Errno, Result};
use {Error, Result};
use errno::Errno;
use std::os::unix::io::RawFd;
use libc::{c_void, off_t, size_t};
use libc;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/epoll.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {Errno, Result};
use Result;
use errno::Errno;
use libc::{self, c_int};
use std::os::unix::io::RawFd;
use std::ptr;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/eventfd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc;
use std::os::unix::io::RawFd;
use {Errno, Result};
use Result;
use errno::Errno;

libc_bitflags! {
pub struct EfdFlags: libc::c_int {
Expand Down
8 changes: 5 additions & 3 deletions src/sys/ioctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
//! ```
//! # #[macro_use] extern crate nix;
//! # use std::mem;
//! # use nix::{Errno, libc, Result};
//! # use nix::{libc, Result};
//! # use nix::errno::Errno;
//! # use nix::libc::c_int as c_int;
//! # const SPI_IOC_MAGIC: u8 = b'k'; // Defined in linux/spi/spidev.h
//! # const SPI_IOC_TYPE_MODE: u8 = 1;
Expand Down Expand Up @@ -176,7 +177,8 @@
//! ```
//! # #[macro_use] extern crate nix;
//! # use std::mem;
//! # use nix::{Errno, libc, Result};
//! # use nix::{libc, Result};
//! # use nix::errno::Errno;
//! # use nix::libc::c_int as c_int;
//! # const SPI_IOC_MAGIC: u8 = b'k';
//! # const SPI_IOC_TYPE_MESSAGE: u8 = 0;
Expand Down Expand Up @@ -248,7 +250,7 @@ pub use self::platform::*;
macro_rules! convert_ioctl_res {
($w:expr) => (
{
$crate::Errno::result($w)
$crate::errno::Errno::result($w)
}
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/sys/memfd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc;
use std::os::unix::io::RawFd;
use {Errno, Result};
use Result;
use errno::Errno;
use std::ffi::CStr;

libc_bitflags!(
Expand Down
3 changes: 2 additions & 1 deletion src/sys/mman.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {Errno, Error, Result, NixPath};
use {Error, Result, NixPath};
use errno::Errno;
use fcntl::OFlag;
use libc::{self, c_int, c_void, size_t, off_t};
use sys::stat::Mode;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/ptrace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! For detailed description of the ptrace requests, consult `man ptrace`.
use std::{mem, ptr};
use {Errno, Error, Result};
use {Error, Result};
use errno::Errno;
use libc::{self, c_void, c_long, siginfo_t};
use ::unistd::Pid;
use sys::signal::Signal;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use std::default::Default;
use std::{mem, ptr};
use libc::{self, c_int, c_char};
use {Errno, Result, NixPath};
use {Result, NixPath};
use errno::Errno;

struct QuotaCmd(QuotaSubCmd, QuotaType);

Expand Down
3 changes: 2 additions & 1 deletion src/sys/reboot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Reboot/shutdown or enable/disable Ctrl-Alt-Delete.
use {Errno, Error, Result};
use {Error, Result};
use errno::Errno;
use libc;
use void::Void;
use std::mem::drop;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::mem;
use std::os::unix::io::RawFd;
use std::ptr::null_mut;
use libc::{self, c_int};
use {Errno, Result};
use Result;
use errno::Errno;
use sys::time::TimeVal;

pub use libc::FD_SETSIZE;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::ptr;

use libc::{self, off_t};

use {Errno, Result};
use Result;
use errno::Errno;

pub fn sendfile(out_fd: RawFd, in_fd: RawFd, offset: Option<&mut off_t>, count: usize) -> Result<usize> {
let offset = offset.map(|offset| offset as *mut _).unwrap_or(ptr::null_mut());
Expand Down
3 changes: 2 additions & 1 deletion src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// See http://rust-lang.org/COPYRIGHT.

use libc;
use {Errno, Error, Result};
use {Error, Result};
use errno::Errno;
use std::mem;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
use std::os::unix::io::RawFd;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/signalfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
//! signal handlers.
use libc;
use unistd;
use {Error, Errno, Result};
use {Error, Result};
use errno::Errno;
pub use sys::signal::{self, SigSet};
pub use libc::signalfd_siginfo as siginfo;

Expand Down
3 changes: 2 additions & 1 deletion src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::sa_family_t;
use {Errno, Error, Result, NixPath};
use {Error, Result, NixPath};
use errno::Errno;
use libc;
use std::{fmt, hash, mem, net, ptr, slice};
use std::ffi::OsStr;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Socket interface functions
//!
//! [Further reading](http://man7.org/linux/man-pages/man7/socket.7.html)
use {Error, Errno, Result};
use {Error, Result};
use errno::Errno;
use features;
use libc::{self, c_void, c_int, socklen_t, size_t, pid_t, uid_t, gid_t};
use std::{mem, ptr, slice};
Expand Down
3 changes: 2 additions & 1 deletion src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{GetSockOpt, SetSockOpt};
use {Errno, Result};
use Result;
use errno::Errno;
use sys::time::TimeVal;
use libc::{self, c_int, uint8_t, c_void, socklen_t};
use std::mem;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/stat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub use libc::dev_t;
pub use libc::stat as FileStat;

use {Errno, Result, NixPath};
use {Result, NixPath};
use errno::Errno;
use fcntl::AtFlags;
use libc::{self, mode_t};
use std::mem;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/statfs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {Errno, Result, NixPath};
use {Result, NixPath};
use errno::Errno;
use std::os::unix::io::AsRawFd;
use libc;

Expand Down
3 changes: 2 additions & 1 deletion src/sys/statvfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::os::unix::io::AsRawFd;

use libc::{self, c_ulong};

use {Errno, Result, NixPath};
use {Result, NixPath};
use errno::Errno;

bitflags!(
/// File system mount Flags
Expand Down
3 changes: 2 additions & 1 deletion src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
//! termios.control_flags |= ControlFlags::CS5;
//! ```
use {Errno, Result};
use Result;
use errno::Errno;
use libc::{self, c_int, tcflag_t};
use std::cell::{Ref, RefCell};
use std::convert::From;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/uio.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Silence invalid warnings due to rust-lang/rust#16719
#![allow(improper_ctypes)]

use {Errno, Result};
use Result;
use errno::Errno;
use libc::{self, c_int, c_void, size_t, off_t};
use std::marker::PhantomData;
use std::os::unix::io::RawFd;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/wait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use libc::{self, c_int};
use {Errno, Result};
use Result;
use errno::Errno;
use unistd::Pid;

use sys::signal::Signal;
Expand Down
4 changes: 3 additions & 1 deletion src/ucontext.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use libc;
#[cfg(not(target_env = "musl"))]
use {Errno, Result};
use Result;
#[cfg(not(target_env = "musl"))]
use errno::Errno;
use std::mem;
use sys::signal::SigSet;

Expand Down
10 changes: 6 additions & 4 deletions src/unistd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Safe wrappers around functions found in libc "unistd.h" header
use errno;
use {Errno, Error, Result, NixPath};
use errno::{self, Errno};
use {Error, Result, NixPath};
use fcntl::{fcntl, FdFlag, OFlag};
use fcntl::FcntlArg::F_SETFD;
use libc::{self, c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t,
Expand Down Expand Up @@ -1942,7 +1942,8 @@ pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
#[cfg(any(target_os = "android", target_os = "linux"))]
mod pivot_root {
use libc;
use {Errno, Result, NixPath};
use {Result, NixPath};
use errno::Errno;

pub fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
new_root: &P1, put_old: &P2) -> Result<()> {
Expand All @@ -1962,7 +1963,8 @@ mod pivot_root {
target_os = "linux", target_os = "openbsd"))]
mod setres {
use libc;
use {Errno, Result};
use Result;
use errno::Errno;
use super::{Uid, Gid};

/// Sets the real, effective, and saved uid.
Expand Down
3 changes: 2 additions & 1 deletion test/sys/test_epoll.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use nix::sys::epoll::{EpollCreateFlags, EpollFlags, EpollOp, EpollEvent};
use nix::sys::epoll::{epoll_create1, epoll_ctl};
use nix::{Error, Errno};
use nix::Error;
use nix::errno::Errno;

#[test]
pub fn test_epoll_errno() {
Expand Down
Loading

0 comments on commit 512c351

Please sign in to comment.