Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/errno.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::error::Error;
use std::fmt::{self, Display, Formatter};
use std::fmt::{self, Debug, Display, Formatter};
use std::io::Error as IoError;
use std::os::raw::c_int;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Copy, Clone, Eq, PartialEq)]
/// linux errno wrap.
pub struct Errno(c_int);

Expand Down Expand Up @@ -38,7 +38,22 @@ impl From<Errno> for IoError {

impl Display for Errno {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "errno is {}", self.0)
write!(f, "errno {} (", self.0)?;
match self.0 {
libc::ENOENT => write!(f, "does not exist"),
libc::EEXIST => write!(f, "already exists"),
libc::EISDIR => write!(f, "is a directory"),
libc::ENOTDIR => write!(f, "is not a directory"),
_ => write!(f, "unknown"),
}?;
write!(f, ")")?;
Ok(())
}
}

impl Debug for Errno {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(self, f)
}
}

Expand Down