0.3.0: converge relibc to upstream 0.6.0 + Red Bear patches
This commit is contained in:
@@ -2,7 +2,7 @@ sys_includes = ["sys/types.h"]
|
||||
include_guard = "_SYS_TIMEB_H"
|
||||
language = "C"
|
||||
style = "Tag"
|
||||
no_includes = true
|
||||
no_includes = false
|
||||
cpp_compat = true
|
||||
|
||||
[enum]
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
//! 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.
|
||||
|
||||
use core::ptr::NonNull;
|
||||
|
||||
#[allow(deprecated)]
|
||||
use crate::header::sys_time::gettimeofday;
|
||||
use crate::{
|
||||
header::sys_time::{gettimeofday, timeval, timezone},
|
||||
platform::types::*,
|
||||
header::{sys_select::timeval, sys_time::timezone},
|
||||
platform::types::{c_int, c_short, c_ushort, time_t},
|
||||
};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/timeb.h.html>.
|
||||
#[deprecated]
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timeb {
|
||||
@@ -14,18 +27,38 @@ pub struct timeb {
|
||||
pub dstflag: c_short,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/009695399/functions/ftime.html>.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that `tp` is convertible to a `&mut
|
||||
/// MaybeUninit<timeb>`.
|
||||
#[deprecated]
|
||||
#[allow(deprecated)]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ftime(tp: *mut timeb) -> c_int {
|
||||
// SAFETY: the caller is required to ensure that the pointer is valid.
|
||||
let tp_maybe_uninit = unsafe { NonNull::new_unchecked(tp).as_uninit_mut() };
|
||||
|
||||
let mut tv = timeval::default();
|
||||
let mut tz = timezone::default();
|
||||
if gettimeofday(&mut tv, &mut tz) < 0 {
|
||||
|
||||
// SAFETY: tv and tz are created above, and thus will coerce to valid
|
||||
// pointers.
|
||||
if unsafe {
|
||||
#[allow(deprecated)]
|
||||
gettimeofday(&raw mut tv, &raw 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;
|
||||
#[allow(deprecated)]
|
||||
tp_maybe_uninit.write(timeb {
|
||||
time: tv.tv_sec,
|
||||
millitm: (tv.tv_usec / 1000) as c_ushort,
|
||||
timezone: tz.tz_minuteswest as c_short,
|
||||
dstflag: tz.tz_dsttime as c_short,
|
||||
});
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user