Skip to content

Commit 970bc16

Browse files
committed
usb/dev-mtp: use GDateTime for formatting timestamp for objects
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 <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent 3968355 commit 970bc16

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

hw/usb/dev-mtp.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,9 @@ static void usb_mtp_add_str(MTPData *data, const char *str)
772772

773773
static void usb_mtp_add_time(MTPData *data, time_t time)
774774
{
775-
char buf[16];
776-
struct tm tm;
777-
778-
gmtime_r(&time, &tm);
779-
strftime(buf, sizeof(buf), "%Y%m%dT%H%M%S", &tm);
780-
usb_mtp_add_str(data, buf);
775+
g_autoptr(GDateTime) then = g_date_time_new_from_unix_utc(time);
776+
g_autofree char *thenstr = g_date_time_format(then, "%Y%m%dT%H%M%S");
777+
usb_mtp_add_str(data, thenstr);
781778
}
782779

783780
/* ----------------------------------------------------------------------- */

0 commit comments

Comments
 (0)