From 4414d95b6b707a1ae46356c71007001e3b7cad0c Mon Sep 17 00:00:00 2001 From: Xander Masotto Date: Fri, 15 Aug 2014 23:53:23 +0100 Subject: [PATCH] Fix sync and whoami on windows. --- src/sync/sync.rs | 16 +++++++++++----- src/whoami/whoami.rs | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sync/sync.rs b/src/sync/sync.rs index c0cdeab53..e1e84bbdc 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -16,10 +16,12 @@ extern crate getopts; extern crate libc; use getopts::{optflag, getopts, usage}; -#[cfg(windows)]use std::ptr::null; #[path = "../common/util.rs"] mod util; +static NAME: &'static str = "sync"; +static VERSION: &'static str = "1.0.0"; + #[cfg(unix)] mod platform { use super::libc; @@ -38,6 +40,7 @@ mod platform { mod platform { pub use super::libc; use std::{mem, str}; + use std::ptr::null; extern "system" { fn CreateFileA(lpFileName: *const libc::c_char, @@ -87,8 +90,9 @@ mod platform { #[allow(unused_unsafe)] unsafe fn find_first_volume() -> (String, *const libc::c_void) { - let name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH - match FindFirstVolumeA(name.as_ptr(), name.len() as libc::uint32_t) { + let mut name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH + match FindFirstVolumeA(name.as_mut_ptr(), + name.len() as libc::uint32_t) { _x if _x == -1 as *const libc::c_void => { // INVALID_HANDLE_VALUE crash!(GetLastError(), "failed to find first volume"); } @@ -104,8 +108,10 @@ mod platform { (first_volume, next_volume_handle) => { let mut volumes = Vec::from_elem(1, first_volume); loop { - let name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH - match FindNextVolumeA(next_volume_handle, name.as_ptr(), name.len() as libc::uint32_t) { + let mut name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH + match FindNextVolumeA(next_volume_handle, + name.as_mut_ptr(), + name.len() as libc::uint32_t) { 0 => { match GetLastError() { 0x12 => { // ERROR_NO_MORE_FILES diff --git a/src/whoami/whoami.rs b/src/whoami/whoami.rs index 705fcdcfd..0090b023a 100644 --- a/src/whoami/whoami.rs +++ b/src/whoami/whoami.rs @@ -56,8 +56,8 @@ mod platform { #[allow(unused_unsafe)] pub unsafe fn getusername() -> String { - let buffer: [libc::c_char, ..2048] = mem::uninitialized(); // XXX: it may be possible that this isn't long enough. I don't know - if !GetUserNameA(buffer.as_ptr(), &(buffer.len() as libc::uint32_t)) == 0 { + let mut buffer: [libc::c_char, ..2048] = mem::uninitialized(); // XXX: it may be possible that this isn't long enough. I don't know + if !GetUserNameA(buffer.as_mut_ptr(), &mut (buffer.len() as libc::uint32_t)) == 0 { crash!(1, "username is too long"); } str::raw::from_c_str(buffer.as_ptr())