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
6 changes: 6 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ impl Seek for &File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
self.inner.seek(pos)
}
fn stream_position(&mut self) -> io::Result<u64> {
self.inner.tell()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1275,6 +1278,9 @@ impl Seek for File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(&*self).seek(pos)
}
fn stream_position(&mut self) -> io::Result<u64> {
(&*self).stream_position()
}
}

#[stable(feature = "io_traits_arc", since = "1.73.0")]
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/hermit/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ impl File {
Err(Error::from_raw_os_error(22))
}

pub fn tell(&self) -> io::Result<u64> {
self.seek(SeekFrom::Current(0))
}

pub fn duplicate(&self) -> io::Result<File> {
Err(Error::from_raw_os_error(22))
}
Expand Down
5 changes: 4 additions & 1 deletion library/std/src/sys/pal/solid/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ impl File {
abi::SOLID_FS_Lseek(self.fd.raw(), pos, whence)
})
.map_err(|e| e.as_io_error())?;

// Get the new offset
self.tell()
}

pub fn tell(&self) -> io::Result<u64> {
unsafe {
let mut out_offset = MaybeUninit::uninit();
error::SolidError::err_if_negative(abi::SOLID_FS_Ftell(
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/uefi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ impl File {
self.0
}

pub fn tell(&self) -> io::Result<u64> {
self.0
}

pub fn duplicate(&self) -> io::Result<File> {
self.0
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,10 @@ impl File {
Ok(n as u64)
}

pub fn tell(&self) -> io::Result<u64> {
self.seek(SeekFrom::Current(0))
}

pub fn duplicate(&self) -> io::Result<File> {
self.0.duplicate().map(File)
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/unsupported/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ impl File {
self.0
}

pub fn tell(&self) -> io::Result<u64> {
self.0
}

pub fn duplicate(&self) -> io::Result<File> {
self.0
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ impl File {
self.fd.seek(pos)
}

pub fn tell(&self) -> io::Result<u64> {
self.fd.tell()
}

pub fn duplicate(&self) -> io::Result<File> {
// https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-rationale.md#why-no-dup
unsupported()
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ impl File {
Ok(newpos as u64)
}

pub fn tell(&self) -> io::Result<u64> {
self.seek(SeekFrom::Current(0))
}

pub fn duplicate(&self) -> io::Result<File> {
Ok(Self { handle: self.handle.try_clone()? })
}
Expand Down
Loading