Dpkg::Vendor::Debian: Add support for new hardening branch feature
[dpkg.git] / lib / dpkg / fsys-iter.c
blob807aabbb011339b34b35daf45a90eca13b094401
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * fsys-iter.c - filesystem nodes iterators
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2000, 2001 Wichert Akkerman <wakkerma@debian.org>
7 * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 #include <config.h>
24 #include <compat.h>
26 #include <stdlib.h>
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/pkg-list.h>
32 #include "fsys.h"
35 * Reverse iterator.
39 * Initializes an iterator that appears to go through the file list ‘files’
40 * in reverse order, returning the namenode from each. What actually happens
41 * is that we walk the list here, building up a reverse list, and then peel
42 * it apart one entry at a time.
44 void
45 fsys_hash_rev_iter_init(struct fsys_hash_rev_iter *iter,
46 struct fsys_namenode_list *files)
48 struct fsys_namenode_list *newent;
50 iter->todo = NULL;
51 while (files) {
52 newent = m_malloc(sizeof(*newent));
53 newent->namenode = files->namenode;
54 newent->next = iter->todo;
55 iter->todo = newent;
56 files = files->next;
60 struct fsys_namenode *
61 fsys_hash_rev_iter_next(struct fsys_hash_rev_iter *iter)
63 struct fsys_namenode *next;
64 struct fsys_namenode_list *todo;
66 todo = iter->todo;
67 if (!todo)
68 return NULL;
69 next = todo->namenode;
70 iter->todo = todo->next;
71 free(todo);
73 return next;
77 * Clients must call this function to clean up the fsys_hash_rev_iter
78 * if they wish to break out of the iteration before it is all done.
79 * Calling this function is not necessary if fsys_hash_rev_iter_next() has
80 * been called until it returned 0.
82 void
83 fsys_hash_rev_iter_abort(struct fsys_hash_rev_iter *iter)
85 while (fsys_hash_rev_iter_next(iter))
90 * Iterator for packages owning a file.
93 struct fsys_node_pkgs_iter {
94 struct pkg_list *pkg_node;
97 struct fsys_node_pkgs_iter *
98 fsys_node_pkgs_iter_new(struct fsys_namenode *fnn)
100 struct fsys_node_pkgs_iter *iter;
102 iter = m_malloc(sizeof(*iter));
103 iter->pkg_node = fnn->packages;
105 return iter;
108 struct pkginfo *
109 fsys_node_pkgs_iter_next(struct fsys_node_pkgs_iter *iter)
111 struct pkg_list *pkg_node;
113 if (iter->pkg_node == NULL)
114 return NULL;
116 pkg_node = iter->pkg_node;
117 iter->pkg_node = pkg_node->next;
119 return pkg_node->pkg;
122 void
123 fsys_node_pkgs_iter_free(struct fsys_node_pkgs_iter *iter)
125 free(iter);