diff --git a/include/fast_io_core.h b/include/fast_io_core.h index ba5a5fc9..e2ed5141 100644 --- a/include/fast_io_core.h +++ b/include/fast_io_core.h @@ -9,10 +9,13 @@ #if !defined(__cpp_concepts) #error "fast_io requires at least C++20 standard compiler." #else + +#include +#include +#include +#include #include #include -#include -#include #if __cpp_lib_three_way_comparison >= 201907L #include diff --git a/include/fast_io_core_impl/char_category/char_category.h b/include/fast_io_core_impl/char_category/char_category.h index f525a447..03faa7e7 100644 --- a/include/fast_io_core_impl/char_category/char_category.h +++ b/include/fast_io_core_impl/char_category/char_category.h @@ -1795,7 +1795,7 @@ inline constexpr bool is_html_whitespace_wide_impl(wchar_t ch) noexcept }; } -inline constexpr bool is_dos_path_invalid_character_impl(char32_t ch) noexcept +inline constexpr bool is_dos_file_invalid_character_impl(char32_t ch) noexcept { if (ch < static_cast(32u)) { @@ -1926,15 +1926,15 @@ To do: to_c_fullwidth */ template <::std::integral T> -inline constexpr bool is_dos_path_invalid_character(T ch) noexcept +inline constexpr bool is_dos_file_invalid_character(T ch) noexcept { if constexpr (::std::signed_integral) { - return ::fast_io::char_category::details::is_dos_path_invalid_character_impl(static_cast(static_cast<::std::make_unsigned_t>(ch))); + return ::fast_io::char_category::details::is_dos_file_invalid_character_impl(static_cast(static_cast<::std::make_unsigned_t>(ch))); } else { - return ::fast_io::char_category::details::is_dos_path_invalid_character_impl(static_cast(ch)); + return ::fast_io::char_category::details::is_dos_file_invalid_character_impl(static_cast(ch)); } } diff --git a/include/fast_io_core_impl/char_category/char_category_traits.h b/include/fast_io_core_impl/char_category/char_category_traits.h index fd637cea..574493e2 100644 --- a/include/fast_io_core_impl/char_category/char_category_traits.h +++ b/include/fast_io_core_impl/char_category/char_category_traits.h @@ -19,7 +19,7 @@ enum class char_category_family : ::std::uint_least32_t c_space, // Whitespace characters (space, tab, newline, etc.) c_upper, // Uppercase alphabetic characters c_xdigit, // Hexadecimal digits (0-9, A-F, a-f) - dos_path_invalid_character, // DOS Path invalid character + dos_file_invalid_character, // DOS Path invalid character html_whitespace // HTML whitespace }; @@ -96,9 +96,9 @@ class char_category_traits { ret = ::fast_io::char_category::is_c_fullwidth(ch); } - else if constexpr (fam == ::fast_io::char_category::char_category_family::dos_path_invalid_character) + else if constexpr (fam == ::fast_io::char_category::char_category_family::dos_file_invalid_character) { - ret = ::fast_io::char_category::is_dos_path_invalid_character(ch); + ret = ::fast_io::char_category::is_dos_file_invalid_character(ch); } if constexpr (negate) { @@ -192,7 +192,7 @@ using c_punct = ::fast_io::char_category::char_category_traits<::fast_io::char_c using c_space = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::c_space, false>; using c_upper = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::c_upper, false>; using c_xdigit = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::c_xdigit, false>; -using dos_path_invalid_character = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::dos_path_invalid_character, false>; +using dos_file_invalid_character = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::dos_file_invalid_character, false>; using html_whitespace = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::html_whitespace, false>; @@ -210,7 +210,7 @@ using not_c_punct = ::fast_io::char_category::char_category_traits<::fast_io::ch using not_c_space = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::c_space, true>; using not_c_upper = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::c_upper, true>; using not_c_xdigit = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::c_xdigit, true>; -using not_dos_path_invalid_character = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::dos_path_invalid_character, true>; +using not_dos_file_invalid_character = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::dos_file_invalid_character, true>; using not_html_whitespace = ::fast_io::char_category::char_category_traits<::fast_io::char_category::char_category_family::html_whitespace, true>; namespace details diff --git a/include/fast_io_device.h b/include/fast_io_device.h index cc4b4d4f..cc663b16 100644 --- a/include/fast_io_device.h +++ b/include/fast_io_device.h @@ -29,6 +29,20 @@ using dir_file = directory_file_wrapper< #endif >; +// Note: +// The Win32 API layer is not well-suited for precise "dirfile" semantics, +// because it abstracts away the underlying NT object types. Unlike the NT I/O +// manager (where FILE_DIRECTORY_FILE and FILE_NON_DIRECTORY_FILE flags enforce +// strict open-type constraints), Win32’s CreateFileW does not distinguish +// between files and directories unless explicitly checked afterwards. +// +// FILE_FLAG_BACKUP_SEMANTICS merely *permits* opening a directory handle, +// but does not *require* the target to be a directory. Similarly, adding +// FILE_ATTRIBUTE_DIRECTORY has no enforcement effect — it's only a metadata hint. +// Therefore, to emulate dirfile-style correctness, one must explicitly query +// the object type (e.g., via GetFileInformationByHandle or GetFileAttributes) +// after opening the handle. + /* template region */ diff --git a/include/fast_io_driver/install_path/impl.h b/include/fast_io_driver/install_path/impl.h index a4adc88d..4d2635e8 100644 --- a/include/fast_io_driver/install_path/impl.h +++ b/include/fast_io_driver/install_path/impl.h @@ -2,15 +2,15 @@ #include"install_path.h" -#if defined(_WIN32) +#if defined(_WIN32) || defined(__CYGWIN__) #include "argv0_null.h" #else #include "argv0.h" #endif -#if (defined(__linux) || defined(__linux__) || defined(__gnu_linux__)) || defined(__CYGWIN__) || defined(__sun) +#if (defined(__linux) || defined(__linux__) || defined(__gnu_linux__)) || defined(__sun) #include "linux.h" -#elif defined(_WIN32) +#elif defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32_WINDOWS) #include "win32_9xa.h" #else diff --git a/include/fast_io_dsal/impl/misc/push_macros.h b/include/fast_io_dsal/impl/misc/push_macros.h index 4e2b06c7..1082f819 100644 --- a/include/fast_io_dsal/impl/misc/push_macros.h +++ b/include/fast_io_dsal/impl/misc/push_macros.h @@ -14,7 +14,14 @@ #undef move #pragma push_macro("new") +#if __GNUC__ >= 16 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wkeyword-macro" #undef new +#pragma GCC diagnostic pop +#else +#undef new +#endif #pragma push_macro("refresh") #undef refresh diff --git a/include/fast_io_hosted/dll/win32.h b/include/fast_io_hosted/dll/win32.h index 58ef7b30..4e31cb98 100644 --- a/include/fast_io_hosted/dll/win32.h +++ b/include/fast_io_hosted/dll/win32.h @@ -98,7 +98,7 @@ inline void *create_win32_dll_9xa(char const *filename) // 9x kernel does not su inline void *create_win32_dll_ntw(char16_t const *filename, [[maybe_unused]] dll_mode mode) { auto hmodule{ -#if _WIN32_WINNT <= 0x0500 +#if (defined(_WIN32_WINNT) && _WIN32_WINNT <= 0x0500) // Windows 2000 does not support Ex apis ::fast_io::win32::LoadLibraryW(filename) #else diff --git a/include/fast_io_hosted/filesystem/dos.h b/include/fast_io_hosted/filesystem/dos.h index 0f236cf8..e1f3dfcc 100644 --- a/include/fast_io_hosted/filesystem/dos.h +++ b/include/fast_io_hosted/filesystem/dos.h @@ -60,6 +60,8 @@ namespace posix // extern char const* my_dos_get_fd_name(int) noexcept __asm__("___get_fd_name"); extern DIR *my_dos_opendir(char const *) noexcept __asm__("_opendir"); +extern int my_dos_closedir(DIR *) noexcept __asm__("_closedir"); + inline DIR *my_dos_fdopendir(int fd) noexcept { return my_dos_opendir(::fast_io::noexcept_call(::__get_fd_name, fd)); @@ -69,6 +71,16 @@ inline DIR *my_dos_fdopendir(int fd) noexcept namespace details { +inline void check_dos_fd_is_dir(int fd) +{ + auto const dir{::fast_io::posix::my_dos_fdopendir(fd)}; + if (dir == nullptr) [[unlikely]] + { + throw_posix_error(ENOTDIR); + } + ::fast_io::posix::my_dos_closedir(dir); +} + inline dos_DIR sys_dup_dir(dos_DIR dirp) { if (dirp.dirp == nullptr) [[unlikely]] @@ -127,7 +139,7 @@ class dos_directory_file FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public dos_ auto newdir{details::sys_dup_dir(other.dirp)}; if (this->dirp.dirp) [[likely]] { - noexcept_call(::closedir, this->dirp.dirp); + ::fast_io::posix::my_dos_closedir(this->dirp.dirp); } if (this->dirp.fd != -1) [[likely]] { @@ -149,7 +161,7 @@ class dos_directory_file FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public dos_ } if (this->dirp.dirp) [[likely]] { - noexcept_call(::closedir, this->dirp.dirp); + ::fast_io::posix::my_dos_closedir(this->dirp.dirp); } if (this->dirp.fd != -1) [[likely]] { @@ -163,7 +175,7 @@ class dos_directory_file FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public dos_ { if (this->dirp.dirp) [[likely]] { - noexcept_call(::closedir, this->dirp.dirp); + ::fast_io::posix::my_dos_closedir(this->dirp.dirp); } if (this->dirp.fd != -1) [[likely]] { @@ -177,7 +189,7 @@ class dos_directory_file FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public dos_ if (*this) [[likely]] { int fd_to_close{this->dirp.fd}; - int ret{noexcept_call(::closedir, this->dirp.dirp)}; + int ret{::fast_io::posix::my_dos_closedir(this->dirp.dirp)}; this->dirp.dirp = nullptr; this->dirp.fd = -1; if (fd_to_close != -1) @@ -195,7 +207,7 @@ class dos_directory_file FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public dos_ { if (this->dirp.dirp) [[likely]] { - noexcept_call(::closedir, this->dirp.dirp); + ::fast_io::posix::my_dos_closedir(this->dirp.dirp); } if (this->dirp.fd != -1) [[likely]] { diff --git a/include/fast_io_hosted/filesystem/nt_at.h b/include/fast_io_hosted/filesystem/nt_at.h index 802eb55e..3be2375a 100644 --- a/include/fast_io_hosted/filesystem/nt_at.h +++ b/include/fast_io_hosted/filesystem/nt_at.h @@ -93,15 +93,21 @@ inline void nt_unlinkat_impl(void *dirhd, char16_t const *path_c_str, ::std::siz template inline void nt_mkdirat_impl(void *dirhd, char16_t const *path_c_str, ::std::size_t path_size, perms pm, bool kernel) { - constexpr fast_io::win32::nt::details::nt_open_mode create_dir_mode{ - fast_io::win32::nt::details::calculate_nt_open_mode( - {fast_io::open_mode::creat | fast_io::open_mode::directory})}; - auto m_dir_mode{create_dir_mode}; + nt_open_mode m_dir_mode{ + .DesiredAccess = 0x00100000 | 0x0001, // SYNCHRONIZE | FILE_LIST_DIRECTORY + .FileAttributes = 0x80, // FILE_ATTRIBUTE_NORMAL + .ShareAccess = 0x00000003, // FILE_SHARE_READ | FILE_SHARE_WRITE + .CreateDisposition = 0x00000002, // CREATE_NEW => FILE_CREATE (0x00000002) + .CreateOptions = 0x00004021 // FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT + }; + if ((pm & perms::owner_write) == perms::none) { m_dir_mode.FileAttributes |= 0x00000001; // FILE_ATTRIBUTE_READONLY } + auto status{nt_close(nt_call_determine_kernel_callback(dirhd, path_c_str, path_size, kernel, nt_create_callback{m_dir_mode}))}; + if (status) { throw_nt_error(status); @@ -775,7 +781,7 @@ inline ::fast_io::details::basic_ct_string nt_readlinkat_impl(void *d .FileAttributes = 0x80, // FILE_ATTRIBUTE_NORMAL .ShareAccess = 0x00000007, // FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE .CreateDisposition = 0x00000001, // OPEN_EXISTING => FILE_OPEN - .CreateOptions = 0x00200000 // FILE_FLAG_OPEN_REPARSE_POINT => FILE_OPEN_REPARSE_POINT (0x00200000) + .CreateOptions = 0x00200000 | 0x00000020 // FILE_FLAG_OPEN_REPARSE_POINT | FILE_SYNCHRONOUS_IO_NONALERT }; ::fast_io::basic_nt_family_file<(zw ? nt_family::zw : nt_family::nt), char> file{ diff --git a/include/fast_io_hosted/filesystem/posix.h b/include/fast_io_hosted/filesystem/posix.h index 19776fad..e8940aa2 100644 --- a/include/fast_io_hosted/filesystem/posix.h +++ b/include/fast_io_hosted/filesystem/posix.h @@ -6,6 +6,28 @@ namespace fast_io namespace details { +#if defined(__CYGWIN__) +struct my_cygwin_DIR +{ + /* This is first to set alignment in non _LIBC case. */ + unsigned long __d_cookie; + struct dirent *__d_dirent; + char *__d_dirname; /* use for internal caching */ + ::std::int32_t __d_position; /* used by telldir/seekdir */ + int __d_fd; + ::std::uintptr_t __d_internal; + void *__handle; + void *__fh; + unsigned __flags; +}; + +using my_cygwin_DIR_may_alias_ptr = +#if __has_cpp_attribute(__gnu__::__may_alias__) + [[__gnu__::__may_alias__]] +#endif + my_cygwin_DIR *; +#endif + inline int dirp_to_fd(DIR *dirp) noexcept { if (dirp == nullptr) @@ -13,7 +35,7 @@ inline int dirp_to_fd(DIR *dirp) noexcept return -1; } #if defined(__CYGWIN__) - return dirp->__d_fd; + return reinterpret_cast(dirp)->__d_fd; #else return dirfd(dirp); #endif @@ -58,7 +80,7 @@ inline DIR *sys_dup_dir(DIR *dirp) } auto fd{ #if defined(__CYGWIN__) - dirp->__d_fd + reinterpret_cast(dirp)->__d_fd #else dirfd(dirp) #endif diff --git a/include/fast_io_hosted/filesystem/posix_at.h b/include/fast_io_hosted/filesystem/posix_at.h index 04967922..9dbf5954 100644 --- a/include/fast_io_hosted/filesystem/posix_at.h +++ b/include/fast_io_hosted/filesystem/posix_at.h @@ -447,7 +447,7 @@ inline void posix_utimensat_impl(int dirfd, char const *path, unix_timestamp_opt } template<::std::integral char_type> -inline ::fast_io::details::basic_ct_string posix_readlinkat_impl(int dirfd, char const *pathname) +inline ::fast_io::details::basic_ct_string posix_readlinkat_impl([[maybe_unused]] int dirfd, [[maybe_unused]] char const *pathname) { #if defined(AT_SYMLINK_NOFOLLOW) using posix_ssize_t = ::std::make_signed_t<::std::size_t>; diff --git a/include/fast_io_hosted/platforms/dos_filename.h b/include/fast_io_hosted/platforms/dos_filename.h index dfb7fb1c..b890e339 100644 --- a/include/fast_io_hosted/platforms/dos_filename.h +++ b/include/fast_io_hosted/platforms/dos_filename.h @@ -29,7 +29,7 @@ inline constexpr bool is_invalid_dos_filename_with_size(char_type const *filenam for (; curr != end; ++curr) { - if (auto fc{*curr}; ::fast_io::char_category::is_dos_path_invalid_character(fc)) [[unlikely]] + if (auto fc{*curr}; ::fast_io::char_category::is_dos_file_invalid_character(fc)) [[unlikely]] { return true; } diff --git a/include/fast_io_hosted/platforms/posix.h b/include/fast_io_hosted/platforms/posix.h index cb2f6054..29af7df8 100644 --- a/include/fast_io_hosted/platforms/posix.h +++ b/include/fast_io_hosted/platforms/posix.h @@ -271,11 +271,11 @@ inline constexpr int calculate_posix_open_mode(open_mode value) noexcept #ifdef _O_SEQUENTIAL if ((value & open_mode::random_access) != open_mode::none) { - mode |= _O_SEQUENTIAL; + mode |= _O_RANDOM; } else { - mode |= _O_RANDOM; + mode |= _O_SEQUENTIAL; } #endif #ifdef O_LARGEFILE @@ -522,10 +522,36 @@ template <::fast_io::posix_family family, ::std::integral ch_type> inline constexpr basic_posix_family_io_observer io_bytes_stream_ref_define(basic_posix_family_io_observer other) noexcept { - return {other.handle}; + return {other.fd}; +} + +#if defined(__CYGWIN__) + +// https://github.com/cygwin/cygwin/blob/c43ec5f5951c7f4b882a0f8e619601a45ae70a91/newlib/libc/include/sys/_default_fcntl.h#L168 + +inline constexpr posix_at_entry posix_at_fdcwd() noexcept +{ + return posix_at_entry( +#if defined(AT_FDCWD) + AT_FDCWD +#else + -2 +#endif + ); } -#if !(defined(_WIN32) && !defined(__WINE__) && !defined(__BIONIC__)) && defined(AT_FDCWD) +inline constexpr posix_at_entry at_fdcwd() noexcept +{ + return posix_at_entry( +#if defined(AT_FDCWD) + AT_FDCWD +#else + -2 +#endif + ); +} + +#elif !(defined(_WIN32) && !defined(__WINE__) && !defined(__BIONIC__)) && defined(AT_FDCWD) inline constexpr posix_at_entry posix_at_fdcwd() noexcept { @@ -536,6 +562,7 @@ inline constexpr posix_at_entry at_fdcwd() noexcept { return posix_at_entry(AT_FDCWD); } + #elif defined(__MSDOS__) || defined(__DJGPP__) inline constexpr posix_at_entry posix_at_fdcwd() noexcept @@ -547,6 +574,7 @@ inline constexpr posix_at_entry at_fdcwd() noexcept { return posix_at_entry(-100); } + #endif namespace details @@ -775,7 +803,7 @@ template <::fast_io::posix_family family, ::std::integral ch_type> inline auto redirect_handle(basic_posix_family_io_observer h) noexcept { #if (defined(_WIN32) && !defined(__WINE__) && !defined(__BIONIC__)) - return my_get_osfile_handle(h.fd); + return details::my_get_osfile_handle(h.fd); #else return h.fd; #endif @@ -892,10 +920,12 @@ inline constexpr my_dos_concat_tlc_path_common_result my_dos_concat_tlc_path_com return {true}; } - if (::fast_io::details::is_invalid_dos_filename_with_size(pathname, sz)) [[unlikely]] +#if 0 + if (::fast_io::details::is_invalid_dos_pathname_with_size(pathname, sz)) [[unlikely]] { return {true}; } +#endif // concat return {false, concat_dos_path_tlc_string(::fast_io::mnp::os_c_str(fd_pathname_cstr), ::fast_io::mnp::chvw('\\'), ::fast_io::mnp::os_c_str(pathname))}; @@ -921,7 +951,7 @@ inline int my_posix_openat(int dirfd, char const *pathname, int flags, mode_t mo return fd; } -#elif defined(__NEWLIB__) || defined(_PICOLIBC__) +#elif (defined(__NEWLIB__) || defined(_PICOLIBC__)) && !defined(__CYGWIN__) template inline int my_posix_openat(int, char const *, int, mode_t) @@ -980,11 +1010,11 @@ inline constexpr unsigned calculate_win32_cygwin_open_mode(open_mode value) unsigned access{}; if ((value & open_mode::out) == open_mode::out) { - access |= 0x80000000; + access |= 0x40000000 /*GENERIC_WRITE*/; } if ((value & open_mode::in) == open_mode::in) { - access |= 0x40000000; + access |= 0x80000000 /*GENERIC_READ*/; } return access; } @@ -1052,7 +1082,7 @@ struct my_posix_open_paramter } }; -#if (defined(__NEWLIB__) && !defined(AT_FDCWD)) || defined(_PICOLIBC__) +#if ((defined(__NEWLIB__) && !defined(AT_FDCWD)) || defined(_PICOLIBC__)) && !defined(__CYGWIN__) template <::fast_io::constructible_to_os_c_str T> inline constexpr int posix_openat_file_impl(int, T const &, open_mode, perms) @@ -1528,7 +1558,7 @@ class basic_posix_family_pipe { throw_posix_error(); } -#elif (defined(__MSDOS__) || defined(__DJGPP__)) || defined(__NEWLIB__) +#elif (defined(__MSDOS__) || defined(__DJGPP__)) || (defined(__NEWLIB__) && !defined(__CYGWIN__)) if (noexcept_call(::pipe, a2) == -1) { throw_posix_error(); diff --git a/include/fast_io_hosted/platforms/win32.h b/include/fast_io_hosted/platforms/win32.h index 5a00c15d..0de1ee0b 100644 --- a/include/fast_io_hosted/platforms/win32.h +++ b/include/fast_io_hosted/platforms/win32.h @@ -700,7 +700,7 @@ namespace win32::details inline ::fast_io::intfpos_t seek_impl(void *handle, ::fast_io::intfpos_t offset, seekdir s) { -#if (_WIN32_WINNT <= 0x0500) || defined(_WIN32_WINDOWS) +#if (defined(_WIN32_WINNT) && _WIN32_WINNT <= 0x0500) || defined(_WIN32_WINDOWS) if constexpr (sizeof(::fast_io::intfpos_t) > sizeof(::std::int_least32_t)) { constexpr ::fast_io::intfpos_t l32mx{INT_LEAST32_MAX}; @@ -781,7 +781,7 @@ inline ::std::byte *win32_read_some_bytes_impl(void *__restrict handle, ::std::b } inline ::std::byte *win32_ntw_pread_some_bytes_impl(void *__restrict handle, ::std::byte *first, ::std::byte *last, - ::fast_io::intfpos_t off) + ::fast_io::intfpos_t off) { // The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows, // the functions will advance the position by the number of bytes written or read after each write/read operation. @@ -808,13 +808,13 @@ inline ::std::byte const *write_or_pwrite_some_bytes_common_impl(void *__restric } inline ::std::byte const *win32_write_some_bytes_impl(void *__restrict handle, ::std::byte const *first, - ::std::byte const *last) + ::std::byte const *last) { return ::fast_io::win32::details::write_or_pwrite_some_bytes_common_impl(handle, first, last, nullptr); } inline ::std::byte const *win32_ntw_pwrite_some_bytes_impl(void *__restrict handle, ::std::byte const *first, - ::std::byte const *last, ::fast_io::intfpos_t off) + ::std::byte const *last, ::fast_io::intfpos_t off) { // The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows, // the functions will advance the position by the number of bytes written or read after each write/read operation. @@ -853,7 +853,7 @@ inline ::fast_io::intfpos_t io_stream_seek_bytes_define(basic_win32_family_io_ob I am not confident that i understand semantics correctly. Disabled first and test it later */ -// Windows 9x does not support atomic p-series functions. When using operation::p-series functions, +// Windows 9x does not support atomic p-series functions. When using operation::p-series functions, // they will be emulated through seek and non-p-series functions. // For Win9x, use the operation::p series functions, which automatically combine seek operations with non-p series functions. #if !defined(_WIN32_WINDOWS) @@ -1001,7 +1001,7 @@ inline void check_win32_9xa_dir_is_valid(win32_9xa_dir_handle const &h) auto find_struct{::fast_io::win32::FindFirstFileA(reinterpret_cast(temp_find_path.c_str()), __builtin_addressof(wfda))}; if (find_struct == reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))) [[unlikely]] { - throw_win32_error(0x5); + throw_win32_error(0x2); } else { @@ -1098,10 +1098,12 @@ inline win32_9xa_dir_handle basic_win32_9xa_create_dir_file_at_fs_dirent_impl(wi auto const beg{reinterpret_cast(filename_c_str)}; - if (::fast_io::details::is_invalid_dos_filename_with_size(beg, filename_c_str_len)) [[unlikely]] +#if 0 + if (::fast_io::details::is_invalid_dos_pathname_with_size(beg, filename_c_str_len)) [[unlikely]] { throw_win32_error(3); } +#endif check_win32_9xa_dir_is_valid(*directory_handle); win32_9xa_dir_handle ret{concat_win32_9xa_dir_handle_path_str(directory_handle->path, u8"\\", ::fast_io::mnp::os_c_str_with_known_size(beg, filename_c_str_len))}; @@ -1121,10 +1123,12 @@ inline void *basic_win32_9xa_create_file_at_fs_dirent_impl(win32_9xa_dir_handle auto const beg{reinterpret_cast(filename_c_str)}; - if (::fast_io::details::is_invalid_dos_filename_with_size(beg, filename_c_str_len)) [[unlikely]] +#if 0 + if (::fast_io::details::is_invalid_dos_pathname_with_size(beg, filename_c_str_len)) [[unlikely]] { throw_win32_error(3); } +#endif check_win32_9xa_dir_is_valid(*directory_handle); tlc_win32_9xa_dir_handle_path_str str{concat_tlc_win32_9xa_dir_handle_path_str(directory_handle->path, u8"\\", ::fast_io::mnp::os_c_str_with_known_size(beg, filename_c_str_len))}; @@ -1136,10 +1140,12 @@ inline ::fast_io::win32::details::tlc_win32_9xa_dir_handle_path_str concat_tlc_w { auto const beg{path_c_str}; - if (::fast_io::details::is_invalid_dos_filename_with_size(beg, path_size)) [[unlikely]] +#if 0 + if (::fast_io::details::is_invalid_dos_pathname_with_size(beg, path_size)) [[unlikely]] { throw_win32_error(3); } +#endif return ::fast_io::win32::details::concat_tlc_win32_9xa_dir_handle_path_str(dirhd.path, u8"\\", ::fast_io::mnp::os_c_str_with_known_size(beg, path_size)); } @@ -1745,9 +1751,9 @@ inline posix_file_status win32_9xa_dir_file_status_impl(win32_9xa_dir_handle con tmp_file.perm = static_cast(pm); tmp_file.type = ::fast_io::file_type::directory; tmp_file.nlink = 1u; - tmp_file.size = static_cast<::std::uintmax_t>((static_cast<::std::uint_least64_t>(wfda.nFileSizeHigh) << 32u) | wfda.nFileSizeLow); // always zero - tmp_file.blksize = 512u; // default - tmp_file.blocks = (tmp_file.size + 511u) / 512u; // default + tmp_file.size = static_cast<::std::uintmax_t>((static_cast<::std::uint_least64_t>(wfda.nFileSizeHigh) << 32u) | wfda.nFileSizeLow); // always zero + tmp_file.blksize = 512u; // default + tmp_file.blocks = (tmp_file.size + 511u) / 512u; // default tmp_file.atim = to_unix_timestamp(wfda.ftLastAccessTime); tmp_file.mtim = to_unix_timestamp(wfda.ftLastWriteTime); tmp_file.ctim = tmp_file.mtim; @@ -1781,7 +1787,7 @@ inline posix_file_status win32_9xa_dir_file_status_impl(win32_9xa_dir_handle con { tmp_file.dev = static_cast<::std::uintmax_t>(serial); } - + // get blocksize ::std::uint_least32_t sector_per_cluster{}; ::std::uint_least32_t bytes_per_sector{}; diff --git a/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h b/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h index eb8cabb6..ec045698 100644 --- a/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h +++ b/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h @@ -221,7 +221,7 @@ class win32_9xa_dns_file : public win32_9xa_dns_io_observer } }; -#if (defined(_WIN32_WINDOWS) || _WIN32_WINNT <= 0x0500) +#if (defined(_WIN32_WINDOWS) || (defined(_WIN32_WINNT) && _WIN32_WINNT <= 0x0500)) using native_dns_io_observer = win32_9xa_dns_io_observer; using native_dns_file = win32_9xa_dns_file; using native_dns_iterator = win32_9xa_dns_iterator; diff --git a/include/fast_io_hosted/process/process/win32.h b/include/fast_io_hosted/process/process/win32.h index 09cc3a14..719bb96c 100644 --- a/include/fast_io_hosted/process/process/win32.h +++ b/include/fast_io_hosted/process/process/win32.h @@ -567,11 +567,13 @@ struct win32_9xa_win9x_create_process_at_fs_dirent #endif = char8_t const *; +#if 0 auto const beg{reinterpret_cast(filename)}; - if (::fast_io::details::is_invalid_dos_filename_with_size(beg, filename_c_str_len)) [[unlikely]] + if (::fast_io::details::is_invalid_dos_pathname_with_size(beg, filename_c_str_len)) [[unlikely]] { throw_win32_error(3); } +#endif // check path handle ::fast_io::win32::details::check_win32_9xa_dir_is_valid(*directory_handle); diff --git a/include/fast_io_hosted/white_hole/white_hole.h b/include/fast_io_hosted/white_hole/white_hole.h index b431d35c..39923012 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(__linux__) && __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 @@ -69,7 +69,7 @@ inline int random_entropy(basic_posix_io_observer piob) noexcept template <::std::integral char_type> using basic_native_white_hole = #if defined(_WIN32) && !defined(__WINE__) -#if defined(_WIN32_WINDOWS) || (_WIN32_WINNT <= 0x0500) +#if defined(_WIN32_WINDOWS) || (defined(_WIN32_WINNT) && _WIN32_WINNT <= 0x0500) basic_win32_crypt_gen_random_file; #else basic_rtl_gen_random; @@ -79,7 +79,7 @@ using basic_native_white_hole = #elif (((defined(__linux__) && defined(__GLIBC__)) || (defined(__BSD_VISIBLE) && !defined(__DARWIN_C_LEVEL)))) && 0 basic_bsd_arc4random; #elif (defined(__linux__) && defined(__NR_getrandom)) || \ - (!defined(__linux__) && __has_include()) && !defined(__DARWIN_C_LEVEL) + (!defined(__linux__) && __has_include()) && !defined(__DARWIN_C_LEVEL) && !defined(__CYGWIN__) basic_linux_getrandom; #else basic_posix_dev_urandom;