1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 09:12:24 +00:00

Include the numeric error code in win_strerror's output.

This will be useful if someone gets a mysterious Windows error on a
system configured into a language we don't speak - if they cut and
paste the error message to send to us, then we won't have to try to
translate it.

[originally from svn r10092]
This commit is contained in:
Simon Tatham 2013-11-22 19:41:43 +00:00
parent 98eb785c9b
commit d1e4f9c8fb

View File

@ -211,25 +211,23 @@ const char *win_strerror(int error)
if (!es) { if (!es) {
int bufsize; int bufsize;
char msgtext[65536]; /* maximum size for FormatMessage is 64K */
es = snew(struct errstring); es = snew(struct errstring);
es->error = error; es->error = error;
/* maximum size for FormatMessage is 64K */
bufsize = 65535;
es->text = snewn(bufsize, char);
if (!FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM | if (!FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS), NULL, error, FORMAT_MESSAGE_IGNORE_INSERTS), NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
es->text, bufsize, NULL)) { msgtext, lenof(msgtext)-1, NULL)) {
sprintf(es->text, sprintf(msgtext,
"Windows error code %d (and FormatMessage returned %d)", "(unable to format: FormatMessage returned %d)",
error, GetLastError()); error, GetLastError());
} else { } else {
int len = strlen(es->text); int len = strlen(msgtext);
if (len > 0 && es->text[len-1] == '\n') if (len > 0 && msgtext[len-1] == '\n')
es->text[len-1] = '\0'; msgtext[len-1] = '\0';
} }
es->text = sresize(es->text, strlen(es->text) + 1, char); es->text = dupprintf("Error %d: %s", error, msgtext);
add234(errstrings, es); add234(errstrings, es);
} }