summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-04-21 13:14:47 +0100
committerPhilip Withnall <withnall@endlessm.com>2017-04-21 14:06:19 +0100
commit2b82858169186d2758c5fe60ad1099eab7f46a25 (patch)
treec50957bd6e9503e38c367437baeb46fa53bce7d5
parent6746e6f54d6d29066011bace3b7820e9ca240ac6 (diff)
downloadlibglnx-2b82858169186d2758c5fe60ad1099eab7f46a25.tar.gz
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: Philip Withnall <withnall@endlessm.com>
-rw-r--r--glnx-fdio.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/glnx-fdio.h b/glnx-fdio.h
index c3e7573..56d0b78 100644
--- a/glnx-fdio.h
+++ b/glnx-fdio.h
@@ -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