ZIP_FILE_RENAME(3)
π ZIP_FILE_RENAME(3) π
okay so bestie, welcome to the library functions manual, and today's main character is zip_file_rename from libzip. yes that libzip. the one you link with -lzip. she renames files inside zip archives and she does it flawlessly, no cap. π¦
β¨ NAME β¨
zip_file_rename β rename a file in a zip archive, literally the glow-up button for filenames π
π LIBRARY π
libzip (-lzip) β link her in and she's yours π«Ά
πΈ SYNOPSIS πΈ
#include <zip.h>
int
zip_file_rename(zip_t *archive, zip_uint64_t index, const char *name,
zip_flags_t flags);
like yes, four args, we love a clean signature, no drama β¨
π DESCRIPTION π
so here's the vibe: the file sitting at position index inside the zip archive archive gets renamed to name. that's it. that's the whole job. iconic.
now the flags argument β she can be any of these three, pick your fighter:
ZIP_FL_ENC_GUESSβ guess the encoding ofname(this is the default, the fallback queen). heads up tho: only CP-437 and UTF-8 are recognized, so don't get cute with anything else πZIP_FL_ENC_UTF_8β interpretnameas UTF-8, periodt.ZIP_FL_ENC_CP437β interpretnameas code page 437 (CP-437), old-school flavor π
β RETURN VALUES β
- if it ate and left no crumbs?
0is returned. success. slay. - if it didn't?
-1comes back, and the error code inarchivegets set to tell you exactly what went wrong. she's not gonna leave you guessing, bestie π
π¨ ERRORS π¨
zip_file_rename() fails when:
[ZIP_ER_DELETED]β the file you're trying to rename has already been deleted from the archive. it's gone, girl. you cannot rename a ghost π»[ZIP_ER_EXISTS]β there's already a file callednamein the archive. name collision, we don't do that here π«[ZIP_ER_INVAL]βindexisn't a valid file index inarchive, ornameisNULL, or it's the empty string, or it's not a valid UTF-8 encoded string. also, a file cannot be renamed to a directory or vice versa β and just so you know, directories are denoted by a trailing slash. that slash is load-bearing, iykyk π§
π SEE ALSO π
go read those too, they're part of the lore π
π°οΈ HISTORY π°οΈ
zip_file_rename() was added in libzip 0.11. a legend since day one, fr fr π
π AUTHORS π
Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β the duo, the icons, the blueprint π
and that's the whole page bestie!! this lil manual came from the Debian crew and the date on it is September 22, 2020, so shoutout to them for shipping it β now go rename something and be the main character of your own archive πβ¨π
π¦ 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