Skip to content
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

refactor: take AsFd by value #1932

Merged
merged 2 commits into from
Dec 9, 2022
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
2 changes: 1 addition & 1 deletion src/kmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ libc_bitflags!(
///
/// See [`man init_module(2)`](https://man7.org/linux/man-pages/man2/init_module.2.html) for more information.
pub fn finit_module<Fd: AsFd>(
fd: &Fd,
fd: Fd,
param_values: &CStr,
flags: ModuleInitFlags,
) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub unsafe fn mmap<F: AsFd>(
length: NonZeroUsize,
prot: ProtFlags,
flags: MapFlags,
f: Option<&F>,
f: Option<F>,
offset: off_t,
) -> Result<*mut c_void> {
let ptr =
Expand Down
2 changes: 1 addition & 1 deletion src/sys/statfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ pub fn statfs<P: ?Sized + NixPath>(path: &P) -> Result<Statfs> {
/// # Arguments
///
/// `fd` - File descriptor of any open file within the file system to describe
pub fn fstatfs<Fd: AsFd>(fd: &Fd) -> Result<Statfs> {
pub fn fstatfs<Fd: AsFd>(fd: Fd) -> Result<Statfs> {
unsafe {
let mut stat = mem::MaybeUninit::<type_of_statfs>::uninit();
Errno::result(LIBC_FSTATFS(fd.as_fd().as_raw_fd(), stat.as_mut_ptr()))
Expand Down
14 changes: 7 additions & 7 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ pub fn cfmakesane(termios: &mut Termios) {
/// `tcgetattr()` returns a `Termios` structure with the current configuration for a port. Modifying
/// this structure *will not* reconfigure the port, instead the modifications should be done to
/// the `Termios` structure and then the port should be reconfigured using `tcsetattr()`.
pub fn tcgetattr<Fd: AsFd>(fd: &Fd) -> Result<Termios> {
pub fn tcgetattr<Fd: AsFd>(fd: Fd) -> Result<Termios> {
let mut termios = mem::MaybeUninit::uninit();

let res = unsafe {
Expand All @@ -1162,7 +1162,7 @@ pub fn tcgetattr<Fd: AsFd>(fd: &Fd) -> Result<Termios> {
/// takes affect at a time specified by `actions`. Note that this function may return success if
/// *any* of the parameters were successfully set, not only if all were set successfully.
pub fn tcsetattr<Fd: AsFd>(
fd: &Fd,
fd: Fd,
actions: SetArg,
termios: &Termios,
) -> Result<()> {
Expand All @@ -1179,7 +1179,7 @@ pub fn tcsetattr<Fd: AsFd>(

/// Block until all output data is written (see
/// [tcdrain(3p)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcdrain.html)).
pub fn tcdrain<Fd: AsFd>(fd: &Fd) -> Result<()> {
pub fn tcdrain<Fd: AsFd>(fd: Fd) -> Result<()> {
Errno::result(unsafe { libc::tcdrain(fd.as_fd().as_raw_fd()) }).map(drop)
}

Expand All @@ -1188,7 +1188,7 @@ pub fn tcdrain<Fd: AsFd>(fd: &Fd) -> Result<()> {
///
/// `tcflow()` suspends of resumes the transmission or reception of data for the given port
/// depending on the value of `action`.
pub fn tcflow<Fd: AsFd>(fd: &Fd, action: FlowArg) -> Result<()> {
pub fn tcflow<Fd: AsFd>(fd: Fd, action: FlowArg) -> Result<()> {
Errno::result(unsafe {
libc::tcflow(fd.as_fd().as_raw_fd(), action as c_int)
})
Expand All @@ -1200,7 +1200,7 @@ pub fn tcflow<Fd: AsFd>(fd: &Fd, action: FlowArg) -> Result<()> {
///
/// `tcflush()` will discard data for a terminal port in the input queue, output queue, or both
/// depending on the value of `action`.
pub fn tcflush<Fd: AsFd>(fd: &Fd, action: FlushArg) -> Result<()> {
pub fn tcflush<Fd: AsFd>(fd: Fd, action: FlushArg) -> Result<()> {
Errno::result(unsafe {
libc::tcflush(fd.as_fd().as_raw_fd(), action as c_int)
})
Expand All @@ -1212,7 +1212,7 @@ pub fn tcflush<Fd: AsFd>(fd: &Fd, action: FlushArg) -> Result<()> {
///
/// When using asynchronous data transmission `tcsendbreak()` will transmit a continuous stream
/// of zero-valued bits for an implementation-defined duration.
pub fn tcsendbreak<Fd: AsFd>(fd: &Fd, duration: c_int) -> Result<()> {
pub fn tcsendbreak<Fd: AsFd>(fd: Fd, duration: c_int) -> Result<()> {
Errno::result(unsafe {
libc::tcsendbreak(fd.as_fd().as_raw_fd(), duration)
})
Expand All @@ -1223,7 +1223,7 @@ feature! {
#![feature = "process"]
/// Get the session controlled by the given terminal (see
/// [tcgetsid(3)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetsid.html)).
pub fn tcgetsid<Fd: AsFd>(fd: &Fd) -> Result<Pid> {
pub fn tcgetsid<Fd: AsFd>(fd: Fd) -> Result<Pid> {
let res = unsafe { libc::tcgetsid(fd.as_fd().as_raw_fd()) };

Errno::result(res).map(Pid::from_raw)
Expand Down
2 changes: 1 addition & 1 deletion test/sys/test_termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nix::sys::termios::{self, tcgetattr, LocalFlags, OutputFlags};
use nix::unistd::{read, write};

/// Helper function analogous to `std::io::Write::write_all`, but for `Fd`s
fn write_all<Fd: AsFd>(f: &Fd, buf: &[u8]) {
fn write_all<Fd: AsFd>(f: Fd, buf: &[u8]) {
let mut len = 0;
while len < buf.len() {
len += write(f.as_fd().as_raw_fd(), &buf[len..]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use std::os::unix::io::{AsFd, AsRawFd};
use std::path::PathBuf;

/// Helper function analogous to `std::io::Read::read_exact`, but for `Fd`s
fn read_exact<Fd: AsFd>(f: &Fd, buf: &mut [u8]) {
fn read_exact<Fd: AsFd>(f: Fd, buf: &mut [u8]) {
let mut len = 0;
while len < buf.len() {
// get_mut would be better than split_at_mut, but it requires nightly
Expand Down
6 changes: 3 additions & 3 deletions test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ fn test_open_ptty_pair() {
}

/// Put the terminal in raw mode.
fn make_raw<Fd: AsFd>(fd: &Fd) {
let mut termios = tcgetattr(fd).unwrap();
fn make_raw<Fd: AsFd>(fd: Fd) {
let mut termios = tcgetattr(&fd).unwrap();
cfmakeraw(&mut termios);
tcsetattr(fd, SetArg::TCSANOW, &termios).unwrap();
tcsetattr(&fd, SetArg::TCSANOW, &termios).unwrap();
}

/// Test `io::Read` on the PTTY master
Expand Down