From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id D46F538432E8 for ; Sun, 4 Dec 2022 21:34:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D46F538432E8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org Message-ID: <08776f09871ef817669410c7b1a26122e3c2c75b.camel@gentoo.org> Subject: Resource use fopen-vs-freopen From: David Seifert To: libc-alpha@sourceware.org Date: Sun, 04 Dec 2022 22:34:32 +0100 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.2 MIME-Version: 1.0 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi glibc, this came up recently as a point of interest. Say we have snippet 1: #include void reset_std_streams(void) { stdin =3D fopen("/dev/null", "r"); } int main(void) { reset_std_streams(); // A /* -- actual program code -- */ } and snippet 2: #include void reset_std_streams(void) { freopen("/dev/null", "r", stdin); } int main(void) { reset_std_streams(); // B /* -- actual program code -- */ } 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? Are there any resources in terms of buffers, memory mapped pages or other static or dynamic resources that freopen() variant would use that the fopen() variant would not?