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/>.
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/pkg-list.h>
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.
45 fsys_hash_rev_iter_init(struct fsys_hash_rev_iter
*iter
,
46 struct fsys_namenode_list
*files
)
48 struct fsys_namenode_list
*newent
;
52 newent
= m_malloc(sizeof(*newent
));
53 newent
->namenode
= files
->namenode
;
54 newent
->next
= iter
->todo
;
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
;
69 next
= todo
->namenode
;
70 iter
->todo
= todo
->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.
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
;
109 fsys_node_pkgs_iter_next(struct fsys_node_pkgs_iter
*iter
)
111 struct pkg_list
*pkg_node
;
113 if (iter
->pkg_node
== NULL
)
116 pkg_node
= iter
->pkg_node
;
117 iter
->pkg_node
= pkg_node
->next
;
119 return pkg_node
->pkg
;
123 fsys_node_pkgs_iter_free(struct fsys_node_pkgs_iter
*iter
)