1 /* Error handling for Windows
2 Copyright (C) 1996-2012 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
23 * Description: the windows32 version of perror()
25 * Returns: a pointer to a static error
27 * Notes/Dependencies: I got this from
28 * comp.os.ms-windows.programmer.win32
31 map_windows32_error_to_string (DWORD ercode
) {
33 * We used to have an MSVC-specific '__declspec (thread)' qualifier
34 * here, with the following comment:
36 * __declspec (thread) necessary if you will use multiple threads on MSVC
38 * However, Make was never multithreaded on Windows (except when
39 * Ctrl-C is hit, in which case the main thread is stopped
40 * immediately, so it doesn't matter in this context). The functions
41 * on sub_proc.c that started and stopped additional threads were
42 * never used, and are now #ifdef'ed away. Until we need more than
43 * one thread, we have no problems with the following buffer being
44 * static. (If and when we do need it to be in thread-local storage,
45 * the corresponding GCC qualifier is '__thread'.)
47 static char szMessageBuffer
[128];
48 /* Fill message buffer with a default message in
49 * case FormatMessage fails
51 wsprintf (szMessageBuffer
, "Error %ld\n", ercode
);
54 * Special code for winsock error handling.
56 if (ercode
> WSABASEERR
) {
58 HMODULE hModule
= GetModuleHandle("wsock32");
59 if (hModule
!= NULL
) {
60 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
,
65 sizeof(szMessageBuffer
),
70 fatal(NILF
, szMessageBuffer
);
74 * Default system message handling
76 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
,
81 sizeof(szMessageBuffer
),
84 return szMessageBuffer
;