Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: comp.os.linux.development.apps Subject: Re: How to dup a FILE* Date: Tue, 06 Dec 2011 20:38:47 +0000 Lines: 20 Message-ID: <8762hto2p4.fsf@sapphire.mobileactivedefense.com> References: <20111206195333.49dd7a9d@dwnoon.ntlworld.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net JgUeFk1UbU/Fbhw1N91wGANYZijdkBaU0vWHQbhBC9kWGIMGM= Cancel-Lock: sha1:xT5EEDYpa3qwc9SUYqM1jF5m7ao= sha1:jR9luxqYAwqgMv6sJzRjLnY9U0w= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Xref: x330-a1.tempe.blueboxinc.net comp.os.linux.development.apps:299 David W Noon writes: > On Tue, 06 Dec 2011 09:51:43 +0100, Josef Moellers wrote about How to > dup a FILE*: > >>I need to juggle with stderr: redirecting it from one file to another >>and back. > [snip] > > I think you're over-complicating things here. After all, stderr is > simply a pointer. So, cache the old pointer; open a new file stream > stored in stderr; fclose(stderr) when done; reinstate the original > pointer. That's a thoroughly stupid idea because it won't affect output to 'standard error filedescriptor' which doesn't go through the stderr stream *and* while the glibc documentation claims that this should work, it actually doesn't (or at least didn't for some random version where I tried this about ten years ago -- only to be told that I "should use freopen instead" by Ulrich Drepper [which I couldn't do because I was trying to divert the output to a socket]).