K
Kenneth Brody
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:[email protected]>
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:[email protected]>