Coverage Report

Created: 2026-09-28 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/libsmartcols/src/iter.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2009-2014 Karel Zak <kzak@redhat.com>
3
 * Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
4
 *
5
 * This file may be redistributed under the terms of the
6
 * GNU Lesser General Public License.
7
 */
8
9
/**
10
 * SECTION: iter
11
 * @title: Iterator
12
 * @short_description: unified iterator
13
 *
14
 * The iterator keeps the direction and the last position
15
 * for access to the internal library tables/lists.
16
 */
17
18
#include <string.h>
19
#include <stdlib.h>
20
21
#include "smartcolsP.h"
22
23
/**
24
 * scols_new_iter:
25
 * @direction: SCOLS_INTER_{FOR,BACK}WARD direction
26
 *
27
 * Returns: newly allocated generic libmount iterator.
28
 */
29
struct libscols_iter *scols_new_iter(int direction)
30
0
{
31
0
  struct libscols_iter *itr = calloc(1, sizeof(*itr));
32
0
  if (!itr)
33
0
    return NULL;
34
0
  itr->direction = direction;
35
0
  return itr;
36
0
}
37
38
/**
39
 * scols_free_iter:
40
 * @itr: iterator pointer
41
 *
42
 * Deallocates the iterator.
43
 */
44
void scols_free_iter(struct libscols_iter *itr)
45
0
{
46
0
  free(itr);
47
0
}
48
49
/**
50
 * scols_reset_iter:
51
 * @itr: iterator pointer
52
 * @direction: SCOLS_INTER_{FOR,BACK}WARD or -1 to keep the direction unchanged
53
 *
54
 * Resets the iterator.
55
 */
56
void scols_reset_iter(struct libscols_iter *itr, int direction)
57
0
{
58
0
  if (direction == -1)
59
0
    direction = itr->direction;
60
61
0
  memset(itr, 0, sizeof(*itr));
62
0
  itr->direction = direction;
63
0
}
64
65
/**
66
 * scols_iter_get_direction:
67
 * @itr: iterator pointer
68
 *
69
 * Returns: SCOLS_INTER_{FOR,BACK}WARD
70
 */
71
int scols_iter_get_direction(const struct libscols_iter *itr)
72
0
{
73
0
  return itr->direction;
74
0
}