ZIP_GET_NAME(3)
π 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]βindexrefers to a file that has been deleted (seezip_delete(3)). she's gone, bestie, you can't get her name. π»[ZIP_ER_INVAL]βindexis not a valid file index inarchive, orindexpoints to an added file andZIP_FL_UNCHANGEDis 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 π¦πβ
π¦ where this page comes from
- arch rolling: libzip 1.11.4-1 Β· BSD
- debian trixie: libzip-dev 1.11.3-2 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 43: libzip-devel 1.11.4-2.fc43 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- fedora 44: libzip-devel 1.11.4-3.fc44 Β· BSD-3-Clause
- nixpkgs unstable: libzip 1.11.4
- ubuntu questing: libzip-dev 1.11.3-2
- ubuntu resolute: libzip-dev 1.11.4-2 Β· BSD-3-Clause
- ubuntu stonking: libzip-dev 1.11.4-2build1 Β· BSD-3-Clause
- Copyright (C) 2003-2021 Dieter Baron and Thomas Klausner
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms