LC_MMAPFILE(3)
π LC_MMAPFILE(3) π
okay bestie, welcome to Librecast's little cutie of a function β meet lc_mmapfile, the girl who maps (or unmaps!) files or devices straight into memory. she lives in the Librecast Programmer's Manual, and yes she's part of the Librecast library β that's liblibrecast, linked with -llibrecast. slay. β¨
πΈ LIBRARY πΈ
Librecast library (liblibrecast, -llibrecast) π«Ά
β¨ SYNOPSIS β¨
#include <librecast/sync.h>
void *lc_mmapfile(const char *pathname, size_t *len, int prot, int flags,
off_t offset, struct stat *sb);
Compile and link with -llibrecast. no cap, that's the whole vibe π
π¦ DESCRIPTION π¦
so lc_mmapfile() is literally just a convenience wrapper for mmap(2) β it open(2)s and maps a file in a single call, because who has time for two calls when one will do. if you want the full lore, go read mmap(2).
here's the tea, ok:
- if
prothas thePROT_WRITEflag set, thenpathnamegetsopen(2)'ed with theO_RDWRandO_CREATflags set β so the file is created and opened read-write π - otherwise it's opened
O_RDONLYπΈ - wanna set the mode for the file being created? set
st_modeinsbwhen you calllc_mmapfile(). that's it, that's the trick β¨
and about len:
- if
lenpoints to a value greater than zero, thenftruncate(2)is called to truncate the file to that specified length βοΈ - otherwise, the variable
lenpoints to is set to the size of the file π
when you're done, the file can be unmapped and the memory freed by calling munmap(3). clean up after yourself, bestie π§Ή
π₯ RETURN VALUE π₯
on success, lc_mmapfile() returns a pointer to the mapped area. iconic. π
on error, the value MAP_FAILED (that is, (void*)-1) is returned, and errno is set to indicate the error. it's giving sad girl era π
π ERRORS π
ENODATAβ File is zero length. yeah. nothing there. empty. the void. π«
See also open(2), mmap(2), fstat(2), and ftruncate(2).
π SEE ALSO π
π that's the whole page bestie, go forth and map some memory. iykyk.
LIBRECAST Β· 2023-07-24 Β· LC_MMAPFILE(3) β mwah, bye, love u, see u in the group chat π ππ¦
π¦ where this page comes from
- debian trixie: liblibrecast-dev 0.9.1-1 Β· GPL-2.0-only OR GPL-3.0-only
- nixos 26.05: librecast 0.11.2
- nixpkgs unstable: librecast 0.11.2
- ubuntu noble: liblibrecast-dev 0.8.0-1.1build1 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu questing: liblibrecast-dev 0.9.1-1
- ubuntu resolute: liblibrecast-dev 0.11.2-2 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu stonking: liblibrecast-dev 0.11.2-2build1 Β· GPL-2.0-only OR GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms