]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - libfdisk/src/iter.c
2 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
11 * @short_description: unified iterator
13 * The iterator keeps the direction and the last position for access to the
14 * internal library tables/lists.
16 * It's very unusual to use the same iterator on multiple places in your
17 * application or share the same iterator, for this purpose libfdisk does not
18 * provide reference counting for this object. It's recommended to initialize
19 * the iterator by fdisk_new_iter() at begin of your function and then
20 * fdisk_free_iter() before you return from the function.
22 * Don't forget to call fdisk_reset_iter() if you want to use the iterator more
33 * @direction: FDISK_INTER_{FOR,BACK}WARD direction
35 * Returns: newly allocated generic libmount iterator.
37 struct fdisk_iter
*fdisk_new_iter(int direction
)
39 struct fdisk_iter
*itr
= calloc(1, sizeof(*itr
));
42 itr
->direction
= direction
;
48 * @itr: iterator pointer
50 * Deallocates the iterator.
52 void fdisk_free_iter(struct fdisk_iter
*itr
)
59 * @itr: iterator pointer
60 * @direction: FDISK_ITER_{FOR,BACK}WARD or -1 to keep the direction unchanged
62 * Resets the iterator.
64 void fdisk_reset_iter(struct fdisk_iter
*itr
, int direction
)
67 direction
= itr
->direction
;
69 memset(itr
, 0, sizeof(*itr
));
70 itr
->direction
= direction
;
74 * fdisk_iter_get_direction:
75 * @itr: iterator pointer
77 * Returns: FDISK_INTER_{FOR,BACK}WARD
79 int fdisk_iter_get_direction(struct fdisk_iter
*itr
)
81 return itr
->direction
;