---
name: "zzip_disk_findnext"
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_findfile"
---

# zzip\_disk\_findnext(3)

search for files in the (mmapped) zip central directory

Part of [zzip\_disk\_findfile(3)](/zzip_disk_findfile/3.md).

## NAME

zzip\_disk\_findfile, zzip\_disk\_findfirst, zzip\_disk\_findnext, zzip\_disk\_findmatch -  search for files in the (mmapped) zip central directory

## SYNOPSIS

```
#include <zzip/mmapped.h>

struct zzip_disk_entry *
zzip_disk_findfile(ZZIP_DISK * disk, char *filename,
                   struct zzip_disk_entry *after, zzip_strcmp_fn_t compare)
struct zzip_disk_entry *
zzip_disk_findfirst(ZZIP_DISK * disk)
struct zzip_disk_entry *
zzip_disk_findnext(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
struct zzip_disk_entry *
zzip_disk_findmatch(ZZIP_DISK * disk, char *filespec,
                    struct zzip_disk_entry *after,
                    zzip_fnmatch_fn_t compare, int flags)
```

## DESCRIPTION

 The *zzip\_disk\_findfile* function is given a filename as an additional argument, to find the disk\_entry matching a given filename. The compare-function is usually strcmp or strcasecmp or perhaps strcoll, if null then strcmp is used. - use null as argument for "after"-entry when searching the first matching entry, otherwise the last returned value if you look for other entries with a special "compare" function (if null then a doubled search is rather useless with this variant of \_findfile).

 The *zzip\_disk\_findfile* functionreturns the entry pointer. The *zzip\_disk\_findfile* function may return null on error. (errno = ENOMEM\|EBADMSG\|ENOENT)

 The *zzip\_disk\_findfirst* function is the first call of all the zip access functions here. It contains the code to find the first entry of the zip central directory. Here we require the mmapped block to represent a real zip file where the disk\_trailer is \_last\_ in the file area, so that its position would be at a fixed offset from the end of the file area if not for the comment field allowed to be of variable length (which needs us to do a little search for the disk\_tailer). However, in this simple implementation we disregard any disk\_trailer info telling about multidisk archives, so we just return a pointer to the zip central directory.

 For an actual means, we are going to search backwards from the end of the mmaped block looking for the PK-magic signature of a disk\_trailer. If we see one then we check the rootseek value to find the first disk\_entry of the root central directory. If we find the correct PK-magic signature of a disk\_entry over there then we assume we are done and we are going to return a pointer to that label.

 The return value is a pointer to the first zzip\_disk\_entry being checked to be within the bounds of the file area specified by the arguments. If no disk\_trailer was found then null is returned, and likewise we only accept a disk\_trailer with a seekvalue that points to a disk\_entry and both parts have valid PK-magic parts. Beyond some sanity check we try to catch a common brokeness with zip archives that still allows us to find the start of the zip central directory.So the *zzip\_disk\_findfirst* function may return null and sets errno.

 The *zzip\_disk\_findnext* function takes an existing disk\_entry in the central root directory (e.g. from zzip\_disk\_findfirst) and returns the next entry within in the given bounds of the mmapped file area.

 The *zzip\_disk\_findnext* function returns null if no next entry can be found. The *zzip\_disk\_findnext* function may return null on errors. (errno = ENOENT\|EINVAL\|EBADMSG)

 The *zzip\_disk\_findmatch* function uses a compare-function with an additional argument and it is called just like [fnmatch(3)](/fnmatch/3.md) from POSIX.2 AD:1993), i.e. the argument filespec first and the ziplocal filename second with the integer-flags put in as third to the indirect call. If the platform has fnmatch available then null-compare will use that one and otherwise we fall back to mere strcmp, so if you need fnmatch searching then please provide an implementation somewhere else. - use null as argument for "after"-entry when searching the first matching entry, or the last disk\_entry return-value to find the next entry matching the given filespec.

 The *zzip\_disk\_findmatch* function will return the matching entry pointer. The *zzip\_disk\_findmatch* function may return null on error. (errno = ENOMEM\|EBADMSG\|ENOENT)

## AUTHOR

 Guido Draheim \<guidod@gmx.de\>

## COPYRIGHT

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