8#include <botan/exceptn.h>
10#include <botan/assert.h>
11#include <botan/internal/filesystem.h>
17#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
21 #include <sys/types.h>
22#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
32#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
34std::vector<std::string> impl_readdir(std::string_view dir_path) {
35 std::vector<std::string> out;
36 std::deque<std::string> dir_list;
37 dir_list.push_back(std::string(dir_path));
39 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);
46 while(
struct dirent* dirent = ::readdir(dir.get())) {
47 const std::string filename = dirent->d_name;
48 if(filename ==
"." || filename ==
"..") {
52 std::ostringstream full_path_sstr;
53 full_path_sstr << cur_path <<
"/" << filename;
54 const std::string full_path = full_path_sstr.str();
58 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);
74#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
76std::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()) {
82 const std::string cur_path = dir_list[0];
85 WIN32_FIND_DATAA find_data;
86 HANDLE dir = ::FindFirstFileA((cur_path +
"/*").c_str(), &find_data);
88 if(dir != INVALID_HANDLE_VALUE) {
90 const std::string filename = find_data.cFileName;
91 if(filename ==
"." || filename ==
"..")
93 const std::string full_path = cur_path +
"/" + filename;
95 if(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
96 dir_list.push_back(full_path);
98 out.push_back(full_path);
100 }
while(::FindNextFileA(dir, &find_data));
113#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
115#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
123 std::vector<std::string> files;
125#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
126 files = impl_readdir(dir);
127#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
128 files = impl_win32(dir);
134 std::sort(files.begin(), files.end());
bool has_filesystem_impl()
std::vector< std::string > get_files_recursive(std::string_view dir)