From b0825f36b7b5dade1693fdbddfec7eef3f5ed86f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 8 Aug 2003 19:39:41 +0000 Subject: [PATCH] Better error messages under Windows. --- lib/utils.c | 5 ++++- lib/utils.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utils.c b/lib/utils.c index 43abf96..2e40ef5 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -86,13 +86,16 @@ void cp_trace() #endif char *winerror(int err) { - static char buf[1024]; + static char buf[1024], *newline; if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) { strncpy(buf, _("(unable to format errormessage)"), sizeof(buf)); }; + if((newline = strchr(buf, '\r'))) + *newline = '\0'; + return buf; } #endif diff --git a/lib/utils.h b/lib/utils.h index d8dc476..af65427 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -40,6 +40,7 @@ extern void bin2hex(char *src, char *dst, int length); #ifdef HAVE_MINGW extern char *winerror(int); +#define strerror(x) (x>0?strerror(x):winerror(GetLastError())) #endif #endif /* __TINC_UTILS_H__ */ -- 2.25.1