about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-12-28 14:33:48 +0000
committerbors <bors@rust-lang.org>2016-12-28 14:33:48 +0000
commit371f4d6bf697ac4b08845b6e739ab263df6f8395 (patch)
treec26eddb3a9020558787e77dae71244a24eb7384d /src/libstd/sys
parent469fd779ee24f8348acd438f471c8c3a5cef309a (diff)
parent88df0e391842f89dbd95fb8e375e11d8263ae156 (diff)
downloadrust-371f4d6bf697ac4b08845b6e739ab263df6f8395.tar.gz
rust-371f4d6bf697ac4b08845b6e739ab263df6f8395.zip
Auto merge of #38626 - redox-os:args_fix, r=alexcrichton
Fix argument handling on Redox

After switching the start code to be handled in libc, we are no longer passing in slices as arguments into the libstd main function. This means that handling had to be rewritten to match the unix way of doing things.

Additional commits on this branch are going to be merged in this PR: https://github.com/rust-lang/rust/pull/38577#issuecomment-269138394
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/redox/args.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/libstd/sys/redox/args.rs b/src/libstd/sys/redox/args.rs
index f6fea2f1076..212895d7b76 100644
--- a/src/libstd/sys/redox/args.rs
+++ b/src/libstd/sys/redox/args.rs
@@ -52,10 +52,9 @@ impl DoubleEndedIterator for Args {
 mod imp {
     use os::unix::prelude::*;
     use mem;
-    use ffi::OsString;
+    use ffi::{CStr, OsString};
     use marker::PhantomData;
-    use slice;
-    use str;
+    use libc;
     use super::Args;
 
     use sys_common::mutex::Mutex;
@@ -64,12 +63,9 @@ mod imp {
     static LOCK: Mutex = Mutex::new();
 
     pub unsafe fn init(argc: isize, argv: *const *const u8) {
-        let mut args: Vec<Vec<u8>> = Vec::new();
-        for i in 0..argc {
-            let len = *(argv.offset(i * 2)) as usize;
-            let ptr = *(argv.offset(i * 2 + 1));
-            args.push(slice::from_raw_parts(ptr, len).to_vec());
-        }
+        let args = (0..argc).map(|i| {
+            CStr::from_ptr(*argv.offset(i) as *const libc::c_char).to_bytes().to_vec()
+        }).collect();
 
         LOCK.lock();
         let ptr = get_global_ptr();