libstdc++: Use correct error category for Windows error codes

When the result of GetLastError() is stored in a std::error_code it
should use std::system_category(), not std::generic_category() that is
used for POSIX errno values.

libstdc++-v3/ChangeLog:

	* src/c++17/fs_ops.cc (fs::create_hard_link, fs::equivalent)
	(fs::remove): Use std::system_category() for error codes from
	GetLastError().
	* src/filesystem/ops.cc (fs::create_hard_link, fs::remove):
	Likewise.
This commit is contained in:
Jonathan Wakely 2021-02-10 16:45:38 +00:00
parent 6a6f74be9d
commit 313e2dc377
2 changed files with 6 additions and 6 deletions

View File

@ -690,7 +690,7 @@ fs::create_hard_link(const path& to, const path& new_hard_link,
if (CreateHardLinkW(new_hard_link.c_str(), to.c_str(), NULL))
ec.clear();
else
ec.assign((int)GetLastError(), generic_category());
ec.assign((int)GetLastError(), system_category());
#else
ec = std::make_error_code(std::errc::not_supported);
#endif
@ -882,12 +882,12 @@ fs::equivalent(const path& p1, const path& p2, error_code& ec) noexcept
if (!h1 || !h2)
{
if (!h1 && !h2)
ec.assign((int)GetLastError(), generic_category());
ec.assign((int)GetLastError(), system_category());
return false;
}
if (!h1.get_info() || !h2.get_info())
{
ec.assign((int)GetLastError(), generic_category());
ec.assign((int)GetLastError(), system_category());
return false;
}
return h1.info.dwVolumeSerialNumber == h2.info.dwVolumeSerialNumber
@ -1263,7 +1263,7 @@ fs::remove(const path& p, error_code& ec) noexcept
return true;
}
else if (!ec)
ec.assign((int)GetLastError(), generic_category());
ec.assign((int)GetLastError(), system_category());
}
else if (status_known(st))
ec.clear();

View File

@ -590,7 +590,7 @@ fs::create_hard_link(const path& to, const path& new_hard_link,
if (CreateHardLinkW(new_hard_link.c_str(), to.c_str(), NULL))
ec.clear();
else
ec.assign((int)GetLastError(), generic_category());
ec.assign((int)GetLastError(), system_category());
#else
ec = std::make_error_code(std::errc::not_supported);
#endif
@ -1062,7 +1062,7 @@ fs::remove(const path& p, error_code& ec) noexcept
return true;
}
else if (!ec)
ec.assign((int)GetLastError(), generic_category());
ec.assign((int)GetLastError(), system_category());
}
else if (status_known(st))
ec.clear();