Use unsafe blocks in sys/time.h implementation
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_time.h.html>.
|
||||
|
||||
// TODO: set this for entire crate when possible
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
error::ResultExt,
|
||||
@@ -85,7 +88,7 @@ pub struct timezone {
|
||||
#[deprecated]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int {
|
||||
Sys::getitimer(which, &mut *value)
|
||||
Sys::getitimer(which, unsafe { &mut *value })
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
@@ -101,7 +104,7 @@ pub unsafe extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int
|
||||
#[deprecated]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
Sys::gettimeofday(Out::nonnull(tp), Out::nullable(tzp))
|
||||
Sys::gettimeofday(unsafe { Out::nonnull(tp) }, unsafe { Out::nullable(tzp) })
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
@@ -121,7 +124,7 @@ pub unsafe extern "C" fn setitimer(
|
||||
ovalue: *mut itimerval,
|
||||
) -> c_int {
|
||||
// TODO setitimer is unimplemented on Redox
|
||||
Sys::setitimer(which, &*value, ovalue.as_mut())
|
||||
Sys::setitimer(which, unsafe { &*value }, unsafe { ovalue.as_mut() })
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
@@ -133,7 +136,7 @@ pub unsafe extern "C" fn setitimer(
|
||||
/// Specifications Issue 6, and then unmarked in Issue 7.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c_int {
|
||||
let path = CStr::from_ptr(path);
|
||||
let path = unsafe { CStr::from_ptr(path) };
|
||||
// Nullptr is valid here, it means "use current time"
|
||||
let times_spec = if times.is_null() {
|
||||
null()
|
||||
@@ -141,18 +144,18 @@ pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c
|
||||
{
|
||||
[
|
||||
timespec {
|
||||
tv_sec: (*times.offset(0)).tv_sec,
|
||||
tv_nsec: ((*times.offset(0)).tv_usec as c_long) * 1000,
|
||||
tv_sec: unsafe { (*times.offset(0)).tv_sec },
|
||||
tv_nsec: (unsafe { (*times.offset(0)).tv_usec } as c_long) * 1000,
|
||||
},
|
||||
timespec {
|
||||
tv_sec: (*times.offset(1)).tv_sec,
|
||||
tv_nsec: ((*times.offset(1)).tv_usec as c_long) * 1000,
|
||||
tv_sec: unsafe { (*times.offset(1)).tv_sec },
|
||||
tv_nsec: (unsafe { (*times.offset(1)).tv_usec } as c_long) * 1000,
|
||||
},
|
||||
]
|
||||
}
|
||||
.as_ptr()
|
||||
};
|
||||
Sys::utimens(path, times_spec)
|
||||
unsafe { Sys::utimens(path, times_spec) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user