diff options
author | Karel Zak | 2011-06-09 21:59:52 +0200 |
---|---|---|
committer | Karel Zak | 2011-06-09 21:59:52 +0200 |
commit | 2aefc0a8f267ddb57804755af9095d3cd5ceb0d7 (patch) | |
tree | 8601dca144fccbb9b6a895708868a520caccaddf /libmount/src/iter.c | |
parent | build-sys: use top-level directory for libuuid rather than shlibs/uuid (diff) | |
download | kernel-qcow2-util-linux-2aefc0a8f267ddb57804755af9095d3cd5ceb0d7.tar.gz kernel-qcow2-util-linux-2aefc0a8f267ddb57804755af9095d3cd5ceb0d7.tar.xz kernel-qcow2-util-linux-2aefc0a8f267ddb57804755af9095d3cd5ceb0d7.zip |
build-sys: use top-level directory for libmount rather than shlibs/mount
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/iter.c')
-rw-r--r-- | libmount/src/iter.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/libmount/src/iter.c b/libmount/src/iter.c new file mode 100644 index 000000000..99fedd17b --- /dev/null +++ b/libmount/src/iter.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2009 Karel Zak <kzak@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +/** + * SECTION: iter + * @title: Iterator + * @short_description: unified iterator + * + * The iterator keeps direction and last position for access to the internal + * library tables/lists. + */ +#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. + */ +struct libmnt_iter *mnt_new_iter(int direction) +{ + struct libmnt_iter *itr = calloc(1, sizeof(*itr)); + if (!itr) + return NULL; + itr->direction = direction; + return itr; +} + +/** + * mnt_free_iter: + * @itr: iterator pointer + * + * Deallocates iterator. + */ +void mnt_free_iter(struct libmnt_iter *itr) +{ + free(itr); +} + +/** + * mnt_reset_iter: + * @itr: iterator pointer + * @direction: MNT_INTER_{FOR,BACK}WARD or -1 to keep the derection unchanged + * + * Resets iterator. + */ +void mnt_reset_iter(struct libmnt_iter *itr, int direction) +{ + assert(itr); + + if (direction == -1) + direction = itr->direction; + + if (itr) { + memset(itr, 0, sizeof(*itr)); + itr->direction = direction; + } +} + +/** + * mnt_iter_get_direction: + * @itr: iterator pointer + * + * Returns: MNT_INTER_{FOR,BACK}WARD or negative number in case of error. + */ +int mnt_iter_get_direction(struct libmnt_iter *itr) +{ + assert(itr); + return itr ? itr->direction : -EINVAL; +} |