Skip to content
Open
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
26 changes: 26 additions & 0 deletions library/std/src/sys/fd/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod tests;
target_os = "l4re",
target_os = "android",
target_os = "hurd",
target_os = "vxworks",
)))]
use libc::off_t as off64_t;
#[cfg(any(
Expand All @@ -18,6 +19,7 @@ use libc::off_t as off64_t;
))]
use libc::off64_t;

#[cfg(not(target_os = "vxworks"))]
cfg_select! {
any(
all(target_os = "linux", not(target_env = "musl")),
Expand Down Expand Up @@ -45,6 +47,12 @@ use crate::sys::pal::weak::syscall;
use crate::sys::pal::weak::weak;
use crate::sys::{AsInner, FromInner, IntoInner, cvt};

// VxWorks does not have pread/pwrite, so we here define an error to tell it's unsupported.
// ref. <https://github.com/rust-lang/libc/issues/5328>
#[cfg(target_os = "vxworks")]
const POSITIONED_IO_UNSUPPORTED: io::Error =
io::const_error!(io::ErrorKind::Unsupported, "positioned I/O is not supported on VxWorks",);

#[derive(Debug)]
pub struct FileDesc(OwnedFd);

Expand Down Expand Up @@ -166,6 +174,7 @@ impl FileDesc {
(&mut me).read_to_end(buf)
}

#[cfg(not(target_os = "vxworks"))]
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
cvt(unsafe {
pread64(
Expand All @@ -178,6 +187,11 @@ impl FileDesc {
.map(|n| n as usize)
}

#[cfg(target_os = "vxworks")]
pub fn read_at(&self, _buf: &mut [u8], _offset: u64) -> io::Result<usize> {
Err(POSITIONED_IO_UNSUPPORTED)
}

pub fn read_buf(&self, mut cursor: BorrowedCursor<'_, u8>) -> io::Result<()> {
// SAFETY: `cursor.as_mut()` starts with `cursor.capacity()` writable bytes
let ret = cvt(unsafe {
Expand All @@ -195,6 +209,7 @@ impl FileDesc {
Ok(())
}

#[cfg(not(target_os = "vxworks"))]
pub fn read_buf_at(&self, mut cursor: BorrowedCursor<'_, u8>, offset: u64) -> io::Result<()> {
// SAFETY: `cursor.as_mut()` starts with `cursor.capacity()` writable bytes
let ret = cvt(unsafe {
Expand All @@ -213,6 +228,11 @@ impl FileDesc {
Ok(())
}

#[cfg(target_os = "vxworks")]
pub fn read_buf_at(&self, _cursor: BorrowedCursor<'_, u8>, _offset: u64) -> io::Result<()> {
Err(POSITIONED_IO_UNSUPPORTED)
}

#[cfg(any(
target_os = "aix",
target_os = "dragonfly", // DragonFly 1.5
Expand Down Expand Up @@ -397,6 +417,7 @@ impl FileDesc {
)))
}

#[cfg(not(target_os = "vxworks"))]
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
#[cfg(not(any(
all(target_os = "linux", not(target_env = "musl")),
Expand All @@ -422,6 +443,11 @@ impl FileDesc {
}
}

#[cfg(target_os = "vxworks")]
pub fn write_at(&self, _buf: &[u8], _offset: u64) -> io::Result<usize> {
Err(POSITIONED_IO_UNSUPPORTED)
}

#[cfg(any(
target_os = "aix",
target_os = "dragonfly", // DragonFly 1.5
Expand Down
Loading