Skip to content

Commit 88fd945

Browse files
committed
update args
1 parent 4dee102 commit 88fd945

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libstd/sys/wasi/args.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ pub struct Args {
1818

1919
/// Returns the command line arguments
2020
pub fn args() -> Args {
21-
let mut buf = Vec::new();
22-
let _ = wasi::get_args(|arg| buf.push(OsString::from_vec(arg.to_vec())));
21+
let buf = wasi::args_sizes_get().and_then(|args_sizes| {
22+
let mut buf = Vec::with_capacity(args_sizes.get_count());
23+
wasi::get_args(args_sizes, |arg| {
24+
let arg = OsString::from_vec(arg.to_vec());
25+
buf.push(arg);
26+
})?;
27+
Ok(buf)
28+
}).unwrap_or(vec![]);
2329
Args {
2430
iter: buf.into_iter(),
2531
_dont_send_or_sync_me: PhantomData

0 commit comments

Comments
 (0)