Skip to content

Commit

Permalink
take AsFd by value
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Dec 9, 2022
1 parent 5ee09e7 commit 92cd909
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod sched_linux_like {
/// reassociate thread with a namespace
///
/// See also [setns(2)](https://man7.org/linux/man-pages/man2/setns.2.html)
pub fn setns<Fd: AsFd>(fd: &Fd, nstype: CloneFlags) -> Result<()> {
pub fn setns<Fd: AsFd>(fd: Fd, nstype: CloneFlags) -> Result<()> {
let res = unsafe { libc::setns(fd.as_fd().as_raw_fd(), nstype.bits()) };

Errno::result(res).map(drop)
Expand Down
12 changes: 6 additions & 6 deletions src/sys/uio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::os::unix::io::{AsFd, AsRawFd};
/// Low-level vectored write to a raw file descriptor
///
/// See also [writev(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/writev.html)
pub fn writev<Fd: AsFd>(fd: &Fd, iov: &[IoSlice<'_>]) -> Result<usize> {
pub fn writev<Fd: AsFd>(fd: Fd, iov: &[IoSlice<'_>]) -> Result<usize> {
// SAFETY: to quote the documentation for `IoSlice`:
//
// [IoSlice] is semantically a wrapper around a &[u8], but is
Expand All @@ -27,7 +27,7 @@ pub fn writev<Fd: AsFd>(fd: &Fd, iov: &[IoSlice<'_>]) -> Result<usize> {
/// Low-level vectored read from a raw file descriptor
///
/// See also [readv(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html)
pub fn readv<Fd: AsFd>(fd: &Fd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
pub fn readv<Fd: AsFd>(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
// SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec
let res = unsafe {
libc::readv(fd.as_fd().as_raw_fd(), iov.as_ptr() as *const libc::iovec, iov.len() as c_int)
Expand All @@ -44,7 +44,7 @@ pub fn readv<Fd: AsFd>(fd: &Fd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
/// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html)
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn pwritev<Fd: AsFd>(fd: &Fd, iov: &[IoSlice<'_>], offset: off_t) -> Result<usize> {
pub fn pwritev<Fd: AsFd>(fd: Fd, iov: &[IoSlice<'_>], offset: off_t) -> Result<usize> {
#[cfg(target_env = "uclibc")]
let offset = offset as libc::off64_t; // uclibc doesn't use off_t

Expand All @@ -71,7 +71,7 @@ pub fn pwritev<Fd: AsFd>(fd: &Fd, iov: &[IoSlice<'_>], offset: off_t) -> Result<
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn preadv<Fd: AsFd>(
fd: &Fd,
fd: Fd,
iov: &mut [IoSliceMut<'_>],
offset: off_t,
) -> Result<usize> {
Expand All @@ -95,7 +95,7 @@ pub fn preadv<Fd: AsFd>(
///
/// See also [pwrite(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html)
// TODO: move to unistd
pub fn pwrite<Fd: AsFd>(fd: &Fd, buf: &[u8], offset: off_t) -> Result<usize> {
pub fn pwrite<Fd: AsFd>(fd: Fd, buf: &[u8], offset: off_t) -> Result<usize> {
let res = unsafe {
libc::pwrite(
fd.as_fd().as_raw_fd(),
Expand All @@ -112,7 +112,7 @@ pub fn pwrite<Fd: AsFd>(fd: &Fd, buf: &[u8], offset: off_t) -> Result<usize> {
///
/// See also [pread(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html)
// TODO: move to unistd
pub fn pread<Fd: AsFd>(fd: &Fd, buf: &mut [u8], offset: off_t) -> Result<usize> {
pub fn pread<Fd: AsFd>(fd: Fd, buf: &mut [u8], offset: off_t) -> Result<usize> {
let res = unsafe {
libc::pread(
fd.as_fd().as_raw_fd(),
Expand Down

0 comments on commit 92cd909

Please sign in to comment.