mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-01-12 16:45:31 +00:00
sys_util: Add conversion from errno io::Error.
Change-Id: Ia49aa8eac1dedbc4e3f6277120bf332404e8b818 Reviewed-on: https://chromium-review.googlesource.com/509918 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
parent
d6c579fcef
commit
37285dc09d
1 changed files with 9 additions and 2 deletions
|
@ -3,11 +3,12 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
use std::result;
|
||||
use std::io;
|
||||
|
||||
use libc::__errno_location;
|
||||
|
||||
/// An error number, retrieved from [errno](http://man7.org/linux/man-pages/man3/errno.3.html), set
|
||||
/// by a libc function that returned an error.
|
||||
/// An error number, retrieved from errno (man 3 errno), set by a libc
|
||||
/// function that returned an error.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Error(i32);
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
@ -32,6 +33,12 @@ impl Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(e: io::Error) -> Self {
|
||||
Error::new(e.raw_os_error().unwrap_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the last errno as a Result that is always an error.
|
||||
pub fn errno_result<T>() -> Result<T> {
|
||||
Err(Error::last())
|
||||
|
|
Loading…
Reference in a new issue