Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fopen(3S) — AUX SR8.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

open(2)

fclose(3S)

FOPEN(3S)

NAME

fopen, freopen, fdopen − open a stream

SYNOPSIS

#include <stdio.h>

FILE ∗fopen (file-name, type)
char ∗file-name, ∗type;

FILE ∗freopen (file-name, type, stream)
char ∗file-name, ∗type;
FILE ∗stream;

FILE ∗fdopen (fildes, type)
int fildes;
char ∗type;

DESCRIPTION

Fopen opens the file named by file-name 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

"r+" open for update (reading and writing)

"w+" create for update

"a+" append; open or create for update at end of file

Freopen substitutes the named file in place of the open stream. It returns the original value of stream. The original stream is closed, regardless of whether the open ultimately succeeds.

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 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 end of file.

SEE ALSO

open(2), fclose(3S). 

DIAGNOSTICS

Fopen and freopen return the pointer NULL if file-name cannot be accessed. 

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