Skip to content

Commit e7f2f77

Browse files
committed
util: Use strerror_s for SysErrorString on Windows
1 parent 46971c6 commit e7f2f77

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util/syserror.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ std::string SysErrorString(int err)
1515
{
1616
char buf[256];
1717
buf[0] = 0;
18-
/* Too bad there are two incompatible implementations of the
18+
/* Too bad there are three incompatible implementations of the
1919
* thread-safe strerror. */
2020
const char *s;
21+
#ifdef WIN32
22+
s = buf;
23+
if (strerror_s(buf, sizeof(buf), err) != 0)
24+
buf[0] = 0;
25+
#else
2126
#ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */
2227
s = strerror_r(err, buf, sizeof(buf));
2328
#else /* POSIX variant always returns message in buffer */
2429
s = buf;
2530
if (strerror_r(err, buf, sizeof(buf)))
2631
buf[0] = 0;
32+
#endif
2733
#endif
2834
return strprintf("%s (%d)", s, err);
2935
}

0 commit comments

Comments
 (0)