[PATCH v2] test-skeleton: redirect stderr to stdout
Mike Frysinger
vapier@gentoo.org
Fri Jun 17 14:47:00 GMT 2016
On 17 Jun 2016 12:12, Pedro Alves wrote:
> On 06/17/2016 06:29 AM, Mike Frysinger wrote:
>
> > + /* 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);
>
> Why do you need to fclose/fdopen stderr at all?
> Just the "dup2 (STDOUT_FILENO, STDERR_FILENO)" should be enough.
we discussed it here where i asked for docs:
https://sourceware.org/ml/libc-alpha/2016-06/msg00636.html
> Note that that's what
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html
>
> suggests in its example section:
>
> ~~~~~~~~~~~~~~~~~~~~~
> Redirecting Error Messages
>
> The following example redirects messages from stderr to stdout.
>
> #include <unistd.h>
> ...
> dup2(1, 2);
> ...
> ~~~~~~~~~~~~~~~~~~~~~
that only guarantees the fd level. where do we guarantee the stdio level ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160617/52c43409/attachment.sig>
More information about the Libc-alpha
mailing list