Skip to content

Commit 371f4d6

Browse files
committed
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: #38577 (comment)
2 parents 469fd77 + 88df0e3 commit 371f4d6

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/libstd/sys/redox/args.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ impl DoubleEndedIterator for Args {
5252
mod imp {
5353
use os::unix::prelude::*;
5454
use mem;
55-
use ffi::OsString;
55+
use ffi::{CStr, OsString};
5656
use marker::PhantomData;
57-
use slice;
58-
use str;
57+
use libc;
5958
use super::Args;
6059

6160
use sys_common::mutex::Mutex;
@@ -64,12 +63,9 @@ mod imp {
6463
static LOCK: Mutex = Mutex::new();
6564

6665
pub unsafe fn init(argc: isize, argv: *const *const u8) {
67-
let mut args: Vec<Vec<u8>> = Vec::new();
68-
for i in 0..argc {
69-
let len = *(argv.offset(i * 2)) as usize;
70-
let ptr = *(argv.offset(i * 2 + 1));
71-
args.push(slice::from_raw_parts(ptr, len).to_vec());
72-
}
66+
let args = (0..argc).map(|i| {
67+
CStr::from_ptr(*argv.offset(i) as *const libc::c_char).to_bytes().to_vec()
68+
}).collect();
7369

7470
LOCK.lock();
7571
let ptr = get_global_ptr();

0 commit comments

Comments
 (0)