]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Make std::system_category() recognize Windows error codes
authorJonathan Wakely <jwakely@redhat.com>
Wed, 10 Feb 2021 16:10:46 +0000 (16:10 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 23 Sep 2021 15:07:39 +0000 (16:07 +0100)
commit477897451e46d67acb46f3ac45585e6eb9e7dde5
treeeb482e7cf9d8251e5e00bbb6b901d99c4918d5d3
parentdd396a321be5099536af36e64454c1fcf9d67e12
libstdc++: Make std::system_category() recognize Windows error codes

The std::system_category error category should be used for
system-specific error codes, which means on Windows it should be used
for Windows error codes.  Currently that category assumes that the error
numbers it deals with are errno numbers, which means that
ERROR_ACCESS_DENIED (which has value 0x5) gets treated as whichever
errno number happens to have that value (EIO on mingw32-w64).

This adds a mapping from known Windows error codes to generic errno
ones. This means we correctly treat ERROR_ACCESS_DENIED as corresponding
to EACCES.

Also make std::system_category().message(int) return the right message
for Windows errors, by using FormatMessage instead of strerror. The
output of FormatMessage includes ".\r\n" at the end, so we strip that
off to allow the message to be used in contexts where that would be
problematic.

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

* src/c++11/system_error.cc (system_error_category) [_WIN32]:
Map Windows error codes to generic POSIX error numbers. Use
FormatMessage instead of strerror.
* testsuite/19_diagnostics/error_category/system_category.cc:
Adjust for new behaviour on Windows.
libstdc++-v3/src/c++11/system_error.cc
libstdc++-v3/testsuite/19_diagnostics/error_category/system_category.cc