glib: Don’t use time(NULL) to get current time

Use either g_get_real_time() or g_date_time_new_now_local(). This means
we don’t need to worry about time_t being 32b in future (the year 2038
problem), and it makes the need for error handling a bit more explicit.
Improve the error handling in several cases.

Based on a patch by Niels De Graef
(https://gitlab.gnome.org/GNOME/glib/merge_requests/142).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/1402
This commit is contained in:
Philip Withnall
2018-07-06 13:49:55 +01:00
parent c5321810f4
commit 92e059280f
7 changed files with 33 additions and 22 deletions

View File

@@ -603,7 +603,7 @@ keyring_generate_entry (const gchar *cookie_context,
gchar **lines;
gint max_line_id;
GString *new_contents;
guint64 now;
gint64 now;
gboolean have_id;
gint use_id;
gchar *use_cookie;
@@ -658,7 +658,7 @@ keyring_generate_entry (const gchar *cookie_context,
}
new_contents = g_string_new (NULL);
now = (guint64) time (NULL);
now = g_get_real_time () / G_USEC_PER_SEC;
changed_file = FALSE;
max_line_id = 0;
@@ -672,7 +672,7 @@ keyring_generate_entry (const gchar *cookie_context,
gchar **tokens;
gchar *endp;
gint line_id;
guint64 line_when;
gint64 line_when;
gboolean keep_entry;
if (line[0] == '\0')
@@ -807,9 +807,9 @@ keyring_generate_entry (const gchar *cookie_context,
g_free (raw_cookie);
g_string_append_printf (new_contents,
"%d %" G_GUINT64_FORMAT " %s\n",
"%d %" G_GINT64_FORMAT " %s\n",
*out_id,
(guint64) time (NULL),
g_get_real_time () / G_USEC_PER_SEC,
*out_cookie);
changed_file = TRUE;
}