Add configure operations to support MINGW on Windows.
[make.git] / w32 / subproc / w32err.c
blob712fccdfcc80576308ca9d67eabd370811df6250
1 #include <windows.h>
2 #include "w32err.h"
4 /*
5 * Description: the windows32 version of perror()
7 * Returns: a pointer to a static error
9 * Notes/Dependencies: I got this from
10 * comp.os.ms-windows.programmer.win32
12 char *
13 map_windows32_error_to_string (DWORD ercode) {
14 /* __declspec (thread) necessary if you will use multiple threads on MSVC */
15 #ifdef _MSC_VER
16 __declspec (thread) static char szMessageBuffer[128];
17 #else
18 static char szMessageBuffer[128];
19 #endif
20 /* Fill message buffer with a default message in
21 * case FormatMessage fails
23 wsprintf (szMessageBuffer, "Error %ld\n", ercode);
26 * Special code for winsock error handling.
28 if (ercode > WSABASEERR) {
29 HMODULE hModule = GetModuleHandle("wsock32");
30 if (hModule != NULL) {
31 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
32 hModule,
33 ercode,
34 LANG_NEUTRAL,
35 szMessageBuffer,
36 sizeof(szMessageBuffer),
37 NULL);
38 FreeLibrary(hModule);
40 } else {
42 * Default system message handling
44 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
45 NULL,
46 ercode,
47 LANG_NEUTRAL,
48 szMessageBuffer,
49 sizeof(szMessageBuffer),
50 NULL);
52 return szMessageBuffer;