diff options
-rw-r--r-- | gsystem-file-utils.c | 39 | ||||
-rw-r--r-- | gsystem-file-utils.h | 8 |
2 files changed, 47 insertions, 0 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 28c55d9..c734d2d 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -32,6 +32,7 @@ #include "gsystem-glib-compat.h" #include <glib/gstdio.h> #include <gio/gunixinputstream.h> +#include <gio/gfiledescriptorbased.h> #include <gio/gunixoutputstream.h> #include <glib-unix.h> #include <limits.h> @@ -130,6 +131,44 @@ gs_file_read_noatime (GFile *file, } /** + * gs_stream_fstat: + * @stream: A stream containing a Unix file descriptor + * @stbuf: Memory location to write stat buffer + * @cancellable: + * @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 @cancellable and @error. + */ +gboolean +gs_stream_fstat (GFileDescriptorBased *stream, + struct stat *stbuf, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + int fd; + + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + goto out; + + fd = g_file_descriptor_based_get_fd (stream); + + if (fstat (fd, stbuf) == -1) + { + _set_error_from_errno (error); + goto out; + } + + ret = TRUE; + out: + return ret; +} + +/** * gs_file_map_noatime: (skip) * @file: a #GFile * @cancellable: a #GCancellable diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h index 0d9994d..aae9944 100644 --- a/gsystem-file-utils.h +++ b/gsystem-file-utils.h @@ -22,6 +22,7 @@ #define __GSYSTEM_FILE_UTILS_H__ #include <gio/gio.h> +#include <sys/stat.h> G_BEGIN_DECLS @@ -42,6 +43,13 @@ GMappedFile *gs_file_map_noatime (GFile *file, GCancellable *cancellable, GError **error); +#ifndef __GI_SCANNER__ +gboolean gs_stream_fstat (GFileDescriptorBased *stream, + struct stat *out_stbuf, + GCancellable *cancellable, + GError **error); +#endif + #if GLIB_CHECK_VERSION(2,34,0) GBytes *gs_file_map_readonly (GFile *file, GCancellable *cancellable, |