mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
util: Use strerror_s for SysErrorString on Windows
This commit is contained in:
parent
46971c6dbf
commit
e7f2f77756
1 changed files with 7 additions and 1 deletions
|
@ -15,15 +15,21 @@ std::string SysErrorString(int err)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
/* Too bad there are two incompatible implementations of the
|
/* Too bad there are three incompatible implementations of the
|
||||||
* thread-safe strerror. */
|
* thread-safe strerror. */
|
||||||
const char *s;
|
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 */
|
#ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */
|
||||||
s = strerror_r(err, buf, sizeof(buf));
|
s = strerror_r(err, buf, sizeof(buf));
|
||||||
#else /* POSIX variant always returns message in buffer */
|
#else /* POSIX variant always returns message in buffer */
|
||||||
s = buf;
|
s = buf;
|
||||||
if (strerror_r(err, buf, sizeof(buf)))
|
if (strerror_r(err, buf, sizeof(buf)))
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return strprintf("%s (%d)", s, err);
|
return strprintf("%s (%d)", s, err);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue