ZIP_FILE_RENAME(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_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 of name (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 β€” interpret name as UTF-8, periodt.
  • ZIP_FL_ENC_CP437 β€” interpret name as code page 437 (CP-437), old-school flavor 🌈

⭐ RETURN VALUES ⭐

  • if it ate and left no crumbs? 0 is returned. success. slay.
  • if it didn't? -1 comes back, and the error code in archive gets 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 called name in the archive. name collision, we don't do that here 🚫
  • [ZIP_ER_INVAL] β€” index isn't a valid file index in archive, or name is NULL, 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 πŸ’–βœ¨πŸŽ€