Update copyright notices.
[make.git] / w32 / subproc / w32err.c
blobe0bb110fa87860d596bec4d0822510376bd1583a
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
9 version.
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/>. */
18 #include <windows.h>
19 #include "w32err.h"
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
29 char *
30 map_windows32_error_to_string (DWORD ercode) {
31 /* __declspec (thread) necessary if you will use multiple threads on MSVC */
32 #ifdef _MSC_VER
33 __declspec (thread) static char szMessageBuffer[128];
34 #else
35 static char szMessageBuffer[128];
36 #endif
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,
49 hModule,
50 ercode,
51 LANG_NEUTRAL,
52 szMessageBuffer,
53 sizeof(szMessageBuffer),
54 NULL);
55 FreeLibrary(hModule);
57 } else {
59 * Default system message handling
61 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
62 NULL,
63 ercode,
64 LANG_NEUTRAL,
65 szMessageBuffer,
66 sizeof(szMessageBuffer),
67 NULL);
69 return szMessageBuffer;