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

Function raw_fd

src/backend/linux_raw/conv.rs:162–176  ·  view source on GitHub ↗
(fd: RawFd)

Source from the content-addressed store, hash-verified

160/// `fd` must be a valid open file descriptor.
161#[inline]
162pub(super) unsafe fn raw_fd<'a, Num: ArgNumber>(fd: RawFd) -> ArgReg<'a, Num> {
163 // Use `no_fd` when passing `-1` is intended.
164 #[cfg(feature = "fs")]
165 debug_assert!(fd == crate::fs::CWD.as_raw_fd() || fd == crate::fs::ABS.as_raw_fd() || fd >= 0);
166
167 // Don't pass the `IORING_REGISTER_FILES_SKIP` sentry value this way.
168 #[cfg(feature = "io_uring")]
169 debug_assert_ne!(fd, crate::io_uring::IORING_REGISTER_FILES_SKIP.as_raw_fd());
170
171 // Linux doesn't look at the high bits beyond the `c_int`, so use
172 // zero-extension rather than sign-extension because it's a smaller
173 // instruction.
174 let fd: c::c_int = fd;
175 pass_usize(fd as c::c_uint as usize)
176}
177
178/// Deliberately pass `-1` to a file-descriptor argument, for system calls
179/// like `mmap` where this indicates the argument is omitted.

Callers 1

fromMethod · 0.85

Calls 1

pass_usizeFunction · 0.85

Tested by

no test coverage detected