Skip to content

Commit 47bf2cb

Browse files
committed
---
yaml --- r: 22251 b: refs/heads/snap-stage3 c: 2df1688 h: refs/heads/master i: 22249: 1b5782b 22247: a1bbde7 v: v3
1 parent 40d848e commit 47bf2cb

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5e7ff924b5931bb90f381d2bf5936616224d4e85
4+
refs/heads/snap-stage3: 2df168812d3abd3878a55058b12d911ff17c95ad
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/os.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,46 @@ fn real_args() -> ~[~str] {
761761

762762
#[cfg(windows)]
763763
fn real_args() -> ~[~str] {
764-
fail // Needs implementing.
764+
let mut nArgs: c_int = 0;
765+
let lpArgCount = ptr::to_mut_unsafe_ptr(&mut nArgs);
766+
let lpCmdLine = GetCommandLineW();
767+
let szArgList = CommandLineToArgvW(lpCmdLine, lpArgCount);
768+
769+
let mut args = ~[];
770+
for uint::range(0, nArgs as uint) |i| {
771+
unsafe {
772+
// Determine the length of this argument.
773+
let ptr = *szArgList.offset(i);
774+
let mut len = 0;
775+
while *ptr.offset(len) != 0 { len += 1; }
776+
777+
// Push it onto the list.
778+
vec::push(&mut args, vec::raw::form_slice(ptr, len, str::from_utf16));
779+
}
780+
}
781+
782+
unsafe {
783+
LocalFree(cast::transmute(szArgList));
784+
}
785+
786+
return args;
787+
}
788+
789+
type LPCWSTR = *u16;
790+
791+
#[cfg(windows)]
792+
#[link_name="kernel32"]
793+
#[abi="stdcall"]
794+
extern {
795+
fn GetCommandLineW() -> LPCWSTR;
796+
fn LocalFree(ptr: *c_void);
797+
}
798+
799+
#[cfg(windows)]
800+
#[link_name="shell32"]
801+
#[abi="stdcall"]
802+
extern {
803+
fn CommandLineToArgvW(lpCmdLine: LPCWSTR, pNumArgs: *mut c_int) -> **u16;
765804
}
766805

767806
struct OverriddenArgs {
@@ -845,6 +884,12 @@ mod tests {
845884
log(debug, last_os_error());
846885
}
847886

887+
#[test]
888+
pub fn test_args() {
889+
let a = real_args();
890+
assert a.len() >= 1;
891+
}
892+
848893
fn make_rand_name() -> ~str {
849894
let rng: rand::Rng = rand::Rng();
850895
let n = ~"TEST" + rng.gen_str(10u);

0 commit comments

Comments
 (0)