~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libmount/src/iter.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
 
3
 *
 
4
 * This file may be redistributed under the terms of the
 
5
 * GNU Lesser General Public License.
 
6
 */
 
7
 
 
8
/**
 
9
 * SECTION: iter
 
10
 * @title: Iterator
 
11
 * @short_description: unified iterator
 
12
 *
 
13
 * The iterator keeps direction and last position for access to the internal
 
14
 * library tables/lists.
 
15
 */
 
16
#include <stdio.h>
 
17
#include <string.h>
 
18
#include <stdlib.h>
 
19
 
 
20
#include "mountP.h"
 
21
 
 
22
/**
 
23
 * mnt_new_iter:
 
24
 * @direction: MNT_INTER_{FOR,BACK}WARD direction
 
25
 *
 
26
 * Returns: newly allocated generic libmount iterator.
 
27
 */
 
28
struct libmnt_iter *mnt_new_iter(int direction)
 
29
{
 
30
        struct libmnt_iter *itr = calloc(1, sizeof(*itr));
 
31
        if (!itr)
 
32
                return NULL;
 
33
        itr->direction = direction;
 
34
        return itr;
 
35
}
 
36
 
 
37
/**
 
38
 * mnt_free_iter:
 
39
 * @itr: iterator pointer
 
40
 *
 
41
 * Deallocates iterator.
 
42
 */
 
43
void mnt_free_iter(struct libmnt_iter *itr)
 
44
{
 
45
        free(itr);
 
46
}
 
47
 
 
48
/**
 
49
 * mnt_reset_iter:
 
50
 * @itr: iterator pointer
 
51
 * @direction: MNT_INTER_{FOR,BACK}WARD or -1 to keep the derection unchanged
 
52
 *
 
53
 * Resets iterator.
 
54
 */
 
55
void mnt_reset_iter(struct libmnt_iter *itr, int direction)
 
56
{
 
57
        assert(itr);
 
58
 
 
59
        if (direction == -1)
 
60
                direction = itr->direction;
 
61
 
 
62
        if (itr) {
 
63
                memset(itr, 0, sizeof(*itr));
 
64
                itr->direction = direction;
 
65
        }
 
66
}
 
67
 
 
68
/**
 
69
 * mnt_iter_get_direction:
 
70
 * @itr: iterator pointer
 
71
 *
 
72
 * Returns: MNT_INTER_{FOR,BACK}WARD or negative number in case of error.
 
73
 */
 
74
int mnt_iter_get_direction(struct libmnt_iter *itr)
 
75
{
 
76
        assert(itr);
 
77
        return itr ? itr->direction : -EINVAL;
 
78
}