FOPEN(3S)
NAME
fopen, freopen, fdopen − open a stream
USAGE
#include <stdio.h>
FILE *fopen(filename, type) char *filename, *type;
FILE *freopen(filename, type, stream) char *filename, *type; FILE *stream;
FILE *fdopen(fildes, type) char *type;
DESCRIPTION
Fopen opens filename and associates a stream with it. Fopen returns a pointer that identifies the stream in later operations.
Type is a character string with one of the following values:
r open for reading
w create for writing
a append: open for writing at end of file, or create for writing
In addition, each type may be followed by a plus sign (+) to have the file opened for reading and writing. "r+" positions the stream at the beginning of the file, "w+" creates or truncates it, and "a+" positions it at the end. Both reads and writes may be used on read/write streams, with the limitation that an fseek, rewind, or reading an end-of-file must be used between a read and a write, or between a write and a read.
Freopen substitutes the file named for the open stream. It returns the original value of stream. The original stream is closed.
Freopen is typically used to attach the preopened constant names, stdin, stdout, and stderr to specified files.
Fdopen associates a stream with a file descriptor obtained from open, dup, creat, or pipe(2). The type of stream must agree with the mode of the open file.
DIAGNOSTICS
Fopen and freopen return a null pointer if filename cannot be accessed.