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