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