al_fopen_slice(3)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in arch rolling

πŸ’… NAME πŸ’…

al_fopen_slice β€” Allegro 5 API, straight from the Library Functions Manual, bestie. We're opening a slice of a file like it's a whole separate file. Slay.

✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

ALLEGRO_FILE *al_fopen_slice(ALLEGRO_FILE *fp, size_t initial_size, const char *mode)

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so picture this: al_fopen_slice opens a slice β€” a subset β€” of an already open random access file, and treats it like it's a stand-alone file. Iconic. But while the slice is open, the parent file handle must not be used in any way. Not even a little. Don't touch it, bestie. πŸ™ˆ

The slice opens at the current location of the parent file, up through initial_size bytes. The initial_size can be any non-negative integer that will not exceed the bounds of the parent file. No cap, except the actual parent file bounds, obviously. πŸ’…

Seeking with ALLEGRO_SEEK_SET will be relative to this starting location. Seeking with ALLEGRO_SEEK_END will be relative to the starting location plus the size of the slice. Math but make it file I/O. ✨

The mode can be any combination of:

  • r β€” read access
  • w β€” write access
  • e β€” expandable
  • s β€” seek to the end of the slice upon al_close(3) (this is the default behavior)
  • n β€” disable the seeking behavior of β€œs”

For example, a mode of β€œrw” indicates the file can be read and written. (Note that this is slightly different from the stdio modes.) Keep in mind that the parent file must support random access and be open in normal write mode (not append) for the slice to work in a well defined way. That part is important, don't skip it.

If the slice is marked as expandable, then reads and writes can happen after the initial end point, and the slice will grow accordingly. Otherwise, all activity is restricted to the initial size of the slice. No sneaky growth unless you asked for e, periodt.

A slice must be closed with al_fclose(3). The parent file will then be positioned immediately after the end of the slice. This behavior can be disabled by setting the β€œn” mode. So yeah, close it properly or the vibes are off. 😭

🌸 SINCE 🌸

5.0.6, 5.1.0 β€” it's been around, bestie.

πŸŽ€ SEE ALSO πŸŽ€


Later, bestie! πŸ’– Source/version vibe: Allegro reference manual β€” page tag al_fopen_slice(3). No date on this footer, just pure Allegro reference manual energy. Mwah! πŸ’…

πŸ“¦ where this page comes from
  • arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms