diff options
author | Cyril Plisko <cyril.plisko@mountall.com> | 2016-11-03 18:46:13 +0200 |
---|---|---|
committer | Cyril Plisko <cyril.plisko@mountall.com> | 2016-11-03 19:14:47 +0200 |
commit | 5a3d95aad4bfa77370ae05412d8c745d8c31eda5 (patch) | |
tree | d36bf059e44547d0a0e652f35ebf87f9c62ea4e1 /src | |
parent | 04ae203f3e7c9bb3c4e84992bbaa898d04d4f55e (diff) |
Support pager command with whitespaces
Closes #3
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/utils.rs | 13 |
2 files changed, 11 insertions, 4 deletions
@@ -97,7 +97,7 @@ impl Pager { // I am parent utils::dup2(pager_stdin, libc::STDIN_FILENO); utils::close(main_stdout); - utils::execvp(vec![pager]); + utils::execvp(pager); } } } diff --git a/src/utils.rs b/src/utils.rs index ded9524..fc5fdfe 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,15 +9,22 @@ fn osstring2cstring(s: &OsString) -> CString { unsafe { CString::from_vec_unchecked(s.clone().into_vec()) } } +fn split_string(s: &OsString) -> Vec<OsString> { + match s.clone().into_string() { + Ok(cmd) => cmd.split_whitespace().map(OsString::from).collect(), + Err(cmd) => vec![cmd], + } +} + // Helper wrappers around libc::* API pub fn fork() -> libc::pid_t { unsafe { libc::fork() } } -pub fn execvp(argv: Vec<&OsString>) { +pub fn execvp(cmd: &OsString) { let mut args = Vec::with_capacity(2); - for arg in &argv { - args.push(osstring2cstring(arg).as_ptr()); + for arg in split_string(cmd) { + args.push(osstring2cstring(&arg).as_ptr()) } args.push(ptr::null()); assert!(unsafe { libc::execvp(args[0], args.as_ptr()) } > -1); |