mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
Merge pull request #380 from xmasotto/master
Fix sync and whoami on windows.
This commit is contained in:
commit
8c8a3757bd
2 changed files with 13 additions and 7 deletions
|
@ -16,10 +16,12 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use getopts::{optflag, getopts, usage};
|
use getopts::{optflag, getopts, usage};
|
||||||
#[cfg(windows)]use std::ptr::null;
|
|
||||||
|
|
||||||
#[path = "../common/util.rs"] mod util;
|
#[path = "../common/util.rs"] mod util;
|
||||||
|
|
||||||
|
static NAME: &'static str = "sync";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
mod platform {
|
mod platform {
|
||||||
use super::libc;
|
use super::libc;
|
||||||
|
@ -38,6 +40,7 @@ mod platform {
|
||||||
mod platform {
|
mod platform {
|
||||||
pub use super::libc;
|
pub use super::libc;
|
||||||
use std::{mem, str};
|
use std::{mem, str};
|
||||||
|
use std::ptr::null;
|
||||||
|
|
||||||
extern "system" {
|
extern "system" {
|
||||||
fn CreateFileA(lpFileName: *const libc::c_char,
|
fn CreateFileA(lpFileName: *const libc::c_char,
|
||||||
|
@ -87,8 +90,9 @@ mod platform {
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe fn find_first_volume() -> (String, *const libc::c_void) {
|
unsafe fn find_first_volume() -> (String, *const libc::c_void) {
|
||||||
let name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH
|
let mut name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH
|
||||||
match FindFirstVolumeA(name.as_ptr(), name.len() as libc::uint32_t) {
|
match FindFirstVolumeA(name.as_mut_ptr(),
|
||||||
|
name.len() as libc::uint32_t) {
|
||||||
_x if _x == -1 as *const libc::c_void => { // INVALID_HANDLE_VALUE
|
_x if _x == -1 as *const libc::c_void => { // INVALID_HANDLE_VALUE
|
||||||
crash!(GetLastError(), "failed to find first volume");
|
crash!(GetLastError(), "failed to find first volume");
|
||||||
}
|
}
|
||||||
|
@ -104,8 +108,10 @@ mod platform {
|
||||||
(first_volume, next_volume_handle) => {
|
(first_volume, next_volume_handle) => {
|
||||||
let mut volumes = Vec::from_elem(1, first_volume);
|
let mut volumes = Vec::from_elem(1, first_volume);
|
||||||
loop {
|
loop {
|
||||||
let name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH
|
let mut name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH
|
||||||
match FindNextVolumeA(next_volume_handle, name.as_ptr(), name.len() as libc::uint32_t) {
|
match FindNextVolumeA(next_volume_handle,
|
||||||
|
name.as_mut_ptr(),
|
||||||
|
name.len() as libc::uint32_t) {
|
||||||
0 => {
|
0 => {
|
||||||
match GetLastError() {
|
match GetLastError() {
|
||||||
0x12 => { // ERROR_NO_MORE_FILES
|
0x12 => { // ERROR_NO_MORE_FILES
|
||||||
|
|
|
@ -56,8 +56,8 @@ mod platform {
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
pub unsafe fn getusername() -> String {
|
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
|
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_ptr(), &(buffer.len() as libc::uint32_t)) == 0 {
|
if !GetUserNameA(buffer.as_mut_ptr(), &mut (buffer.len() as libc::uint32_t)) == 0 {
|
||||||
crash!(1, "username is too long");
|
crash!(1, "username is too long");
|
||||||
}
|
}
|
||||||
str::raw::from_c_str(buffer.as_ptr())
|
str::raw::from_c_str(buffer.as_ptr())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue