Skip to content

Commit 5b52bb8

Browse files
authored
Merge pull request RustPython#1896 from mrmiywj/add_umask_support
Add umask support
2 parents 57ebfde + b286e5d commit 5b52bb8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

vm/src/stdlib/os.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,18 @@ fn os_urandom(size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
13021302
}
13031303
}
13041304

1305+
#[cfg(target_os = "linux")]
1306+
type ModeT = u32;
1307+
1308+
#[cfg(target_os = "macos")]
1309+
type ModeT = u16;
1310+
1311+
#[cfg(any(target_os = "macos", target_os = "linux"))]
1312+
fn os_umask(mask: ModeT, _vm: &VirtualMachine) -> PyResult<ModeT> {
1313+
let ret_mask = unsafe { libc::umask(mask) };
1314+
Ok(ret_mask)
1315+
}
1316+
13051317
#[pystruct_sequence(name = "os.uname_result")]
13061318
#[derive(Debug)]
13071319
#[cfg(unix)]
@@ -1510,6 +1522,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
15101522
SupportFunc::new(vm, "chmod", os_chmod, Some(false), Some(false), Some(false)),
15111523
#[cfg(not(target_os = "redox"))]
15121524
SupportFunc::new(vm, "chroot", os_chroot, Some(false), None, None),
1525+
SupportFunc::new(vm, "umask", os_umask, Some(false), Some(false), Some(false)),
15131526
]);
15141527
let supports_fd = PySet::default().into_ref(vm);
15151528
let supports_dir_fd = PySet::default().into_ref(vm);

0 commit comments

Comments
 (0)