rust/chg/src/procutil.rs
changeset 44683 065048e66f32
parent 43818 ce088b38f92b
child 45620 426294d06ddc
--- a/rust/chg/src/procutil.rs	Sun Oct 07 16:14:21 2018 +0900
+++ b/rust/chg/src/procutil.rs	Thu Oct 04 22:44:37 2018 +0900
@@ -25,6 +25,19 @@
     unsafe { libc::geteuid() }
 }
 
+/// Returns the umask of the current process.
+///
+/// # Safety
+///
+/// This is unsafe because the umask value is temporarily changed, and
+/// the change can be observed from the other threads. Don't call this in
+/// multi-threaded context.
+pub unsafe fn get_umask() -> u32 {
+    let mask = libc::umask(0);
+    libc::umask(mask);
+    mask
+}
+
 /// Changes the given fd to blocking mode.
 pub fn set_blocking_fd(fd: RawFd) -> io::Result<()> {
     let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) };