mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
parent
c1fba4663b
commit
5f9e9cbe74
3 changed files with 45 additions and 6 deletions
|
@ -799,12 +799,14 @@ impl EnvUniversal {
|
||||||
// unlikely to affect users.
|
// unlikely to affect users.
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
{
|
{
|
||||||
let mut times: [libc::timespec; 2] = unsafe { std::mem::zeroed() };
|
use crate::libc::{clock_gettime64, futimens64, timespec64};
|
||||||
times[0].tv_nsec = libc::UTIME_OMIT; // don't change ctime
|
#[allow(clippy::useless_conversion)]
|
||||||
if unsafe { libc::clock_gettime(libc::CLOCK_REALTIME, &mut times[1]) } != 0 {
|
let t0 = timespec64 {
|
||||||
unsafe {
|
tv_sec: 0,
|
||||||
libc::futimens(private_fd.as_raw_fd(), ×[0]);
|
tv_nsec: libc::UTIME_OMIT.try_into().unwrap(), // don't change ctime
|
||||||
}
|
};
|
||||||
|
if let Some(t1) = clock_gettime64(libc::CLOCK_REALTIME) {
|
||||||
|
futimens64(private_fd.as_raw_fd(), t0, t1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
src/libc.c
19
src/libc.c
|
@ -285,3 +285,22 @@ int C_getrusage64(int resource, struct rusage64* usage) {
|
||||||
usage->ru_nsignals = tmp.ru_nsignals;
|
usage->ru_nsignals = tmp.ru_nsignals;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool C_clock_gettime64(clockid_t clock_id, struct timespec64* tp) {
|
||||||
|
struct timespec tp_;
|
||||||
|
if (clock_gettime(clock_id, &tp_) == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
tp->tv_sec = tp_.tv_sec;
|
||||||
|
tp->tv_nsec = tp_.tv_nsec;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool C_futimens64(int fd, struct timespec64 times0, struct timespec64 times1) {
|
||||||
|
struct timespec times[2];
|
||||||
|
times[0].tv_sec = times0.tv_sec;
|
||||||
|
times[0].tv_nsec = times0.tv_nsec;
|
||||||
|
times[1].tv_sec = times1.tv_sec;
|
||||||
|
times[1].tv_nsec = times1.tv_nsec;
|
||||||
|
return futimens(fd, ×[0]) == 0;
|
||||||
|
}
|
||||||
|
|
18
src/libc.rs
18
src/libc.rs
|
@ -201,3 +201,21 @@ pub fn getrusage64(resource: c_int) -> Option<rusage64> {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn C_getrusage64(resource: c_int, usage: *mut rusage64) -> c_int;
|
fn C_getrusage64(resource: c_int, usage: *mut rusage64) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn clock_gettime64(clk_id: libc::clockid_t) -> Option<timespec64> {
|
||||||
|
let mut tp = unsafe { std::mem::zeroed() };
|
||||||
|
if !unsafe { C_clock_gettime64(clk_id, &mut tp) } {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(tp)
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
fn C_clock_gettime64(clk_id: libc::clockid_t, tp: *mut timespec64) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn futimens64(fd: c_int, time0: timespec64, time1: timespec64) -> bool {
|
||||||
|
unsafe { C_futimens64(fd, time0, time1) }
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
fn C_futimens64(fd: c_int, time0: timespec64, time1: timespec64) -> bool;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue