2BSD/man/fopen.u

.TH FOPEN UCB 4/8/79
.SH NAME
fopen, freopen \- open a stream
.SH SYNOPSIS
.B #include <nstdio.h>
.PP
.SM
.B FILE
.B *fopen(filename, type)
.br
.B char *filename, *type;
.PP
.SM
.B FILE
.B *freopen(filename, type, stream)
.br
.B char *filename, *type;
.br
.SM
.B FILE
.B *stream;
.SH DESCRIPTION
.I Fopen
opens the file named by
.I filename
and associates a stream with it.
.I Fopen
returns a pointer to be used to identify
the stream in subsequent operations.
.PP
.I Type
is a character string having one of the following values:
.TP 5
"r"
open for reading
.ns
.TP 5
"w"
create for writing
.ns
.TP 5
"rw"
create for concurrent read/write access
.ns
.TP 5
"a"
append: open for writing at end
of file, or create for writing
.ns
.TP 5
"ra"
read and append: open for concurrent read/write access  at end
of file, or create file and open with such access
.PP
.I Freopen
substitutes the named file in place
of the open
.IR stream .
It returns the original value of
.IR stream .
The original stream is closed.
.PP
.I Freopen
is typically used to attach the preopened
constant names,
.B stdin, stdout, stderr,
to specified files.
.SH "SEE ALSO"
open(2),
fclose(3)
.SH DIAGNOSTICS
.I Fopen
and 
.I freopen
return the pointer
.SM
.B NULL
if
.I filename
cannot be accessed.
.SH BUGS
Undoubtedly