fopen(3S-ucb) (BSD Compatibility Package) fopen(3S-ucb)
NAME
fopen, freopen - open a stream
SYNOPSIS
/usr/ucb/cc [flag ...] file ... -lucb
#include <stdio.h>
FILE *fopen(filename, type)
char *filename, *type;
FILE *freopen(filename, type, stream)
char *filename, *type;
FILE *stream;
DESCRIPTION
fopen opens the file named by filename and associates a stream with
it. If the open succeeds, fopen returns a pointer to be used to iden-
tify the stream in subsequent operations.
filename points to a character string that contains the name of the
file to be opened.
type is a character string having one of the following values:
r Open for reading.
w Truncate or create for writing.
a Append: open for writing at end of file, or create for writ-
ing.
r+ Open for update (reading and writing).
w+ Truncate or create for update.
a+ Append; open or create for update at EOF.
freopen opens the file named by filename and associates the stream
pointed to by stream with it. The type argument is used just as in
fopen. The original stream is closed, regardless of whether the open
ultimately succeeds. If the open succeeds, freopen returns the origi-
nal value of stream.
freopen is typically used to attach the preopened streams associated
with stdin, stdout, and stderr to other files.
When a file is opened for update, both input and output may be done on
the resulting stream. However, output may not be directly followed by
input without an intervening fseek or rewind, and input may not be
directly followed by output without an intervening fseek, rewind, or
an input operation which encounters EOF.
Page 1 Reliant UNIX 5.44 Printed 11/98
fopen(3S-ucb) (BSD Compatibility Package) fopen(3S-ucb)
RETURN VALUE
fopen and freopen return a NULL pointer on failure.
NOTES
fopen differs from the library routine of the same name in the base
system only in interface.
In order to support the same number of open files that the system
does, fopen must allocate additional memory for data structures using
calloc after 64 files have been opened. This confuses some programs
which use their own memory allocators.
SEE ALSO
open(2), pipe(2), malloc(3C), fclose(3S), fopen(3S), fseek(3S),
stdio(5).
Page 2 Reliant UNIX 5.44 Printed 11/98