ZIP_FILE_GET_COMMENT(3)

πŸ“¦
version 1.11.4 Β· 3 versions
, in arch rolling, debian trixie, fedora 43, fedora 44, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– ZIP_FILE_GET_COMMENT(3) πŸ’–

okay bestie, so this is a page from the Library Functions Manual (we're in the libzip cinematic universe, and yes, it's giving main character energy πŸ‘‘). Buckle up, because we're getting the comment off a file inside a zip archive and it's honestly so much fun.


✨ NAME ✨

zip_file_get_comment β€” get comment for file in zip


🌸 LIBRARY 🌸

libzip (-lzip) β€” link it, love it, that's the vibe.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <zip.h>

const char *
zip_file_get_comment(zip_t *archive, zip_uint64_t index,
    zip_uint32_t *lenp, zip_flags_t flags);

πŸ’… DESCRIPTION πŸ’…

So, like, zip_file_get_comment() hands you back the comment for the file sitting at position index inside the zip archive. ✨

The name is in UTF-8 encoding unless ZIP_FL_ENC_RAW was specified (peep below, iykyk). And listen β€” this pointer? Do not modify it, do not free(3) it, and heads up: it goes invalid the moment archive is closed. It's a temporary queen, respect her timeline. 😭

If lenp is not NULL, the integer it points to gets set to the length of the comment. Cute, right?

And if flags is set to ZIP_FL_UNCHANGED, you get the original unchanged comment back β€” the pre-glow-up version. 🫢

Additionally, the following flags are supported:

  • ZIP_FL_ENC_RAW β€” Return the unmodified comment as it is in the ZIP archive. raw. unfiltered. no edits, no notes. πŸ’€
  • ZIP_FL_ENC_GUESS β€” (Default.) Guess the encoding of the comment in the ZIP archive and convert it to UTF-8, if necessary. (Only CP-437 and UTF-8 are recognized.) it's giving detective energy πŸ”
  • ZIP_FL_ENC_STRICT β€” Follow the ZIP specification for file names and extend it to file comments, expecting them to be encoded in CP-437 in the ZIP archive (except if it is a UTF-8 comment from the special extra field). Convert it to UTF-8. strict queen, rules are rules. πŸ‘‘
Note: ASCII is a subset of both CP-437 and UTF-8. no cap, that's literally just true. πŸŽ€

⭐ RETURN VALUES ⭐

Upon successful completion, a pointer to the comment is returned β€” slay. Or NULL if there is no comment (sad, empty, tragic πŸ₯²).

In case of an error, NULL is returned and the error code in archive is set to indicate the error. so check your error code, bestie, don't just assume. πŸ™ˆ


πŸ’€ ERRORS πŸ’€

zip_file_get_comment() fails if:

  • [ZIP_ER_INVAL] β€” index is not a valid file index in archive. not a real index, not a real one of us. 🚫

🌈 SEE ALSO 🌈

libzip(3), zip_file_set_comment(3), zip_get_archive_comment(3)

go read the whole friend group, they're all iconic. 🫢


πŸŽ€ HISTORY πŸŽ€

zip_file_get_comment() was added in libzip 0.11. an OG. a legend. periodt. πŸ’–


πŸ‘‘ AUTHORS πŸ‘‘

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at>

the two geniuses behind all of this, we stan. 🌟


and that's the whole page bestie!! this beauty shipped with Debian on September 22, 2020 β€” so go forth, fetch those comments, and remember: pointers expire, but the vibe is forever βœ¨πŸ’œπŸ¦‹