From 14b74b1ab4081138d360bb7402c66712fa60a726 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 28 Jul 2026 07:22:47 +0900 Subject: [PATCH] std: make positioned I/O unsupported on VxWorks --- library/std/src/sys/fd/unix.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/library/std/src/sys/fd/unix.rs b/library/std/src/sys/fd/unix.rs index a96df3972be6a..28115c1b1743c 100644 --- a/library/std/src/sys/fd/unix.rs +++ b/library/std/src/sys/fd/unix.rs @@ -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( @@ -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")), @@ -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. +#[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); @@ -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 { cvt(unsafe { pread64( @@ -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 { + 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 { @@ -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 { @@ -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 @@ -397,6 +417,7 @@ impl FileDesc { ))) } + #[cfg(not(target_os = "vxworks"))] pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(not(any( all(target_os = "linux", not(target_env = "musl")), @@ -422,6 +443,11 @@ impl FileDesc { } } + #[cfg(target_os = "vxworks")] + pub fn write_at(&self, _buf: &[u8], _offset: u64) -> io::Result { + Err(POSITIONED_IO_UNSUPPORTED) + } + #[cfg(any( target_os = "aix", target_os = "dragonfly", // DragonFly 1.5