[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/13] usb/dev-mtp: use GDateTime for formatting timestamp for obj
From: |
Daniel P . Berrangé |
Subject: |
[PULL 13/13] usb/dev-mtp: use GDateTime for formatting timestamp for objects |
Date: |
Mon, 14 Jun 2021 15:15:49 +0100 |
The GDateTime APIs provided by GLib avoid portability pitfalls, such
as some platforms where 'struct timeval.tv_sec' field is still 'long'
instead of 'time_t'. When combined with automatic cleanup, GDateTime
often results in simpler code too.
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
hw/usb/dev-mtp.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 2a895a73b0..c1d1694fd0 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -772,12 +772,9 @@ static void usb_mtp_add_str(MTPData *data, const char *str)
static void usb_mtp_add_time(MTPData *data, time_t time)
{
- char buf[16];
- struct tm tm;
-
- gmtime_r(&time, &tm);
- strftime(buf, sizeof(buf), "%Y%m%dT%H%M%S", &tm);
- usb_mtp_add_str(data, buf);
+ g_autoptr(GDateTime) then = g_date_time_new_from_unix_utc(time);
+ g_autofree char *thenstr = g_date_time_format(then, "%Y%m%dT%H%M%S");
+ usb_mtp_add_str(data, thenstr);
}
/* ----------------------------------------------------------------------- */
--
2.31.1
- [PULL 03/13] docs: document usage of the authorization framework, (continued)
- [PULL 03/13] docs: document usage of the authorization framework, Daniel P . Berrangé, 2021/06/14
- [PULL 04/13] docs: recommend SCRAM-SHA-256 SASL mech instead of SHA-1 variant, Daniel P . Berrangé, 2021/06/14
- [PULL 05/13] sasl: remove comment about obsolete kerberos versions, Daniel P . Berrangé, 2021/06/14
- [PULL 06/13] migration: add trace point when vm_stop_force_state fails, Daniel P . Berrangé, 2021/06/14
- [PULL 07/13] softmmu: add trace point when bdrv_flush_all fails, Daniel P . Berrangé, 2021/06/14
- [PULL 08/13] block: preserve errno from fdatasync failures, Daniel P . Berrangé, 2021/06/14
- [PULL 10/13] block: remove duplicate trace.h include, Daniel P . Berrangé, 2021/06/14
- [PULL 11/13] migration: use GDateTime for formatting timestamp in snapshot names, Daniel P . Berrangé, 2021/06/14
- [PULL 09/13] block: add trace point when fdatasync fails, Daniel P . Berrangé, 2021/06/14
- [PULL 12/13] block: use GDateTime for formatting timestamp when dumping snapshot info, Daniel P . Berrangé, 2021/06/14
- [PULL 13/13] usb/dev-mtp: use GDateTime for formatting timestamp for objects,
Daniel P . Berrangé <=
- Re: [PULL 00/13] Misc fixes patches, Peter Maydell, 2021/06/14