Skip to content
Snippets Groups Projects
Commit 2b828581 authored by Philip Withnall's avatar Philip Withnall
Browse files

glnx-fdio: Add wrappers around fstat() and fstatat() to handle errors


Add two inline wrappers around fstat() and fstatat() which handle
retrying on EINTR and return other errors using GError, to be consistent
with other glnx functions.

Signed-off-by: default avatarPhilip Withnall <withnall@endlessm.com>
parent 6746e6f5
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,8 @@
#include <libgen.h>
#undef basename
#include <glnx-errors.h>
G_BEGIN_DECLS
/* Irritatingly, g_basename() which is what we want
......@@ -155,5 +157,54 @@ int glnx_renameat2_noreplace (int olddirfd, const char *oldpath,
int glnx_renameat2_exchange (int olddirfd, const char *oldpath,
int newdirfd, const char *newpath);
/**
* glnx_fstat:
* @fd: FD to stat
* @buf: (out caller-allocates): Return location for stat details
* @error: Return location for a #GError, or %NULL
*
* Wrapper around fstat() which adds #GError support and ensures that it retries
* on %EINTR.
*
* Returns: %TRUE on success, %FALSE otherwise
* Since: UNRELEASED
*/
static inline gboolean
glnx_fstat (int fd,
struct stat *buf,
GError **error)
{
if (TEMP_FAILURE_RETRY (fstat (fd, buf)) != 0)
return glnx_throw_errno (error);
return TRUE;
}
/**
* glnx_fstatat:
* @dfd: Directory FD to stat beneath
* @path: Path to stat beneath @dfd
* @buf: (out caller-allocates): Return location for stat details
* @flags: Flags to pass to fstatat()
* @error: Return location for a #GError, or %NULL
*
* Wrapper around fstatat() which adds #GError support and ensures that it
* retries on %EINTR.
*
* Returns: %TRUE on success, %FALSE otherwise
* Since: UNRELEASED
*/
static inline gboolean
glnx_fstatat (int dfd,
const gchar *path,
struct stat *buf,
int flags,
GError **error)
{
if (TEMP_FAILURE_RETRY (fstatat (dfd, path, buf, flags)) != 0)
return glnx_throw_errno (error);
return TRUE;
}
G_END_DECLS
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment