1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-22 07:29:01 +00:00

Get correct errors from Windows on failure (errno is not set). See #978

This commit is contained in:
dmiller
2017-10-01 02:50:05 +00:00
parent 3c91ad69b4
commit d0718cd631
2 changed files with 11 additions and 1 deletions

View File

@@ -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);
}