Skip to content
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
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ dependencies = [

[[package]]
name = "hermit-abi"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
checksum = "fbd780fe5cc30f81464441920d82ac8740e2e46b29a6fad543ddd075229ce37e"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-alloc",
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fortanix-sgx-abi = { version = "0.5.0", features = [
], public = true }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit-abi = { version = "0.4.0", features = [
hermit-abi = { version = "0.5.0", features = [
'rustc-dep-of-std',
], public = true }

Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/fs/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
21 changes: 19 additions & 2 deletions library/std/src/sys/pal/hermit/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()
}
Expand Down
Loading