diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 132641a32..883ebf8c6 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -1,7 +1,7 @@ # Boost Filesystem Library Build Jamfile # (C) Copyright Beman Dawes 2002-2006 -# (C) Copyright Andrey Semashev 2020 +# (C) Copyright Andrey Semashev 2020, 2021 # Distributed under the Boost Software License, Version 1.0. # See www.boost.org/LICENSE_1_0.txt @@ -15,6 +15,19 @@ lib advapi32 ; lib coredll ; explicit bcrypt advapi32 coredll ; +# The rule checks if a config macro is defined in the command line or build properties +rule has-config-flag ( flag : properties * ) +{ + if ( "$(flag)" in $(properties) || "$(flag)=1" in $(properties) ) + { + return 1 ; + } + else + { + return ; + } +} + # The rule checks we're building for Windows and selects crypto API to be used rule select-windows-crypto-api ( properties * ) { @@ -22,7 +35,8 @@ rule select-windows-crypto-api ( properties * ) if windows in $(properties) || cygwin in $(properties) { - if [ configure.builds ../config//has_bcrypt : $(properties) : "has BCrypt API" ] + if ! [ has-config-flag BOOST_FILESYSTEM_DISABLE_BCRYPT : $(properties) ] && + [ configure.builds ../config//has_bcrypt : $(properties) : "has BCrypt API" ] { result = BOOST_FILESYSTEM_HAS_BCRYPT bcrypt ; } @@ -44,6 +58,27 @@ rule select-windows-crypto-api ( properties * ) return $(result) ; } +# The rule checks if statx syscall is supported +rule check-statx ( properties * ) +{ + local result ; + + if ! [ has-config-flag BOOST_FILESYSTEM_DISABLE_STATX : $(properties) ] + { + if [ configure.builds ../config//has_statx : $(properties) : "has statx" ] + { + result = BOOST_FILESYSTEM_HAS_STATX ; + } + else if [ configure.builds ../config//has_statx_syscall : $(properties) : "has statx syscall" ] + { + result = BOOST_FILESYSTEM_HAS_STATX_SYSCALL ; + } + } + + #ECHO Result: $(result) ; + return $(result) ; +} + project boost/filesystem : requirements hpux,gcc:_INCLUDE_STDC__SOURCE_199901 @@ -53,8 +88,7 @@ project boost/filesystem [ check-target-builds ../config//has_stat_st_birthtim "has stat::st_birthtim" : BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIM ] [ check-target-builds ../config//has_stat_st_birthtimensec "has stat::st_birthtimensec" : BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMENSEC ] [ check-target-builds ../config//has_stat_st_birthtimespec "has stat::st_birthtimespec" : BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMESPEC ] - [ check-target-builds ../config//has_statx "has statx" : BOOST_FILESYSTEM_HAS_STATX ] - [ check-target-builds ../config//has_statx_syscall "has statx syscall" : BOOST_FILESYSTEM_HAS_STATX_SYSCALL ] + @check-statx @select-windows-crypto-api : source-location ../src : usage-requirements # pass these requirement to dependents (i.e. users) diff --git a/doc/index.htm b/doc/index.htm index 8063562ec..a8308bb78 100644 --- a/doc/index.htm +++ b/doc/index.htm @@ -243,7 +243,7 @@

Implementation

Microsoft Windows, SGI IRIX, and Sun Solaris operating systems using a variety of compilers. It is also used by several smart phone operating systems.

Macros

-

Users may defined the following macros if desired. Sensible defaults are +

Users may define the following macros if desired. Sensible defaults are provided, so users can ignore these macros unless they have special needs.

@@ -270,7 +270,37 @@

Macros

-
Boost.Filesystem library does not use the Boost auto-link facility.
+ + BOOST_FILESYSTEM_DISABLE_SENDFILE + Not defined. sendfile API presence detected at library build time. + Boost.Filesystem library does not use the sendfile system call on Linux. The sendfile system call started accepting regular file descriptors as the target in Linux 2.6.33. + + + BOOST_FILESYSTEM_DISABLE_COPY_FILE_RANGE + Not defined. copy_file_range API presence detected at library build time. + Boost.Filesystem library does not use the copy_file_range system call on Linux. The copy_file_range system call was introduced in Linux kernel 4.5 and started operating across filesystems in 5.3. + + + BOOST_FILESYSTEM_DISABLE_STATX + Not defined. statx presence detected at library build time. + Boost.Filesystem library does not use the statx system call on Linux. The statx system call was introduced in Linux kernel 4.11. + + + BOOST_FILESYSTEM_DISABLE_GETRANDOM + Not defined. getrandom API presence detected at library build time. + Boost.Filesystem library does not use the getrandom system call on Linux. The getrandom system call was introduced in Linux kernel 3.17. + + + BOOST_FILESYSTEM_DISABLE_ARC4RANDOM + Not defined. arc4random API presence detected at library build time. + Boost.Filesystem library does not use the arc4random_buf system call on BSD systems. The arc4random API was introduced in OpenBSD 2.1 and FreeBSD 8.0. + + + BOOST_FILESYSTEM_DISABLE_BCRYPT + Not defined. BCrypt API presence detected at library build time. + Boost.Filesystem library does not use the BCrypt API on Windows. Has no effect on other platforms. + +

