From d0718cd6317e6d6f7d752c4068061e44f81edb70 Mon Sep 17 00:00:00 2001 From: dmiller Date: Sun, 1 Oct 2017 02:50:05 +0000 Subject: [PATCH] Get correct errors from Windows on failure (errno is not set). See #978 --- ncat/ncat.vcxproj | 1 - ncat/util.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ncat/ncat.vcxproj b/ncat/ncat.vcxproj index 185c9338c..fc44dfa59 100644 --- a/ncat/ncat.vcxproj +++ b/ncat/ncat.vcxproj @@ -213,7 +213,6 @@ - diff --git a/ncat/util.c b/ncat/util.c index f2eb63e31..fd845b2ba 100644 --- a/ncat/util.c +++ b/ncat/util.c @@ -235,7 +235,18 @@ void logtest(const char *fmt, ...) /* Exit status 2 indicates a program error other than a network error. */ void die(char *err) { +#ifdef WIN32 + int error_number; + char *strerror_s; + error_number = GetLastError(); + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error_number, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &strerror_s, 0, NULL); + fprintf(stderr, "%s: %s\n", err, strerror_s); + HeapFree(GetProcessHeap(), 0, strerror_s); +#else perror(err); +#endif fflush(stderr); exit(2); }