From a9a1fb90daf4b6e1ebef8a6c3408dcbab81c4f2a Mon Sep 17 00:00:00 2001 From: MacroModel Date: Tue, 4 Nov 2025 21:58:41 +0800 Subject: [PATCH] Refactor timestamp conversion and enhance POSIX linkat functionality - Updated `unix_timestamp_to_time_t` function signature for consistency. - Improved handling of `posix_linkat` and `native_linkat` functions to manage `symlink_nofollow` flags more effectively. - Adjusted conditional compilation checks in `linux_getrandom.h` and `white_hole.h` for better compatibility across platforms. --- include/fast_io_hosted/filesystem/dos_at.h | 2 +- include/fast_io_hosted/filesystem/posix_at.h | 22 +++++++++++++++++++ .../white_hole/linux_getrandom.h | 2 +- .../fast_io_hosted/white_hole/white_hole.h | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/fast_io_hosted/filesystem/dos_at.h b/include/fast_io_hosted/filesystem/dos_at.h index 5d9ef87d..0b37bbbc 100644 --- a/include/fast_io_hosted/filesystem/dos_at.h +++ b/include/fast_io_hosted/filesystem/dos_at.h @@ -201,7 +201,7 @@ inline constexpr #endif ::std::time_t - unix_timestamp_to_time_t(unix_timestamp_option opt) noexcept + unix_timestamp_to_time_t(unix_timestamp_option opt) { switch (opt.flags) { diff --git a/include/fast_io_hosted/filesystem/posix_at.h b/include/fast_io_hosted/filesystem/posix_at.h index 9dbf5954..e19b5eeb 100644 --- a/include/fast_io_hosted/filesystem/posix_at.h +++ b/include/fast_io_hosted/filesystem/posix_at.h @@ -747,6 +747,17 @@ template <::fast_io::constructible_to_os_c_str old_path_type, ::fast_io::constru inline void posix_linkat(posix_at_entry oldent, old_path_type const &oldpath, posix_at_entry newent, new_path_type const &newpath, posix_at_flags flags = posix_at_flags::symlink_nofollow) { + if ((flags & posix_at_flags::symlink_nofollow) == posix_at_flags::symlink_nofollow) + { + flags &= ~posix_at_flags::symlink_nofollow; + } + else + { +#ifdef AT_SYMLINK_FOLLOW + flags |= static_cast(AT_SYMLINK_FOLLOW); +#endif + } + details::posix_deal_with22(oldent.fd, oldpath, newent.fd, newpath, static_cast(flags)); } @@ -755,6 +766,17 @@ template <::fast_io::constructible_to_os_c_str old_path_type, ::fast_io::constru inline void native_linkat(posix_at_entry oldent, old_path_type const &oldpath, posix_at_entry newent, new_path_type const &newpath, posix_at_flags flags = posix_at_flags::symlink_nofollow) { + if ((flags & posix_at_flags::symlink_nofollow) == posix_at_flags::symlink_nofollow) + { + flags &= ~posix_at_flags::symlink_nofollow; + } + else + { +#ifdef AT_SYMLINK_FOLLOW + flags |= static_cast(AT_SYMLINK_FOLLOW); +#endif + } + details::posix_deal_with22(oldent.fd, oldpath, newent.fd, newpath, static_cast(flags)); } diff --git a/include/fast_io_hosted/white_hole/linux_getrandom.h b/include/fast_io_hosted/white_hole/linux_getrandom.h index f52090f3..9114508a 100644 --- a/include/fast_io_hosted/white_hole/linux_getrandom.h +++ b/include/fast_io_hosted/white_hole/linux_getrandom.h @@ -1,5 +1,5 @@ #pragma once -#if !(defined(__linux__) && defined(__NR_getrandom)) && !__has_include() +#if !(defined(__linux__) && defined(__NR_getrandom)) && __has_include() #include #endif diff --git a/include/fast_io_hosted/white_hole/white_hole.h b/include/fast_io_hosted/white_hole/white_hole.h index 39923012..70b07a09 100644 --- a/include/fast_io_hosted/white_hole/white_hole.h +++ b/include/fast_io_hosted/white_hole/white_hole.h @@ -25,7 +25,7 @@ concept minimum_buffer_input_stream_require_size_impl = } // namespace fast_io::details #if ((defined(__linux__) && defined(__NR_getrandom)) || \ - (!defined(__linux__) && __has_include())) && !defined(__wasi__) && !defined(__DARWIN_C_LEVEL) && !defined(__CYGWIN__) + (!(defined(__linux__) && defined(__NR_getrandom)) && __has_include())) && !defined(__wasi__) && !defined(__DARWIN_C_LEVEL) && !defined(__CYGWIN__) #include "linux_getrandom.h" #endif #if ((defined(__linux__) && defined(__GLIBC__)) || (defined(__BSD_VISIBLE) && !defined(__DARWIN_C_LEVEL))) && 0