Skip to content
Snippets Groups Projects
Commit 3d162e77 authored by Colin Walters's avatar Colin Walters
Browse files

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.
parent 85c9dd5c
Branches
Tags
No related merge requests found
......@@ -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;
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment