8#include <botan/exceptn.h>
9#include <botan/internal/filesystem.h>
14#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
15 #include <sys/types.h>
19#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
29#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
31std::vector<std::string> impl_readdir(
const std::string& dir_path)
33 std::vector<std::string> out;
34 std::deque<std::string> dir_list;
35 dir_list.push_back(dir_path);
37 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);
46 while(
struct dirent* dirent = ::readdir(dir.get()))
48 const std::string filename = dirent->d_name;
49 if(filename ==
"." || filename ==
"..")
51 const std::string full_path = cur_path +
"/" + filename;
55 if(::stat(full_path.c_str(), &stat_buf) == -1)
58 if(S_ISDIR(stat_buf.st_mode))
59 dir_list.push_back(full_path);
60 else if(S_ISREG(stat_buf.st_mode))
61 out.push_back(full_path);
69#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
71std::vector<std::string> impl_win32(
const std::string& dir_path)
73 std::vector<std::string> out;
74 std::deque<std::string> dir_list;
75 dir_list.push_back(dir_path);
77 while(!dir_list.empty())
79 const std::string cur_path = dir_list[0];
82 WIN32_FIND_DATAA find_data;
83 HANDLE dir = ::FindFirstFileA((cur_path +
"/*").c_str(), &find_data);
85 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)
96 dir_list.push_back(full_path);
100 out.push_back(full_path);
103 while(::FindNextFileA(dir, &find_data));
117#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
119#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
128 std::vector<std::string> files;
130#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
131 files = impl_readdir(dir);
132#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
133 files = impl_win32(dir);
139 std::sort(files.begin(), files.end());
#define BOTAN_UNUSED(...)
std::vector< std::string > get_files_recursive(const std::string &dir)
bool has_filesystem_impl()