open-bin...put-file(3scm)
π open-binary-input-file, open-binary-output-file β open a binary file
okay bestie, so this page is from the Scheme Programmer's Manual, manpage name open-bin...put-file(3scm), and it's literally about opening binary files. buckle up π
πΈ NAME πΈ
open-binary-input-file, open-binary-output-file β open a binary file, fr fr
π LIBRARY π
This one's living that R7RS life:
(import (scheme file)) ;R7RS
β¨ SYNOPSIS β¨
(open-binary-input-file string)
(open-binary-output-file string)
π₯ DESCRIPTION π₯
So basically you hand it a string β that's your filename β and it gives you back a binary input port or a binary output port respectively. cute, simple, iconic. π
But listen: when you're opening a file for input, that file has got to already exist. no file, no port, no vibe. π
And when you're opening a file for output and the file already exists? the effect is unspecified. yeah. that's the whole warning. we'll get to why that's a whole thing down in BUGS. π
π«Ά RETURN VALUES π«Ά
Both of these procedures return a single value β a fresh binary input port or a fresh binary output port. fresh as in brand new, not reused, main character energy only. β¨
π¦ COMPATIBILITY π¦
These procedures are unique to R7RS β they're not some legacy carryover, they're R7RS originals. π
If you want compatible replacements with stricter specifications, go look at open-file-input-port(3scm) and open-file-output-port(3scm). same job, more rules, more safety. π§
π ERRORS π
These procedures can raise exceptions satisfying the following predicates:
file-error?(R7RS) β raised if the file cannot be opened. In particular,open-binary-input-fileraises this if the file does not exist. (obvi, we said that already, but now it's an error, not just a vibe.)- R7RS β it is an error if the wrong number of arguments was passed, or if 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. yeah. catastrophically. no cap. π
π SEE ALSO π
open-file-input-port(3scm)file-error?(3scm)
π STANDARDS π
R7RS π«Ά
π HISTORY π
These procedures first appeared in R7RS. baby icons from day one. π
π AUTHORS π
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/. π«Ά
π BUGS π
okay this is the part you actually need to read, bestie:
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. so likeβ¦ implementation-dependent chaos. π₯
And no, 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. the file can literally change between your check and your use. not the move. π
If this is a concern then open-file-output-port(3scm) can be used instead with appropriate options. that's the safe route, iykyk. π
mwah π that's the whole page, no notes. this one's dated 2023-02-20, and the source/version footer reads open-bin...put-file(3scm) from the Scheme Programmer's Manual β so go open some binary files responsibly, queen. ππΈπ
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms