]> www.infradead.org Git - qemu-nvme.git/commitdiff
usb/dev-mtp: use GDateTime for formatting timestamp for objects
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 30 Apr 2021 11:59:06 +0000 (12:59 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 14 Jun 2021 12:28:50 +0000 (13:28 +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

index 2a895a73b083315d617e73a12cbd4c9131d02e7a..c1d1694fd0b45e22b62594d592076860d1352f5b 100644 (file)
@@ -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);
 }
 
 /* ----------------------------------------------------------------------- */