FOPEN(3)

NAME
fopen, freopen - open a stream

SYNOPSIS
#include <nstdio.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. Fopen returns a pointer to be used to identify the stream in subsequent operations.

Type is a character string having one of the following values:

"r" open for reading

"w" create for writing

"rw" or "w+"
    Create for concurrent read/write access. The file is first truncated, if it exists, and created if it does not.

"a" Append: open for writing at end of file, or create for writing

"ra" or "a+"
    Read and append: open for concurrent read/write access at end of file, or create file and open with such access

"r+"
    Read and write: open for both reading and writing but do not truncate the file first.

Freopen substitutes the named file in place of 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, stderr, to specified files.

SEE ALSO
open(2), fclose(3)

DIAGNOSTICS
Fopen and freopen return the pointer NULL if filename cannot be accessed.

BUGS
The "+" syntax is included merely for compatibility with the USG stdio, and is not to be viewed as true support. The USG stdio has restrictions on how you can switch from reading to writing or vice versa. LibNS has no such restrictions, at a small runtime cost.