al_fopen_slice(3alleg5)
π 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 uponal_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
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms