Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-59
freopen
freopen
The freopen function opens a file for ANSI I/O by reusing an existing file pointer. It first
attempts to close the file (if any) that is already associated with the existing file pointer.
file_name
points to a string that contains a valid file name, specifying the file that freopen is to
open.
access
points to a string that specifies how you want to access the new file. Refer to
“fopen” on page 3-48 for the possible values of *access.
stream
denotes a file opened for ANSI I/O. stream specifies the file that freopen attempts to
close.
Return Value
is stream if the operation is successful; otherwise, freopen returns the pointer value
NULL.
Usage Guidelines
When you include a system name in the file name, you must precede the system
name with two backslashes instead of one because backslash is an escape character
in C. For example, to open the file \sys.$vol.svol.file, you would use the C string:
"\\sys.$vol.svol.file"
If the file does not already exist, freopen creates a C binary file if you include b in
the access string; otherwise, it creates an Edit file.
The freopen function is typically used to attach the constant names stdin, stdout, and
stderr to specified files.
The freopen function attaches a new file to a previously used file pointer, thus
permitting you to access several files consecutively without declaring a separate
FILE structure for each one.
The freopen function closes the previous file before it reuses the file pointer.
#include <stdioh>
FILE *freopen(const char *file_name, const char *access,
FILE *stream);