This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] cygcheck: eprintf + display_error: Do more.


Hi,

This patch enables eprintf. It also causes stdout and stderr to be
synchronzied (using fflush) when they refer to the same file-descriptor.

Also, when stdout and stderr have a different number, and stdout is not
a tty, the error-message is copied to stdout, allowing it to be easily
captured in a cygcheck.out.

(I'm aware that generally it is a bad idea to do things like this, but
cygcheck being what it is, I think this ought to be an exception.)


ChangeLog-entry:

2004-11-18  Bas van Gompel  <cygwin-patch.buzz@bavag.tmfweb.nl>

	* cygcheck.cc (eprintf): Print to stdout as well, when stdout and
	stderr represent different file-descriptors and stdout is not a tty.
	(display_error): Use eprintf. Flush stdout before, and stderr after
	output, when stdout and stderr refer to the same file-descriptor.


--- src/winsup/utils/cygcheck.cc	2004-11-18 06:35:06.000000000 +0100
+++ src/winsup/utils/cygcheck.cc	2004-11-18 08:35:52.000000000 +0100
@@ -9,6 +9,7 @@
    details. */
 
 #include <stdio.h>
+#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/time.h>
@@ -105,6 +106,12 @@ eprintf (const char *format, ...)
   va_start (ap, format);
   vfprintf (stderr, format, ap);
   va_end (ap);
+  if (fileno (stdout) != fileno (stderr) && !isatty (fileno (stdout)))
+    {
+      va_start (ap, format);
+      vfprintf (stdout, format, ap);
+      va_end (ap);
+    }
 }
 
 /*
@@ -113,12 +120,16 @@ eprintf (const char *format, ...)
 static int
 display_error (const char *name, bool show_error = true, bool print_failed = true)
 {
+  if (fileno (stdout) == fileno (stderr))
+    fflush (stdout);
   if (show_error)
-    fprintf (stderr, "cygcheck: %s%s: %lu\n", name,
+    eprintf ("cygcheck: %s%s: %lu\n", name,
 	print_failed ? " failed" : "", GetLastError ());
   else
-    fprintf (stderr, "cygcheck: %s%s\n", name,
+    eprintf ("cygcheck: %s%s\n", name,
 	print_failed ? " failed" : "");
+  if (fileno (stdout) == fileno (stderr))
+    fflush (stderr);
   return 1;
 }
 


L8r,


Buzz.
-- 
  ) |  | ---/ ---/  Yes, this | This message consists of true | I do not
--  |  |   /    /   really is |   and false bits entirely.    | mail for
  ) |  |  /    /    a 72 by 4 +-------------------------------+ any1 but
--  \--| /--- /---  .sigfile. |   |perl -pe "s.u(z)\1.as."    | me. 4^re


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]