zzip_disk_findfile(3)

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>

b'struct zzip_disk_entry *\fInzzip_disk_findfile(ZZIP_DISK * disk, char *filename,                  struct zzip_disk_entry *after, zzip_strcmp_fn_t compare)
b'struct zzip_disk_entry *\fInzzip_disk_findfirst(ZZIP_DISK * disk)
b'struct zzip_disk_entry *\fInzzip_disk_findnext(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
b'struct zzip_disk_entry *\fInzzip_disk_findmatch(ZZIP_DISK * disk, char *filespec,                   struct zzip_disk_entry *after,                   zzip_fnmatch_fn_t compare, int flags)n'

DESCRIPTION
b'The zzip_disk_findfile function is given a filename as an additional argument, to find thedisk_entry matching a given filename. The compare-function is usuallystrcmp or strcasecmp or perhaps strcoll, if null then strcmp is used.- use null as argument for "after"-entry when searching the firstmatching entry, otherwise the last returned value if you look for otherentries with a special "compare" function (if null then a doubled searchis rather useless with this variant of _findfile).

b'The zzip_disk_findfile functionreturns the entry pointer.The zzip_disk_findfile function may return null on error. (errno = ENOMEM|EBADMSG|ENOENT)n'

b'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 thedisk_trailer is _last_ in the file area, so that its position would be ata fixed offset from the end of the file area if not for the comment fieldallowed to be of variable length (which needs us to do a little searchfor the disk_tailer). However, in this simple implementation we disregardany disk_trailer info telling about multidisk archives, so we just returna pointer to the zip central directory.

b'For an actual means, we are going to search backwards from the endof the mmaped block looking for the PK-magic signature of adisk_trailer. If we see one then we check the rootseek value tofind the first disk_entry of the root central directory. If we findthe correct PK-magic signature of a disk_entry over there then weassume we are done and we are going to return a pointer to that label.

b'The return value is a pointer to the first zzip_disk_entry being checkedto be within the bounds of the file area specified by the arguments. Ifno disk_trailer was found then null is returned, and likewise we onlyaccept a disk_trailer with a seekvalue that points to a disk_entry andboth parts have valid PK-magic parts. Beyond some sanity check we try tocatch a common brokeness with zip archives that still allows us to findthe start of the zip central directory.So the zzip_disk_findfirst function may return nulland sets errno.n'

b'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 inthe given bounds of the mmapped file area.

b'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)n'

b'The zzip_disk_findmatch function uses a compare-function with an additional argumentand it is called just like fnmatch(3) from POSIX.2 AD:1993), i.e.the argument filespec first and the ziplocal filename second withthe integer-flags put in as third to the indirect call. If theplatform has fnmatch available then null-compare will use that oneand otherwise we fall back to mere strcmp, so if you need fnmatchsearching then please provide an implementation somewhere else.- use null as argument for "after"-entry when searching the firstmatching entry, or the last disk_entry return-value to find thenext entry matching the given filespec.

b'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)n

AUTHOR
b'Guido Draheim <guidod@gmx.de>

COPYRIGHT
b'Copyright (c)Guido Draheim, use under copyleft (LGPL,MPL)n'