1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
<html><head><title>zziplib Library Functions</title>
</head><body>
<h2>zziplib Library Functions</h2><p>Version 0.13.58</p><p><big><b><code>#include <zzip/mmapped.h></code></b></big></p><table width="100%"><tr><td valign="top"><code><b><code><a href="#zzip_disk_entry_to_data">zzip_disk_entry_to_data</a></code></b>(ZZIP_DISK * disk, struct zzip_disk_entry * entry)
: zzip_byte_t *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_entry_to_file_header">zzip_disk_entry_to_file_header</a></code></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: struct zzip_file_header *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_entry_strdup_name">zzip_disk_entry_strdup_name</a></code></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: zzip__new__ char *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_entry_strdup_comment">zzip_disk_entry_strdup_comment</a></code></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: zzip__new__ char *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_findfile">zzip_disk_findfile</a></code></b>(ZZIP_DISK * disk, char *filename,
struct zzip_disk_entry *after, zzip_strcmp_fn_t compare)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_findfirst">zzip_disk_findfirst</a></code></b>(ZZIP_DISK * disk)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_findnext">zzip_disk_findnext</a></code></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_findmatch">zzip_disk_findmatch</a></code></b>(ZZIP_DISK * disk, char *filespec,
struct zzip_disk_entry *after,
zzip_fnmatch_fn_t compare, int flags)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_fopen">zzip_disk_fopen</a></code></b>(ZZIP_DISK * disk, char *filename)
: zzip__new__ ZZIP_DISK_FILE *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_entry_fopen">zzip_disk_entry_fopen</a></code></b>(ZZIP_DISK * disk, ZZIP_DISK_ENTRY * entry)
: zzip__new__ ZZIP_DISK_FILE *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_fread">zzip_disk_fread</a></code></b>(void *ptr, zzip_size_t sized, zzip_size_t nmemb,
ZZIP_DISK_FILE * file)
: zzip_size_t
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_fclose">zzip_disk_fclose</a></code></b>(ZZIP_DISK_FILE * file)
: int
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_feof">zzip_disk_feof</a></code></b>(ZZIP_DISK_FILE * file)
: int
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_mmap">zzip_disk_mmap</a></code></b>(int fd)
: zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_init">zzip_disk_init</a></code></b>(ZZIP_DISK * disk, void *buffer, zzip_size_t buflen)
: int
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_new">zzip_disk_new</a></code></b>(void)
: zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_munmap">zzip_disk_munmap</a></code></b>(ZZIP_DISK * disk)
: int
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_open">zzip_disk_open</a></code></b>(char *filename)
: zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_buffer">zzip_disk_buffer</a></code></b>(void *buffer, size_t buflen) : zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><code><a href="#zzip_disk_close">zzip_disk_close</a></code></b>(ZZIP_DISK * disk)
: int
</code></td></tr></table><h3>Documentation</h3><dl><dt><table width="100%"><tr><td valign="top"><code><b><a name="zzip_disk_entry_to_data">zzip_disk_entry_to_data</a></b>(ZZIP_DISK * disk, struct zzip_disk_entry * entry)
: zzip_byte_t *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_entry_to_file_header">zzip_disk_entry_to_file_header</a></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: struct zzip_file_header *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_entry_strdup_name">zzip_disk_entry_strdup_name</a></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: zzip__new__ char *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_entry_strdup_comment">zzip_disk_entry_strdup_comment</a></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: zzip__new__ char *
</code></td></tr></table></dt><dd><table width="100%"><tr><td valign="top"><table border="0" width="100%" cellpadding="0" cellspacing="0"><td> <em> helper functions for (mmapped) zip access api</em> </td><td align="right"> <em><small>/vol/8/src/cvs/workspace/zzip-0/zzip/mmapped.c</small></em></td></table><p>
The <code>zzip_disk_entry_to_data</code> function augments the other zzip_disk_entry_* helpers: here we move
a disk_entry pointer (as returned by _find* functions) into a pointer to
the data block right after the file_header. Only disk->buffer would be
needed to perform the seek but we check the mmapped range end as well.
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_entry_to_file_header</code> function does half the job of <code><a href="#zzip_disk_entry_to_data">zzip_disk_entry_to_data</a></code> where it
can augment with <code><u>zzip_file_header_to_data</u></code> helper from format/fetch.h
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_entry_strdup_name</code> function is a big helper despite its little name: in a zip file the
encoded filenames are usually NOT zero-terminated but for common usage
with libc we need it that way. Secondly, the filename SHOULD be present
in the zip central directory but if not then we fallback to the filename
given in the file_header of each compressed data portion.
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_entry_strdup_comment</code> function is similar creating a reference to a zero terminated
string but it can only exist in the zip central directory entry.
</p>
</td></tr></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"><tr><td valign="top"><code><b><a name="zzip_disk_findfile">zzip_disk_findfile</a></b>(ZZIP_DISK * disk, char *filename,
struct zzip_disk_entry *after, zzip_strcmp_fn_t compare)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_findfirst">zzip_disk_findfirst</a></b>(ZZIP_DISK * disk)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_findnext">zzip_disk_findnext</a></b>(ZZIP_DISK * disk, struct zzip_disk_entry *entry)
: struct zzip_disk_entry *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_findmatch">zzip_disk_findmatch</a></b>(ZZIP_DISK * disk, char *filespec,
struct zzip_disk_entry *after,
zzip_fnmatch_fn_t compare, int flags)
: struct zzip_disk_entry *
</code></td></tr></table></dt><dd><table width="100%"><tr><td valign="top"><table border="0" width="100%" cellpadding="0" cellspacing="0"><td> <em> search for files in the (mmapped) zip central directory</em> </td><td align="right"> <em><small>/vol/8/src/cvs/workspace/zzip-0/zzip/mmapped.c</small></em></td></table><p>
The <code>zzip_disk_findfile</code> 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).
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_findfirst</code> 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.
</p><p>
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.
</p><p>
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.
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_findnext</code> 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.
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_findmatch</code> function uses a compare-function with an additional argument
and it is called just like fnmatch(3) 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.
</p>
</td></tr></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"><tr><td valign="top"><code><b><a name="zzip_disk_fopen">zzip_disk_fopen</a></b>(ZZIP_DISK * disk, char *filename)
: zzip__new__ ZZIP_DISK_FILE *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_entry_fopen">zzip_disk_entry_fopen</a></b>(ZZIP_DISK * disk, ZZIP_DISK_ENTRY * entry)
: zzip__new__ ZZIP_DISK_FILE *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_fread">zzip_disk_fread</a></b>(void *ptr, zzip_size_t sized, zzip_size_t nmemb,
ZZIP_DISK_FILE * file)
: zzip_size_t
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_fclose">zzip_disk_fclose</a></b>(ZZIP_DISK_FILE * file)
: int
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_feof">zzip_disk_feof</a></b>(ZZIP_DISK_FILE * file)
: int
</code></td></tr></table></dt><dd><table width="100%"><tr><td valign="top"><table border="0" width="100%" cellpadding="0" cellspacing="0"><td> <em> openening a file part wrapped within a (mmapped) zip archive</em> </td><td align="right"> <em><small>/vol/8/src/cvs/workspace/zzip-0/zzip/mmapped.c</small></em></td></table><p>
The <code>zzip_disk_fopen</code> function opens a file found by name, so it does a search into
the zip central directory with <code><a href="#zzip_disk_findfile">zzip_disk_findfile</a></code> and whatever
is found first is given to <code><a href="#zzip_disk_entry_fopen">zzip_disk_entry_fopen</a></code>
</p>
</td></tr><tr><td valign="top"><p>
the ZZIP_DISK_FILE* is rather simple in just encapsulating the
arguments given to the <code>zzip_disk_entry_fopen</code> function plus a zlib deflate buffer.
Note that the ZZIP_DISK pointer does already contain the full
mmapped file area of a zip disk, so open()ing a file part within
that area happens to be a lookup of its bounds and encoding. That
information is memorized on the ZZIP_DISK_FILE so that subsequent
_read() operations will be able to get the next data portion or
return an eof condition for that file part wrapped in the zip archive.
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_fread</code> function reads more bytes into the output buffer specified as
arguments. The return value is null on eof or error, the stdio-like
interface can not distinguish between these so you need to check
with <code><a href="#zzip_disk_feof">zzip_disk_feof</a></code> for the difference.
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_fclose</code> function releases any zlib decoder info needed for decompression
and dumps the ZZIP_DISK_FILE* then.
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_feof</code> function allows to distinguish an error from an eof condition.
Actually, if we found an error but we did already reach eof then we
just keep on saying that it was an eof, so the app can just continue.
</p>
</td></tr></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"><tr><td valign="top"><code><b><a name="zzip_disk_mmap">zzip_disk_mmap</a></b>(int fd)
: zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_init">zzip_disk_init</a></b>(ZZIP_DISK * disk, void *buffer, zzip_size_t buflen)
: int
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_new">zzip_disk_new</a></b>(void)
: zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_munmap">zzip_disk_munmap</a></b>(ZZIP_DISK * disk)
: int
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_open">zzip_disk_open</a></b>(char *filename)
: zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_buffer">zzip_disk_buffer</a></b>(void *buffer, size_t buflen) : zzip__new__ ZZIP_DISK *
</code></td></tr><tr><td valign="top"><code><b><a name="zzip_disk_close">zzip_disk_close</a></b>(ZZIP_DISK * disk)
: int
</code></td></tr></table></dt><dd><table width="100%"><tr><td valign="top"><table border="0" width="100%" cellpadding="0" cellspacing="0"><td> <em> turn a filehandle into a mmapped zip disk archive handle</em> </td><td align="right"> <em><small>/vol/8/src/cvs/workspace/zzip-0/zzip/mmapped.c</small></em></td></table><p>
The <code>zzip_disk_mmap</code> function uses the given file-descriptor to detect the length of the
file and calls the system <a href="http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html"><code>mmap(2)</code></a> 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.
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_init</code> function does primary initialization of a disk-buffer struct.
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_new</code> function allocates a new disk-buffer with <a href="http://www.opengroup.org/onlinepubs/000095399/functions/malloc.html"><code>malloc(3)</code></a>
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_munmap</code> function is the inverse of <code><a href="#zzip_disk_mmap">zzip_disk_mmap</a></code> and using the system
munmap(2) on the buffer area and <a href="http://www.opengroup.org/onlinepubs/000095399/functions/free.html"><code>free(3)</code></a> on the ZZIP_DISK structure.
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_open</code> function opens the given archive by name and turn the filehandle
to <code><a href="#zzip_disk_mmap">zzip_disk_mmap</a></code> for bringing it to main memory. If it can not
be <a href="http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html"><code>mmap(2)</code></a>'ed then we slurp the whole file into a newly <a href="http://www.opengroup.org/onlinepubs/000095399/functions/malloc.html"><code>malloc(2)</code></a>'ed
memory block. Only if that fails too then we return null. Since handling
of disk->buffer is ambigous it should not be snatched away please.
</p>
</td></tr><tr><td valign="top"><p> The <code>zzip_disk_buffer</code> 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 <code>zzip_disk_buffer</code> function will do. Note that the <code>zzip_disk_buffer</code> function will not
own the buffer, it will neither be written nor free()d.
</p>
</td></tr><tr><td valign="top"><p>
The <code>zzip_disk_close</code> 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.
</p>
</td></tr></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd><dt><table width="100%"></table></dt><dd><table width="100%"></table></dd></dl>
</body></html>
|