about summary refs log tree commit diff
path: root/src/libstd/sys/windows/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys/windows/mod.rs')
-rw-r--r--src/libstd/sys/windows/mod.rs61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs
index 4df3c561ab1..3f76218eafe 100644
--- a/src/libstd/sys/windows/mod.rs
+++ b/src/libstd/sys/windows/mod.rs
@@ -16,7 +16,6 @@ use prelude::v1::*;
 
 use ffi::{OsStr, OsString};
 use io::{self, ErrorKind};
-use libc;
 use num::Zero;
 use os::windows::ffi::{OsStrExt, OsStringExt};
 use path::PathBuf;
@@ -46,25 +45,28 @@ pub mod stdio;
 pub fn init() {}
 
 pub fn decode_error_kind(errno: i32) -> ErrorKind {
-    match errno as libc::c_int {
-        libc::ERROR_ACCESS_DENIED => ErrorKind::PermissionDenied,
-        libc::ERROR_ALREADY_EXISTS => ErrorKind::AlreadyExists,
-        libc::ERROR_BROKEN_PIPE => ErrorKind::BrokenPipe,
-        libc::ERROR_FILE_NOT_FOUND => ErrorKind::NotFound,
-        c::ERROR_PATH_NOT_FOUND => ErrorKind::NotFound,
-        libc::ERROR_NO_DATA => ErrorKind::BrokenPipe,
-        libc::ERROR_OPERATION_ABORTED => ErrorKind::TimedOut,
-
-        libc::WSAEACCES => ErrorKind::PermissionDenied,
-        libc::WSAEADDRINUSE => ErrorKind::AddrInUse,
-        libc::WSAEADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
-        libc::WSAECONNABORTED => ErrorKind::ConnectionAborted,
-        libc::WSAECONNREFUSED => ErrorKind::ConnectionRefused,
-        libc::WSAECONNRESET => ErrorKind::ConnectionReset,
-        libc::WSAEINVAL => ErrorKind::InvalidInput,
-        libc::WSAENOTCONN => ErrorKind::NotConnected,
-        libc::WSAEWOULDBLOCK => ErrorKind::WouldBlock,
-        libc::WSAETIMEDOUT => ErrorKind::TimedOut,
+    match errno as c::DWORD {
+        c::ERROR_ACCESS_DENIED => return ErrorKind::PermissionDenied,
+        c::ERROR_ALREADY_EXISTS => return ErrorKind::AlreadyExists,
+        c::ERROR_BROKEN_PIPE => return ErrorKind::BrokenPipe,
+        c::ERROR_FILE_NOT_FOUND => return ErrorKind::NotFound,
+        c::ERROR_PATH_NOT_FOUND => return ErrorKind::NotFound,
+        c::ERROR_NO_DATA => return ErrorKind::BrokenPipe,
+        c::ERROR_OPERATION_ABORTED => return ErrorKind::TimedOut,
+        _ => {}
+    }
+
+    match errno {
+        c::WSAEACCES => ErrorKind::PermissionDenied,
+        c::WSAEADDRINUSE => ErrorKind::AddrInUse,
+        c::WSAEADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
+        c::WSAECONNABORTED => ErrorKind::ConnectionAborted,
+        c::WSAECONNREFUSED => ErrorKind::ConnectionRefused,
+        c::WSAECONNRESET => ErrorKind::ConnectionReset,
+        c::WSAEINVAL => ErrorKind::InvalidInput,
+        c::WSAENOTCONN => ErrorKind::NotConnected,
+        c::WSAEWOULDBLOCK => ErrorKind::WouldBlock,
+        c::WSAETIMEDOUT => ErrorKind::TimedOut,
 
         _ => ErrorKind::Other,
     }
@@ -91,7 +93,7 @@ fn to_utf16_os(s: &OsStr) -> Vec<u16> {
 // yielded the data which has been read from the syscall. The return value
 // from this closure is then the return value of the function.
 fn fill_utf16_buf<F1, F2, T>(mut f1: F1, f2: F2) -> io::Result<T>
-    where F1: FnMut(*mut u16, libc::DWORD) -> libc::DWORD,
+    where F1: FnMut(*mut u16, c::DWORD) -> c::DWORD,
           F2: FnOnce(&[u16]) -> T
 {
     // Start off with a stack buf but then spill over to the heap if we end up
@@ -120,13 +122,12 @@ fn fill_utf16_buf<F1, F2, T>(mut f1: F1, f2: F2) -> io::Result<T>
             // error" is still 0 then we interpret it as a 0 length buffer and
             // not an actual error.
             c::SetLastError(0);
-            let k = match f1(buf.as_mut_ptr(), n as libc::DWORD) {
-                0 if libc::GetLastError() == 0 => 0,
+            let k = match f1(buf.as_mut_ptr(), n as c::DWORD) {
+                0 if c::GetLastError() == 0 => 0,
                 0 => return Err(io::Error::last_os_error()),
                 n => n,
             } as usize;
-            if k == n && libc::GetLastError() ==
-                            libc::ERROR_INSUFFICIENT_BUFFER as libc::DWORD {
+            if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER {
                 n *= 2;
             } else if k >= n {
                 n = k;
@@ -157,7 +158,7 @@ fn cvt<I: PartialEq + Zero>(i: I) -> io::Result<I> {
     }
 }
 
-fn dur2timeout(dur: Duration) -> libc::DWORD {
+fn dur2timeout(dur: Duration) -> c::DWORD {
     // Note that a duration is a (u64, u32) (seconds, nanoseconds) pair, and the
     // timeouts in windows APIs are typically u32 milliseconds. To translate, we
     // have two pieces to take care of:
@@ -170,10 +171,10 @@ fn dur2timeout(dur: Duration) -> libc::DWORD {
     }).and_then(|ms| {
         ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 {1} else {0})
     }).map(|ms| {
-        if ms > <libc::DWORD>::max_value() as u64 {
-            libc::INFINITE
+        if ms > <c::DWORD>::max_value() as u64 {
+            c::INFINITE
         } else {
-            ms as libc::DWORD
+            ms as c::DWORD
         }
-    }).unwrap_or(libc::INFINITE)
+    }).unwrap_or(c::INFINITE)
 }