diff --git a/src/mode/mod.rs b/src/mode/mod.rs index 0215d18..f681ecb 100644 --- a/src/mode/mod.rs +++ b/src/mode/mod.rs @@ -1,5 +1,11 @@ //! 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)] pub enum Bits { Suid = 0o4000, @@ -33,6 +39,29 @@ pub enum Who { pub struct Parser { mode: u32, - op: Op, - who: Who, + op: Option, + who: Option, +} + +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, + } + } }