open-bin...put-file(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… 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-file raises 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 πŸ‘€

🌈 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