mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 07:18:58 +00:00
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 <d.csapak@proxmox.com>
This commit is contained in:
parent
c0d2165d75
commit
db1da0f645
@ -3,10 +3,11 @@ use anyhow::{bail, Error};
|
|||||||
/// Safe bindings to libc timelocal
|
/// Safe bindings to libc timelocal
|
||||||
///
|
///
|
||||||
/// We set tm_isdst to -1.
|
/// We set tm_isdst to -1.
|
||||||
pub fn timelocal(mut t: libc::tm) -> Result<i64, Error> {
|
/// This also normalizes the parameter
|
||||||
|
pub fn timelocal(t: &mut libc::tm) -> Result<i64, Error> {
|
||||||
t.tm_isdst = -1;
|
t.tm_isdst = -1;
|
||||||
|
|
||||||
let epoch = unsafe { libc::mktime(&mut t) };
|
let epoch = unsafe { libc::mktime(t) };
|
||||||
if epoch == -1 {
|
if epoch == -1 {
|
||||||
bail!("libc::mktime failed for {:?}", t);
|
bail!("libc::mktime failed for {:?}", t);
|
||||||
}
|
}
|
||||||
@ -16,10 +17,11 @@ pub fn timelocal(mut t: libc::tm) -> Result<i64, Error> {
|
|||||||
/// Safe bindings to libc timegm
|
/// Safe bindings to libc timegm
|
||||||
///
|
///
|
||||||
/// We set tm_isdst to 0.
|
/// We set tm_isdst to 0.
|
||||||
pub fn timegm(mut t: libc::tm) -> Result<i64, Error> {
|
/// This also normalizes the parameter
|
||||||
|
pub fn timegm(t: &mut libc::tm) -> Result<i64, Error> {
|
||||||
t.tm_isdst = 0;
|
t.tm_isdst = 0;
|
||||||
|
|
||||||
let epoch = unsafe { libc::timegm(&mut t) };
|
let epoch = unsafe { libc::timegm(t) };
|
||||||
if epoch == -1 {
|
if epoch == -1 {
|
||||||
bail!("libc::timegm failed for {:?}", t);
|
bail!("libc::timegm failed for {:?}", t);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user