diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fd1287..c0c002b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ add_library(boost_filesystem add_library(Boost::filesystem ALIAS boost_filesystem) target_include_directories(boost_filesystem PUBLIC include) +target_include_directories(boost_filesystem PRIVATE src) target_compile_definitions(boost_filesystem PUBLIC diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index c8da7d0..21456d0 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -64,6 +64,7 @@ SOURCES = lib boost_filesystem : $(SOURCES).cpp : BOOST_FILESYSTEM_SOURCE + ../src shared:BOOST_FILESYSTEM_DYN_LINK=1 static:BOOST_FILESYSTEM_STATIC_LINK=1 : diff --git a/src/codecvt_error_category.cpp b/src/codecvt_error_category.cpp index 827abca..2b5796e 100644 --- a/src/codecvt_error_category.cpp +++ b/src/codecvt_error_category.cpp @@ -9,13 +9,10 @@ //--------------------------------------------------------------------------------------// +#include "platform_config.hpp" + #include -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -#include #include #include #include diff --git a/src/directory.cpp b/src/directory.cpp index 4ad41b3..ae62f03 100644 --- a/src/directory.cpp +++ b/src/directory.cpp @@ -1,4 +1,4 @@ -// operations.cpp --------------------------------------------------------------------// +// directory.cpp --------------------------------------------------------------------// // Copyright 2002-2009, 2014 Beman Dawes // Copyright 2001 Dietmar Kuehl @@ -11,20 +11,7 @@ //--------------------------------------------------------------------------------------// -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this -#endif - -// Include Boost.Predef first so that windows.h is guaranteed to be not included -#include -#include -#if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN -#include -#endif +#include "platform_config.hpp" #include #include diff --git a/src/exception.cpp b/src/exception.cpp index 9824f0f..e977a38 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -8,6 +8,8 @@ // Library home page: http://www.boost.org/libs/filesystem +#include "platform_config.hpp" + #include #include #include diff --git a/src/operations.cpp b/src/operations.cpp index 4a2e52a..2969c0d 100644 --- a/src/operations.cpp +++ b/src/operations.cpp @@ -11,65 +11,8 @@ //--------------------------------------------------------------------------------------// -// define 64-bit offset macros BEFORE including boost/config.hpp (see ticket #5355) -#if defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__ < 24 -// Android fully supports 64-bit file offsets only for API 24 and above. -// -// Trying to define _FILE_OFFSET_BITS=64 for APIs below 24 -// leads to compilation failure for one or another reason, -// depending on target Android API level, Android NDK version, -// used STL, order of include paths and more. -// For more information, please see: -// - https://github.com/boostorg/filesystem/issues/65 -// - https://github.com/boostorg/filesystem/pull/69 -// -// Android NDK developers consider it the expected behavior. -// See their official position here: -// - https://github.com/android-ndk/ndk/issues/501#issuecomment-326447479 -// - https://android.googlesource.com/platform/bionic/+/a34817457feee026e8702a1d2dffe9e92b51d7d1/docs/32-bit-abi.md#32_bit-abi-bugs -// -// Thus we do not define _FILE_OFFSET_BITS in such case. -#else -// Defining _FILE_OFFSET_BITS=64 should kick in 64-bit off_t's -// (and thus st_size) on 32-bit systems that provide the Large File -// Support (LFS) interface, such as Linux, Solaris, and IRIX. -// -// At the time of this comment writing (March 2018), on most systems -// _FILE_OFFSET_BITS=64 definition is harmless: -// either the definition is supported and enables 64-bit off_t, -// or the definition is not supported and is ignored, in which case -// off_t does not change its default size for the target system -// (which may be 32-bit or 64-bit already). -// Thus it makes sense to have _FILE_OFFSET_BITS=64 defined by default, -// instead of listing every system that supports the definition. -// Those few systems, on which _FILE_OFFSET_BITS=64 is harmful, -// for example this definition causes compilation failure on those systems, -// should be exempt from defining _FILE_OFFSET_BITS by adding -// an appropriate #elif block above with the appropriate comment. -// -// _FILE_OFFSET_BITS must be defined before any headers are included -// to ensure that the definition is available to all included headers. -// That is required at least on Solaris, and possibly on other -// systems as well. -#define _FILE_OFFSET_BITS 64 -#endif +#include "platform_config.hpp" -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this -#endif - -// Include Boost.Predef first so that windows.h is guaranteed to be not included -#include -#include -#if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN -#include -#endif - -#include #include #include #include diff --git a/src/path.cpp b/src/path.cpp index fa4d1f5..5ee9e99 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -7,12 +7,7 @@ // Library home page: http://www.boost.org/libs/filesystem -// Include Boost.Predef first so that windows.h is guaranteed to be not included -#include -#include -#if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN -#include -#endif +#include "platform_config.hpp" // Old standard library configurations, particularly MingGW, don't support wide strings. // Report this with an explicit error message. @@ -21,11 +16,6 @@ # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support # endif -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -#include #include #include // for filesystem_error #include diff --git a/src/path_traits.cpp b/src/path_traits.cpp index 6bb609a..9a018cd 100644 --- a/src/path_traits.cpp +++ b/src/path_traits.cpp @@ -9,11 +9,8 @@ //--------------------------------------------------------------------------------------// -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif +#include "platform_config.hpp" -#include #include #include #include diff --git a/src/platform_config.hpp b/src/platform_config.hpp new file mode 100644 index 0000000..f334136 --- /dev/null +++ b/src/platform_config.hpp @@ -0,0 +1,78 @@ +// platform_config.hpp --------------------------------------------------------------------// + +// Copyright 2020 Andrey Semashev + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See library home page at http://www.boost.org/libs/filesystem + +#ifndef BOOST_FILESYSTEM_PLATFORM_CONFIG_HPP_ +#define BOOST_FILESYSTEM_PLATFORM_CONFIG_HPP_ + +// define 64-bit offset macros BEFORE including boost/config.hpp (see ticket #5355) +#if defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__ < 24 +// Android fully supports 64-bit file offsets only for API 24 and above. +// +// Trying to define _FILE_OFFSET_BITS=64 for APIs below 24 +// leads to compilation failure for one or another reason, +// depending on target Android API level, Android NDK version, +// used STL, order of include paths and more. +// For more information, please see: +// - https://github.com/boostorg/filesystem/issues/65 +// - https://github.com/boostorg/filesystem/pull/69 +// +// Android NDK developers consider it the expected behavior. +// See their official position here: +// - https://github.com/android-ndk/ndk/issues/501#issuecomment-326447479 +// - https://android.googlesource.com/platform/bionic/+/a34817457feee026e8702a1d2dffe9e92b51d7d1/docs/32-bit-abi.md#32_bit-abi-bugs +// +// Thus we do not define _FILE_OFFSET_BITS in such case. +#else +// Defining _FILE_OFFSET_BITS=64 should kick in 64-bit off_t's +// (and thus st_size) on 32-bit systems that provide the Large File +// Support (LFS) interface, such as Linux, Solaris, and IRIX. +// +// At the time of this comment writing (March 2018), on most systems +// _FILE_OFFSET_BITS=64 definition is harmless: +// either the definition is supported and enables 64-bit off_t, +// or the definition is not supported and is ignored, in which case +// off_t does not change its default size for the target system +// (which may be 32-bit or 64-bit already). +// Thus it makes sense to have _FILE_OFFSET_BITS=64 defined by default, +// instead of listing every system that supports the definition. +// Those few systems, on which _FILE_OFFSET_BITS=64 is harmful, +// for example this definition causes compilation failure on those systems, +// should be exempt from defining _FILE_OFFSET_BITS by adding +// an appropriate #elif block above with the appropriate comment. +// +// _FILE_OFFSET_BITS must be defined before any headers are included +// to ensure that the definition is available to all included headers. +// That is required at least on Solaris, and possibly on other +// systems as well. +#define _FILE_OFFSET_BITS 64 +#endif + +#ifndef _POSIX_PTHREAD_SEMANTICS +#define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this +#endif + +#if !defined(_INCLUDE_STDCSOURCE_199901) && (defined(hpux) || defined(_hpux) || defined(__hpux)) +// For HP-UX, request that WCHAR_MAX and WCHAR_MIN be defined as macros, +// not casts. See ticket 5048 +#define _INCLUDE_STDCSOURCE_199901 +#endif + +#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) ||\ + defined(__CYGWIN__) +// Define target Windows version macros before including any other headers +#include +#endif + +#ifndef BOOST_SYSTEM_NO_DEPRECATED +#define BOOST_SYSTEM_NO_DEPRECATED +#endif + +#include + +#endif // BOOST_FILESYSTEM_PLATFORM_CONFIG_HPP_ diff --git a/src/portability.cpp b/src/portability.cpp index 3c1bb75..cda7236 100644 --- a/src/portability.cpp +++ b/src/portability.cpp @@ -9,11 +9,8 @@ //--------------------------------------------------------------------------------------// -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif +#include "platform_config.hpp" -#include #include namespace fs = boost::filesystem; diff --git a/src/unique_path.cpp b/src/unique_path.cpp index 0b073de..56bba4b 100644 --- a/src/unique_path.cpp +++ b/src/unique_path.cpp @@ -10,21 +10,11 @@ //--------------------------------------------------------------------------------------// -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -// Include Boost.Predef first so that windows.h is guaranteed to be not included -#include -#include -#if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN -#include -#endif +#include "platform_config.hpp" #include #include #include -#include #ifdef BOOST_POSIX_API # include diff --git a/src/utf8_codecvt_facet.cpp b/src/utf8_codecvt_facet.cpp index e46778c..e3c51c9 100644 --- a/src/utf8_codecvt_facet.cpp +++ b/src/utf8_codecvt_facet.cpp @@ -3,15 +3,7 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -// For HP-UX, request that WCHAR_MAX and WCHAR_MIN be defined as macros, -// not casts. See ticket 5048 -#define _INCLUDE_STDCSOURCE_199901 - -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -#include +#include "platform_config.hpp" #define BOOST_UTF8_BEGIN_NAMESPACE \ namespace boost { namespace filesystem { namespace detail { diff --git a/src/windows_file_codecvt.cpp b/src/windows_file_codecvt.cpp index 4f656d4..6baf40b 100644 --- a/src/windows_file_codecvt.cpp +++ b/src/windows_file_codecvt.cpp @@ -9,70 +9,55 @@ //--------------------------------------------------------------------------------------// -// Include Boost.Predef first so that windows.h is guaranteed to be not included -#include -#include -#if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN -#include -#endif +#include "platform_config.hpp" -#ifndef BOOST_SYSTEM_NO_DEPRECATED -# define BOOST_SYSTEM_NO_DEPRECATED -#endif - -#include #include // for mbstate_t #ifdef BOOST_WINDOWS_API #include "windows_file_codecvt.hpp" -// Versions of MinGW prior to GCC 4.6 requires this -#ifndef WINVER -# define WINVER 0x0500 -#endif - #include - std::codecvt_base::result windows_file_codecvt::do_in( - std::mbstate_t &, - const char* from, const char* from_end, const char*& from_next, - wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const +std::codecvt_base::result windows_file_codecvt::do_in( + std::mbstate_t &, + const char* from, const char* from_end, const char*& from_next, + wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const +{ + UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; + + int count; + if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, + static_cast(from_end - from), to, static_cast(to_end - to))) == 0) { - UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; - - int count; - if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, - static_cast(from_end - from), to, static_cast(to_end - to))) == 0) - { - return error; // conversion failed - } - - from_next = from_end; - to_next = to + count; - *to_next = L'\0'; - return ok; - } - - std::codecvt_base::result windows_file_codecvt::do_out( - std::mbstate_t &, - const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next, - char* to, char* to_end, char* & to_next) const - { - UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; - - int count; - if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, - static_cast(from_end - from), to, static_cast(to_end - to), 0, 0)) == 0) - { - return error; // conversion failed - } - - from_next = from_end; - to_next = to + count; - *to_next = '\0'; - return ok; + return error; // conversion failed } - # endif // BOOST_WINDOWS_API + from_next = from_end; + to_next = to + count; + *to_next = L'\0'; + return ok; +} + +std::codecvt_base::result windows_file_codecvt::do_out( + std::mbstate_t &, + const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next, + char* to, char* to_end, char* & to_next) const +{ + UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; + + int count; + if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, + static_cast(from_end - from), to, static_cast(to_end - to), 0, 0)) == 0) + { + return error; // conversion failed + } + + from_next = from_end; + to_next = to + count; + *to_next = '\0'; + return ok; +} + +# endif // BOOST_WINDOWS_API diff --git a/src/windows_file_codecvt.hpp b/src/windows_file_codecvt.hpp index 97cbf16..e03f577 100644 --- a/src/windows_file_codecvt.hpp +++ b/src/windows_file_codecvt.hpp @@ -13,44 +13,44 @@ #include #include - //------------------------------------------------------------------------------------// - // // - // class windows_file_codecvt // - // // - // Warning: partial implementation; even do_in and do_out only partially meet the // - // standard library specifications as the "to" buffer must hold the entire result. // - // // - //------------------------------------------------------------------------------------// +//------------------------------------------------------------------------------------// +// // +// class windows_file_codecvt // +// // +// Warning: partial implementation; even do_in and do_out only partially meet the // +// standard library specifications as the "to" buffer must hold the entire result. // +// // +//------------------------------------------------------------------------------------// - class BOOST_FILESYSTEM_DECL windows_file_codecvt - : public std::codecvt< wchar_t, char, std::mbstate_t > - { - public: - explicit windows_file_codecvt(std::size_t refs = 0) - : std::codecvt(refs) {} - protected: +class BOOST_FILESYSTEM_DECL windows_file_codecvt + : public std::codecvt< wchar_t, char, std::mbstate_t > +{ +public: + explicit windows_file_codecvt(std::size_t refs = 0) + : std::codecvt(refs) {} +protected: - virtual bool do_always_noconv() const throw() { return false; } + virtual bool do_always_noconv() const throw() { return false; } - // seems safest to assume variable number of characters since we don't - // actually know what codepage is active - virtual int do_encoding() const throw() { return 0; } + // seems safest to assume variable number of characters since we don't + // actually know what codepage is active + virtual int do_encoding() const throw() { return 0; } - virtual std::codecvt_base::result do_in(std::mbstate_t& state, - const char* from, const char* from_end, const char*& from_next, - wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const; + virtual std::codecvt_base::result do_in(std::mbstate_t& state, + const char* from, const char* from_end, const char*& from_next, + wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const; - virtual std::codecvt_base::result do_out(std::mbstate_t & state, - const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, - char* to, char* to_end, char*& to_next) const; + virtual std::codecvt_base::result do_out(std::mbstate_t & state, + const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, + char* to, char* to_end, char*& to_next) const; - virtual std::codecvt_base::result do_unshift(std::mbstate_t&, - char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; } + virtual std::codecvt_base::result do_unshift(std::mbstate_t&, + char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; } - virtual int do_length(std::mbstate_t&, - const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; } + virtual int do_length(std::mbstate_t&, + const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; } - virtual int do_max_length() const throw () { return 0; } - }; + virtual int do_max_length() const throw () { return 0; } +}; #endif // BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP