From: Guus Sliepen Date: Sun, 21 Oct 2018 14:24:10 +0000 (+0200) Subject: Fix compiling test binaries on Windows. X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=65f48924ff16a8471ad4464de1ee547bfb8a114c;p=oweals%2Ftinc.git Fix compiling test binaries on Windows. --- diff --git a/test/splice.c b/test/splice.c index 5345148..ee77d1b 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)