diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-10 09:32:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-10 09:32:13 +0100 |
| commit | 2f1908df61469fad9b09507d2b8e1585438700d3 (patch) | |
| tree | dddd9afd2a4fa8e1822efff24362b1137a0c0545 /library/std/src | |
| parent | cbde8b9dcfb2017b1265da4a92cec640b0065d6d (diff) | |
| parent | 1abaacd375bf74b3dc01fb578d8064771e327805 (diff) | |
| download | rust-2f1908df61469fad9b09507d2b8e1585438700d3.tar.gz rust-2f1908df61469fad9b09507d2b8e1585438700d3.zip | |
Rollup merge of #138074 - thaliaarchi:hermit-seek, r=ChrisDenton
Support `File::seek` for Hermit `lseek` was added in `hermit-abi` in commit [87dd201](https://github.com/hermit-os/hermit-rs/commit/87dd201a14ac7661e1a4b761273e24d750496286) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0. cc ``@mkroening,`` ``@stlankes`` Fixes https://github.com/hermit-os/hermit-rs/issues/652
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/fs/hermit.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sys/pal/hermit/fd.rs | 21 |
2 files changed, 22 insertions, 5 deletions
diff --git a/library/std/src/sys/fs/hermit.rs b/library/std/src/sys/fs/hermit.rs index e9339ff261c..1191e335daa 100644 --- a/library/std/src/sys/fs/hermit.rs +++ b/library/std/src/sys/fs/hermit.rs @@ -417,12 +417,12 @@ impl File { Ok(()) } - pub fn seek(&self, _pos: SeekFrom) -> io::Result<u64> { - Err(Error::from_raw_os_error(22)) + pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> { + self.0.seek(pos) } pub fn tell(&self) -> io::Result<u64> { - self.seek(SeekFrom::Current(0)) + self.0.tell() } pub fn duplicate(&self) -> io::Result<File> { diff --git a/library/std/src/sys/pal/hermit/fd.rs b/library/std/src/sys/pal/hermit/fd.rs index 79fc13bd4a8..3d6b99cd77b 100644 --- a/library/std/src/sys/pal/hermit/fd.rs +++ b/library/std/src/sys/pal/hermit/fd.rs @@ -2,8 +2,8 @@ use super::hermit_abi; use crate::cmp; -use crate::io::{self, IoSlice, IoSliceMut, Read}; -use crate::os::hermit::io::{FromRawFd, OwnedFd, RawFd, *}; +use crate::io::{self, IoSlice, IoSliceMut, Read, SeekFrom}; +use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::sys::{cvt, unsupported}; use crate::sys_common::{AsInner, FromInner, IntoInner}; @@ -66,9 +66,26 @@ impl FileDesc { true } + pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> { + let (whence, pos) = match pos { + // Casting to `i64` is fine, too large values will end up as + // negative which will cause an error in `lseek`. + SeekFrom::Start(off) => (hermit_abi::SEEK_SET, off as i64), + SeekFrom::End(off) => (hermit_abi::SEEK_END, off), + SeekFrom::Current(off) => (hermit_abi::SEEK_CUR, off), + }; + let n = cvt(unsafe { hermit_abi::lseek(self.as_raw_fd(), pos as isize, whence) })?; + Ok(n as u64) + } + + pub fn tell(&self) -> io::Result<u64> { + self.seek(SeekFrom::Current(0)) + } + pub fn duplicate(&self) -> io::Result<FileDesc> { self.duplicate_path(&[]) } + pub fn duplicate_path(&self, _path: &[u8]) -> io::Result<FileDesc> { unsupported() } |
