Skip to content

Commit 7910ef5

Browse files
committed
---
yaml --- r: 30959 b: refs/heads/incoming c: 2df1688 h: refs/heads/master i: 30957: f938c7e 30955: 3302583 30951: c5ef3b0 30943: f6c3c25 v: v3
1 parent 4f4da2c commit 7910ef5

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
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 5e7ff924b5931bb90f381d2bf5936616224d4e85
9+
refs/heads/incoming: 2df168812d3abd3878a55058b12d911ff17c95ad
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/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)