1 /* Host support routines for MinGW, for GDB, the GNU debugger.
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "gdb_string.h"
29 /* The strerror() function can return NULL for errno values that are
30 out of range. Provide a "safe" version that always returns a
33 The Windows runtime implementation of strerror never returns NULL,
34 but does return a useless string for anything above sys_nerr;
35 unfortunately this includes all socket-related error codes.
36 This replacement tries to find a system-provided error message. */
39 safe_strerror (int errnum
)
44 if (errnum
>= 0 && errnum
< sys_nerr
)
45 return strerror (errnum
);
53 if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
54 | FORMAT_MESSAGE_FROM_SYSTEM
,
56 MAKELANGID (LANG_NEUTRAL
, SUBLANG_DEFAULT
),
57 (LPTSTR
) &buffer
, 0, NULL
) == 0)
60 xsnprintf (buf
, sizeof buf
, "(undocumented errno %d)", errnum
);
64 /* Windows error messages end with a period and a CR-LF; strip that
66 len
= strlen (buffer
);
67 if (len
> 3 && strcmp (buffer
+ len
- 3, ".\r\n") == 0)
68 buffer
[len
- 3] = '\0';