io_readwritefile(3)

πŸ“¦
version 0.34 Β· 3 versions
, in alpine 3.24, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu resolute, ubuntu stonking

πŸ’– io_readwritefile β€” bestie's guide to opening a file both ways πŸ’–

okay so this one lives in the Library Functions Manual (yes the whole manual, she's fancy) and we're gonna get you fluent in it in like 30 seconds, no cap ✨


🌸 NAME 🌸

io_readfile β€” open a file for reading and writing 🫢

ngl the NAME line says io_readfile and the rest of the page is all about io_readwritefile. that's not me being sloppy, that's just literally what the page says. iconic of it honestly πŸ’…

✨ SYNTAX ✨

like, exactly this, character for character, don't freestyle it:

#include <libowfat/io.h>

int io_readwritefile(int64* d,const char* filename);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so io_readwritefile does the thing: it sets d to the number of a new descriptor that reads from and writes to the disk file named filename, and then it returns 1. πŸŽ€

that file? it needs to exist. like, the file has to already be there. this is not a "make me a file" situation, bestie, it's a "let me at the file that's already there" situation.

⚠️ lowkey important: if something goes wrong, io_readwritefile sets errno to indicate the error and returns 0. it does not create a new descriptor, and it does not touch d. so your d stays exactly how it was β€” untouched, unbothered, minding its own business. πŸ’€

🌈 SEE ALSO 🌈


and that's the whole page, bestie!! 🫢 it's short, it's sweet, it reads and writes, it returns 1 when it's happy and 0 when it's not, and it never touches your d unless it's actually doing the thing.

this one's from the Library Functions Manual, and the footer just signs off as io_readwritefile(3) β€” no date, no version drama, just vibes. take care of your file descriptors and hydrate!! πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’