Skip to content

Commit

Permalink
Fix all formating problems to pass CI formating test
Browse files Browse the repository at this point in the history
Signed-off-by: Costin-Robert Sin <[email protected]>
  • Loading branch information
costinsin committed Jun 19, 2022
1 parent 469567c commit 6498cee
Show file tree
Hide file tree
Showing 46 changed files with 3,822 additions and 2,960 deletions.
2,987 changes: 1,614 additions & 1,373 deletions src/errno.rs

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ use std::os::raw;
use std::os::unix::ffi::OsStringExt;
use std::os::unix::io::RawFd;

#[cfg(feature = "fs")]
use crate::{sys::stat::Mode, NixPath, Result};
#[cfg(any(target_os = "android", target_os = "linux"))]
use std::ptr; // For splice and copy_file_range
#[cfg(feature = "fs")]
use crate::{
NixPath,
Result,
sys::stat::Mode
};

#[cfg(any(
target_os = "linux",
Expand All @@ -25,7 +21,7 @@ use crate::{
target_os = "freebsd"
))]
#[cfg(feature = "fs")]
pub use self::posix_fadvise::{PosixFadviseAdvice, posix_fadvise};
pub use self::posix_fadvise::{posix_fadvise, PosixFadviseAdvice};

#[cfg(not(target_os = "redox"))]
#[cfg(any(feature = "fs", feature = "process"))]
Expand Down Expand Up @@ -241,10 +237,7 @@ pub fn renameat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
}
}

#[cfg(all(
target_os = "linux",
target_env = "gnu",
))]
#[cfg(all(target_os = "linux", target_env = "gnu",))]
#[cfg(feature = "fs")]
libc_bitflags! {
#[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
Expand Down
57 changes: 34 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]
#![warn(missing_docs)]

#![cfg_attr(docsrs, feature(doc_cfg))]

// Re-exported external crates
pub use libc;

// Private internal modules
#[macro_use] mod macros;
#[macro_use]
mod macros;

