fopen(3BSD) (BSD System Compatibility) fopen(3BSD)
NAME
fopen, freopen, fdopen - (BSD) open a stream
SYNOPSIS
/usr/ucb/cc [flag . . . ] file . . .
#include <stdio.h>
FILE *fopen(const char *filename, const char *type);
FILE *freopen(const char *filename, const char *type, FILE *stream);
FILE *fdopen(int fildes, const char *type);
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 identify 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
writing
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 original value of stream.
freopen is typically used to attach the preopened streams
associated with stdin, stdout, and stderr to other files.
fdopen associates a stream with the file descriptor fildes.
File descriptors are obtained from calls like open, dup,
creat, or pipe(2), which open files but do not return streams.
Streams are necessary input for many of the Section 3S library
Copyright 1994 Novell, Inc. Page 1
fopen(3BSD) (BSD System Compatibility) fopen(3BSD)
routines. The type of the stream must agree with the mode of
the open file.
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.
REFERENCES
fclose(3S), fopen(3S), fseek(3S), malloc(3C), open(2), pipe(2)
RETURN VALUE
fopen, freopen, and fdopen return a NULL pointer on failure.
NOTICES
The BSD System Compatibility Package fopen and freopen are
identical to the routines in libc with one exception. When
type is a, fopen and freopen insists that the file position
indicator for the stream be set to the end of file.
Copyright 1994 Novell, Inc. Page 2