---
name: "zzip_disk_mmap"
section: "3"
platform: "linux"
package: "libzzip-dev"
version: "0.13.72+dfsg.1-1.1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/zzip_disk_mmap"
---

# zzip\_disk\_mmap(3)

turn a filehandle into a mmapped zip disk archive handle

## 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

 The *zzip\_disk\_mmap* function uses the given file-descriptor to detect the length of the file and calls the system *[mmap(2)](/mmap/2.md)* to put it in main memory. If it is successful then a newly allocated ZZIP\_DISK\* is returned with disk-\>buffer pointing to the mapview of the zipdisk content.

 The *zzip\_disk\_mmap* function may return null on errors (errno).

 The *zzip\_disk\_init* function does primary initialization of a disk-buffer struct.

 The *zzip\_disk\_init* function always returns 0 as success.

 The *zzip\_disk\_new* function allocates a new disk-buffer with *[malloc(3)](/malloc/3.md)*

 The *zzip\_disk\_new* function may return null on errors (errno).

 The *zzip\_disk\_munmap* function is the inverse of *zzip\_disk\_mmap* and using the system [munmap(2)](/munmap/2.md) on the buffer area and *[free(3)](/free/3.md)* on the ZZIP\_DISK structure.

 The *zzip\_disk\_open* function opens the given archive by name and turn the filehandle to *zzip\_disk\_mmap* for bringing it to main memory. If it can not be *[mmap(2)](/mmap/2.md)*'ed then we slurp the whole file into a newly *malloc(2)*'ed memory block. Only if that fails too then we return null. Since handling of disk-\>buffer is ambiguous it should not be snatched away please.

 The *zzip\_disk\_open* function 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. Note that 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. Note that the *zzip\_disk\_buffer* function will not own the buffer, it will neither be written nor free()d.

 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.

 The *zzip\_disk\_close* function returns 0 on success (or whatever *munmap* says).

## AUTHOR

 Guido Draheim \<guidod@gmx.de\>

## COPYRIGHT

 Copyright (c)Guido Draheim, use under copyleft (LGPL,MPL)
