mmap_readat(3)
β¨ mmap_readat β¨
okay so bestie, this one lives in the Library Functions Manual and it's literally the "give me this whole file in memory, right now, no drama" function π
πΈ NAME πΈ
mmap_readat β memory map a file for reading πΊοΈβ¨
π SYNTAX π
#include <libowfat/mmap.h>
const char* mmap_readat(const char* filename,size_t* filesize,int dirfd);
π¦ DESCRIPTION π¦
so here's the vibe: mmap_readat opens filename for reading, maps the entire file into memory, then closes the file. after that it writes the length of the file into filesize and hands you back a pointer to the mapped file. boom. whole file, right there, zero scrolling. π₯
if filename is a relative path and dirfd is not AT_FDCWD (which is defined in fcntl.h, iykyk), then filename gets interpreted relative to dirfd β and dirfd must be an open directory. no cap, it has to be an actual open dir. π
the file gets unmapped by the operating system all on its own when the process terminates (she's independent like that π). but if you wanna do it manually, you can call munmap from <sys/mman.h> β main character energy, taking things into your own hands.
and if the file could not be opened or mapped? you get (void*)0 back. not a vibe, but that's the deal. π
π SEE ALSO π
that's the whole page bestie, mwah π from the Library Functions Manual with love β go map something iconic πβ¨
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms