[uClibc]Re: stderr problem
Miles Bader
miles at gnu.org
Wed Aug 28 12:47:07 UTC 2002
On Wed, Aug 28, 2002 at 08:36:58AM -0400, cfowler wrote:
> fd = open(ttyname(), O_WRONLY);
> dup2(fd, 2);
> close(fd);
That's not really a good method, because it (1) redirects stderr to the tty
(if there _is_ a tty!), and (2) doesn't re-establish the stderr stdio stream
(you can use fdopen to do that).
I think it's better to just stash away the stderr file-descriptor with `dup'
before you redirect stderr in the first place.
But you're probably right, it's a good idea to dup2 the `restored' stderr fd
back to fd 2, just so anybody that expects that won't get confused.
So a revised recipe might be:
(1) Before you do the `freopen', do:
int saved_fd = dup (2);
(2) After you've closed f, do:
dup2 (saved_fd, 2)
close (saved_fd);
stderr = fdopen (2, "w");'
-Miles
--
P.S. All information contained in the above letter is false,
for reasons of military security.
More information about the uClibc
mailing list