HP C/iX Library Reference Manual (30026-90004)
Chapter 5 173
HP C/iX Library Function Descriptions
freopen
freopen
Closes and reopens a stream.
Syntax
#include <stdio.h>
FILE *freopen (const char *
fname
, const char *
type
,
FILE *
stream
);
Parameters
fname
A pointer to a character string that contains the name of the file to be
opened.
type
A pointer to a character string defining the mode of the file open.
stream
A pointer to an open stream.
Return Values
x If successful, a pointer to the FILE structure associated with the stream.
NULL The file open operation failed.
Description
The freopen function substitutes the named file in place of the open
stream
. The original
stream is closed, regardless of whether the open succeeds (close errors are ignored). This
function returns a pointer to new
stream
.
This function is typically used to attach the preopened streams associated with stdin,
stdout and stderr to other files.
Opening a file in read mode fails if the file does not exist or cannot be read.
When a file is opened for update, both input and output may be done on the resulting
stream. Do not directly follow output with input without an intervening call to fflush()
or to a file positioning function (fseek(), fsetpos(), or rewind()). Do not directly follow
input with output without an intervening call to a file positioning function unless the input
operation encounters end-of-file.
When a file is opened for appending, it is impossible to overwrite information already in
the file. fseek() may be used to reposition the file pointer to any position in the file, but
when output is written to the file, the current file pointer is disregarded. All output is
written at the end of the file and the file pointer is repositioned at the end of the output.
When opening a binary file the file position indicator may, in some cases, be positioned
beyond the last data written, because of blank or null padding.
When opened, a stream is fully buffered only if it can be determined not to refer to an
interactive device. The error and end-of-file indicators for a stream are cleared.