libstdc++: Fix error handling in fs::hard_link_count for Windows
commit71b1639c67b91554420cc38eb4c82323e535c816
authorJonathan Wakely <jwakely@redhat.com>
Mon, 2 Sep 2024 11:16:49 +0000 (2 12:16 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 3 Sep 2024 15:18:21 +0000 (3 16:18 +0100)
tree591ab161927ae4d10756bafb49114be21656fdfc
parent819deae0a5bee079a7d5582fafaa098c26144ae8
libstdc++: Fix error handling in fs::hard_link_count for Windows

The recent change to use auto_win_file_handle for
std::filesystem::hard_link_count caused a regression. The
std::error_code argument should be cleared if no error occurs, but this
no longer happens. Add a call to ec.clear() in fs::hard_link_count to
fix this.

Also change the auto_win_file_handle class to take a reference to the
std::error_code and set it if an error occurs, to slightly simplify the
control flow in the fs::equiv_files function.

libstdc++-v3/ChangeLog:

* src/c++17/fs_ops.cc (auto_win_file_handle): Add error_code&
member and set it if CreateFileW or GetFileInformationByHandle
fails.
(fs::equiv_files) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Simplify
control flow.
(fs::hard_link_count) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Clear ec
on success.
* testsuite/27_io/filesystem/operations/hard_link_count.cc:
Check error handling.
libstdc++-v3/src/c++17/fs_ops.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/hard_link_count.cc