#include <stdio.h>
#include <stdlib.h>
#include "putty.h"
+#define SECURITY_WIN32
#include <security.h>
OSVERSIONINFO osVersion;
es = find234(errstrings, &error, errstring_find);
if (!es) {
- int bufsize, bufused;
+ char msgtext[65536]; /* maximum size for FormatMessage is 64K */
es = snew(struct errstring);
es->error = error;
- /* maximum size for FormatMessage is 64K */
- bufsize = 65535;
- es->text = snewn(bufsize, char);
if (!FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS), NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- es->text + bufused, bufsize - bufused, NULL)) {
- sprintf(es->text,
- "Windows error code %d (and FormatMessage returned %d)",
- error, GetLastError());
+ msgtext, lenof(msgtext)-1, NULL)) {
+ sprintf(msgtext,
+ "(unable to format: FormatMessage returned %d)",
+ GetLastError());
} else {
- int len = strlen(es->text);
- if (len > 0 && es->text[len-1] == '\n')
- es->text[len-1] = '\0';
+ int len = strlen(msgtext);
+ if (len > 0 && msgtext[len-1] == '\n')
+ 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);
}