summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-04-22 15:40:51 +0100
committerSimon McVittie <smcv@collabora.com>2021-04-22 15:59:05 +0100
commita0750a00b1b2282c9db6becf9a9664e509c84ba3 (patch)
tree561b542a9344c0805b258efed0a7944ee9c1cd9b
parent4c9055ac08bb64dca146724f488cce4c1ce4c628 (diff)
downloadlibglnx-wip/smcv/rewinddir.tar.gz
glnx-dirfd: Add a rewinddir() wrapperwip/smcv/rewinddir
This is useful in the same situations rewinddir() is. My use-case right now is to remove some of the files from a directory, then go back through the directory removing symlinks that pointed to those files. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--glnx-dirfd.c18
-rw-r--r--glnx-dirfd.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/glnx-dirfd.c b/glnx-dirfd.c
index 6d1e2d2..0a63bcb 100644
--- a/glnx-dirfd.c
+++ b/glnx-dirfd.c
@@ -174,6 +174,24 @@ glnx_dirfd_iterator_next_dent (GLnxDirFdIterator *dfd_iter,
}
/**
+ * glnx_dirfd_iterator_rewind:
+ * @dfd_iter: A directory iterator
+ *
+ * Rewind to the beginning of @dfd_iter. The next call to
+ * glnx_dirfd_iterator_next_dent() will provide the first entry in the
+ * directory.
+ */
+void
+glnx_dirfd_iterator_rewind (GLnxDirFdIterator *dfd_iter)
+{
+ GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
+
+ g_return_if_fail (dfd_iter->initialized);
+
+ rewinddir (real_dfd_iter->d);
+}
+
+/**
* glnx_dirfd_iterator_next_dent_ensure_dtype:
* @dfd_iter: A directory iterator
* @out_dent: (out) (transfer none): Pointer to dirent; do not free
diff --git a/glnx-dirfd.h b/glnx-dirfd.h
index 0046ac8..d5773e7 100644
--- a/glnx-dirfd.h
+++ b/glnx-dirfd.h
@@ -66,6 +66,7 @@ gboolean glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator *dfd_ite
struct dirent **out_dent,
GCancellable *cancellable,
GError **error);
+void glnx_dirfd_iterator_rewind (GLnxDirFdIterator *dfd_iter);
void glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxDirFdIterator, glnx_dirfd_iterator_clear)