From 7eed8a8f10f00d19177b6f7b4665a87dff122068 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Thu, 5 Jan 2017 15:45:01 +1300 Subject: [PATCH] fopen.3: Describe freopen() behavior for NULL pathname argument See https://bugzilla.kernel.org/show_bug.cgi?id=191261 Reported-by: Helmut Eller Signed-off-by: Michael Kerrisk --- man3/fopen.3 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/man3/fopen.3 b/man3/fopen.3 index 12619976f..20f94bcc5 100644 --- a/man3/fopen.3 +++ b/man3/fopen.3 @@ -202,6 +202,28 @@ The argument is used just as in the .BR fopen () function. + +If the +.I path +argument is a null pointer, +.BR freopen () +changes the mode of the stream to that specified in +.IR mode ; +that is, +.BR freopen () +reopens the pathname that is associated with the stream. +The specification for this behavior was added in the C99 standard, which says: + +.RS +In this case, +the file descriptor associated with the stream need not be closed +if the call to +.BR freopen () +succeeds. +It is implementation-defined which changes of mode are permitted (if any), +and under what circumstances. +.RE +.PP The primary use of the .BR freopen () function is to change the file associated with a standard text stream