summaryrefslogtreecommitdiff
path: root/src/gsystem-file-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gsystem-file-utils.c')
-rw-r--r--src/gsystem-file-utils.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/gsystem-file-utils.c b/src/gsystem-file-utils.c
index 27e0e2d..545fb30 100644
--- a/src/gsystem-file-utils.c
+++ b/src/gsystem-file-utils.c
@@ -464,6 +464,34 @@ gs_file_open_dir_fd (GFile *path,
}
/**
+ * gs_file_open_dir_fd_at:
+ * @parent_dfd: Parent directory file descriptor
+ * @name: Directory name
+ * @out_fd: (out): File descriptor for directory
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * On success, sets @out_fd to a file descriptor for the directory
+ * that can be used with UNIX functions such as openat().
+ */
+gboolean
+gs_file_open_dir_fd_at (int parent_dfd,
+ const char *name,
+ int *out_fd,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* Linux specific probably */
+ *out_fd = openat (parent_dfd, name, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC);
+ if (*out_fd == -1)
+ {
+ _set_error_from_errno (error);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
* gs_file_open_in_tmpdir_at:
* @tmpdir_fd: Directory to place temporary file
* @mode: Default mode (will be affected by umask)