[glib] Switch all open() calls to use g_open()



commit 6e64ba58b90d1d834a6b5f61acec6755e4b80072
Author: Colin Walters <walters verbum org>
Date:   Mon Aug 27 18:30:06 2012 -0400

    Switch all open() calls to use g_open()
    
    Because it now handles EINTR.  And we should do so.  While most people
    use Linux, which tries very hard to avoid propagating EINTR back up
    into userspace, it can still happen.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682833

 gio/glocalfile.c          |    2 +-
 gio/glocalfileinfo.c      |    4 ++--
 gio/gresource-tool.c      |    3 ++-
 gio/tests/gdbus-peer.c    |    2 +-
 gio/tests/pollable.c      |    3 ++-
 glib/giounix.c            |    8 ++------
 glib/gtestutils.c         |    3 ++-
 glib/tests/mappedfile.c   |    5 +++--
 gobject/glib-genmarshal.c |    3 ++-
 9 files changed, 17 insertions(+), 16 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 0c54727..c0b6f9d 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -2017,7 +2017,7 @@ g_local_file_trash (GFile         *file,
     infofile = g_build_filename (infodir, infoname, NULL);
     g_free (infoname);
 
-    fd = open (infofile, O_CREAT | O_EXCL, 0666);
+    fd = g_open (infofile, O_CREAT | O_EXCL, 0666);
   } while (fd == -1 && errno == EEXIST);
 
   g_free (basename);
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 407067a..af4fc43 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -1247,10 +1247,10 @@ get_content_type (const char          *basename,
 	    sniff_length = 4096;
 
 #ifdef O_NOATIME	  
-          fd = open (path, O_RDONLY | O_NOATIME);
+          fd = g_open (path, O_RDONLY | O_NOATIME, 0);
           if (fd < 0 && errno == EPERM)
 #endif
-	    fd = open (path, O_RDONLY);
+	    fd = g_open (path, O_RDONLY, 0);
 
 	  if (fd != -1)
 	    {
diff --git a/gio/gresource-tool.c b/gio/gresource-tool.c
index db607fc..70c9ee6 100644
--- a/gio/gresource-tool.c
+++ b/gio/gresource-tool.c
@@ -37,6 +37,7 @@
 #endif
 
 #include <gio/gio.h>
+#include <glib/gstdio.h>
 #include <gi18n.h>
 
 /* GResource functions {{{1 */
@@ -142,7 +143,7 @@ get_elf (const gchar *file,
   if (elf_version (EV_CURRENT) == EV_NONE )
     return NULL;
 
-  *fd = open (file, O_RDONLY);
+  *fd = g_open (file, O_RDONLY, 0);
   if (*fd < 0)
     return NULL;
 
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index 934ebda..d25f9f6 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -178,7 +178,7 @@ test_interface_method_call (GDBusConnection       *connection,
 
       error = NULL;
 
-      fd = open (path, O_RDONLY);
+      fd = g_open (path, O_RDONLY, 0);
       g_unix_fd_list_append (fd_list, fd, &error);
       g_assert_no_error (error);
       close (fd);
diff --git a/gio/tests/pollable.c b/gio/tests/pollable.c
index e30abf8..8a27da8 100644
--- a/gio/tests/pollable.c
+++ b/gio/tests/pollable.c
@@ -19,6 +19,7 @@
  */
 
 #include <gio/gio.h>
+#include <glib/gstdio.h>
 
 #ifdef G_OS_UNIX
 #include <fcntl.h>
@@ -154,7 +155,7 @@ test_pollable_unix (void)
   g_object_unref (out);
 
   /* Non-pipe/socket unix streams are not pollable */
-  fd = open ("/dev/null", O_RDWR);
+  fd = g_open ("/dev/null", O_RDWR, 0);
   g_assert_cmpint (fd, !=, -1);
   in = G_POLLABLE_INPUT_STREAM (g_unix_input_stream_new (fd, FALSE));
   out = g_unix_output_stream_new (fd, FALSE);
diff --git a/glib/giounix.c b/glib/giounix.c
index 969c3cc..ee5ae54 100644
--- a/glib/giounix.c
+++ b/glib/giounix.c
@@ -42,6 +42,7 @@
 #include <errno.h>
 #include <string.h>
 #include <fcntl.h>
+#include <glib/gstdio.h>
 
 #include "giochannel.h"
 
@@ -525,12 +526,7 @@ g_io_channel_new_file (const gchar *filename,
 
   create_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
 
-  do
-    {
-      fid = open (filename, flags, create_mode);
-    }
-  while (fid == -1 && errno == EINTR);
-
+  fid = g_open (filename, flags, create_mode);
   if (fid == -1)
     {
       int err = errno;
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index e4b4331..f0e8f6c 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -28,6 +28,7 @@
 #include <sys/wait.h>
 #include <sys/time.h>
 #include <fcntl.h>
+#include <glib/gstdio.h>
 #endif
 #include <string.h>
 #include <stdlib.h>
@@ -2177,7 +2178,7 @@ g_test_trap_fork (guint64        usec_timeout,
       close (stderr_pipe[0]);
       close (stdtst_pipe[0]);
       if (!(test_trap_flags & G_TEST_TRAP_INHERIT_STDIN))
-        fd0 = open ("/dev/null", O_RDONLY);
+        fd0 = g_open ("/dev/null", O_RDONLY, 0);
       if (sane_dup2 (stdout_pipe[1], 1) < 0 || sane_dup2 (stderr_pipe[1], 2) < 0 || (fd0 >= 0 && sane_dup2 (fd0, 0) < 0))
         g_error ("failed to dup2() in forked test program: %s", g_strerror (errno));
       if (fd0 >= 3)
diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c
index f61f44e..3de9393 100644
--- a/glib/tests/mappedfile.c
+++ b/glib/tests/mappedfile.c
@@ -6,6 +6,7 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#include <glib/gstdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -120,7 +121,7 @@ test_writable_fd (void)
     }
 
   error = NULL;
-  fd = open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
+  fd = g_open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
   g_assert (fd != -1);
   file = g_mapped_file_new_from_fd (fd, TRUE, &error);
   g_assert_no_error (error);
@@ -135,7 +136,7 @@ test_writable_fd (void)
   close (fd);
 
   error = NULL;
-  fd = open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
+  fd = g_open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
   g_assert (fd != -1);
   file = g_mapped_file_new_from_fd (fd, TRUE, &error);
   g_assert_no_error (error);
diff --git a/gobject/glib-genmarshal.c b/gobject/glib-genmarshal.c
index 5aaaf1d..24b95ff 100644
--- a/gobject/glib-genmarshal.c
+++ b/gobject/glib-genmarshal.c
@@ -28,6 +28,7 @@
 #endif
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <glib/gstdio.h>
 
 #undef G_LOG_DOMAIN
 #define G_LOG_DOMAIN "GLib-Genmarshal"
@@ -848,7 +849,7 @@ main (int   argc,
 	/* Mostly for Win32. This is equivalent to opening /dev/stdin */
 	fd = dup (0);
       else
-	fd = open (file, O_RDONLY);
+	fd = g_open (file, O_RDONLY, 0);
 
       if (fd < 0)
 	{



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