native: Recognize EISDIR

This recognizes the EISDIR error code on both windows and unix platforms to
provide a more descriptive error condition.
This commit is contained in:
Alex Crichton 2014-02-26 13:06:45 -08:00
parent 40ab198356
commit 8c157ed63d
2 changed files with 9 additions and 0 deletions

View File

@ -105,6 +105,13 @@ fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"), libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"),
libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"), libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"),
// libuv maps this error code to EISDIR. we do too. if it is found
// to be incorrect, we can add in some more machinery to only
// return this message when ERROR_INVALID_FUNCTION after certain
// win32 calls.
libc::ERROR_INVALID_FUNCTION => (io::InvalidInput,
"illegal operation on a directory"),
x => { x => {
debug!("ignoring {}: {}", x, os::last_os_error()); debug!("ignoring {}: {}", x, os::last_os_error());
(io::OtherIoError, "unknown error") (io::OtherIoError, "unknown error")
@ -127,6 +134,7 @@ fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) {
libc::EADDRNOTAVAIL => (io::ConnectionRefused, "address not available"), libc::EADDRNOTAVAIL => (io::ConnectionRefused, "address not available"),
libc::EADDRINUSE => (io::ConnectionRefused, "address in use"), libc::EADDRINUSE => (io::ConnectionRefused, "address in use"),
libc::ENOENT => (io::FileNotFound, "no such file or directory"), libc::ENOENT => (io::FileNotFound, "no such file or directory"),
libc::EISDIR => (io::InvalidInput, "illegal operation on a directory"),
// These two constants can have the same value on some systems, but // These two constants can have the same value on some systems, but
// different values on others, so we can't use a match clause // different values on others, so we can't use a match clause

View File

@ -1623,6 +1623,7 @@ pub mod extra {
pub static O_NOINHERIT: c_int = 128; pub static O_NOINHERIT: c_int = 128;
pub static ERROR_SUCCESS : c_int = 0; pub static ERROR_SUCCESS : c_int = 0;
pub static ERROR_INVALID_FUNCTION: c_int = 1;
pub static ERROR_FILE_NOT_FOUND: c_int = 2; pub static ERROR_FILE_NOT_FOUND: c_int = 2;
pub static ERROR_ACCESS_DENIED: c_int = 5; pub static ERROR_ACCESS_DENIED: c_int = 5;
pub static ERROR_INVALID_HANDLE : c_int = 6; pub static ERROR_INVALID_HANDLE : c_int = 6;