1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // directory.h author Russ Combs <rucombs@cisco.com>
19 
20 #ifndef DIRECTORY_H
21 #define DIRECTORY_H
22 
23 // simple directory traversal
24 
25 #include <dirent.h>
26 #include <string>
27 
28 class Directory
29 {
30 public:
31     Directory(const char*, const char* filter = nullptr);
32     ~Directory();
33 
34     int error_on_open();
35     void rewind();
36     const char* next();
37 
38 private:
39     DIR* dir;
40     std::string root;
41     std::string filter;
42     std::string path;
43     unsigned len;
44     Directory* sub;
45     int error;
46 };
47 
48 #endif
49 
50