From e8a6474236f945d1d7675f0e25d68cfc5137eb84 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Jul 2020 12:15:04 +0100 Subject: [PATCH] libsysprof-capture: Use strftime() to format dates rather than GLib This means we lose support for local timezones other than UTC, but is otherwise equivalent. Signed-off-by: Philip Withnall Helps: #40 --- .../sysprof-capture-writer.c | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c index 88c5697a..ca3dd56c 100644 --- a/src/libsysprof-capture/sysprof-capture-writer.c +++ b/src/libsysprof-capture/sysprof-capture-writer.c @@ -478,8 +478,8 @@ SysprofCaptureWriter * sysprof_capture_writer_new_from_fd (int fd, size_t buffer_size) { - g_autofree gchar *nowstr = NULL; - g_autoptr(GDateTime) now = NULL; + time_t now; + char now_str[sizeof ("2020-06-30T14:34:00Z")]; SysprofCaptureWriter *self; SysprofCaptureFileHeader *header; size_t header_len = sizeof(*header); @@ -511,18 +511,14 @@ sysprof_capture_writer_new_from_fd (int fd, self->len = buffer_size; self->next_counter_id = 1; - now = g_date_time_new_now_local (); - -#if GLIB_CHECK_VERSION(2, 62, 0) - nowstr = g_date_time_format_iso8601 (now); -#else - { - GTimeVal tv; - - g_date_time_to_timeval (now, &tv); - nowstr = g_time_val_to_iso8601 (&tv); - } -#endif + /* Format the time as ISO 8601, in UTC */ + time (&now); + if (strftime (now_str, sizeof (now_str), "%FT%TZ", gmtime (&now)) == 0) + { + free (self->buf); + free (self); + return NULL; + } header = sysprof_capture_writer_allocate (self, &header_len);