buffer_mmapread(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– buffer_mmapread β€” like, the manual page but make it make sense πŸ’–

okay bestie, pull up a chair, we're in the Library Functions Manual today and honestly? this one's a little gem. no cap.


✨ NAME ✨

buffer_mmapread β€” create a read-only memory-mapped file buffer πŸ¦‹

like the name literally says what it does. read-only. memory-mapped. file. buffer. slay.


🌸 SYNTAX 🌸

first things first, you gotta invite the header to the function:

#include <libowfat/buffer.h>

int buffer_mmapread(buffer &b,const char* filename);

that's the whole vibe. b is your buffer, filename is the file. easy. πŸŽ€


πŸ’… DESCRIPTION πŸ’…

so here's the tea, bestie: buffer_mmapread opens filename for reading and fills b up so you can read the file's contents straight out of it. like, it's giving "the file is right there, just grab it." ✨

using mmap is genuinely more efficient than reading through a real buffer β€” highkey a glow-up β€” but here's the part you cannot skip:

🚨 you have to call buffer_close at the end to unmap the memory. not optional. not a suggestion. it's giving "clean up after yourself, main character." 🫢

πŸ”₯ EXAMPLE πŸ”₯

here's the whole thing in action, stealing the first line of /etc/passwd like it's gossip:

#include <libowfat/buffer.h>
#include <libowfat/open.h>

buffer input;
char x;

buffer_mmapread(&input,"/etc/passwd");
while (buffer_get(&input,&x,1)==1) {
  buffer_put(buffer_1,&x,1);
  if (x=='\n') break;
}
buffer_flush(buffer_1);
buffer_close(&input);

look at her go πŸ’… reading one byte at a time, printing it, bailing the second it hits a '\n', then flushing and closing like a responsible icon. periodt.


⭐ RETURN VALUE ⭐

  • 0 β€” everything was fine, we ate, no notes πŸ‘‘
  • -1 β€” error, and it sets errno so you can go find out what went wrong 😭

🌈 SEE ALSO 🌈

go read those too, they're part of the same little friend group, iykyk 🧚


and that's the whole page!! πŸ’œ this one came straight out of the Library Functions Manual, filed under buffer_mmapread(3) β€” no version or date info on this one, so that's all the fine print we got. mwah, go map some memory responsibly πŸŽ€πŸ’–βœ¨