8#include <botan/exceptn.h>
10#include <botan/assert.h>
11#include <botan/internal/filesystem.h>
12#include <botan/internal/target_info.h>
18#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
22 #include <sys/types.h>
23#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
33#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
35std::vector<std::string> impl_readdir(std::string_view dir_path) {
36 std::vector<std::string> out;
37 std::deque<std::string> dir_list;
38 dir_list.push_back(std::string(dir_path));
40 while(!dir_list.empty()) {
41 const std::string cur_path = dir_list[0];
44 std::unique_ptr<DIR, std::function<int(DIR*)>> dir(::opendir(cur_path.c_str()), ::closedir);
47 while(
struct dirent* dirent = ::readdir(dir.get())) {
48 const std::string filename = dirent->d_name;
49 if(filename ==
"." || filename ==
"..") {
53 std::ostringstream full_path_sstr;
54 full_path_sstr << cur_path <<
"/" << filename;
55 const std::string full_path = full_path_sstr.str();
59 if(::stat(full_path.c_str(), &stat_buf) == -1) {
63 if(S_ISDIR(stat_buf.st_mode)) {
64 dir_list.push_back(full_path);
65 }
else if(S_ISREG(stat_buf.st_mode)) {
66 out.push_back(full_path);
75#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
77std::vector<std::string> impl_win32(std::string_view dir_path) {
78 std::vector<std::string> out;
79 std::deque<std::string> dir_list;
80 dir_list.push_back(std::string(dir_path));
82 while(!dir_list.empty()) {
83 const std::string cur_path = dir_list[0];
86 WIN32_FIND_DATAA find_data;
87 HANDLE dir = ::FindFirstFileA((cur_path +
"/*").c_str(), &find_data);
89 if(dir != INVALID_HANDLE_VALUE) {
91 const std::string filename = find_data.cFileName;
92 if(filename ==
"." || filename ==
"..")
94 const std::string full_path = cur_path +
"/" + filename;
96 if(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
97 dir_list.push_back(full_path);
99 out.push_back(full_path);
101 }
while(::FindNextFileA(dir, &find_data));
114#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
116#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
124 std::vector<std::string> files;
126#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
127 files = impl_readdir(dir);
128#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
129 files = impl_win32(dir);
135 std::sort(files.begin(), files.end());
bool has_filesystem_impl()
std::vector< std::string > get_files_recursive(std::string_view dir)