summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gsystem-file-utils.c44
-rw-r--r--src/gsystem-file-utils.h10
2 files changed, 54 insertions, 0 deletions
diff --git a/src/gsystem-file-utils.c b/src/gsystem-file-utils.c
index c157d1d..30ccc9d 100644
--- a/src/gsystem-file-utils.c
+++ b/src/gsystem-file-utils.c
@@ -492,6 +492,50 @@ gs_file_open_dir_fd_at (int parent_dfd,
}
/**
+ * gs_opendirat_with_errno:
+ * @dfd: File descriptor for origin directory
+ * @name: Pathname, relative to @dfd
+ * @follow: Whether or not to follow symbolic links
+ *
+ * Use openat() to open a directory, using a standard set of flags.
+ * This function sets errno.
+ */
+int
+gs_opendirat_with_errno (int dfd, const char *path, gboolean follow)
+{
+ int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY;
+ if (!follow)
+ flags |= O_NOFOLLOW;
+ return openat (dfd, path, flags);
+}
+
+/**
+ * gs_opendirat:
+ * @dfd: File descriptor for origin directory
+ * @path: Pathname, relative to @dfd
+ * @follow: Whether or not to follow symbolic links
+ * @error: Error
+ *
+ * Use openat() to open a directory, using a standard set of flags.
+ */
+gboolean
+gs_opendirat (int dfd,
+ const char *path,
+ gboolean follow,
+ int *out_fd,
+ GError **error)
+{
+ int ret = gs_opendirat_with_errno (dfd, path, follow);
+ if (ret == -1)
+ {
+ _set_error_from_errno ("openat", error);
+ return FALSE;
+ }
+ *out_fd = ret;
+ return TRUE;
+}
+
+/**
* gs_file_open_in_tmpdir_at:
* @tmpdir_fd: Directory to place temporary file
* @mode: Default mode (will be affected by umask)
diff --git a/src/gsystem-file-utils.h b/src/gsystem-file-utils.h
index d792c81..82b7070 100644
--- a/src/gsystem-file-utils.h
+++ b/src/gsystem-file-utils.h
@@ -81,6 +81,16 @@ gboolean gs_file_open_dir_fd_at (int parent_dfd,
GCancellable *cancellable,
GError **error);
+int gs_opendirat_with_errno (int dfd,
+ const char *path,
+ gboolean follow);
+gboolean gs_opendirat (int dfd,
+ const char *path,
+ gboolean follow,
+ int *out_fd,
+ GError **error);
+
+
gboolean gs_file_open_in_tmpdir_at (int tmpdir_fd,
int mode,
char **out_name,