zzip_disk_mmap(3)
π zzip_disk_mmap(3) β zziplib Function List π
okay bestie, buckle up, this is the one where you take a plain old filehandle and turn it into a whole mmapped zip disk archive handle β¨ it's giving main character energy for real.
πΈ NAME πΈ
zzip_disk_mmap, zzip_disk_init, zzip_disk_new, zzip_disk_munmap, zzip_disk_open, zzip_disk_buffer, zzip_disk_close β turn a filehandle into a mmapped zip disk archive handle π«Ά
β¨ SYNOPSIS β¨
#include <zzip/mmapped.h>
zzip__new__ ZZIP_DISK *
zzip_disk_mmap(int fd)
int
zzip_disk_init(ZZIP_DISK * disk, void *buffer, zzip_size_t buflen)
zzip__new__ ZZIP_DISK *
zzip_disk_new(void)
int
zzip_disk_munmap(ZZIP_DISK * disk)
zzip__new__ ZZIP_DISK *
zzip_disk_open(char *filename)
zzip__new__ ZZIP_DISK *
zzip_disk_buffer(void *buffer, size_t buflen)
int
zzip_disk_close(ZZIP_DISK * disk)
π DESCRIPTION π
So zzip_disk_mmap takes the file-descriptor you hand it, peeks at how long the file actually is, and then calls the system mmap(2) to yeet it into main memory. And if that works? Congrats babes π you get a brand-new allocated ZZIP_DISK* back, with disk->buffer pointing right at the mapview of the zipdisk content. iconic.
And just so we're clear β zzip_disk_mmap may return null on errors (errno). that's the vibe check.
The zzip_disk_init function does primary initialization of a disk-buffer struct. that's it, that's the job π
And zzip_disk_init always returns 0 as success. always. no drama, no notes.
The zzip_disk_new function allocates a new disk-buffer with malloc(3) π
The zzip_disk_new function may return null on errors (errno). π
The zzip_disk_munmap function is the inverse of zzip_disk_mmap β it uses the system munmap(2) on the buffer area and free(3) on the ZZIP_DISK structure. it's the breakup era, everything gets released β¨
The zzip_disk_open function opens the given archive by name and turns the filehandle over to zzip_disk_mmap to bring it into main memory. And if it can't be mmap(2)'ed? no worries, we slurp the whole file into a newly malloc(2)'ed memory block instead π only if that fails too do we return null. fr fr, two chances.
β οΈ lowkey important: since handling of disk->buffer is ambiguous it should not be snatched away please. hands off, bestie π
And yes β zzip_disk_open may return null on errors (errno).
The zzip_disk_buffer function will attach a buffer with a zip image that was acquired from another source than a file. And heads up: if zzip_disk_mmap fails then zzip_disk_open will fall back and try to read the full file to memory, wrapping a ZZIP_DISK around the memory buffer β just as the zzip_disk_buffer function will do. π¦
π another one: thezzip_disk_bufferfunction will not own the buffer β it will neither be written norfree()d. not your buffer, not your problem, don't touch it.
The zzip_disk_buffer function may return null (errno).
The zzip_disk_close function will release all data needed to access a (mmapped) zip archive, including any malloc()ed blocks, sharedmem mappings β and it dumps the handle struct as well. full cleanup, no crumbs left behind π
And zzip_disk_close returns 0 on success (or whatever munmap says). periodt.
π AUTHOR π
Guido Draheim <guidod@gmx.de>
π COPYRIGHT π
Copyright (c)Guido Draheim, use under copyleft (LGPL,MPL)
okay that's the whole page bestie, and this was the zziplib 0.13.72 era of zzip_disk_mmap(3) β mwah, go mmap something and slay πβ¨π¦
π¦ where this page comes from
- debian bookworm: libzzip-dev 0.13.72+dfsg.1-1.1
- ubuntu jammy: libzzip-dev 0.13.72+dfsg.1-1.1
- ubuntu noble: libzzip-dev 0.13.72+dfsg.1-1.2build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms