1 /* 2 * libdpkg - Debian packaging suite library routines 3 * treewalk.h - directory tree walk support 4 * 5 * Copyright © 2013-2015 Guillem Jover <guillem@debian.org> 6 * 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. 11 * 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. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef LIBDPKG_TREEWALK_H 22 #define LIBDPKG_TREEWALK_H 23 24 #include <dpkg/macros.h> 25 26 #include <sys/stat.h> 27 #include <sys/types.h> 28 29 #include <stdbool.h> 30 31 DPKG_BEGIN_DECLS 32 33 /** 34 * @defgroup treewalk Directory tree walking 35 * @ingroup dpkg-internal 36 * @{ 37 */ 38 39 enum treewalk_options { 40 TREEWALK_NONE = 0, 41 TREEWALK_FORCE_STAT = DPKG_BIT(0), 42 TREEWALK_FOLLOW_LINKS = DPKG_BIT(1), 43 }; 44 45 struct treenode; 46 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); 50 51 struct treewalk_funcs { 52 treenode_visit_func *visit; 53 treenode_sort_func *sort; 54 treenode_skip_func *skip; 55 }; 56 57 struct treeroot * 58 treewalk_open(const char *rootdir, enum treewalk_options options, 59 struct treewalk_funcs *funcs); 60 struct treenode * 61 treewalk_node(struct treeroot *tree); 62 struct treenode * 63 treewalk_next(struct treeroot *tree); 64 void 65 treewalk_close(struct treeroot *tree); 66 67 int 68 treewalk(const char *rootdir, enum treewalk_options options, 69 struct treewalk_funcs *funcs); 70 71 struct treenode * 72 treenode_get_parent(struct treenode *node); 73 const char * 74 treenode_get_name(struct treenode *node); 75 const char * 76 treenode_get_pathname(struct treenode *node); 77 const char * 78 treenode_get_virtname(struct treenode *node); 79 mode_t 80 treenode_get_mode(struct treenode *node); 81 struct stat * 82 treenode_get_stat(struct treenode *node); 83 84 /** @} */ 85 86 DPKG_END_DECLS 87 88 #endif /* LIBDPKG_TREEWALK_H */ 89