1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Fix sync and whoami on windows.

This commit is contained in:
Xander Masotto 2014-08-15 23:53:23 +01:00
parent 61239f998c
commit 4414d95b6b
2 changed files with 13 additions and 7 deletions

View file

@ -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

View file

@ -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())