open-binary-input-file(3scm) Scheme Programmer's Manual open-binary-input-file(3scm)

open-binary-input-file, open-binary-output-file - open a binary file

(import (scheme file))              ;R7RS

(open-binary-input-file string)
(open-binary-output-file string)

Takes a string for a filename and returns a binary input or output port respectively.

When opening a file for input it must already exist. If the file already exists when opening it for output the effect is unspecified.

Both procedures return a single value; a fresh binary input or output port.

These procedures are unique to R7RS. The open-file-input-port(3scm) and open-file-output-port(3scm) procedures are compatible replacements with stricter specifications.

These procedure can raise exceptions satisfying the following predicates:
file-error? (R7RS)
Raised if the file cannot be opened. In particular, this is raised by open-binary-input-file if the file does not exist.
R7RS
It is an error if the wrong number of arguments was passed or an argument was outside its domain. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

open-file-input-port(3scm), file-error?(3scm)

R7RS

These procedures first appeared in R7RS.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

You should be aware of what your implementation does when the file already exists because there is no way to check for this condition before attempting to open a file. The text in R7RS explicitly says that the effect is unspecified when this happens.

You cannot check for this condition ahead of time using file-exists?(3scm) and delete-file(3scm) because they are prone to time-to-check to time-of-use (TTCTOU) bugs.

If this is a concern then open-file-output-port(3scm) can be used instead with appropriate options.

2023-02-20