[glib] GLocalFileOutputStream: Further deduplicate error code path



commit 7fc2ab9493dbb480e2b6815813af9cf8bbfc081e
Author: Colin Walters <walters verbum org>
Date:   Thu May 9 18:47:50 2013 +0100

    GLocalFileOutputStream: Further deduplicate error code path
    
    Just code cleanup.
    
    https://bugzilla.gnome.org/699959

 gio/glocalfileoutputstream.c |   56 ++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 32 deletions(-)
---
diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
index 520f771..b408ae9 100644
--- a/gio/glocalfileoutputstream.c
+++ b/gio/glocalfileoutputstream.c
@@ -544,6 +544,28 @@ _g_local_file_output_stream_new (int fd)
   return G_FILE_OUTPUT_STREAM (stream);
 }
 
+static void
+set_error_from_open_errno (const char *filename,
+                           GError    **error)
+{
+  int errsv = errno;
+  
+  if (errsv == EINVAL)
+    /* This must be an invalid filename, on e.g. FAT */
+    g_set_error_literal (error, G_IO_ERROR,
+                         G_IO_ERROR_INVALID_FILENAME,
+                         _("Invalid filename"));
+  else
+    {
+      char *display_name = g_filename_display_name (filename);
+      g_set_error (error, G_IO_ERROR,
+                   g_io_error_from_errno (errsv),
+                   _("Error opening file '%s': %s"),
+                      display_name, g_strerror (errsv));
+      g_free (display_name);
+    }
+}
+
 static GFileOutputStream *
 output_stream_open (const char    *filename,
                     gint           open_flags,
@@ -557,22 +579,7 @@ output_stream_open (const char    *filename,
   fd = g_open (filename, open_flags, mode);
   if (fd == -1)
     {
-      int errsv = errno;
-
-      if (errsv == EINVAL)
-       /* This must be an invalid filename, on e.g. FAT */
-       g_set_error_literal (error, G_IO_ERROR,
-                             G_IO_ERROR_INVALID_FILENAME,
-                             _("Invalid filename"));
-      else
-       {
-         char *display_name = g_filename_display_name (filename);
-         g_set_error (error, G_IO_ERROR,
-                      g_io_error_from_errno (errsv),
-                      _("Error opening file '%s': %s"),
-                      display_name, g_strerror (errsv));
-         g_free (display_name);
-       }
+      set_error_from_open_errno (filename, error);
       return NULL;
     }
   
@@ -1111,22 +1118,7 @@ _g_local_file_output_stream_replace (const char        *filename,
     }
   else if (fd == -1)
     {
-      int errsv = errno;
-
-      if (errsv == EINVAL)
-       /* This must be an invalid filename, on e.g. FAT */
-       g_set_error_literal (error, G_IO_ERROR,
-                             G_IO_ERROR_INVALID_FILENAME,
-                             _("Invalid filename"));
-      else
-       {
-         char *display_name = g_filename_display_name (filename);
-         g_set_error (error, G_IO_ERROR,
-                      g_io_error_from_errno (errsv),
-                      _("Error opening file '%s': %s"),
-                      display_name, g_strerror (errsv));
-         g_free (display_name);
-       }
+      set_error_from_open_errno (filename, error);
       return NULL;
     }
   


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]