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.h)
16 /// Contains the C-compatible error codes.
25 match super::Error::try_from_errno(-(crate::bindings::$err as i32)) {
43 declare_err!(ENOMEM, "Out of memory.");
49 declare_err!(EXDEV, "Cross-device link.");
61 declare_err!(EROFS, "Read-only file system.");
64 declare_err!(EDOM, "Math argument out of domain of func.");
94 /// The value is a valid `errno` (i.e. `>= -MAX_ERRNO && < 0`).
101 /// It is a bug to pass an out-of-range `errno`. `EINVAL` would
103 pub fn from_errno(errno: crate::ffi::c_int) -> Error {
104 if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 {
107 "attempted to create `Error` with out of range `errno`: {}",
121 /// Returns [`None`] if `errno` is out-of-range.
122 const fn try_from_errno(errno: crate::ffi::c_int) -> Option<Error> {
123 if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 {
135 /// `errno` must be within error code range (i.e. `>= -MAX_ERRNO && < 0`).
136 const unsafe fn from_errno_unchecked(errno: crate::ffi::c_int) -> Error {
139 // SAFETY: The caller guarantees `errno` is non-zero.
144 pub fn to_errno(self) -> crate::ffi::c_int {
149 pub(crate) fn to_blk_status(self) -> bindings::blk_status_t {
155 pub fn to_ptr<T>(self) -> *mut T {
165 pub fn name(&self) -> Option<&'static CStr> {
167 let ptr = unsafe { bindings::errname(-self.0.get()) };
171 // SAFETY: The string returned by `errname` is static and `NUL`-terminated.
182 pub fn name(&self) -> Option<&'static CStr> {
188 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
190 // Print out number if no name can be found.
191 None => f.debug_tuple("Error").field(&-self.0).finish(),
194 // SAFETY: These strings are ASCII-only.
203 fn from(_: AllocError) -> Error {
209 fn from(_: TryFromIntError) -> Error {
215 fn from(_: Utf8Error) -> Error {
221 fn from(_: LayoutError) -> Error {
227 fn from(_: core::fmt::Error) -> Error {
233 fn from(e: core::convert::Infallible) -> Error {
240 /// To be used as the return type for functions that may fail.
244 /// In C, it is common that functions indicate success or failure through
245 /// their return value; modifying or returning extra data through non-`const`
246 /// pointer parameters. In particular, in the kernel, functions that may fail
250 /// In Rust, it is idiomatic to model functions that may fail as returning
251 /// a [`Result`]. Since in the kernel many functions return an error code,
262 pub fn to_result(err: crate::ffi::c_int) -> Result {
272 /// Some kernel C API functions return an "error pointer" which optionally
285 /// ) -> Result<*mut kernel::ffi::c_void> {
291 pub fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T> {
302 // negative value greater-or-equal to `-bindings::MAX_ERRNO`,
308 // negative value greater-or-equal to `-bindings::MAX_ERRNO`.
317 /// This is useful when calling Rust functions that return [`crate::error::Result<T>`]
318 /// from inside `extern "C"` functions that need to return an integer error result.
329 /// ) -> kernel::ffi::c_int {
337 pub fn from_result<T, F>(f: F) -> T
340 F: FnOnce() -> Result<T>,
344 // NO-OVERFLOW: negative `errno`s are no smaller than `-bindings::MAX_ERRNO`,
345 // `-bindings::MAX_ERRNO` fits in an `i16` as per invariant above,