Add a test for path_open read rights
This commit is contained in:
committed by
Dan Gohman
parent
d651408b5a
commit
5efa640e23
@@ -43,3 +43,24 @@ pub unsafe fn create_file(dir_fd: wasi::Fd, filename: &str) {
|
||||
);
|
||||
wasi::fd_close(file_fd).expect("closing a file");
|
||||
}
|
||||
|
||||
// Returns: (rights_base, rights_inheriting)
|
||||
pub unsafe fn fd_get_rights(fd: wasi::Fd) -> (wasi::Rights, wasi::Rights) {
|
||||
let fdstat = wasi::fd_fdstat_get(fd).expect("fd_fdstat_get failed");
|
||||
(fdstat.fs_rights_base, fdstat.fs_rights_inheriting)
|
||||
}
|
||||
|
||||
pub unsafe fn drop_rights(
|
||||
fd: wasi::Fd,
|
||||
drop_base: wasi::Rights,
|
||||
drop_inheriting: wasi::Rights,
|
||||
) {
|
||||
let (current_base, current_inheriting) = fd_get_rights(fd);
|
||||
|
||||
let new_base = current_base & !drop_base;
|
||||
let new_inheriting = current_inheriting & !drop_inheriting;
|
||||
|
||||
wasi::fd_fdstat_set_rights(fd, new_base, new_inheriting).expect(
|
||||
"dropping fd rights",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user