Add docs for sys/timeb.h, require unsafe blocks

This commit is contained in:
Peter Limkilde Svendsen
2024-10-31 12:04:48 +00:00
committed by Jeremy Soller
parent 1d5c02ab92
commit 76f36f09df
2 changed files with 21 additions and 6 deletions
+1
View File
@@ -55,6 +55,7 @@ pub mod sys_socket;
pub mod sys_stat;
pub mod sys_statvfs;
pub mod sys_time;
#[deprecated]
pub mod sys_timeb;
//pub mod sys_times;
pub mod arch_aarch64_user;
+20 -6
View File
@@ -1,10 +1,21 @@
//! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html
//! `sys/timeb.h` implementation.
//!
//! See <https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/timeb.h.html>.
//!
//! # Deprecation
//! The `ftime()` function was marked as legacy in the Open Group Base
//! Specifications Issue 6, and the entire `sys/timeb.h` header was removed in
//! Issue 7.
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
use crate::{
header::sys_time::{gettimeofday, timeval, timezone},
platform::types::*,
};
/// See <https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/timeb.h.html>.
#[repr(C)]
#[derive(Default)]
pub struct timeb {
@@ -14,18 +25,21 @@ pub struct timeb {
pub dstflag: c_short,
}
/// See <https://pubs.opengroup.org/onlinepubs/009695399/functions/ftime.html>.
#[no_mangle]
pub unsafe extern "C" fn ftime(tp: *mut timeb) -> c_int {
let tp_mut = unsafe { &mut *tp };
let mut tv = timeval::default();
let mut tz = timezone::default();
if gettimeofday(&mut tv, &mut tz) < 0 {
if unsafe { gettimeofday(&mut tv, &mut tz) } < 0 {
return -1;
}
(*tp).time = tv.tv_sec;
(*tp).millitm = (tv.tv_usec / 1000) as c_ushort;
(*tp).timezone = tz.tz_minuteswest as c_short;
(*tp).dstflag = tz.tz_dsttime as c_short;
tp_mut.time = tv.tv_sec;
tp_mut.millitm = (tv.tv_usec / 1000) as c_ushort;
tp_mut.timezone = tz.tz_minuteswest as c_short;
tp_mut.dstflag = tz.tz_dsttime as c_short;
0
}