From 65f48924ff16a8471ad4464de1ee547bfb8a114c Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 21 Oct 2018 16:24:10 +0200 Subject: [PATCH] Fix compiling test binaries on Windows. --- test/splice.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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) -- 2.20.1