1 /* Error handling for Windows
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009 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/>. */
22 * Description: the windows32 version of perror()
24 * Returns: a pointer to a static error
26 * Notes/Dependencies: I got this from
27 * comp.os.ms-windows.programmer.win32
30 map_windows32_error_to_string (DWORD ercode
) {
31 /* __declspec (thread) necessary if you will use multiple threads on MSVC */
33 __declspec (thread
) static char szMessageBuffer
[128];
35 static char szMessageBuffer
[128];
37 /* Fill message buffer with a default message in
38 * case FormatMessage fails
40 wsprintf (szMessageBuffer
, "Error %ld\n", ercode
);
43 * Special code for winsock error handling.
45 if (ercode
> WSABASEERR
) {
46 HMODULE hModule
= GetModuleHandle("wsock32");
47 if (hModule
!= NULL
) {
48 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
,
53 sizeof(szMessageBuffer
),
59 * Default system message handling
61 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
,
66 sizeof(szMessageBuffer
),
69 return szMessageBuffer
;