]> asedeno.scripts.mit.edu Git - PuTTY_svn.git/commitdiff
Include the numeric error code in win_strerror's output.
authorSimon Tatham <anakin@pobox.com>
Fri, 22 Nov 2013 19:41:43 +0000 (19:41 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 22 Nov 2013 19:41:43 +0000 (19:41 +0000)
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.

git-svn-id: http://svn.tartarus.org/sgt/putty@10092 cda61777-01e9-0310-a592-d414129be87e

windows/winmisc.c

index c719c7265e9b77bf1776fa8668dcb59d0ad1bf23..7823b43e4917745369485938fd404ee940dac305 100644 (file)
@@ -211,25 +211,23 @@ const char *win_strerror(int error)
 
     if (!es) {
         int bufsize;
+        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, bufsize, NULL)) {
-            sprintf(es->text,
-                    "Windows error code %d (and FormatMessage returned %d)", 
+                           msgtext, lenof(msgtext)-1, NULL)) {
+            sprintf(msgtext,
+                    "(unable to format: FormatMessage returned %d)", 
                     error, 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);
     }