From 2c869433aad96fab0e7640a2ac7397653b3bdefa Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 10 Sep 2017 06:32:34 -0400 Subject: Well, it compiles --- src/lib/utils/filesystem.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/utils/filesystem.cpp b/src/lib/utils/filesystem.cpp index 36e1f5446..8c899dc9b 100644 --- a/src/lib/utils/filesystem.cpp +++ b/src/lib/utils/filesystem.cpp @@ -1,5 +1,5 @@ /* -* (C) 2015 Jack Lloyd +* (C) 2015,2017 Jack Lloyd * (C) 2015 Simon Warta (Kullo GmbH) * * Botan is released under the Simplified BSD License (see license.txt) @@ -20,6 +20,12 @@ #include #include #include +#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) + #define NOMINMAX 1 + #define _WINSOCKAPI_ // stop windows.h including winsock.h + #include + #include + #include #endif namespace Botan { @@ -48,7 +54,9 @@ std::vector impl_stl_filesystem(const std::string& dir) return out; } + #elif defined(BOTAN_HAS_BOOST_FILESYSTEM) + std::vector impl_boost_filesystem(const std::string& dir_path) { namespace fs = boost::filesystem; @@ -65,6 +73,7 @@ std::vector impl_boost_filesystem(const std::string& dir_path) return out; } + #elif defined(BOTAN_TARGET_OS_HAS_READDIR) std::vector impl_readdir(const std::string& dir_path) { @@ -103,6 +112,45 @@ std::vector impl_readdir(const std::string& dir_path) return out; } + +#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) + +std::vector impl_win32(const std::string& dir_path) + { + std::vector out; + std::deque dir_list; + dir_list.push_back(dir_path); + + while(!dir_list.empty()) + { + const std::string cur_path = dir_list[0]; + dir_list.pop_front(); + + WIN32_FIND_DATA find_data; + HANDLE dir = ::FindFirstFile(cur_path.c_str(), &find_data); + + if(dir != INVALID_HANDLE_VALUE) + { + do + { + const std::string filename = find_data.cFileName; + if(filename == "." || filename == "..") + continue; + const std::string full_path = cur_path + "/" + filename; + + if(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + dir_list.push_back(full_path); + else if(find_data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) + out.push_back(full_path); + } + while(::FindNextFile(dir, &find_data)); + } + + ::FindClose(dir); + } + + return out; +} #endif } @@ -117,6 +165,8 @@ std::vector get_files_recursive(const std::string& dir) files = impl_boost_filesystem(dir); #elif defined(BOTAN_TARGET_OS_HAS_READDIR) files = impl_readdir(dir); +#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) + files = impl_win32(dir); #else BOTAN_UNUSED(dir); throw No_Filesystem_Access(); -- cgit v1.2.3