8#include <botan/exceptn.h>
9#include <botan/internal/filesystem.h>
15#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
16 #include <sys/types.h>
20#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
30#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
32std::vector<std::string> impl_readdir(std::string_view dir_path)
34 std::vector<std::string> out;
35 std::deque<std::string> dir_list;
36 dir_list.push_back(std::string(dir_path));
38 while(!dir_list.empty())
40 const std::string cur_path = dir_list[0];
43 std::unique_ptr<DIR, std::function<int (DIR*)>> dir(::opendir(cur_path.c_str()), ::closedir);
47 while(
struct dirent* dirent = ::readdir(dir.get()))
49 const std::string filename = dirent->d_name;
50 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)
62 if(S_ISDIR(stat_buf.st_mode))
63 dir_list.push_back(full_path);
64 else if(S_ISREG(stat_buf.st_mode))
65 out.push_back(full_path);
73#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
75std::vector<std::string> impl_win32(std::string_view dir_path)
77 std::vector<std::string> out;
78 std::deque<std::string> dir_list;
79 dir_list.push_back(std::string(dir_path));
81 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)
93 const std::string filename = find_data.cFileName;
94 if(filename ==
"." || filename ==
"..")
96 const std::string full_path = cur_path +
"/" + filename;
98 if(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
100 dir_list.push_back(full_path);
104 out.push_back(full_path);
107 while(::FindNextFileA(dir, &find_data));
121#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
123#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
132 std::vector<std::string> files;
134#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
135 files = impl_readdir(dir);
136#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
137 files = impl_win32(dir);
143 std::sort(files.begin(), files.end());
#define BOTAN_UNUSED(...)
bool has_filesystem_impl()
std::vector< std::string > get_files_recursive(std::string_view dir)