Skip to content

Commit 3968355

Browse files
committed
block: use GDateTime for formatting timestamp when dumping snapshot info
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: Max Reitz <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent 85cd1cc commit 3968355

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

block/qapi.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,21 +663,18 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
663663

664664
void bdrv_snapshot_dump(QEMUSnapshotInfo *sn)
665665
{
666-
char date_buf[128], clock_buf[128];
666+
char clock_buf[128];
667667
char icount_buf[128] = {0};
668-
struct tm tm;
669-
time_t ti;
670668
int64_t secs;
671669
char *sizing = NULL;
672670

673671
if (!sn) {
674672
qemu_printf("%-10s%-17s%8s%20s%13s%11s",
675673
"ID", "TAG", "VM SIZE", "DATE", "VM CLOCK", "ICOUNT");
676674
} else {
677-
ti = sn->date_sec;
678-
localtime_r(&ti, &tm);
679-
strftime(date_buf, sizeof(date_buf),
680-
"%Y-%m-%d %H:%M:%S", &tm);
675+
g_autoptr(GDateTime) date = g_date_time_new_from_unix_local(sn->date_sec);
676+
g_autofree char *date_buf = g_date_time_format(date, "%Y-%m-%d %H:%M:%S");
677+
681678
secs = sn->vm_clock_nsec / 1000000000;
682679
snprintf(clock_buf, sizeof(clock_buf),
683680
"%02d:%02d:%02d.%03d",

0 commit comments

Comments
 (0)