This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v2] test-skeleton: redirect stderr to stdout
- From: Mike Frysinger <vapier at gentoo dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 17 Jun 2016 01:29:21 -0400
- Subject: [PATCH v2] test-skeleton: redirect stderr to stdout
- Authentication-results: sourceware.org; auth=none
- References: <1466052483-27705-1-git-send-email-vapier at gentoo dot org>
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