@@ -761,7 +761,46 @@ fn real_args() -> ~[~str] {
761
761
762
762
#[ cfg( windows) ]
763
763
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 ;
765
804
}
766
805
767
806
struct OverriddenArgs {
@@ -845,6 +884,12 @@ mod tests {
845
884
log ( debug, last_os_error ( ) ) ;
846
885
}
847
886
887
+ #[ test]
888
+ pub fn test_args ( ) {
889
+ let a = real_args ( ) ;
890
+ assert a. len ( ) >= 1 ;
891
+ }
892
+
848
893
fn make_rand_name ( ) -> ~str {
849
894
let rng: rand:: Rng = rand:: Rng ( ) ;
850
895
let n = ~"TEST " + rng. gen_str ( 10 u) ;
0 commit comments