ZOPEN(3)
π 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]β themodeorbitsarguments specified tozopen()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 π
β οΈ thezopen()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 asorry bestiemoment π 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
- Copyright (c) 1992, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms