Skip to main content

strat9_syscall/
schemev2.rs

1#[derive(Debug, Clone, Copy)]
2#[repr(C)]
3/// Fixed-size ABI representation of a registered scheme.
4pub struct SchemeV2 {
5    pub name: [u8; 256],
6    pub id: u32,
7    pub flags: u32,
8}
9
10impl SchemeV2 {
11    /// Create a scheme descriptor from name, id and flags.
12    pub fn new(name: &str, id: u32, flags: u32) -> Self {
13        let mut scheme = Self {
14            name: [0; 256],
15            id,
16            flags,
17        };
18
19        let name_bytes = name.as_bytes();
20        let len = core::cmp::min(name_bytes.len(), 255);
21        scheme.name[..len].copy_from_slice(&name_bytes[..len]);
22
23        scheme
24    }
25
26    /// Return the scheme name up to the first NUL byte.
27    pub fn name(&self) -> &str {
28        let len = self.name.iter().position(|&b| b == 0).unwrap_or(256);
29        core::str::from_utf8(&self.name[..len]).unwrap_or("<invalid>")
30    }
31}