summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel A <pavel_a at live.com>2014-07-01 08:00:11 +0200
committerStef Walter <stef@thewalter.net>2014-07-01 08:00:19 +0200
commita2bd1a8c5ba3c611899f7dfc27d553010899eeec (patch)
tree3e829200091bce0f3409f3c309a81d40140998d0
parent6527f5d3b24a96369a24281db7593d5c4fc73408 (diff)
common: Fixed implementation of strerror_r for WinXP
ie: when streror_s is missing in msvcrt.dll https://bugs.freedesktop.org/show_bug.cgi?id=76594
-rw-r--r--common/compat.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/compat.c b/common/compat.c
index 85a33c8..fef618b 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -844,7 +844,22 @@ strerror_r (int errnum,
size_t buflen)
{
#ifdef OS_WIN32
+#if _WIN32_WINNT < 0x502 /* WinXP or older */
+ int n = sys_nerr;
+ const char *p;
+ if (errnum < 0 || errnum >= n)
+ p = sys_errlist[n];
+ else
+ p = sys_errlist[errnum];
+ if (buf == NULL || buflen == 0)
+ return EINVAL;
+ strncpy(buf, p, buflen);
+ buf[buflen-1] = 0;
+ return 0;
+#else /* Server 2003 or newer */
return strerror_s (buf, buflen, errnum);
+#endif /*_WIN32_WINNT*/
+
#else
#error no strerror_r implementation
#endif