al_fopen_slice(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_fopen_slice πŸ’–

okay bestie, welcome to the Allegro 5 API corner of the manual, where we're talking about al_fopen_slice β€” the girl who takes one file and says "actually, I'm gonna be a whole file myself, but smaller." iconic behavior fr fr. πŸŽ€


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

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

🌸 DESCRIPTION 🌸

So basically: it opens a slice (aka a subset, a lil' window, a mini-me) of a file that's already open and is random access, and it hands it back to you like it's a totally standalone file. cute, right? πŸ¦‹

⚠️ But listen β€” while that slice is open, you must NOT touch the parent file handle in any way. not for anything. it's giving "do not perceive me." πŸ™ˆ

The slice starts at the current location of the parent file, and it runs up through initial_size bytes. And initial_size can be any non-negative integer, as long as it doesn't exceed the bounds of the parent file. no overreaching, bestie, know your limits. πŸ’…

Here's the tea on seeking:

  • ALLEGRO_SEEK_SET β€” seeking is relative to this starting location.
  • ALLEGRO_SEEK_END β€” seeking is relative to the starting location plus the size of the slice.

Now, the mode? It can be any combo of these:

  • r β€” read access πŸ“–
  • w β€” write access ✍️
  • e β€” expandable 🎈
  • s β€” seek to the end of the slice upon al_close(3alleg5) (and this one is the default, no cap)
  • n β€” disable the seeking behavior of "s" 🚫

Like, for example, a mode of "rw" means the file can be read and written. (And yeah, heads up: that's slightly different from the stdio modes. just so you know. πŸ‘€)

Also keep in mind: for the slice to work in a well defined way, the parent file has to support random access and be open in normal write mode β€” not append. periodt.

If the slice is marked as expandable, then reads and writes can happen after the initial end point, and the slice will just grow accordingly. 🌱 Otherwise? All activity is restricted to the initial size of the slice. no growing, no expanding, stay in your lane.

A slice must be closed with al_fclose(3alleg5). Once you do, the parent file gets positioned immediately after the end of the slice. and if you don't want that? you can turn it off by setting the "n" mode. slay.


⭐ SINCE ⭐

5.0.6, 5.1.0


🫢 SEE ALSO 🫢


and that's the whole page, bestie!! you ate this. go forth and slice responsibly. πŸ’œβœ¨

later, legend β€” this was the Allegro reference manual telling you all about al_fopen_slice(3alleg5), mwah πŸŽ€πŸ’–

πŸ“¦ where this page comes from