2 * libdpkg - Debian packaging suite library routines
3 * treewalk.h - directory tree walk support
5 * Copyright © 2013-2015 Guillem Jover <guillem@debian.org>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 #ifndef LIBDPKG_TREEWALK_H
22 #define LIBDPKG_TREEWALK_H
24 #include <dpkg/macros.h>
27 #include <sys/types.h>
34 * @defgroup treewalk Directory tree walking
35 * @ingroup dpkg-internal
39 enum DPKG_ATTR_ENUM_FLAGS treewalk_options
{
41 TREEWALK_FORCE_STAT
= DPKG_BIT(0),
42 TREEWALK_FOLLOW_LINKS
= DPKG_BIT(1),
47 typedef int treenode_visit_func(struct treenode
*node
);
48 typedef bool treenode_skip_func(struct treenode
*node
);
49 typedef int treenode_sort_func(struct treenode
*node
);
51 struct treewalk_funcs
{
52 treenode_visit_func
*visit
;
53 treenode_sort_func
*sort
;
54 treenode_skip_func
*skip
;
57 #if __STDC_VERSION__ > 201710L
58 #define TREEWALK_OBJECT (struct treewalk_funcs){ }
60 #define TREEWALK_OBJECT (struct treewalk_funcs){ 0 }
64 treewalk_open(const char *rootdir
, enum treewalk_options options
,
65 const struct treewalk_funcs
*funcs
);
67 treewalk_node(struct treeroot
*tree
);
69 treewalk_next(struct treeroot
*tree
);
71 treewalk_close(struct treeroot
*tree
);
74 treewalk(const char *rootdir
, enum treewalk_options options
,
75 struct treewalk_funcs
*funcs
);
78 treenode_get_parent(struct treenode
*node
);
80 treenode_get_name(struct treenode
*node
);
82 treenode_get_pathname(struct treenode
*node
);
84 treenode_get_virtname(struct treenode
*node
);
86 treenode_get_mode(struct treenode
*node
);
88 treenode_get_stat(struct treenode
*node
);
94 #endif /* LIBDPKG_TREEWALK_H */