system/Error: use std::generic_category() for errno on Windows

It's wrong to use std::system_category() for both GetLastError() and
errno on Windows.  Apparently, everybody uses std::generic_category()
for errno values, which appears to be a safe choice.

Some discussion on this confusing topic can be found here:

 https://stackoverflow.com/questions/28746372/system-error-categories-and-standard-system-error-codes
This commit is contained in:
Max Kellermann
2016-12-04 19:50:21 +01:00
parent 30dc473697
commit c6e1ca1c22
2 changed files with 28 additions and 7 deletions

View File

@@ -21,8 +21,7 @@
#include "FlacIOHandle.hxx"
#include "Log.hxx"
#include "Compiler.h"
#include <system_error>
#include "system/Error.hxx"
#include <errno.h>
#include <stdio.h>
@@ -49,7 +48,7 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
#ifndef WIN32
} catch (const std::system_error &e) {
errno = e.code().category() == std::system_category()
errno = e.code().category() == ErrnoCategory()
? e.code().value()
/* just some random non-zero errno
value */