]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] cmd/dist: Make windows.c's fatal() print to stderr
authorPieter Droogendijk <pieter@binky.org.uk>
Fri, 21 Sep 2012 19:53:55 +0000 (05:53 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Fri, 21 Sep 2012 19:53:55 +0000 (05:53 +1000)
««« backport 3f7501fdb220
cmd/dist: Make windows.c's fatal() print to stderr

Generating env.bat using dist env -wp > env.bat failed silently
if case of an error, because the message was redirected to env.bat.
Verbose messages still go to stdout, causing problems, but that's
a seperate change.
Made errprintf() identical to xprintf(), except for the output handle.
Yes, it's duplicate code, but most of the function is unpacking
the argument list and preparing it for WriteFile(), which has to be
done anyway.

R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/6343047

»»»

src/cmd/dist/windows.c

index 557e4b00311c4d0183c5b8a8ed4aec342d4367c6..a2c2e65effa92dbeb4d73669e56aca66e8916be9 100644 (file)
@@ -121,6 +121,22 @@ errstr(void)
        return bstr(&b);  // leak but we're dying anyway
 }
 
+static void
+errprintf(char *fmt, ...) {
+       va_list arg;
+       char *p;
+       DWORD n, w;
+
+       va_start(arg, fmt);
+       n = vsnprintf(NULL, 0, fmt, arg);
+       p = xmalloc(n+1);
+       vsnprintf(p, n+1, fmt, arg);
+       va_end(arg);
+       w = 0;
+       WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
+       xfree(p);
+}
+
 void
 xgetenv(Buf *b, char *name)
 {
@@ -707,7 +723,7 @@ fatal(char *msg, ...)
        vsnprintf(buf1, sizeof buf1, msg, arg);
        va_end(arg);
 
-       xprintf("go tool dist: %s\n", buf1);
+       errprintf("go tool dist: %s\n", buf1);
        
        bgwait();
        ExitProcess(1);