Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fopen(3S) — bsd — Apollo Domain/OS SR10.3.5

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

open(2)

fclose(3)

fseek(3S)

FOPEN(3S)                            BSD                             FOPEN(3S)



NAME
     fopen, freopen, fdopen - open a stream

SYNOPSIS
     #include <stdio.h>

     FILE *fopen(filename, type)
     const char *filename, *type;

     FILE *freopen(filename, type, stream)
     const char *filename, *type;
     FILE *stream;

     FILE *fdopen(fildes, type)
     char *type;

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

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

     Each type may be followed by a plus sign (+) to have the file opened for
     update (reading and writing).  The value "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 can be used on read/write streams,
     with the limitation that an fseek(3S), rewind, or reading an end-of-file
     must be used between a read and a write or vice-versa.  Opening a file
     with "a" as the first character in the type argument causes all
     subsequent writes to the file to be forced to the then current end-of-
     file, regardless of intervening calls to fseek.

     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.

     In addition, each type specified to fopen and freopen may be followed by
     a "b", indicating a binary file.  The "b" may precede or follow the "+",
     if present.  Domain/OS BSD, however, ignores the "b" flag.

     fdopen associates a stream with a file descriptor obtained from open(2),
     dup(2), creat(2), or pipe(2).  The type of the stream must agree with the
     mode of the open file.

SEE ALSO
     open(2), fclose(3), fseek(3S)

DIAGNOSTICS
     fopen and freopen return the pointer NULL if filename cannot be accessed,
     if too many files are already open, or if other resources needed cannot
     be allocated.

BUGS
     fdopen is not portable to systems other than the UNIX operating system.

     The read/write types do not exist on all systems.  Those systems without
     read/write modes will probably treat the type as if the "+" was not
     present.  These are unreliable in any event.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026