// Public crates
#[cfg(not(target_os = "redox"))]
Expand Down Expand Up @@ -100,24 +100,23 @@ feature! {
#[deny(missing_docs)]
pub mod net;
}
#[cfg(any(target_os = "android",
target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "linux"))]
feature! {
#![feature = "kmod"]
#[allow(missing_docs)]
pub mod kmod;
}
#[cfg(any(target_os = "android",
target_os = "freebsd",
target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
feature! {
#![feature = "mount"]
pub mod mount;
}
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux",
target_os = "netbsd"))]
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux",
target_os = "netbsd"
))]
feature! {
#![feature = "mqueue"]
#[allow(missing_docs)]
Expand Down Expand Up @@ -145,9 +144,10 @@ feature! {
}
// This can be implemented for other platforms as soon as libc
// provides bindings for them.
#[cfg(all(target_os = "linux",
any(target_arch = "s390x", target_arch = "x86",
target_arch = "x86_64")))]
#[cfg(all(
target_os = "linux",
any(target_arch = "s390x", target_arch = "x86", target_arch = "x86_64")
))]
feature! {
#![feature = "ucontext"]
#[allow(missing_docs)]
Expand Down Expand Up @@ -191,7 +191,8 @@ pub trait NixPath {
///
/// Mostly used internally by Nix.
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T;
where
F: FnOnce(&CStr) -> T;
}

impl NixPath for str {
Expand All @@ -204,9 +205,11 @@ impl NixPath for str {
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T {
OsStr::new(self).with_nix_path(f)
}
where
F: FnOnce(&CStr) -> T,
{
OsStr::new(self).with_nix_path(f)
}
}

impl NixPath for OsStr {
Expand All @@ -219,9 +222,11 @@ impl NixPath for OsStr {
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T {
self.as_bytes().with_nix_path(f)
}
where
F: FnOnce(&CStr) -> T,
{
self.as_bytes().with_nix_path(f)
}
}

impl NixPath for CStr {
Expand Down Expand Up @@ -302,7 +307,10 @@ impl NixPath for Path {
NixPath::len(self.as_os_str())
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T> where F: FnOnce(&CStr) -> T {
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where
F: FnOnce(&CStr) -> T,
{
self.as_os_str().with_nix_path(f)
}
}
Expand All @@ -316,7 +324,10 @@ impl NixPath for PathBuf {
NixPath::len(self.as_os_str())
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T> where F: FnOnce(&CStr) -> T {
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where
F: FnOnce(&CStr) -> T,
{
self.as_os_str().with_nix_path(f)
}
}
37 changes: 28 additions & 9 deletions src/sys/ioctl/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod consts {
#[allow(overflowing_literals)]
pub const IN: ioctl_num_type = 0x8000_0000;
#[doc(hidden)]
pub const INOUT: ioctl_num_type = IN|OUT;
pub const INOUT: ioctl_num_type = IN | OUT;
#[doc(hidden)]
pub const IOCPARM_MASK: ioctl_num_type = 0x1fff;
}
Expand All @@ -31,9 +31,13 @@ pub use self::consts::*;
#[macro_export]
#[doc(hidden)]
macro_rules! ioc {
($inout:expr, $group:expr, $num:expr, $len:expr) => (
$inout | (($len as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::IOCPARM_MASK) << 16) | (($group as $crate::sys::ioctl::ioctl_num_type) << 8) | ($num as $crate::sys::ioctl::ioctl_num_type)
)
($inout:expr, $group:expr, $num:expr, $len:expr) => {
$inout
| (($len as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::IOCPARM_MASK)
<< 16)
| (($group as $crate::sys::ioctl::ioctl_num_type) << 8)
| ($num as $crate::sys::ioctl::ioctl_num_type)
};
}

/// Generate an ioctl request code for a command that passes no data.
Expand All @@ -53,7 +57,9 @@ macro_rules! ioc {
/// ```
#[macro_export(local_inner_macros)]
macro_rules! request_code_none {
($g:expr, $n:expr) => (ioc!($crate::sys::ioctl::VOID, $g, $n, 0))
($g:expr, $n:expr) => {
ioc!($crate::sys::ioctl::VOID, $g, $n, 0)
};
}

/// Generate an ioctl request code for a command that passes an integer
Expand All @@ -64,7 +70,14 @@ macro_rules! request_code_none {
/// with is "bad" and you cannot use `ioctl_write_int!()` directly.
#[macro_export(local_inner_macros)]
macro_rules! request_code_write_int {
($g:expr, $n:expr) => (ioc!($crate::sys::ioctl::VOID, $g, $n, ::std::mem::size_of::<$crate::libc::c_int>()))
($g:expr, $n:expr) => {
ioc!(
$crate::sys::ioctl::VOID,
$g,
$n,
::std::mem::size_of::<$crate::libc::c_int>()
)
};
}

/// Generate an ioctl request code for a command that reads.
Expand All @@ -79,7 +92,9 @@ macro_rules! request_code_write_int {
/// writing.
#[macro_export(local_inner_macros)]
macro_rules! request_code_read {
($g:expr, $n:expr, $len:expr) => (ioc!($crate::sys::ioctl::OUT, $g, $n, $len))
($g:expr, $n:expr, $len:expr) => {
ioc!($crate::sys::ioctl::OUT, $g, $n, $len)
};
}

/// Generate an ioctl request code for a command that writes.
Expand All @@ -94,7 +109,9 @@ macro_rules! request_code_read {
/// reading.
#[macro_export(local_inner_macros)]
macro_rules! request_code_write {
($g:expr, $n:expr, $len:expr) => (ioc!($crate::sys::ioctl::IN, $g, $n, $len))
($g:expr, $n:expr, $len:expr) => {
ioc!($crate::sys::ioctl::IN, $g, $n, $len)
};
}

/// Generate an ioctl request code for a command that reads and writes.
Expand All @@ -105,5 +122,7 @@ macro_rules! request_code_write {
/// with is "bad" and you cannot use `ioctl_readwrite!()` directly.
#[macro_export(local_inner_macros)]
macro_rules! request_code_readwrite {
($g:expr, $n:expr, $len:expr) => (ioc!($crate::sys::ioctl::INOUT, $g, $n, $len))
($g:expr, $n:expr, $len:expr) => {
ioc!($crate::sys::ioctl::INOUT, $g, $n, $len)
};
}
60 changes: 43 additions & 17 deletions src/sys/ioctl/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ pub const NRBITS: ioctl_num_type = 8;
#[doc(hidden)]
pub const TYPEBITS: ioctl_num_type = 8;

#[cfg(any(target_arch = "mips", target_arch = "mips64", target_arch = "powerpc", target_arch = "powerpc64", target_arch = "sparc64"))]
#[cfg(any(
target_arch = "mips",
target_arch = "mips64",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "sparc64"
))]
mod consts {
#[doc(hidden)]
pub const NONE: u8 = 1;
Expand All @@ -29,13 +35,15 @@ mod consts {
}

// "Generic" ioctl protocol
#[cfg(any(target_arch = "x86",
target_arch = "arm",
target_arch = "s390x",
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "riscv32",
target_arch = "riscv64"))]
#[cfg(any(
target_arch = "x86",
target_arch = "arm",
target_arch = "s390x",
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "riscv32",
target_arch = "riscv64"
))]
mod consts {
#[doc(hidden)]
pub const NONE: u8 = 0;
Expand Down Expand Up @@ -73,11 +81,16 @@ pub const DIRMASK: ioctl_num_type = (1 << DIRBITS) - 1;
#[macro_export]
#[doc(hidden)]
macro_rules! ioc {
($dir:expr, $ty:expr, $nr:expr, $sz:expr) => (
(($dir as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::DIRMASK) << $crate::sys::ioctl::DIRSHIFT) |
(($ty as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::TYPEMASK) << $crate::sys::ioctl::TYPESHIFT) |
(($nr as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::NRMASK) << $crate::sys::ioctl::NRSHIFT) |
(($sz as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::SIZEMASK) << $crate::sys::ioctl::SIZESHIFT))
($dir:expr, $ty:expr, $nr:expr, $sz:expr) => {
(($dir as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::DIRMASK)
<< $crate::sys::ioctl::DIRSHIFT)
| (($ty as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::TYPEMASK)
<< $crate::sys::ioctl::TYPESHIFT)
| (($nr as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::NRMASK)
<< $crate::sys::ioctl::NRSHIFT)
| (($sz as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::SIZEMASK)
<< $crate::sys::ioctl::SIZESHIFT)
};
}

/// Generate an ioctl request code for a command that passes no data.
Expand All @@ -97,7 +110,9 @@ macro_rules! ioc {
/// ```
#[macro_export(local_inner_macros)]
macro_rules! request_code_none {
($ty:expr, $nr:expr) => (ioc!($crate::sys::ioctl::NONE, $ty, $nr, 0))
($ty:expr, $nr:expr) => {
ioc!($crate::sys::ioctl::NONE, $ty, $nr, 0)
};
}

/// Generate an ioctl request code for a command that reads.
Expand All @@ -112,7 +127,9 @@ macro_rules! request_code_none {
/// writing.
#[macro_export(local_inner_macros)]
macro_rules! request_code_read {
($ty:expr, $nr:expr, $sz:expr) => (ioc!($crate::sys::ioctl::READ, $ty, $nr, $sz))
($ty:expr, $nr:expr, $sz:expr) => {
ioc!($crate::sys::ioctl::READ, $ty, $nr, $sz)
};
}

/// Generate an ioctl request code for a command that writes.
Expand All @@ -127,7 +144,9 @@ macro_rules! request_code_read {
/// reading.
#[macro_export(local_inner_macros)]
macro_rules! request_code_write {
($ty:expr, $nr:expr, $sz:expr) => (ioc!($crate::sys::ioctl::WRITE, $ty, $nr, $sz))
($ty:expr, $nr:expr, $sz:expr) => {
ioc!($crate::sys::ioctl::WRITE, $ty, $nr, $sz)
};
}

/// Generate an ioctl request code for a command that reads and writes.
Expand All @@ -138,5 +157,12 @@ macro_rules! request_code_write {
/// with is "bad" and you cannot use `ioctl_readwrite!()` directly.
#[macro_export(local_inner_macros)]
macro_rules! request_code_readwrite {
($ty:expr, $nr:expr, $sz:expr) => (ioc!($crate::sys::ioctl::READ | $crate::sys::ioctl::WRITE, $ty, $nr, $sz))
($ty:expr, $nr:expr, $sz:expr) => {
ioc!(
$crate::sys::ioctl::READ | $crate::sys::ioctl::WRITE,
$ty,
$nr,
$sz
)
};
}
Loading

0 comments on commit 6498cee

Please sign in to comment.