[libglnx] fdio: Add glnx_stream_fstat



commit 3d162e772db80f6664a78583268150d2e1d1d29e
Author: Colin Walters <walters verbum org>
Date:   Tue May 3 17:20:43 2016 -0400

    fdio: Add glnx_stream_fstat
    
    Migrated from libgsystem's `gs_stream_fstat()`.  It's a small function
    but I end up using it in OSTree a fair bit.

 glnx-fdio.c |   28 ++++++++++++++++++++++++++++
 glnx-fdio.h |    6 ++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/glnx-fdio.c b/glnx-fdio.c
index 466cbc4..62371d0 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -748,3 +748,31 @@ glnx_file_replace_contents_with_perms_at (int                   dfd,
  out:
   return ret;
 }
+
+/**
+ * glnx_stream_fstat:
+ * @stream: A stream containing a Unix file descriptor
+ * @stbuf: Memory location to write stat buffer
+ * @error:
+ *
+ * Some streams created via libgsystem are #GUnixInputStream; these do
+ * not support e.g. g_file_input_stream_query_info().  This function
+ * allows dropping to the raw unix fstat() call for these types of
+ * streams, while still conveniently wrapped with the normal GLib
+ * handling of @error.
+ */
+gboolean
+glnx_stream_fstat (GFileDescriptorBased *stream,
+                   struct stat          *stbuf,
+                   GError              **error)
+{
+  int fd = g_file_descriptor_based_get_fd (stream);
+
+  if (fstat (fd, stbuf) == -1)
+    {
+      glnx_set_prefix_error_from_errno (error, "%s", "fstat");
+      return FALSE;
+    }
+
+  return TRUE;
+}
diff --git a/glnx-fdio.h b/glnx-fdio.h
index c0fd4e4..3ca1a66 100644
--- a/glnx-fdio.h
+++ b/glnx-fdio.h
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <glnx-backport-autocleanups.h>
+#include <gio/gfiledescriptorbased.h>
 #include <limits.h>
 #include <dirent.h>
 #include <sys/stat.h>
@@ -121,4 +122,9 @@ glnx_file_copy_at (int                   src_dfd,
                    GCancellable         *cancellable,
                    GError              **error);
 
+gboolean
+glnx_stream_fstat (GFileDescriptorBased *stream,
+                   struct stat          *stbuf,
+                   GError              **error);
+
 G_END_DECLS


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