From 681eef7fbb5b13fd747ad074eea216c72e673940 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 27 Feb 2014 11:46:49 -0500 Subject: fileutils: Add gs_file_open_dir_fd_at() This will be used in the OSTree checkout code, where we want to mkdir() and then open it. --- src/gsystem-file-utils.c | 28 ++++++++++++++++++++++++++++ src/gsystem-file-utils.h | 6 ++++++ 2 files changed, 34 insertions(+) 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 @@ -463,6 +463,34 @@ gs_file_open_dir_fd (GFile *path, return TRUE; } +/** + * 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 diff --git a/src/gsystem-file-utils.h b/src/gsystem-file-utils.h index 2da6646..85ef9ad 100644 --- a/src/gsystem-file-utils.h +++ b/src/gsystem-file-utils.h @@ -75,6 +75,12 @@ gboolean gs_file_open_dir_fd (GFile *path, GCancellable *cancellable, GError **error); +gboolean gs_file_open_dir_fd_at (int parent_dfd, + const char *name, + int *out_fd, + GCancellable *cancellable, + GError **error); + gboolean gs_file_open_in_tmpdir_at (int tmpdir_fd, int mode, char **out_name, -- cgit v1.2.1