diff options
author | laanwj <126646+laanwj@users.noreply.github.com> | 2022-04-20 16:43:07 +0200 |
---|---|---|
committer | laanwj <126646+laanwj@users.noreply.github.com> | 2022-04-28 10:24:06 +0200 |
commit | e7f2f77756d33c6be9c8998a575b263ff2d39270 (patch) | |
tree | e6387fb099622dbd512a03cb5cab2b89e12c2cb9 /src/util/syserror.cpp | |
parent | 46971c6dbfbc39ebbc74ab1ed8c00edc12859373 (diff) |
util: Use strerror_s for SysErrorString on Windows
Diffstat (limited to 'src/util/syserror.cpp')
-rw-r--r-- | src/util/syserror.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/util/syserror.cpp b/src/util/syserror.cpp index bcd249200d..20f89057fc 100644 --- a/src/util/syserror.cpp +++ b/src/util/syserror.cpp @@ -15,9 +15,14 @@ std::string SysErrorString(int err) { char buf[256]; buf[0] = 0; - /* Too bad there are two incompatible implementations of the + /* Too bad there are three incompatible implementations of the * thread-safe strerror. */ const char *s; +#ifdef WIN32 + s = buf; + if (strerror_s(buf, sizeof(buf), err) != 0) + buf[0] = 0; +#else #ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */ s = strerror_r(err, buf, sizeof(buf)); #else /* POSIX variant always returns message in buffer */ @@ -25,5 +30,6 @@ std::string SysErrorString(int err) if (strerror_r(err, buf, sizeof(buf))) buf[0] = 0; #endif +#endif return strprintf("%s (%d)", s, err); } |