From: Pavel A Date: Tue, 1 Jul 2014 06:00:11 +0000 (+0200) Subject: common: Fixed implementation of strerror_r for WinXP X-Git-Tag: 0.20.3~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2bd1a8c5ba3c611899f7dfc27d553010899eeec;p=p11-kit 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 --- 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