Lines Matching +full:out +full:- +full:functions
1 // SPDX-License-Identifier: GPL-2.0
5 //! C header: [`include/uapi/asm-generic/errno-base.h`](srctree/include/uapi/asm-generic/errno-base…
17 /// Contains the C-compatible error codes.
26 match super::Error::try_from_errno(-(crate::bindings::$err as i32)) {
44 declare_err!(ENOMEM, "Out of memory.");
50 declare_err!(EXDEV, "Cross-device link.");
62 declare_err!(EROFS, "Read-only file system.");
65 declare_err!(EDOM, "Math argument out of domain of func.");
95 /// The value is a valid `errno` (i.e. `>= -MAX_ERRNO && < 0`).
102 /// It is a bug to pass an out-of-range `errno`. `EINVAL` would
104 pub fn from_errno(errno: crate::ffi::c_int) -> Error { in from_errno()
110 "attempted to create `Error` with out of range `errno`: {}\n", in from_errno()
119 /// Returns [`None`] if `errno` is out-of-range.
120 const fn try_from_errno(errno: crate::ffi::c_int) -> Option<Error> { in try_from_errno()
121 if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 { in try_from_errno()
133 /// `errno` must be within error code range (i.e. `>= -MAX_ERRNO && < 0`).
134 const unsafe fn from_errno_unchecked(errno: crate::ffi::c_int) -> Error { in from_errno_unchecked()
137 // SAFETY: The caller guarantees `errno` is non-zero. in from_errno_unchecked()
142 pub fn to_errno(self) -> crate::ffi::c_int { in to_errno()
147 pub(crate) fn to_blk_status(self) -> bindings::blk_status_t { in to_blk_status()
153 pub fn to_ptr<T>(self) -> *mut T { in to_ptr()
160 pub fn name(&self) -> Option<&'static CStr> { in name()
162 let ptr = unsafe { bindings::errname(-self.0.get()) }; in name()
166 // SAFETY: The string returned by `errname` is static and `NUL`-terminated. in name()
177 pub fn name(&self) -> Option<&'static CStr> { in name()
183 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { in fmt()
185 // Print out number if no name can be found. in fmt()
186 None => f.debug_tuple("Error").field(&-self.0).finish(), in fmt()
189 // SAFETY: These strings are ASCII-only. in fmt()
198 fn from(_: AllocError) -> Error { in from()
204 fn from(_: TryFromIntError) -> Error { in from()
210 fn from(_: Utf8Error) -> Error { in from()
216 fn from(_: LayoutError) -> Error { in from()
222 fn from(_: core::fmt::Error) -> Error { in from()
228 fn from(e: core::convert::Infallible) -> Error { in from()
235 /// To be used as the return type for functions that may fail.
239 /// In C, it is common that functions indicate success or failure through
240 /// their return value; modifying or returning extra data through non-`const`
241 /// pointer parameters. In particular, in the kernel, functions that may fail
245 /// In Rust, it is idiomatic to model functions that may fail as returning
246 /// a [`Result`]. Since in the kernel many functions return an error code,
257 pub fn to_result(err: crate::ffi::c_int) -> Result { in to_result()
267 /// Some kernel C API functions return an "error pointer" which optionally
280 /// ) -> Result<*mut kernel::ffi::c_void> {
286 pub fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T> { in from_err_ptr()
297 // negative value greater-or-equal to `-bindings::MAX_ERRNO`, in from_err_ptr()
303 // negative value greater-or-equal to `-bindings::MAX_ERRNO`. in from_err_ptr()
312 /// This is useful when calling Rust functions that return [`crate::error::Result<T>`]
313 /// from inside `extern "C"` functions that need to return an integer error result.
324 /// ) -> kernel::ffi::c_int {
332 pub fn from_result<T, F>(f: F) -> T in from_result()
335 F: FnOnce() -> Result<T>, in from_result()
339 // NO-OVERFLOW: negative `errno`s are no smaller than `-bindings::MAX_ERRNO`, in from_result()
340 // `-bindings::MAX_ERRNO` fits in an `i16` as per invariant above, in from_result()