MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / fstat

Function fstat

src/backend/linux_raw/fs/syscalls.rs:488–522  ·  view source on GitHub ↗
(fd: BorrowedFd<'_>)

Source from the content-addressed store, hash-verified

486
487#[inline]
488pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {
489 // 32-bit and mips64 Linux: `struct stat64` is not y2038 compatible; use
490 // `statx`.
491 //
492 // And, some old platforms don't support `statx`, and some fail with a
493 // confusing error code, so we call `crate::fs::statx` to handle that. If
494 // `statx` isn't available, fall back to the buggy system call.
495 #[cfg(any(
496 target_pointer_width = "32",
497 target_arch = "mips64",
498 target_arch = "mips64r6"
499 ))]
500 {
501 match crate::fs::statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) {
502 Ok(x) => statx_to_stat(x),
503 Err(io::Errno::NOSYS) => fstat_old(fd),
504 Err(err) => Err(err),
505 }
506 }
507
508 #[cfg(all(
509 target_pointer_width = "64",
510 not(target_arch = "mips64"),
511 not(target_arch = "mips64r6")
512 ))]
513 unsafe {
514 let mut result = MaybeUninit::<Stat>::uninit();
515 ret(syscall!(__NR_fstat, fd, &mut result))?;
516
517 #[cfg(sanitize_memory)]
518 crate::msan::unpoison_maybe_uninit(&result);
519
520 Ok(result.assume_init())
521 }
522}
523
524#[cfg(any(
525 target_pointer_width = "32",

Callers 2

statMethod · 0.70
ttynameFunction · 0.50

Calls 6

unpoison_maybe_uninitFunction · 0.85
assume_initMethod · 0.80
statxFunction · 0.70
statx_to_statFunction · 0.70
fstat_oldFunction · 0.70
retFunction · 0.50

Tested by

no test coverage detected