Manual Page Result
0
Command: fopen | Section: 3 | Source: UNIX v10 | File: fopen.3
FOPEN(3S) FOPEN(3S)
NAME
fopen, freopen, fdopen, fclose, fflush - open, close, or flush a stream
SYNOPSIS
#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;
int fclose(stream)
FILE *stream;
int fflush(stream)
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
"r+w"
"w+r" open for reading and writing
"a" append: open for writing at end of file, or create for writing
Freopen substitutes the named file in place of the open stream. It re-
turns the original value of stream. The original stream is closed.
Freopen is typically used to attach the preopened constant names and to
specified files.
Fdopen associates a stream with a file descriptor. The type of the
stream must agree with the mode of the open file.
Fclose causes any buffers for the named stream to be emptied, and the
file to be closed. Buffers allocated by the standard input/output sys-
tem are freed.
Fclose is performed automatically upon calling exit(3).
Fflush causes any buffered data for the named output stream to be writ-
ten to that file. The stream remains open.
SEE ALSO
open(2), popen(3), stdio(3), ferror(3)
DIAGNOSTICS
Fopen and freopen return NULL if filename cannot be accessed.
Fclose and fflush return EOF if stream is not associated with a file,
or if buffered data cannot be transferred to that file.
FOPEN(3S)