Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Jul 15, 2024
1 parent c61111d commit 8bcf61e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions process_context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme.workspace = true
repository.workspace = true

[features]
libc = []
std = ["dep:once_cell"]

[dependencies]
Expand Down
4 changes: 4 additions & 0 deletions process_context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "libc")]
mod libc;
#[cfg(feature = "std")]
mod os;
mod process_context;
mod void;

#[cfg(feature = "libc")]
pub use libc::LibcProcessContext;
#[cfg(feature = "std")]
pub use os::OsProcessContext;
pub use process_context::ProcessContext;
Expand Down
30 changes: 30 additions & 0 deletions process_context/src/libc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.
pub 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)> {
[]
}
}

0 comments on commit 8bcf61e

Please sign in to comment.