Skip to content

Commit 24ebbb4

Browse files
committed
windows: Fix INVALID_HANDLE_VALUE
Made INVALID_HANDLE_VALUE actually a HANDLE. Removed all useless casts during INVALID_HANDLE_VALUE comparisons. Signed-off-by: Peter Atashian <[email protected]>
1 parent feb219d commit 24ebbb4

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

src/liblibc/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,7 @@ pub mod types {
11421142
pub mod os {
11431143
pub mod common {
11441144
pub mod posix01 {
1145-
use types::os::arch::c95::{c_short, time_t,
1146-
c_long};
1145+
use types::os::arch::c95::{c_short, time_t, c_long};
11471146
use types::os::arch::extra::{int64, time64_t};
11481147
use types::os::arch::posix88::{dev_t, ino_t};
11491148

@@ -1947,7 +1946,7 @@ pub mod consts {
19471946
}
19481947
pub mod extra {
19491948
use types::os::arch::c95::c_int;
1950-
use types::os::arch::extra::{WORD, DWORD, BOOL};
1949+
use types::os::arch::extra::{WORD, DWORD, BOOL, HANDLE};
19511950

19521951
pub static TRUE : BOOL = 1;
19531952
pub static FALSE : BOOL = 0;
@@ -1976,7 +1975,7 @@ pub mod consts {
19761975
pub static ERROR_IO_PENDING: c_int = 997;
19771976
pub static ERROR_FILE_INVALID : c_int = 1006;
19781977
pub static ERROR_NOT_FOUND: c_int = 1168;
1979-
pub static INVALID_HANDLE_VALUE : c_int = -1;
1978+
pub static INVALID_HANDLE_VALUE: HANDLE = -1 as HANDLE;
19801979

19811980
pub static DELETE : DWORD = 0x00010000;
19821981
pub static READ_CONTROL : DWORD = 0x00020000;

src/libnative/io/file_win32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub fn open(path: &CString, fm: rtio::FileMode, fa: rtio::FileAccess)
320320
dwFlagsAndAttributes,
321321
ptr::mut_null())
322322
};
323-
if handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
323+
if handle == libc::INVALID_HANDLE_VALUE {
324324
Err(super::last_error())
325325
} else {
326326
let fd = unsafe {
@@ -368,7 +368,7 @@ pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
368368
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
369369
let find_handle = libc::FindFirstFileW(path.as_ptr(),
370370
wfd_ptr as libc::HANDLE);
371-
if find_handle as libc::c_int != libc::INVALID_HANDLE_VALUE {
371+
if find_handle != libc::INVALID_HANDLE_VALUE {
372372
let mut paths = vec!();
373373
let mut more_files = 1 as libc::c_int;
374374
while more_files != 0 {
@@ -440,7 +440,7 @@ pub fn readlink(p: &CString) -> IoResult<CString> {
440440
libc::FILE_ATTRIBUTE_NORMAL,
441441
ptr::mut_null())
442442
};
443-
if handle as int == libc::INVALID_HANDLE_VALUE as int {
443+
if handle == libc::INVALID_HANDLE_VALUE {
444444
return Err(super::last_error())
445445
}
446446
// Specify (sz - 1) because the documentation states that it's the size

src/libnative/io/pipe_win32.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl UnixStream {
223223
libc::FILE_FLAG_OVERLAPPED,
224224
ptr::mut_null())
225225
};
226-
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
226+
if result != libc::INVALID_HANDLE_VALUE {
227227
return Some(result)
228228
}
229229

@@ -238,7 +238,7 @@ impl UnixStream {
238238
libc::FILE_FLAG_OVERLAPPED,
239239
ptr::mut_null())
240240
};
241-
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
241+
if result != libc::INVALID_HANDLE_VALUE {
242242
return Some(result)
243243
}
244244
}
@@ -253,7 +253,7 @@ impl UnixStream {
253253
libc::FILE_FLAG_OVERLAPPED,
254254
ptr::mut_null())
255255
};
256-
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
256+
if result != libc::INVALID_HANDLE_VALUE {
257257
return Some(result)
258258
}
259259
}
@@ -565,7 +565,7 @@ impl UnixListener {
565565
// and such.
566566
let addr_v = try!(to_utf16(addr));
567567
let ret = unsafe { pipe(addr_v.as_ptr(), true) };
568-
if ret == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
568+
if ret == libc::INVALID_HANDLE_VALUE {
569569
Err(super::last_error())
570570
} else {
571571
Ok(UnixListener { handle: ret, name: addr.clone() })
@@ -680,7 +680,7 @@ impl UnixAcceptor {
680680
// create a second server pipe. If this fails, we disconnect the
681681
// connected client and return an error (see comments above).
682682
let new_handle = unsafe { pipe(name.as_ptr(), false) };
683-
if new_handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
683+
if new_handle == libc::INVALID_HANDLE_VALUE {
684684
let ret = Err(super::last_error());
685685
// If our disconnection fails, then there's not really a whole lot
686686
// that we can do, so fail the task.

src/libnative/io/process.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,13 @@ fn spawn_process_os(cfg: ProcessConfig,
359359
libc::OPEN_EXISTING,
360360
0,
361361
ptr::mut_null());
362-
if *slot == INVALID_HANDLE_VALUE as libc::HANDLE {
362+
if *slot == INVALID_HANDLE_VALUE {
363363
return Err(super::last_error())
364364
}
365365
}
366366
Some(ref fd) => {
367367
let orig = get_osfhandle(fd.fd()) as HANDLE;
368-
if orig == INVALID_HANDLE_VALUE as HANDLE {
368+
if orig == INVALID_HANDLE_VALUE {
369369
return Err(super::last_error())
370370
}
371371
if DuplicateHandle(cur_proc, orig, cur_proc, slot,
@@ -450,9 +450,9 @@ fn zeroed_startupinfo() -> libc::types::os::arch::extra::STARTUPINFO {
450450
wShowWindow: 0,
451451
cbReserved2: 0,
452452
lpReserved2: ptr::mut_null(),
453-
hStdInput: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
454-
hStdOutput: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
455-
hStdError: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
453+
hStdInput: libc::INVALID_HANDLE_VALUE,
454+
hStdOutput: libc::INVALID_HANDLE_VALUE,
455+
hStdError: libc::INVALID_HANDLE_VALUE,
456456
}
457457
}
458458

src/librustdoc/flock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod imp {
197197
libc::FILE_ATTRIBUTE_NORMAL,
198198
ptr::mut_null())
199199
};
200-
if handle as uint == libc::INVALID_HANDLE_VALUE as uint {
200+
if handle == libc::INVALID_HANDLE_VALUE {
201201
fail!("create file error: {}", os::last_os_error());
202202
}
203203
let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };

0 commit comments

Comments
 (0)