[PATCH v2] test-skeleton: redirect stderr to stdout

Mike Frysinger vapier@gentoo.org
Fri Jun 17 05:30:00 GMT 2016


Rather than worry if we use funcs that dirty stderr instead of writing
to stdout, redirect stderr internally to stdout.  Now all output will
go to stdout regardless.
---
 test-skeleton.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/test-skeleton.c b/test-skeleton.c
index a9ad4ab7e9c6..d07d0d76ca11 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -343,6 +343,19 @@ main (int argc, char *argv[])
   setbuf (stdout, NULL);
 #endif
 
+  /* Bind stderr to stdout so that tests don't have to worry about which
+     one to use, and whether funcs they use (e.g. assert) will go to the
+     wrong place.  */
+  fclose (stderr);
+  if (dup2 (STDOUT_FILENO, STDERR_FILENO) == -1)
+    {
+      printf ("binding stderr to stdout failed: %m\n");
+      exit (1);
+    }
+  stderr = fdopen (STDERR_FILENO, "w");
+  /* Since stderr always starts out unbuffered, recreate that here.  */
+  setbuf (stderr, NULL);
+
   while ((opt = getopt_long (argc, argv, "+", options, NULL)) != -1)
     switch (opt)
       {
-- 
2.8.2



More information about the Libc-alpha mailing list