8#include <botan/exceptn.h>
10#include <botan/internal/filesystem.h>
16#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
20 #include <sys/types.h>
21#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
31#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
33std::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()) {
39 const std::string cur_path = dir_list[0];
42 std::unique_ptr<DIR, std::function<int(DIR*)>> dir(::opendir(cur_path.c_str()), ::closedir);
45 while(
struct dirent* dirent = ::readdir(dir.get())) {
46 const std::string filename = dirent->d_name;
47 if(filename ==
"." || filename ==
"..") {
51 std::ostringstream full_path_sstr;
52 full_path_sstr << cur_path <<
"/" << filename;
53 const std::string full_path = full_path_sstr.str();
57 if(::stat(full_path.c_str(), &stat_buf) == -1) {
61 if(S_ISDIR(stat_buf.st_mode)) {
62 dir_list.push_back(full_path);
63 }
else if(S_ISREG(stat_buf.st_mode)) {
64 out.push_back(full_path);
73#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
75std::vector<std::string> impl_win32(std::string_view dir_path) {
76 std::vector<std::string> out;
77 std::deque<std::string> dir_list;
78 dir_list.push_back(std::string(dir_path));
80 while(!dir_list.empty()) {
81 const std::string cur_path = dir_list[0];
84 WIN32_FIND_DATAA find_data;
85 HANDLE dir = ::FindFirstFileA((cur_path +
"/*").c_str(), &find_data);
87 if(dir != INVALID_HANDLE_VALUE) {
89 const std::string filename = find_data.cFileName;
90 if(filename ==
"." || filename ==
"..")
92 const std::string full_path = cur_path +
"/" + filename;
94 if(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
95 dir_list.push_back(full_path);
97 out.push_back(full_path);
99 }
while(::FindNextFileA(dir, &find_data));
112#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
114#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
122 std::vector<std::string> files;
124#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
125 files = impl_readdir(dir);
126#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
127 files = impl_win32(dir);
133 std::sort(files.begin(), files.end());
bool has_filesystem_impl()
std::vector< std::string > get_files_recursive(std::string_view dir)