Skip to content

Convert the crate to edition 2018 #1254

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

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "nix"
description = "Rust friendly bindings to *nix APIs"
edition = "2018"
version = "0.17.0"
authors = ["The nix-rust Project Developers"]
repository = "https://github.com/nix-rust/nix"
Expand Down Expand Up @@ -57,6 +58,6 @@ name = "test-mount"
path = "test/test_mount.rs"
harness = false

[[target.'cfg(not(target_os = "redox"))'.test]]
[[test]]
name = "test-ptymaster-drop"
path = "test/test_ptymaster_drop.rs"
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,13 @@ Tier 3:

`nix` requires Rust 1.36.0 or newer.

To use `nix`, first add this to your `Cargo.toml`:
To use `nix`, add this to your `Cargo.toml`:

```toml
[dependencies]
nix = "0.17.0"
```

Then, add this to your crate root:

```rust,ignore
extern crate nix;
```

## Contributing

Contributions are very welcome. Please See [CONTRIBUTING](CONTRIBUTING.md) for
Expand Down
3 changes: 0 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(target_os = "dragonfly")]
extern crate cc;

#[cfg(target_os = "dragonfly")]
fn main() {
cc::Build::new()
Expand Down
9 changes: 4 additions & 5 deletions src/dir.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {Error, NixPath, Result};
use errno::Errno;
use fcntl::{self, OFlag};
use libc;
use crate::{Error, NixPath, Result};
use crate::errno::Errno;
use crate::fcntl::{self, OFlag};
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::ptr;
use std::ffi;
use sys;
use crate::sys;

#[cfg(target_os = "linux")]
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
Expand Down
3 changes: 2 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {Error, Result};
use cfg_if::cfg_if;
use crate::{Error, Result};

/// Clear the environment of all name-value pairs.
///
Expand Down
18 changes: 2 additions & 16 deletions src/errno.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cfg_if::cfg_if;
#[cfg(not(target_os = "dragonfly"))]
use libc;
use libc::{c_int, c_void};
use std::{fmt, io, error};
use {Error, Result};
use crate::{Error, Result};

pub use self::consts::*;

Expand Down Expand Up @@ -584,8 +584,6 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "linux", target_os = "android"))]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down Expand Up @@ -873,8 +871,6 @@ mod consts {

#[cfg(any(target_os = "macos", target_os = "ios"))]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down Expand Up @@ -1110,8 +1106,6 @@ mod consts {

#[cfg(target_os = "freebsd")]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down Expand Up @@ -1328,8 +1322,6 @@ mod consts {

#[cfg(target_os = "dragonfly")]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down Expand Up @@ -1543,8 +1535,6 @@ mod consts {

#[cfg(target_os = "openbsd")]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down Expand Up @@ -1757,8 +1747,6 @@ mod consts {

#[cfg(target_os = "netbsd")]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down Expand Up @@ -1973,8 +1961,6 @@ mod consts {

#[cfg(target_os = "redox")]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
Expand Down
12 changes: 6 additions & 6 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use errno::Errno;
use crate::errno::Errno;
use libc::{self, c_char, c_int, c_uint, size_t, ssize_t};
use std::ffi::OsString;
#[cfg(not(target_os = "redox"))]
use std::os::raw;
use std::os::unix::ffi::OsStringExt;
use std::os::unix::io::RawFd;
use sys::stat::Mode;
use {NixPath, Result};
use crate::sys::stat::Mode;
use crate::{NixPath, Result};

#[cfg(any(target_os = "android", target_os = "linux"))]
use std::ptr; // For splice and copy_file_range
#[cfg(any(target_os = "android", target_os = "linux"))]
use sys::uio::IoVec; // For vmsplice
use crate::sys::uio::IoVec; // For vmsplice

#[cfg(any(
target_os = "linux",
Expand Down Expand Up @@ -586,10 +586,10 @@ pub fn fallocate(
target_env = "freebsd"
))]
mod posix_fadvise {
use errno::Errno;
use crate::errno::Errno;
use libc;
use std::os::unix::io::RawFd;
use Result;
use crate::Result;

libc_enum! {
#[repr(i32)]
Expand Down
2 changes: 1 addition & 1 deletion src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use self::os::*;

#[cfg(any(target_os = "linux", target_os = "android"))]
mod os {
use sys::utsname::uname;
use crate::sys::utsname::uname;

// Features:
// * atomic cloexec on socket: 2.6.27
Expand Down
9 changes: 4 additions & 5 deletions src/ifaddrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
//! Uses the Linux and/or BSD specific function `getifaddrs` to query the list
//! of interfaces and their associated addresses.

use cfg_if::cfg_if;
use std::ffi;
use std::iter::Iterator;
use std::mem;
use std::option::Option;

use libc;

use {Result, Errno};
use sys::socket::SockAddr;
use net::if_::*;
use crate::{Result, Errno};
use crate::sys::socket::SockAddr;
use crate::net::if_::*;

/// Describes a single address for an interface as returned by `getifaddrs`.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions src/kmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use libc;
use std::ffi::CStr;
use std::os::unix::io::AsRawFd;

use errno::Errno;
use Result;
use crate::errno::Errno;
use crate::Result;

/// Loads a kernel module from a buffer.
///
Expand Down
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]

// External crates
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate cfg_if;

// Re-exported external crates
pub extern crate libc;
pub use libc;

// Private internal modules
#[macro_use] mod macros;
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ macro_rules! libc_bitflags {
)+
}
) => {
bitflags! {
::bitflags::bitflags! {
$(#[$outer])*
pub struct $BitFlags: $T {
$(
Expand Down
4 changes: 2 additions & 2 deletions src/mount.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use libc::{self, c_ulong, c_int};
use {Result, NixPath};
use errno::Errno;
use crate::{Result, NixPath};
use crate::errno::Errno;

libc_bitflags!(
pub struct MsFlags: c_ulong {
Expand Down
6 changes: 3 additions & 3 deletions src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
//!
//! [Further reading and details on the C API](http://man7.org/linux/man-pages/man7/mq_overview.7.html)

use Result;
use errno::Errno;
use crate::Result;
use crate::errno::Errno;

use libc::{self, c_char, c_long, mqd_t, size_t};
use std::ffi::CString;
use sys::stat::Mode;
use crate::sys::stat::Mode;
use std::mem;

libc_bitflags!{
Expand Down
3 changes: 1 addition & 2 deletions src/net/if_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
//! Uses Linux and/or POSIX functions to resolve interface names like "eth0"
//! or "socan1" into device numbers.

use libc;
use libc::c_uint;
use {Result, Error, NixPath};
use crate::{Result, Error, NixPath};

/// Resolve an interface into a interface number.
pub fn if_nametoindex<P: ?Sized + NixPath>(name: &P) -> Result<c_uint> {
Expand Down
9 changes: 4 additions & 5 deletions src/poll.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Wait for events to trigger on specific file descriptors
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
use sys::time::TimeSpec;
use crate::sys::time::TimeSpec;
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
use sys::signal::SigSet;
use crate::sys::signal::SigSet;
use std::os::unix::io::RawFd;

use libc;
use Result;
use errno::Errno;
use crate::Result;
use crate::errno::Errno;

/// This is a wrapper around `libc::pollfd`.
///
Expand Down
22 changes: 9 additions & 13 deletions src/pty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Create master and slave virtual pseudo-terminals (PTYs)

use libc;

pub use libc::pid_t as SessionId;
pub use libc::winsize as Winsize;

Expand All @@ -10,10 +8,10 @@ use std::io;
use std::mem;
use std::os::unix::prelude::*;

use sys::termios::Termios;
use unistd::ForkResult;
use {Result, Error, fcntl};
use errno::Errno;
use crate::sys::termios::Termios;
use crate::unistd::{self, ForkResult, Pid};
use crate::{Result, Error, fcntl};
use crate::errno::Errno;

/// Representation of a master/slave pty pair
///
Expand Down Expand Up @@ -71,7 +69,7 @@ impl Drop for PtyMaster {
// invalid file descriptor. That frequently indicates a double-close
// condition, which can cause confusing errors for future I/O
// operations.
let e = ::unistd::close(self.0);
let e = unistd::close(self.0);
if e == Err(Error::Sys(Errno::EBADF)) {
panic!("Closing an invalid file descriptor!");
};
Expand All @@ -80,13 +78,13 @@ impl Drop for PtyMaster {

impl io::Read for PtyMaster {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
::unistd::read(self.0, buf).map_err(|e| e.as_errno().unwrap().into())
unistd::read(self.0, buf).map_err(|e| e.as_errno().unwrap().into())
}
}

impl io::Write for PtyMaster {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
::unistd::write(self.0, buf).map_err(|e| e.as_errno().unwrap().into())
unistd::write(self.0, buf).map_err(|e| e.as_errno().unwrap().into())
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
Expand Down Expand Up @@ -309,8 +307,6 @@ pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
termios: U,
) -> Result<ForkptyResult> {
use std::ptr;
use unistd::Pid;
use unistd::ForkResult::*;

let mut master = mem::MaybeUninit::<libc::c_int>::uninit();

Expand All @@ -332,8 +328,8 @@ pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>
};

let fork_result = Errno::result(res).map(|res| match res {
0 => Child,
res => Parent { child: Pid::from_raw(res) },
0 => ForkResult::Child,
res => ForkResult::Parent { child: Pid::from_raw(res) },
})?;

unsafe {
Expand Down
9 changes: 4 additions & 5 deletions src/sched.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use libc;
use {Errno, Result};
use crate::{Errno, Result};

#[cfg(any(target_os = "android", target_os = "linux"))]
pub use self::sched_linux_like::*;

#[cfg(any(target_os = "android", target_os = "linux"))]
mod sched_linux_like {
use errno::Errno;
use crate::errno::Errno;
use libc::{self, c_int, c_void};
use std::mem;
use std::option::Option;
use std::os::unix::io::RawFd;
use unistd::Pid;
use {Error, Result};
use crate::unistd::Pid;
use crate::{Error, Result};

// For some functions taking with a parameter of type CloneFlags,
// only a subset of these flags have an effect.
Expand Down
Loading