From: Guus Sliepen Date: Sun, 21 Oct 2018 14:24:10 +0000 (+0200) Subject: Fix compiling test binaries on Windows. X-Git-Tag: release-1.1pre18~40 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=65f48924ff16a8471ad4464de1ee547bfb8a114c;p=tinc Fix compiling test binaries on Windows. --- diff --git a/test/splice.c b/test/splice.c index 53451481..ee77d1bf 100644 --- a/test/splice.c +++ b/test/splice.c @@ -17,16 +17,26 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include -#include -#include -#include -#include +#include "../src/system.h" #ifdef HAVE_MINGW -extern const char *winerror(int); +static const char *winerror(int err) { + static char buf[1024], *ptr; + + ptr = buf + snprintf(buf, sizeof(buf), "(%d) ", err); + + if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) { + strncpy(buf, "(unable to format errormessage)", sizeof(buf)); + }; + + if((ptr = strchr(buf, '\r'))) { + *ptr = '\0'; + } + + return buf; +} + #define strerror(x) ((x)>0?strerror(x):winerror(GetLastError())) #define sockerrno WSAGetLastError() #define sockstrerror(x) winerror(x)