Skip to content

Commit fd0232d

Browse files
committed
add umask support in os
1 parent ad111b0 commit fd0232d

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
@@ -1280,6 +1280,18 @@ fn os_urandom(size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
12801280
}
12811281
}
12821282

1283+
#[cfg(target_os = "linux")]
1284+
type MODE_t = u32;
1285+
1286+
#[cfg(target_os = "macos")]
1287+
type MODE_t = u16;
1288+
1289+
#[cfg(any(target_os = "macos", target_os = "linux"))]
1290+
fn os_umask(mask: MODE_t, _vm: &VirtualMachine) -> PyResult<MODE_t> {
1291+
let ret_mask = unsafe { libc::umask(mask) };
1292+
Ok(ret_mask)
1293+
}
1294+
12831295
#[pystruct_sequence(name = "os.uname_result")]
12841296
#[derive(Debug)]
12851297
#[cfg(unix)]
@@ -1488,6 +1500,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
14881500
SupportFunc::new(vm, "chmod", os_chmod, Some(false), Some(false), Some(false)),
14891501
#[cfg(not(target_os = "redox"))]
14901502
SupportFunc::new(vm, "chroot", os_chroot, Some(false), None, None),
1503+
SupportFunc::new(vm, "umask", os_umask, Some(false), Some(false), Some(false)),
14911504
]);
14921505
let supports_fd = PySet::default().into_ref(vm);
14931506
let supports_dir_fd = PySet::default().into_ref(vm);

0 commit comments

Comments
 (0)