diff options
| author | Thalia Archibald <thalia@archibald.dev> | 2025-02-16 22:11:46 -0800 |
|---|---|---|
| committer | Thalia Archibald <thalia@archibald.dev> | 2025-02-17 05:25:14 -0800 |
| commit | 711247413465fc015420574d6afe929186ab0bb4 (patch) | |
| tree | 36e10df2fa513ef3ac72c391d0458dad08131af8 | |
| parent | d5eb31c9347ae3c494c8d723711dacca7d1cfe8b (diff) | |
| download | rust-711247413465fc015420574d6afe929186ab0bb4.tar.gz rust-711247413465fc015420574d6afe929186ab0bb4.zip | |
Use tell for <File as Seek>::stream_position
| -rw-r--r-- | library/std/src/fs.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sys/pal/hermit/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/pal/solid/fs.rs | 5 | ||||
| -rw-r--r-- | library/std/src/sys/pal/uefi/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/pal/unix/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/pal/unsupported/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/pal/wasi/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/pal/windows/fs.rs | 4 |
8 files changed, 34 insertions, 1 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 83b009c86dc..6001a2e2f39 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -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")] @@ -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")] diff --git a/library/std/src/sys/pal/hermit/fs.rs b/library/std/src/sys/pal/hermit/fs.rs index 783623552bb..45fe7e093cd 100644 --- a/library/std/src/sys/pal/hermit/fs.rs +++ b/library/std/src/sys/pal/hermit/fs.rs @@ -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)) } diff --git a/library/std/src/sys/pal/solid/fs.rs b/library/std/src/sys/pal/solid/fs.rs index cc424141ea8..70b5400bde4 100644 --- a/library/std/src/sys/pal/solid/fs.rs +++ b/library/std/src/sys/pal/solid/fs.rs @@ -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( diff --git a/library/std/src/sys/pal/uefi/fs.rs b/library/std/src/sys/pal/uefi/fs.rs index 9585ec24f68..45e93deffa3 100644 --- a/library/std/src/sys/pal/uefi/fs.rs +++ b/library/std/src/sys/pal/uefi/fs.rs @@ -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 } diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index 00cfa7a7fcf..e13ce580d45 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -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) } diff --git a/library/std/src/sys/pal/unsupported/fs.rs b/library/std/src/sys/pal/unsupported/fs.rs index 9585ec24f68..45e93deffa3 100644 --- a/library/std/src/sys/pal/unsupported/fs.rs +++ b/library/std/src/sys/pal/unsupported/fs.rs @@ -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 } diff --git a/library/std/src/sys/pal/wasi/fs.rs b/library/std/src/sys/pal/wasi/fs.rs index faf3edd5da6..513f038b554 100644 --- a/library/std/src/sys/pal/wasi/fs.rs +++ b/library/std/src/sys/pal/wasi/fs.rs @@ -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() diff --git a/library/std/src/sys/pal/windows/fs.rs b/library/std/src/sys/pal/windows/fs.rs index 62d4d727432..9b283a7a117 100644 --- a/library/std/src/sys/pal/windows/fs.rs +++ b/library/std/src/sys/pal/windows/fs.rs @@ -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()? }) } |
