From: Zack Weinberg <zack@owlfolio.org>
To: libc-alpha@sourceware.org
Subject: Re: Resource use fopen-vs-freopen
Date: Mon, 5 Dec 2022 13:55:38 -0500 [thread overview]
Message-ID: <83b50ed9-9391-2413-6375-fe5e4650d169@owlfolio.org> (raw)
In-Reply-To: <08776f09871ef817669410c7b1a26122e3c2c75b.camel@gentoo.org>
On 2022-12-04 4:34 PM, David Seifert via Libc-alpha wrote:
...
> void reset_std_streams(void) {
> stdin = fopen("/dev/null", "r");
> }
...
> void reset_std_streams(void) {
> freopen("/dev/null", "r", stdin);
> }
...
> When comparing the total tally of all resources used at point A in
> snippet 1 and point B in snippet 2, is there an actual difference?
Yes. Snippet 1 leaks the old FILE object and, critically, *does not
change file descriptor 0*, which remains open on the old stdin.
zw
prev parent reply other threads:[~2022-12-05 18:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-04 21:34 David Seifert
2022-12-05 18:55 ` Zack Weinberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83b50ed9-9391-2413-6375-fe5e4650d169@owlfolio.org \
--to=zack@owlfolio.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).