Skip to content

Commit

Permalink
Implement umask and settime.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Mar 31, 2023
1 parent c5cb41a commit 8e1770b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions c-scape/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod kill;
mod pid;
mod sid;
mod uid;
mod umask;
mod wait;

// this entire module is
Expand Down
8 changes: 8 additions & 0 deletions c-scape/src/process/umask.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use libc::mode_t;
use rustix::fs::Mode;

#[no_mangle]
unsafe extern "C" fn umask(mask: mode_t) -> mode_t {
libc!(libc::umask(mask));
rustix::process::umask(Mode::from_raw_mode(mask)).as_raw_mode()
}
23 changes: 23 additions & 0 deletions c-scape/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use core::convert::TryInto;
use errno::{set_errno, Errno};
use libc::c_int;

use crate::convert_res;

fn rustix_timespec_to_libc_timespec(
rustix_time: rustix::time::Timespec,
) -> Result<libc::timespec, core::num::TryFromIntError> {
Expand Down Expand Up @@ -94,3 +96,24 @@ unsafe extern "C" fn nanosleep(req: *const libc::timespec, rem: *mut libc::times
}
}
}

#[no_mangle]
unsafe extern "C" fn clock_settime(id: c_int, tp: *mut libc::timespec) -> c_int {
libc!(libc::clock_settime(id, tp));

let id = match id {
libc::CLOCK_MONOTONIC => rustix::time::ClockId::Monotonic,
libc::CLOCK_REALTIME => rustix::time::ClockId::Realtime,
_ => panic!("unimplemented clock({})", id),
};

let timespec = rustix::time::Timespec {
tv_sec: (*tp).tv_sec.into(),
tv_nsec: (*tp).tv_nsec as _,
};

match convert_res(rustix::time::clock_settime(id, timespec)) {
Some(()) => 0,
None => -1,
}
}

0 comments on commit 8e1770b

Please sign in to comment.