From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] tools/time: give tm struct as mut reference
Date: Thu, 3 Sep 2020 13:37:59 +0200 [thread overview]
Message-ID: <20200903113759.32251-1-d.csapak@proxmox.com> (raw)
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 is necessary for my upcoming series for calendarevents
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 033e778..50cce01 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<i64, Error> {
+/// This also normalizes the parameter
+pub fn timelocal(t: &mut libc::tm) -> Result<i64, Error> {
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<i64, Error> {
/// Safe bindings to libc timegm
///
/// 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;
- let epoch = unsafe { libc::timegm(&mut t) };
+ let epoch = unsafe { libc::timegm(t) };
if epoch == -1 {
bail!("libc::timegm failed for {:?}", t);
}
--
2.20.1
next reply other threads:[~2020-09-03 11:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-03 11:37 Dominik Csapak [this message]
2020-09-04 4:40 ` [pbs-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200903113759.32251-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox