make-dfsg/w32/subproc/w32err.c

71 lines
2.1 KiB
C
Raw Normal View History

/* Error handling for Windows
2006-02-11 22:16:04 +00:00
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
1996-07-19 21:41:07 +00:00
#include <windows.h>
#include "w32err.h"
/*
1997-04-07 07:21:16 +00:00
* Description: the windows32 version of perror()
1996-07-19 21:41:07 +00:00
*
* Returns: a pointer to a static error
*
* Notes/Dependencies: I got this from
1996-07-19 21:41:07 +00:00
* comp.os.ms-windows.programmer.win32
*/
char *
1997-04-07 07:21:16 +00:00
map_windows32_error_to_string (DWORD ercode) {
/* __declspec (thread) necessary if you will use multiple threads on MSVC */
#ifdef _MSC_VER
1996-07-19 21:41:07 +00:00
__declspec (thread) static char szMessageBuffer[128];
#else
static char szMessageBuffer[128];
#endif
/* Fill message buffer with a default message in
* case FormatMessage fails
1996-07-19 21:41:07 +00:00
*/
wsprintf (szMessageBuffer, "Error %ld\n", ercode);
1996-07-19 21:41:07 +00:00
/*
* Special code for winsock error handling.
*/
if (ercode > WSABASEERR) {
HMODULE hModule = GetModuleHandle("wsock32");
if (hModule != NULL) {
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
hModule,
ercode,
LANG_NEUTRAL,
szMessageBuffer,
sizeof(szMessageBuffer),
NULL);
FreeLibrary(hModule);
}
1996-07-19 21:41:07 +00:00
} else {
/*
* Default system message handling
*/
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
ercode,
LANG_NEUTRAL,
szMessageBuffer,
sizeof(szMessageBuffer),
NULL);
}
return szMessageBuffer;
}