ZIP_FILE_GET_EXTERNAL_ATTRIBUTES(3)
π zip_file_get_external_attributes β get external attributes for file in zip π
okay bestie, welcome to the Library Functions Manual corner of the internet π this one lives in the libzip section, and it's about snooping on the external attributes of a file inside a zip. yes, that's the little blob where the operating system keeps its file permissions and stuff. let's get into it π
β¨ LIBRARY β¨
libzip (-lzip)
πΈ SYNOPSIS πΈ
#include <zip.h>
int
zip_file_get_external_attributes(zip_t *archive, zip_uint64_t index,
zip_flags_t flags, zip_uint8_t *opsys, zip_uint32_t *attributes);
π¦ DESCRIPTION π¦
so, zip_file_get_external_attributes() hands you back the operating system and the external attributes for the file sitting at position index inside the zip archive. and like, those external attributes? usually they're holding the operating system-specific file permissions, no cap. π₯
if you set flags to ZIP_FL_UNCHANGED, you get the original unchanged values β the ones before anything got messed with. and if opsys or attributes is NULL? no worries, they just don't get filled in. π
the following operating systems are defined by the zip specification:
ZIP_OPSYS_ACORN_RISCZIP_OPSYS_ALTERNATE_MVSZIP_OPSYS_AMIGAZIP_OPSYS_ATARI_STZIP_OPSYS_BEOSZIP_OPSYS_CPMZIP_OPSYS_DOSZIP_OPSYS_MACINTOSHZIP_OPSYS_MVSZIP_OPSYS_OPENVMSZIP_OPSYS_OS_2ZIP_OPSYS_OS_400ZIP_OPSYS_OS_XZIP_OPSYS_TANDEMZIP_OPSYS_UNIXZIP_OPSYS_VFATZIP_OPSYS_VM_CMSZIP_OPSYS_VSEZIP_OPSYS_WINDOWS_NTFS(uncommon, useZIP_OPSYS_DOSinstead)ZIP_OPSYS_Z_SYSTEM
all those defines above are following the PKWARE Inc. Appnote, just so you know. β but heads up β the InfoZIP Appnote has a slightly different mapping. so don't @ me if they disagree, they're just built different π
π RETURN VALUES π
- if everything goes right,
0comes back. slay. β¨ - if something goes wrong,
-1comes back, and the error code inarchiveis set to tell you what the actual problem was. π
π EXAMPLES π
here's the code you can use to expand attributes when the operating system is ZIP_OPSYS_DOS. it's giving very much "translate DOS land into POSIX mode bits":
#include <sys/stat.h>
#define FA_RDONLY 0x01 // FILE_ATTRIBUTE_READONLY
#define FA_DIREC 0x10 // FILE_ATTRIBUTE_DIRECTORY
static mode_t
_zip_dos_attr2mode(zip_uint32_t attr)
{
mode_t m = S_IRUSR | S_IRGRP | S_IROTH;
if (0 == (attr & FA_RDONLY))
m |= S_IWUSR | S_IWGRP | S_IWOTH;
if (attr & FA_DIREC)
m = (S_IFDIR | (m & ~S_IFMT)) | S_IXUSR | S_IXGRP | S_IXOTH;
return m;
}
π ERRORS π
zip_file_get_external_attributes() fails if:
[ZIP_ER_INVAL]βindexis not a valid file index inarchive.
π SEE ALSO π
libzip(3), zip_file_set_external_attributes(3)
π§ HISTORY π§
zip_file_get_external_attributes() was added in libzip 0.11.2. vintage but still iconic β¨
π«Ά AUTHORS π«Ά
Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β the actual legends behind this π
and that's the whole page bestie!! this one shipped with Debian, dated December 18, and the manual name is ZIP_FILE_GET_EXTERNAL_ATTRIBUTES(3). go forth and read those attributes πππ
π¦ 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) 2013-2017 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