Add mode::Parser and constructors

This commit is contained in:
Nathan Fisher 2023-01-15 01:28:57 -05:00
parent 68a4c08fe9
commit c727a1b6f8

View File

@ -1,5 +1,11 @@
//! Functions for parsing and managing permissions //! Functions for parsing and managing permissions
pub fn get_umask() -> u32 {
let mask = unsafe { libc::umask(0) };
let umask = unsafe {libc::umask(mask) };
umask
}
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Bits { pub enum Bits {
Suid = 0o4000, Suid = 0o4000,
@ -33,6 +39,29 @@ pub enum Who {
pub struct Parser { pub struct Parser {
mode: u32, mode: u32,
op: Op, op: Option<Op>,
who: Who, who: Option<Who>,
}
impl Default for Parser {
fn default() -> Self {
let umask = get_umask();
let mut mode = 0o0777;
mode &= umask;
Self {
mode,
op: None,
who: None,
}
}
}
impl Parser {
fn new(mode: u32) -> Self {
Self {
mode,
op: None,
who: None,
}
}
} }