userspace/memory/stack/environment/
entry.rs1use crate::target::arch::Pointer;
2
3ample::r#struct!(
4 #[repr(C)]
5 pub struct Entry {
6 pub prev: *mut Entry,
7 pub next: *mut Entry,
8 pub pointer: Pointer, }
10);
11
12impl Entry {
13 pub fn from_pointer(pointer: Pointer) -> Entry {
14 Entry {
15 prev: core::ptr::null_mut(),
16 next: core::ptr::null_mut(),
17 pointer: pointer,
18 }
19 }
20
21 pub fn key(&self) -> &str {
22 let c_str = unsafe { core::ffi::CStr::from_ptr(self.pointer.0 as *mut i8) };
25
26 let r_str = c_str.to_str().unwrap();
27
28 if let Some(pos) = r_str.find('=') {
29 &r_str[..pos]
30 } else {
31 r_str
32 }
33 }
34
35 pub fn value(&self) -> Option<&str> {
36 let c_str = unsafe { core::ffi::CStr::from_ptr(self.pointer.0 as *mut i8) };
37
38 let r_str = c_str.to_str().unwrap();
39
40 if let Some(pos) = r_str.find('=') {
42 Some(&r_str[(pos + 1)..])
43 } else {
44 None
45 }
46 }
47}
48
49impl core::fmt::Debug for Entry {
50 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
51 let _cstr = self.pointer.0;
54
55 let _ = write!(f, "Entry: {{ ");
56 let _ = write!(f, "{:?} = {:?}, ", self.key(), self.value());
57 let _ = write!(f, " }}");
58 return Ok(());
59 }
61}