Skip to content

Commit 09ecf34

Browse files
committed
Use tell for <File as Seek>::stream_position
1 parent d5eb31c commit 09ecf34

File tree

8 files changed

+42
-0
lines changed

8 files changed

+42
-0
lines changed

library/std/src/fs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ impl Seek for &File {
12291229
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
12301230
self.inner.seek(pos)
12311231
}
1232+
fn stream_position(&mut self) -> io::Result<u64> {
1233+
self.inner.tell()
1234+
}
12321235
}
12331236

12341237
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1275,6 +1278,9 @@ impl Seek for File {
12751278
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
12761279
(&*self).seek(pos)
12771280
}
1281+
fn stream_position(&mut self) -> io::Result<u64> {
1282+
(&*self).stream_position()
1283+
}
12781284
}
12791285

12801286
#[stable(feature = "io_traits_arc", since = "1.73.0")]

library/std/src/sys/pal/hermit/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ impl File {
425425
Err(Error::from_raw_os_error(22))
426426
}
427427

428+
pub fn tell(&self) -> io::Result<u64> {
429+
self.seek(SeekFrom::Current(0))
430+
}
431+
428432
pub fn duplicate(&self) -> io::Result<File> {
429433
Err(Error::from_raw_os_error(22))
430434
}

library/std/src/sys/pal/solid/fs.rs

+12
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,18 @@ impl File {
465465
}
466466
}
467467

468+
pub fn tell(&self) -> io::Result<u64> {
469+
unsafe {
470+
let mut out_offset = MaybeUninit::uninit();
471+
error::SolidError::err_if_negative(abi::SOLID_FS_Ftell(
472+
self.fd.raw(),
473+
out_offset.as_mut_ptr(),
474+
))
475+
.map_err(|e| e.as_io_error())?;
476+
Ok(out_offset.assume_init() as u64)
477+
}
478+
}
479+
468480
pub fn duplicate(&self) -> io::Result<File> {
469481
unsupported()
470482
}

library/std/src/sys/pal/uefi/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ impl File {
258258
self.0
259259
}
260260

261+
pub fn tell(&self) -> io::Result<u64> {
262+
self.0
263+
}
264+
261265
pub fn duplicate(&self) -> io::Result<File> {
262266
self.0
263267
}

library/std/src/sys/pal/unix/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,10 @@ impl File {
14381438
Ok(n as u64)
14391439
}
14401440

1441+
pub fn tell(&self) -> io::Result<u64> {
1442+
self.seek(SeekFrom::Current(0))
1443+
}
1444+
14411445
pub fn duplicate(&self) -> io::Result<File> {
14421446
self.0.duplicate().map(File)
14431447
}

library/std/src/sys/pal/unsupported/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ impl File {
258258
self.0
259259
}
260260

261+
pub fn tell(&self) -> io::Result<u64> {
262+
self.0
263+
}
264+
261265
pub fn duplicate(&self) -> io::Result<File> {
262266
self.0
263267
}

library/std/src/sys/pal/wasi/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ impl File {
517517
self.fd.seek(pos)
518518
}
519519

520+
pub fn tell(&self) -> io::Result<u64> {
521+
self.fd.tell()
522+
}
523+
520524
pub fn duplicate(&self) -> io::Result<File> {
521525
// https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-rationale.md#why-no-dup
522526
unsupported()

library/std/src/sys/pal/windows/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ impl File {
631631
Ok(newpos as u64)
632632
}
633633

634+
pub fn tell(&self) -> io::Result<u64> {
635+
self.seek(SeekFrom::Current(0))
636+
}
637+
634638
pub fn duplicate(&self) -> io::Result<File> {
635639
Ok(Self { handle: self.handle.try_clone()? })
636640
}

0 commit comments

Comments
 (0)