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

Function try_decode_raw_fd

src/backend/linux_raw/io/errno.rs:179–199  ·  view source on GitHub ↗
(
    raw: RetReg<Num>,
)

Source from the content-addressed store, hash-verified

177/// success.
178#[inline]
179pub(in crate::backend) unsafe fn try_decode_raw_fd<Num: RetNumber>(
180 raw: RetReg<Num>,
181) -> io::Result<RawFd> {
182 // Instead of using `check_result` here, we just check for negative, since
183 // this function is only used for system calls which return file
184 // descriptors, and this produces smaller code.
185 if raw.is_negative() {
186 debug_assert!(raw.is_in_range(-4095..0));
187
188 // Tell the optimizer that we know the value is in the error range.
189 // This helps it avoid unnecessary integer conversions.
190 #[cfg(core_intrinsics)]
191 {
192 core::intrinsics::assume(raw.is_in_range(-4095..0));
193 }
194
195 return Err(Errno(raw.decode_error_code()));
196 }
197
198 Ok(raw.decode_raw_fd())
199}
200
201/// Check for an error from the result of a syscall which encodes no value on
202/// success. On success, return the unconsumed `raw` value.

Callers 2

ret_owned_fdFunction · 0.85
ret_discarded_fdFunction · 0.85

Calls 5

is_negativeMethod · 0.80
is_in_rangeMethod · 0.80
decode_error_codeMethod · 0.80
decode_raw_fdMethod · 0.80
ErrnoClass · 0.70

Tested by

no test coverage detected