summaryrefslogtreecommitdiffstats
path: root/shlibs/mount/src/iter.c
diff options
context:
space:
mode:
authorKarel Zak2010-01-05 14:58:16 +0100
committerKarel Zak2010-06-03 15:20:10 +0200
commitefab4b61572516f4c7579e345165e0094c1a2450 (patch)
treedb65d4cf4892fcef156681040f3448e696994f85 /shlibs/mount/src/iter.c
parentlibmount: add mnt_optstr_* functions (diff)
downloadkernel-qcow2-util-linux-efab4b61572516f4c7579e345165e0094c1a2450.tar.gz
kernel-qcow2-util-linux-efab4b61572516f4c7579e345165e0094c1a2450.tar.xz
kernel-qcow2-util-linux-efab4b61572516f4c7579e345165e0094c1a2450.zip
libmount: add list routines and generic iterator
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/iter.c')
-rw-r--r--shlibs/mount/src/iter.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/shlibs/mount/src/iter.c b/shlibs/mount/src/iter.c
new file mode 100644
index 000000000..d64f2d40d
--- /dev/null
+++ b/shlibs/mount/src/iter.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "mountP.h"
+
+/**
+ * mnt_new_iter:
+ * @direction: MNT_INTER_{FOR,BACK}WARD direction
+ *
+ * Returns newly allocated generic libmount iterator.
+ */
+mnt_iter *mnt_new_iter(int direction)
+{
+ mnt_iter *itr = calloc(1, sizeof(struct _mnt_iter));
+ if (!itr)
+ return NULL;
+ itr->direction = direction;
+ return itr;
+}
+
+/**
+ * mnt_free_iter:
+ * @itr: iterator pointer
+ *
+ * Deallocates iterator.
+ */
+void mnt_free_iter(mnt_iter *itr)
+{
+ free(itr);
+}
+
+/**
+ * mnt_reset_iter:
+ * @itr: iterator pointer
+ * @direction: MNT_INTER_{FOR,BACK}WARD iterator direction
+ *
+ * Resets iterator.
+ */
+void mnt_reset_iter(mnt_iter *itr, int direction)
+{
+ assert(itr);
+
+ if (itr) {
+ memset(itr, 0, sizeof(struct _mnt_iter));
+ itr->direction = direction;
+ }
+}