Skip to content

Commit 1d218ab

Browse files
committed
use std::fs::metadata to get file size in tests
1 parent eab7174 commit 1d218ab

File tree

1 file changed

+2
-19
lines changed
  • test-libz-rs-sys/src

1 file changed

+2
-19
lines changed

test-libz-rs-sys/src/gz.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,25 +2033,8 @@ fn gzrewind_error() {
20332033
//
20342034
// - `Ok(size)` on success.
20352035
// - `Err` on error.
2036-
fn file_size(path: &str) -> Result<usize, ()> {
2037-
let mut result = Err(());
2038-
let stat_ptr = unsafe { libc::calloc(1, core::mem::size_of::<libc::stat>() as _) };
2039-
if stat_ptr.is_null() {
2040-
return result;
2041-
}
2042-
let ret = unsafe {
2043-
libc::stat(
2044-
CString::new(path).unwrap().as_ptr(),
2045-
stat_ptr.cast::<libc::stat>(),
2046-
)
2047-
};
2048-
if ret == 0 {
2049-
if let Some(stat_info) = unsafe { stat_ptr.cast::<libc::stat>().as_ref() } {
2050-
result = Ok(stat_info.st_size as usize);
2051-
}
2052-
}
2053-
unsafe { libc::free(stat_ptr) };
2054-
result
2036+
fn file_size(path: &str) -> Result<usize, std::io::Error> {
2037+
Ok(std::fs::metadata(path)?.len() as usize)
20552038
}
20562039

20572040
#[cfg(feature = "gzprintf")]

0 commit comments

Comments
 (0)