ZOPEN(3)

πŸ“¦
version 479 Β· 2 versions
, in nixpkgs unstable

πŸ’– ZOPEN(3) β€” compressed stream open function πŸ’–

okay so real talk, this is from the Library Functions Manual and it's about zopen, which is literally the moment your compressed file gets a whole FILE stream to itself. bestie, it's giving "fopen but make it compressed" and honestly? obsessed. let's get into it 🫢


✨ SYNOPSIS ✨

#include "zopen.h"

FILE *
zopen(const char *path, const char *mode, int bits);

three args, one header, zero drama. slay.


🌸 DESCRIPTION 🌸

so zopen() opens the compressed file whose name is the string pointed to by path, and it associates a stream with it. that's the whole vibe. your file, your stream, iconic behavior πŸ’…

the argument mode points to one of these one-character strings, and you only get to pick from this lil list:

  • "r" β€” open the compressed file for reading ✨ the stream is positioned at the beginning of the file. very demure, very start-of-file.
  • "w" β€” truncate the file to zero length, or create a compressed file for writing πŸ”₯ the stream is positioned at the beginning of the file too. yes, it will absolutely nuke what was there β€” that's the "truncate to zero length" part, no cap.

any files that get created will have mode "S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH" (that's 0666), as modified by the process' umask value (peep umask(2) for the details, iykyk).

πŸ’€ important vibe check: files may only be read or written. seek operations are not allowed. like, at all. don't try it, she's not that kind of stream.

the bits argument, if it's non-zero, is set to the bits code limit ⭐ if it's zero, the default is 16. see compress(1) if you want the full lore on that one.


πŸŽ€ RETURN VALUES πŸŽ€

upon successful completion, zopen() returns a FILE pointer πŸ’– it ate, no crumbs.

otherwise, NULL is returned and the global variable errno is set to indicate the error 😭 not the ending we wanted but it's honest.


πŸ¦‹ ERRORS πŸ¦‹

here's the breakdown of what can go wrong, and bestie, it happens:

  • [EINVAL] β€” the mode or bits arguments specified to zopen() were invalid πŸ™ˆ like, wrong input, wrong energy.
  • [EFTYPE] β€” the compressed file starts with an invalid header, or the compressed file is compressed with more bits than can be handled πŸ’€ she looked at the file and said "I can't work with this."

also, fair warning β€” zopen() may also fail and set errno for any of the errors specified for the routines fopen(3) or funopen(3) 🌈 so it's not just the errors listed above, it can catch hands from those too.


🧚 SEE ALSO 🧚

compress(1), fopen(3), funopen(3)

(the holy trinity, fr fr 🫢)


πŸ‘‘ HISTORY πŸ‘‘

the zopen function first appeared in 4.4BSD ⭐ a true elder, a main character with lore.


🌈 BUGS 🌈

⚠️ the zopen() function may not be portable to systems other than BSD. so if you're out here on some other system expecting her to work, that's a sorry bestie moment 😭 not undefined behavior exactly, just... not portable. plan accordingly.

πŸ’œ okay that's the whole page! zopen β€” compressed stream open function, from the Library Functions Manual, was published by Debian on June 9, 1993. a vintage queen. stay compressed, stay hydrated, and remember: read or write only, no seeking πŸŽ€βœ¨

πŸ“¦ where this page comes from
  • nixpkgs unstable: file_cmds 479
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms