Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Question about ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 25046 of 28234
Post > Topic >>

Question about freopen() failure

by Kenneth Brody <kenbrody@[EMAIL PROTECTED] > Mar 21, 2008 at 10:40 AM

What happens to the existing file stream if freopen() fails?  For
example:

    FILE *f = freopen("/a/filename/that/fails/to/open","w",stdout);

If the specified filename fails to open, is stdout now closed?  From
my reading, it appears so:

7.19.5.4p4:

    The freopen function first attempts to close any file that is
    associated with the specified stream.  Failure to close the file
    is ignored.

In other words, the current stream is closed, and only then does it
attempt to open the specified file.

Am I correct that an freopen() on stdout that fails leaves the program
without any stdout, and that a future fopen() could end up giving that
file to stdout?

(A test program on a particular platform confirms that, on that
platform at least, this does occur.) 

-- 
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@[EMAIL PROTECTED]
>
 




 2 Posts in Topic:
Question about freopen() failure
Kenneth Brody <kenbrod  2008-03-21 10:40:43 
Re: Question about freopen() failure
Eric Sosman <Eric.Sosm  2008-03-21 11:57:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 15:09:23 CST 2008.