From db1da0f6459d7e07e03788a10e3fe96e27decc26 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 3 Sep 2020 13:37:59 +0200 Subject: [PATCH] tools/time: give tm struct as mut reference mktime/timegm can modify the timestruct (to normalize the time, e.g. convert the january 40 to february 9) to use that feature, we have to give a mutable reference, else the struct will be copied and the original left untouched Signed-off-by: Dominik Csapak --- proxmox/src/tools/time.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxmox/src/tools/time.rs b/proxmox/src/tools/time.rs index 033e7789..50cce017 100644 --- a/proxmox/src/tools/time.rs +++ b/proxmox/src/tools/time.rs @@ -3,10 +3,11 @@ use anyhow::{bail, Error}; /// Safe bindings to libc timelocal /// /// We set tm_isdst to -1. -pub fn timelocal(mut t: libc::tm) -> Result { +/// This also normalizes the parameter +pub fn timelocal(t: &mut libc::tm) -> Result { t.tm_isdst = -1; - let epoch = unsafe { libc::mktime(&mut t) }; + let epoch = unsafe { libc::mktime(t) }; if epoch == -1 { bail!("libc::mktime failed for {:?}", t); } @@ -16,10 +17,11 @@ pub fn timelocal(mut t: libc::tm) -> Result { /// Safe bindings to libc timegm /// /// We set tm_isdst to 0. -pub fn timegm(mut t: libc::tm) -> Result { +/// This also normalizes the parameter +pub fn timegm(t: &mut libc::tm) -> Result { t.tm_isdst = 0; - let epoch = unsafe { libc::timegm(&mut t) }; + let epoch = unsafe { libc::timegm(t) }; if epoch == -1 { bail!("libc::timegm failed for {:?}", t); }