User-defined BOOST_POSIX_API and BOOST_WINDOWS_API macros are no longer supported.

Building the object-library

diff --git a/doc/release_history.html b/doc/release_history.html index cf56e20fb..1aa6ddfda 100644 --- a/doc/release_history.html +++ b/doc/release_history.html @@ -38,6 +38,11 @@ +

1.77.0

+
    +
  • Added support for disabling usage of various system APIs at library build time. This can be useful when a certain API is detected as present by the library configuration scripts but must not be used for some reason (for example, when it is known to fail on the target system). See the description of configuration macros for more details.
  • +
+

1.76.0

  • Updated compatibility with WASI platform. (PR#169)
  • diff --git a/src/operations.cpp b/src/operations.cpp index 353ec4b7c..f5c5bcfd7 100644 --- a/src/operations.cpp +++ b/src/operations.cpp @@ -77,15 +77,20 @@ #if defined(linux) || defined(__linux) || defined(__linux__) #include -#include #include +#if !defined(BOOST_FILESYSTEM_DISABLE_SENDFILE) +#include #define BOOST_FILESYSTEM_USE_SENDFILE -#if defined(__NR_copy_file_range) +#endif // !defined(BOOST_FILESYSTEM_DISABLE_SENDFILE) +#if !defined(BOOST_FILESYSTEM_DISABLE_COPY_FILE_RANGE) && defined(__NR_copy_file_range) #define BOOST_FILESYSTEM_USE_COPY_FILE_RANGE -#endif +#endif // !defined(BOOST_FILESYSTEM_DISABLE_COPY_FILE_RANGE) && defined(__NR_copy_file_range) +#if !defined(BOOST_FILESYSTEM_DISABLE_STATX) && (defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL)) #if !defined(BOOST_FILESYSTEM_HAS_STATX) && defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) #include #endif +#define BOOST_FILESYSTEM_USE_STATX +#endif // !defined(BOOST_FILESYSTEM_DISABLE_STATX) && (defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL)) #endif // defined(linux) || defined(__linux) || defined(__linux__) #if defined(BOOST_FILESYSTEM_HAS_STAT_ST_MTIM) @@ -400,7 +405,7 @@ inline bool not_found_error(int errval) BOOST_NOEXCEPT return errval == ENOENT || errval == ENOTDIR; } -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) //! Returns \c true if the two \c statx structures refer to the same file inline bool equivalent_stat(struct ::statx const& s1, struct ::statx const& s2) BOOST_NOEXCEPT @@ -420,7 +425,7 @@ inline uintmax_t get_size(struct ::statx const& st) BOOST_NOEXCEPT return st.stx_size; } -#else // defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#else // defined(BOOST_FILESYSTEM_USE_STATX) //! Returns \c true if the two \c stat structures refer to the same file inline bool equivalent_stat(struct ::stat const& s1, struct ::stat const& s2) BOOST_NOEXCEPT @@ -442,7 +447,7 @@ inline uintmax_t get_size(struct ::stat const& st) BOOST_NOEXCEPT return st.st_size; } -#endif // defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#endif // defined(BOOST_FILESYSTEM_USE_STATX) typedef int(copy_file_data_t)(int infile, int outfile, uintmax_t size); @@ -1196,7 +1201,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod break; } -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) unsigned int statx_data_mask = STATX_TYPE | STATX_MODE | STATX_INO | STATX_SIZE; if ((options & static_cast< unsigned int >(copy_options::update_existing)) != 0u) statx_data_mask |= STATX_MTIME; @@ -1290,7 +1295,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod } } -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) statx_data_mask = STATX_TYPE | STATX_MODE | STATX_INO; if ((oflag & O_TRUNC) == 0) { @@ -1330,7 +1335,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod { // O_TRUNC is not set if copy_options::update_existing is set and an existing file was opened. // We need to check the last write times. -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) if (from_stat.stx_mtime.tv_sec < to_stat.stx_mtime.tv_sec || (from_stat.stx_mtime.tv_sec == to_stat.stx_mtime.tv_sec && from_stat.stx_mtime.tv_nsec <= to_stat.stx_mtime.tv_nsec)) return false; #elif defined(BOOST_FILESYSTEM_STAT_ST_MTIMENSEC) @@ -1517,7 +1522,7 @@ bool create_directory(path const& p, const path* existing, error_code* ec) mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; if (existing) { -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx existing_stat; if (BOOST_UNLIKELY(statx(AT_FDCWD, existing->c_str(), AT_NO_AUTOMOUNT, STATX_TYPE | STATX_MODE, &existing_stat) < 0)) { @@ -1586,7 +1591,7 @@ void copy_directory(path const& from, path const& to, system::error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) int err; struct ::statx from_stat; if (BOOST_UNLIKELY(statx(AT_FDCWD, from.c_str(), AT_NO_AUTOMOUNT, STATX_TYPE | STATX_MODE, &from_stat) < 0)) @@ -1748,7 +1753,7 @@ bool equivalent(path const& p1, path const& p2, system::error_code* ec) #if defined(BOOST_POSIX_API) // p2 is done first, so any error reported is for p1 -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx s2; int e2 = statx(AT_FDCWD, p2.c_str(), AT_NO_AUTOMOUNT, STATX_INO, &s2); if (BOOST_LIKELY(e2 == 0)) @@ -1856,7 +1861,7 @@ uintmax_t file_size(path const& p, error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx path_stat; if (BOOST_UNLIKELY(statx(AT_FDCWD, p.c_str(), AT_NO_AUTOMOUNT, STATX_TYPE | STATX_SIZE, &path_stat) < 0)) { @@ -1919,7 +1924,7 @@ uintmax_t hard_link_count(path const& p, system::error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx path_stat; if (BOOST_UNLIKELY(statx(AT_FDCWD, p.c_str(), AT_NO_AUTOMOUNT, STATX_NLINK, &path_stat) < 0)) { @@ -1986,7 +1991,7 @@ bool is_empty(path const& p, system::error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx path_stat; if (BOOST_UNLIKELY(statx(AT_FDCWD, p.c_str(), AT_NO_AUTOMOUNT, STATX_TYPE | STATX_SIZE, &path_stat) < 0)) { @@ -2041,7 +2046,7 @@ std::time_t creation_time(path const& p, system::error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx stx; if (BOOST_UNLIKELY(statx(AT_FDCWD, p.c_str(), AT_NO_AUTOMOUNT, STATX_BTIME, &stx) < 0)) { @@ -2097,7 +2102,7 @@ std::time_t last_write_time(path const& p, system::error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx stx; if (BOOST_UNLIKELY(statx(AT_FDCWD, p.c_str(), AT_NO_AUTOMOUNT, STATX_MTIME, &stx) < 0)) { @@ -2544,7 +2549,7 @@ file_status status(path const& p, error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx path_stat; int err = statx(AT_FDCWD, p.c_str(), AT_NO_AUTOMOUNT, STATX_TYPE | STATX_MODE, &path_stat); #else @@ -2567,7 +2572,7 @@ file_status status(path const& p, error_code* ec) return fs::file_status(fs::status_error); } -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) if (BOOST_UNLIKELY((path_stat.stx_mask & (STATX_TYPE | STATX_MODE)) != (STATX_TYPE | STATX_MODE))) { emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::status"); @@ -2649,7 +2654,7 @@ file_status symlink_status(path const& p, error_code* ec) #if defined(BOOST_POSIX_API) -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) struct ::statx path_stat; int err = statx(AT_FDCWD, p.c_str(), AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, STATX_TYPE | STATX_MODE, &path_stat); #else @@ -2672,7 +2677,7 @@ file_status symlink_status(path const& p, error_code* ec) return fs::file_status(fs::status_error); } -#if defined(BOOST_FILESYSTEM_HAS_STATX) || defined(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) +#if defined(BOOST_FILESYSTEM_USE_STATX) if (BOOST_UNLIKELY((path_stat.stx_mask & (STATX_TYPE | STATX_MODE)) != (STATX_TYPE | STATX_MODE))) { emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::symlink_status"); diff --git a/src/unique_path.cpp b/src/unique_path.cpp index 0c81f1f3b..007dc68f5 100644 --- a/src/unique_path.cpp +++ b/src/unique_path.cpp @@ -25,13 +25,16 @@ #include #endif +#if !defined(BOOST_FILESYSTEM_DISABLE_ARC4RANDOM) #if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || \ BOOST_OS_BSD_FREE >= BOOST_VERSION_NUMBER(8, 0, 0) || \ BOOST_LIB_C_CLOUDABI #include #define BOOST_FILESYSTEM_HAS_ARC4RANDOM #endif +#endif // !defined(BOOST_FILESYSTEM_DISABLE_ARC4RANDOM) +#if !defined(BOOST_FILESYSTEM_DISABLE_GETRANDOM) #if (defined(__linux__) || defined(__linux) || defined(linux)) && \ (!defined(__ANDROID__) || __ANDROID_API__ >= 28) #include @@ -51,6 +54,7 @@ #include #endif #endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28) +#endif // !defined(BOOST_FILESYSTEM_DISABLE_GETRANDOM) #else // BOOST_WINDOWS_API