libstdc++: Add utility for creating std::error_code from OS errors
authorJonathan Wakely <jwakely@redhat.com>
Wed, 10 Feb 2021 18:00:00 +0000 (18:00 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 1 Oct 2021 19:34:49 +0000 (20:34 +0100)
commitd71476c9df931f3ca674941f1942b03eabea010d
tree33076cef361719f15219ea8cd2b9f32b28996e9c
parenta09bb4a852f82af02b3f965358cd44b0aa266a5b
libstdc++: Add utility for creating std::error_code from OS errors

This adds a helper function to encapsulate obtaining an error code for
errors from OS calls. For Windows we want to use GetLastError() and the
system error category, but otherwise just use errno and the generic
error category.

This should not be used to replace existing uses of
ec.assign(errno, generic_category()) because in those cases we really do
want to get the value of errno, not a system-specific error. Only the
cases that currently use GetLastError() are replace by this new
function.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* src/filesystem/ops-common.h (last_error): New helper function.
(filesystem::do_space): Use last_error().
* src/c++17/fs_ops.cc (fs::absolute, fs::create_hard_link)
(fs::equivalent, fs::remove, fs::temp_directory_path): Use
last_error().
* src/filesystem/ops.cc (fs::create_hard_link)
(fs::remove, fs::temp_directory_path): Likewise.
libstdc++-v3/src/c++17/fs_ops.cc
libstdc++-v3/src/filesystem/ops-common.h
libstdc++-v3/src/filesystem/ops.cc