From 748ae07caf2445f7b75f5c96ae674c6de0b0610a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 16 Jul 2015 18:39:50 +0200 Subject: Add MSVC stl filesystem implementation Closes #199 --- src/lib/utils/filesystem.cpp | 33 ++++++++++++++++++++++++++++++--- src/lib/utils/filesystem.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/utils/filesystem.cpp b/src/lib/utils/filesystem.cpp index 0a31dec7a..950d4d4e2 100644 --- a/src/lib/utils/filesystem.cpp +++ b/src/lib/utils/filesystem.cpp @@ -1,5 +1,6 @@ /* * (C) 2015 Jack Lloyd +* (C) 2015 Simon Warta (Kullo GmbH) * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -8,7 +9,9 @@ #include #include -#if defined(BOTAN_HAS_BOOST_FILESYSTEM) +#if defined(BOTAN_TARGET_OS_HAS_STL_FILESYSTEM_MSVC) && defined(BOTAN_BUILD_COMPILER_IS_MSVC) + #include +#elif defined(BOTAN_HAS_BOOST_FILESYSTEM) #include #elif defined(BOTAN_TARGET_OS_HAS_READDIR) #include @@ -23,7 +26,29 @@ namespace Botan { namespace { -#if defined(BOTAN_HAS_BOOST_FILESYSTEM) +#if defined(BOTAN_TARGET_OS_HAS_STL_FILESYSTEM_MSVC) && defined(BOTAN_BUILD_COMPILER_IS_MSVC) +std::vector impl_stl_filesystem(const std::string& dir) + { + using namespace std::tr2::sys; + + std::vector out; + + path p(dir); + + if (is_directory(p)) + { + for (recursive_directory_iterator itr(p), end; itr != end; ++itr) + { + if (is_regular_file(itr->path())) + { + out.push_back(itr->path().string()); + } + } + } + + return out; + } +#elif defined(BOTAN_HAS_BOOST_FILESYSTEM) std::vector impl_boost_filesystem(const std::string& dir_path) { namespace fs = boost::filesystem; @@ -86,7 +111,9 @@ std::vector get_files_recursive(const std::string& dir) { std::vector files; -#if defined(BOTAN_HAS_BOOST_FILESYSTEM) +#if defined(BOTAN_TARGET_OS_HAS_STL_FILESYSTEM_MSVC) && defined(BOTAN_BUILD_COMPILER_IS_MSVC) + files = impl_stl_filesystem(dir); +#elif defined(BOTAN_HAS_BOOST_FILESYSTEM) files = impl_boost_filesystem(dir); #elif defined(BOTAN_TARGET_OS_HAS_READDIR) files = impl_readdir(dir); diff --git a/src/lib/utils/filesystem.h b/src/lib/utils/filesystem.h index 6f9b5196e..419f94b99 100644 --- a/src/lib/utils/filesystem.h +++ b/src/lib/utils/filesystem.h @@ -1,5 +1,6 @@ /* * (C) 2015 Jack Lloyd +* (C) 2015 Simon Warta (Kullo GmbH) * * Botan is released under the Simplified BSD License (see license.txt) */ -- cgit v1.2.3