ZIP_GET_NAME(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_GET_NAME(3) πŸ’–

okay bestie, welcome to ZIP_GET_NAME(3), part of the Library Functions Manual πŸŽ€ β€” yes this is the libzip girlies' section of the manual, and today we're learning how to get a filename out of a zip archive by index. it's giving gatekeeping the file list? not anymore ✨


🌸 NAME 🌸

zip_get_name β€” get name of file by index πŸ’…


πŸ“š LIBRARY πŸ“š

libzip (-lzip) β€” you already know her 🫢


✨ SYNOPSIS ✨

#include <zip.h>

const char *
zip_get_name(zip_t *archive, zip_uint64_t index, zip_flags_t flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

so. the zip_get_name() function returns the name of the file sitting at position index inside archive. like, "who's that file at slot 7" and she tells you. πŸ’«

the name comes back in UTF-8 encoding unless you specified ZIP_FL_ENC_RAW (more on that in a sec, keep reading bestie).

if flags is set to ZIP_FL_UNCHANGED, you get the original, untouched filename back. the OG one. and listen β€” the returned string must not be modified or freed, and it becomes invalid the moment archive is closed. so don't be out here editing it or holding onto it after the archive's gone, that's not the vibe. πŸ’€

and btw, these flags are also supported:

  • ZIP_FL_ENC_RAW β€” return the unmodified names exactly as they are in the ZIP archive. no glow-up, no conversion, raw as she came. πŸ“
  • ZIP_FL_ENC_GUESS β€” this is the default ✨. it guesses the encoding of the name in the ZIP archive and converts it to UTF-8 if that's needed. (heads up: only CP-437 and UTF-8 get recognized β€” the rest are on their own fr.)
  • ZIP_FL_ENC_STRICT β€” follow the ZIP specification properly and expect CP-437 encoded names in the ZIP archive, except when they're explicitly marked as UTF-8. then convert it to UTF-8. πŸ“
Note: ASCII is a subset of both CP-437 and UTF-8. so like, the overlap is real, iykyk 🧚

πŸ”₯ RETURN VALUES πŸ”₯

upon successful completion, a pointer to the name is returned. slay. πŸ‘‘

otherwise? NULL, and the error code inside archive gets set to indicate the error. not the ending we wanted but okay. 😭


πŸ’€ ERRORS πŸ’€

zip_get_name() fails if:

  • [ZIP_ER_DELETED] β€” index refers to a file that has been deleted (see zip_delete(3)). she's gone, bestie, you can't get her name. πŸ‘»
  • [ZIP_ER_INVAL] β€” index is not a valid file index in archive, or index points to an added file and ZIP_FL_UNCHANGED is set. invalid, no cap. 🚫
  • [ZIP_ER_MEMORY] β€” required memory could not be allocated. the RAM said no. πŸ™ˆ

πŸ‘€ SEE ALSO πŸ‘€

libzip(3), zip_name_locate(3) β€” go read those too, they're icons in their own right πŸ’–


πŸ“œ HISTORY πŸ“œ

zip_get_name() was added in libzip 0.6. then in libzip 0.10 the type of index got changed from int to zip_uint64_t. and in libzip 0.11 the type of flags got changed from int to zip_flags_t. glow-up after glow-up, honestly. ✨


πŸ‘‘ AUTHORS πŸ‘‘

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” the actual main characters, we stan πŸ«ΆπŸ’œ


and that's the whole page babes πŸ’… this one came from Debian, dated September 22, 2020, and it's filed under ZIP_GET_NAME(3) β€” go forth and get those names, you got this πŸ¦‹πŸŒˆβ­