提交 2df16881 编写于 作者: P Patrick Walton

libcore: Implement os::args() on Windows

上级 5e7ff924
......@@ -761,7 +761,46 @@ fn real_args() -> ~[~str] {
#[cfg(windows)]
fn real_args() -> ~[~str] {
fail // Needs implementing.
let mut nArgs: c_int = 0;
let lpArgCount = ptr::to_mut_unsafe_ptr(&mut nArgs);
let lpCmdLine = GetCommandLineW();
let szArgList = CommandLineToArgvW(lpCmdLine, lpArgCount);
let mut args = ~[];
for uint::range(0, nArgs as uint) |i| {
unsafe {
// Determine the length of this argument.
let ptr = *szArgList.offset(i);
let mut len = 0;
while *ptr.offset(len) != 0 { len += 1; }
// Push it onto the list.
vec::push(&mut args, vec::raw::form_slice(ptr, len, str::from_utf16));
}
}
unsafe {
LocalFree(cast::transmute(szArgList));
}
return args;
}
type LPCWSTR = *u16;
#[cfg(windows)]
#[link_name="kernel32"]
#[abi="stdcall"]
extern {
fn GetCommandLineW() -> LPCWSTR;
fn LocalFree(ptr: *c_void);
}
#[cfg(windows)]
#[link_name="shell32"]
#[abi="stdcall"]
extern {
fn CommandLineToArgvW(lpCmdLine: LPCWSTR, pNumArgs: *mut c_int) -> **u16;
}
struct OverriddenArgs {
......@@ -845,6 +884,12 @@ pub fn last_os_error() {
log(debug, last_os_error());
}
#[test]
pub fn test_args() {
let a = real_args();
assert a.len() >= 1;
}
fn make_rand_name() -> ~str {
let rng: rand::Rng = rand::Rng();
let n = ~"TEST" + rng.gen_str(10u);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册