[glib/glib-2-38] gfileutils: Make -Werror=format-nonliteral happy
- From: John Ralls <jralls src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-38] gfileutils: Make -Werror=format-nonliteral happy
- Date: Sun, 29 Sep 2013 18:35:31 +0000 (UTC)
commit 55e6a475b6042298f46297f680247e5ac6f89262
Author: Colin Walters <walters verbum org>
Date: Mon Jun 17 17:49:12 2013 -0400
gfileutils: Make -Werror=format-nonliteral happy
I tried to please it by using G_GNUC_FORMAT, but that didn't work, so
let's just fall back to pushing an ignore.
https://bugzilla.gnome.org/show_bug.cgi?id=702516
glib/gfileutils.c | 50 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index 7e5bedc..51a3464 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -1004,25 +1004,47 @@ rename_file (const char *old_name,
return TRUE;
}
-/* format string must have two '%s':
- *
- * - the place for the filename
- * - the place for the strerror
- */
-static void
-format_error_message (GError **error,
- const gchar *filename,
+static char *
+format_error_message (const gchar *filename,
+ const gchar *format_string) G_GNUC_FORMAT(2);
+
+static char *
+format_error_message (const gchar *filename,
const gchar *format_string)
{
gint saved_errno = errno;
gchar *display_name;
+ gchar *msg;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
display_name = g_filename_display_name (filename);
+ msg = g_strdup_printf (format_string, display_name, g_strerror (saved_errno));
+ g_free (display_name);
- g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
- format_string, display_name, g_strerror (saved_errno));
+#pragma GCC diagnostic pop
- g_free (display_name);
+ return msg;
+}
+
+/* format string must have two '%s':
+ *
+ * - the place for the filename
+ * - the place for the strerror
+ */
+static void
+set_file_error (GError **error,
+ const gchar *filename,
+ const gchar *format_string)
+
+{
+ int saved_errno = errno;
+ char *msg = format_error_message (filename, format_string);
+
+ g_set_error_literal (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
+ msg);
+ g_free (msg);
}
static gchar *
@@ -1044,7 +1066,7 @@ write_to_temp_file (const gchar *contents,
if (fd == -1)
{
- format_error_message (err, tmp_name, _("Failed to create file '%s': %s"));
+ set_file_error (err, tmp_name, _("Failed to create file '%s': %s"));
goto out;
}
@@ -1068,7 +1090,7 @@ write_to_temp_file (const gchar *contents,
if (errno == EINTR)
continue;
- format_error_message (err, tmp_name, _("Failed to write file '%s': write() failed: %s"));
+ set_file_error (err, tmp_name, _("Failed to write file '%s': write() failed: %s"));
close (fd);
g_unlink (tmp_name);
@@ -1108,7 +1130,7 @@ write_to_temp_file (const gchar *contents,
*/
if (g_lstat (dest_file, &statbuf) == 0 && statbuf.st_size > 0 && fsync (fd) != 0)
{
- format_error_message (err, tmp_name, _("Failed to write file '%s': fsync() failed: %s"));
+ set_file_error (err, tmp_name, _("Failed to write file '%s': fsync() failed: %s"));
close (fd);
g_unlink (tmp_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]