-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- **Fix** - **Fix**
- Loading branch information
Showing
8 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::ProcessContext; | ||
use core::{ffi::CStr, slice}; | ||
|
||
/// A process context based on libc. | ||
#[derive(Debug)] | ||
pub struct LibcProcessContext { | ||
arguments: &'static [*const i8], | ||
} | ||
|
||
impl LibcProcessContext { | ||
/// Creates a process context. | ||
/// | ||
/// # Safety | ||
/// | ||
/// The `argc` and `argv` arguments should be the ones passed down as | ||
/// arguments to the `main` function in C. | ||
pub const unsafe fn new(argc: isize, argv: *const *const i8) -> Self { | ||
Self { | ||
arguments: unsafe { slice::from_raw_parts(argv, argc as _) }, | ||
} | ||
} | ||
} | ||
|
||
impl ProcessContext for LibcProcessContext { | ||
fn command_line_rev(&self) -> impl IntoIterator<Item = &str> { | ||
self.arguments | ||
.iter() | ||
.rev() | ||
.map(|&argument| unsafe { CStr::from_ptr(argument) }.to_str().unwrap()) | ||
} | ||
|
||
fn environment_variables(&self) -> impl IntoIterator<Item = (&str, &str)> { | ||
[] | ||
} | ||
} |