author | Wuzzy <almikes@aol.com> |
Sat, 30 Sep 2017 03:28:43 +0200 | |
changeset 12607 | 9bdcd73a4021 |
parent 12213 | bb5522e88ab2 |
permissions | -rw-r--r-- |
7768 | 1 |
/* |
2 |
* High-level PhysicsFS archiver for simple unpacked file formats. |
|
3 |
* |
|
4 |
* This is a framework that basic archivers build on top of. It's for simple |
|
5 |
* formats that can just hand back a list of files and the offsets of their |
|
6 |
* uncompressed data. There are an alarming number of formats like this. |
|
7 |
* |
|
8 |
* RULES: Archive entries must be uncompressed, must not have separate subdir |
|
9 |
* entries (but can have subdirs), must be case insensitive LOW ASCII |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
10 |
* filenames <= 64 bytes. No symlinks, etc. We can relax some of these rules |
7768 | 11 |
* as necessary. |
12 |
* |
|
13 |
* Please see the file LICENSE.txt in the source's root directory. |
|
14 |
* |
|
15 |
* This file written by Ryan C. Gordon. |
|
16 |
*/ |
|
17 |
||
18 |
#define __PHYSICSFS_INTERNAL__ |
|
19 |
#include "physfs_internal.h" |
|
20 |
||
21 |
typedef struct |
|
22 |
{ |
|
23 |
PHYSFS_Io *io; |
|
24 |
PHYSFS_uint32 entryCount; |
|
25 |
UNPKentry *entries; |
|
26 |
} UNPKinfo; |
|
27 |
||
28 |
||
29 |
typedef struct |
|
30 |
{ |
|
31 |
PHYSFS_Io *io; |
|
32 |
UNPKentry *entry; |
|
33 |
PHYSFS_uint32 curPos; |
|
34 |
} UNPKfileinfo; |
|
35 |
||
36 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
37 |
void UNPK_closeArchive(void *opaque) |
7768 | 38 |
{ |
39 |
UNPKinfo *info = ((UNPKinfo *) opaque); |
|
40 |
info->io->destroy(info->io); |
|
41 |
allocator.Free(info->entries); |
|
42 |
allocator.Free(info); |
|
43 |
} /* UNPK_closeArchive */ |
|
44 |
||
45 |
||
46 |
static PHYSFS_sint64 UNPK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len) |
|
47 |
{ |
|
48 |
UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque; |
|
49 |
const UNPKentry *entry = finfo->entry; |
|
50 |
const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos); |
|
51 |
PHYSFS_sint64 rc; |
|
52 |
||
53 |
if (bytesLeft < len) |
|
54 |
len = bytesLeft; |
|
55 |
||
56 |
rc = finfo->io->read(finfo->io, buffer, len); |
|
57 |
if (rc > 0) |
|
58 |
finfo->curPos += (PHYSFS_uint32) rc; |
|
59 |
||
60 |
return rc; |
|
61 |
} /* UNPK_read */ |
|
62 |
||
63 |
||
64 |
static PHYSFS_sint64 UNPK_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len) |
|
65 |
{ |
|
66 |
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, -1); |
|
67 |
} /* UNPK_write */ |
|
68 |
||
69 |
||
70 |
static PHYSFS_sint64 UNPK_tell(PHYSFS_Io *io) |
|
71 |
{ |
|
72 |
return ((UNPKfileinfo *) io->opaque)->curPos; |
|
73 |
} /* UNPK_tell */ |
|
74 |
||
75 |
||
76 |
static int UNPK_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
|
77 |
{ |
|
78 |
UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque; |
|
79 |
const UNPKentry *entry = finfo->entry; |
|
80 |
int rc; |
|
81 |
||
82 |
BAIL_IF_MACRO(offset >= entry->size, PHYSFS_ERR_PAST_EOF, 0); |
|
83 |
rc = finfo->io->seek(finfo->io, entry->startPos + offset); |
|
84 |
if (rc) |
|
85 |
finfo->curPos = (PHYSFS_uint32) offset; |
|
86 |
||
87 |
return rc; |
|
88 |
} /* UNPK_seek */ |
|
89 |
||
90 |
||
91 |
static PHYSFS_sint64 UNPK_length(PHYSFS_Io *io) |
|
92 |
{ |
|
93 |
const UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque; |
|
94 |
return ((PHYSFS_sint64) finfo->entry->size); |
|
95 |
} /* UNPK_length */ |
|
96 |
||
97 |
||
98 |
static PHYSFS_Io *UNPK_duplicate(PHYSFS_Io *_io) |
|
99 |
{ |
|
100 |
UNPKfileinfo *origfinfo = (UNPKfileinfo *) _io->opaque; |
|
101 |
PHYSFS_Io *io = NULL; |
|
102 |
PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
|
103 |
UNPKfileinfo *finfo = (UNPKfileinfo *) allocator.Malloc(sizeof (UNPKfileinfo)); |
|
104 |
GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_duplicate_failed); |
|
105 |
GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_duplicate_failed); |
|
106 |
||
107 |
io = origfinfo->io->duplicate(origfinfo->io); |
|
108 |
if (!io) goto UNPK_duplicate_failed; |
|
109 |
finfo->io = io; |
|
110 |
finfo->entry = origfinfo->entry; |
|
111 |
finfo->curPos = 0; |
|
112 |
memcpy(retval, _io, sizeof (PHYSFS_Io)); |
|
113 |
retval->opaque = finfo; |
|
114 |
return retval; |
|
115 |
||
116 |
UNPK_duplicate_failed: |
|
117 |
if (finfo != NULL) allocator.Free(finfo); |
|
118 |
if (retval != NULL) allocator.Free(retval); |
|
119 |
if (io != NULL) io->destroy(io); |
|
120 |
return NULL; |
|
121 |
} /* UNPK_duplicate */ |
|
122 |
||
123 |
static int UNPK_flush(PHYSFS_Io *io) { return 1; /* no write support. */ } |
|
124 |
||
125 |
static void UNPK_destroy(PHYSFS_Io *io) |
|
126 |
{ |
|
127 |
UNPKfileinfo *finfo = (UNPKfileinfo *) io->opaque; |
|
128 |
finfo->io->destroy(finfo->io); |
|
129 |
allocator.Free(finfo); |
|
130 |
allocator.Free(io); |
|
131 |
} /* UNPK_destroy */ |
|
132 |
||
133 |
||
134 |
static const PHYSFS_Io UNPK_Io = |
|
135 |
{ |
|
136 |
CURRENT_PHYSFS_IO_API_VERSION, NULL, |
|
137 |
UNPK_read, |
|
138 |
UNPK_write, |
|
139 |
UNPK_seek, |
|
140 |
UNPK_tell, |
|
141 |
UNPK_length, |
|
142 |
UNPK_duplicate, |
|
143 |
UNPK_flush, |
|
144 |
UNPK_destroy |
|
145 |
}; |
|
146 |
||
147 |
||
148 |
static int entryCmp(void *_a, size_t one, size_t two) |
|
149 |
{ |
|
150 |
if (one != two) |
|
151 |
{ |
|
152 |
const UNPKentry *a = (const UNPKentry *) _a; |
|
153 |
return __PHYSFS_stricmpASCII(a[one].name, a[two].name); |
|
154 |
} /* if */ |
|
155 |
||
156 |
return 0; |
|
157 |
} /* entryCmp */ |
|
158 |
||
159 |
||
160 |
static void entrySwap(void *_a, size_t one, size_t two) |
|
161 |
{ |
|
162 |
if (one != two) |
|
163 |
{ |
|
164 |
UNPKentry tmp; |
|
165 |
UNPKentry *first = &(((UNPKentry *) _a)[one]); |
|
166 |
UNPKentry *second = &(((UNPKentry *) _a)[two]); |
|
167 |
memcpy(&tmp, first, sizeof (UNPKentry)); |
|
168 |
memcpy(first, second, sizeof (UNPKentry)); |
|
169 |
memcpy(second, &tmp, sizeof (UNPKentry)); |
|
170 |
} /* if */ |
|
171 |
} /* entrySwap */ |
|
172 |
||
173 |
||
174 |
static PHYSFS_sint32 findStartOfDir(UNPKinfo *info, const char *path, |
|
175 |
int stop_on_first_find) |
|
176 |
{ |
|
177 |
PHYSFS_sint32 lo = 0; |
|
178 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
|
179 |
PHYSFS_sint32 middle; |
|
180 |
PHYSFS_uint32 dlen = (PHYSFS_uint32) strlen(path); |
|
181 |
PHYSFS_sint32 retval = -1; |
|
182 |
const char *name; |
|
183 |
int rc; |
|
184 |
||
185 |
if (*path == '\0') /* root dir? */ |
|
186 |
return 0; |
|
187 |
||
188 |
if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */ |
|
189 |
dlen--; |
|
190 |
||
191 |
while (lo <= hi) |
|
192 |
{ |
|
193 |
middle = lo + ((hi - lo) / 2); |
|
194 |
name = info->entries[middle].name; |
|
195 |
rc = __PHYSFS_strnicmpASCII(path, name, dlen); |
|
196 |
if (rc == 0) |
|
197 |
{ |
|
198 |
char ch = name[dlen]; |
|
199 |
if (ch < '/') /* make sure this isn't just a substr match. */ |
|
200 |
rc = -1; |
|
201 |
else if (ch > '/') |
|
202 |
rc = 1; |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
203 |
else |
7768 | 204 |
{ |
205 |
if (stop_on_first_find) /* Just checking dir's existance? */ |
|
206 |
return middle; |
|
207 |
||
208 |
if (name[dlen + 1] == '\0') /* Skip initial dir entry. */ |
|
209 |
return (middle + 1); |
|
210 |
||
211 |
/* there might be more entries earlier in the list. */ |
|
212 |
retval = middle; |
|
213 |
hi = middle - 1; |
|
214 |
} /* else */ |
|
215 |
} /* if */ |
|
216 |
||
217 |
if (rc > 0) |
|
218 |
lo = middle + 1; |
|
219 |
else |
|
220 |
hi = middle - 1; |
|
221 |
} /* while */ |
|
222 |
||
223 |
return retval; |
|
224 |
} /* findStartOfDir */ |
|
225 |
||
226 |
||
227 |
/* |
|
228 |
* Moved to seperate function so we can use alloca then immediately throw |
|
229 |
* away the allocated stack space... |
|
230 |
*/ |
|
231 |
static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata, |
|
232 |
const char *odir, const char *str, PHYSFS_sint32 ln) |
|
233 |
{ |
|
234 |
char *newstr = __PHYSFS_smallAlloc(ln + 1); |
|
235 |
if (newstr == NULL) |
|
236 |
return; |
|
237 |
||
238 |
memcpy(newstr, str, ln); |
|
239 |
newstr[ln] = '\0'; |
|
240 |
cb(callbackdata, odir, newstr); |
|
241 |
__PHYSFS_smallFree(newstr); |
|
242 |
} /* doEnumCallback */ |
|
243 |
||
244 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
245 |
void UNPK_enumerateFiles(void *opaque, const char *dname, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
246 |
PHYSFS_EnumFilesCallback cb, |
7768 | 247 |
const char *origdir, void *callbackdata) |
248 |
{ |
|
249 |
UNPKinfo *info = ((UNPKinfo *) opaque); |
|
250 |
PHYSFS_sint32 dlen, dlen_inc, max, i; |
|
251 |
||
252 |
i = findStartOfDir(info, dname, 0); |
|
253 |
if (i == -1) /* no such directory. */ |
|
254 |
return; |
|
255 |
||
256 |
dlen = (PHYSFS_sint32) strlen(dname); |
|
257 |
if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */ |
|
258 |
dlen--; |
|
259 |
||
260 |
dlen_inc = ((dlen > 0) ? 1 : 0) + dlen; |
|
261 |
max = (PHYSFS_sint32) info->entryCount; |
|
262 |
while (i < max) |
|
263 |
{ |
|
264 |
char *add; |
|
265 |
char *ptr; |
|
266 |
PHYSFS_sint32 ln; |
|
267 |
char *e = info->entries[i].name; |
|
268 |
if ((dlen) && |
|
269 |
((__PHYSFS_strnicmpASCII(e, dname, dlen)) || (e[dlen] != '/'))) |
|
270 |
{ |
|
271 |
break; /* past end of this dir; we're done. */ |
|
272 |
} /* if */ |
|
273 |
||
274 |
add = e + dlen_inc; |
|
275 |
ptr = strchr(add, '/'); |
|
276 |
ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add)); |
|
277 |
doEnumCallback(cb, callbackdata, origdir, add, ln); |
|
278 |
ln += dlen_inc; /* point past entry to children... */ |
|
279 |
||
280 |
/* increment counter and skip children of subdirs... */ |
|
281 |
while ((++i < max) && (ptr != NULL)) |
|
282 |
{ |
|
283 |
char *e_new = info->entries[i].name; |
|
284 |
if ((__PHYSFS_strnicmpASCII(e, e_new, ln) != 0) || |
|
285 |
(e_new[ln] != '/')) |
|
286 |
{ |
|
287 |
break; |
|
288 |
} /* if */ |
|
289 |
} /* while */ |
|
290 |
} /* while */ |
|
291 |
} /* UNPK_enumerateFiles */ |
|
292 |
||
293 |
||
294 |
/* |
|
295 |
* This will find the UNPKentry associated with a path in platform-independent |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
296 |
* notation. Directories don't have UNPKentries associated with them, but |
7768 | 297 |
* (*isDir) will be set to non-zero if a dir was hit. |
298 |
*/ |
|
299 |
static UNPKentry *findEntry(const UNPKinfo *info, const char *path, int *isDir) |
|
300 |
{ |
|
301 |
UNPKentry *a = info->entries; |
|
302 |
PHYSFS_sint32 pathlen = (PHYSFS_sint32) strlen(path); |
|
303 |
PHYSFS_sint32 lo = 0; |
|
304 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
|
305 |
PHYSFS_sint32 middle; |
|
306 |
const char *thispath = NULL; |
|
307 |
int rc; |
|
308 |
||
309 |
while (lo <= hi) |
|
310 |
{ |
|
311 |
middle = lo + ((hi - lo) / 2); |
|
312 |
thispath = a[middle].name; |
|
313 |
rc = __PHYSFS_strnicmpASCII(path, thispath, pathlen); |
|
314 |
||
315 |
if (rc > 0) |
|
316 |
lo = middle + 1; |
|
317 |
||
318 |
else if (rc < 0) |
|
319 |
hi = middle - 1; |
|
320 |
||
321 |
else /* substring match...might be dir or entry or nothing. */ |
|
322 |
{ |
|
323 |
if (isDir != NULL) |
|
324 |
{ |
|
325 |
*isDir = (thispath[pathlen] == '/'); |
|
326 |
if (*isDir) |
|
327 |
return NULL; |
|
328 |
} /* if */ |
|
329 |
||
330 |
if (thispath[pathlen] == '\0') /* found entry? */ |
|
331 |
return &a[middle]; |
|
332 |
/* adjust search params, try again. */ |
|
333 |
else if (thispath[pathlen] > '/') |
|
334 |
hi = middle - 1; |
|
335 |
else |
|
336 |
lo = middle + 1; |
|
337 |
} /* if */ |
|
338 |
} /* while */ |
|
339 |
||
340 |
if (isDir != NULL) |
|
341 |
*isDir = 0; |
|
342 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
343 |
BAIL_MACRO(PHYSFS_ERR_NOT_FOUND, NULL); |
7768 | 344 |
} /* findEntry */ |
345 |
||
346 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
347 |
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name) |
7768 | 348 |
{ |
349 |
PHYSFS_Io *retval = NULL; |
|
350 |
UNPKinfo *info = (UNPKinfo *) opaque; |
|
351 |
UNPKfileinfo *finfo = NULL; |
|
352 |
int isdir = 0; |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
353 |
UNPKentry *entry = findEntry(info, name, &isdir); |
7768 | 354 |
|
355 |
GOTO_IF_MACRO(isdir, PHYSFS_ERR_NOT_A_FILE, UNPK_openRead_failed); |
|
356 |
GOTO_IF_MACRO(!entry, ERRPASS, UNPK_openRead_failed); |
|
357 |
||
358 |
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
|
359 |
GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_openRead_failed); |
|
360 |
||
361 |
finfo = (UNPKfileinfo *) allocator.Malloc(sizeof (UNPKfileinfo)); |
|
362 |
GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_openRead_failed); |
|
363 |
||
364 |
finfo->io = info->io->duplicate(info->io); |
|
365 |
GOTO_IF_MACRO(!finfo->io, ERRPASS, UNPK_openRead_failed); |
|
366 |
||
367 |
if (!finfo->io->seek(finfo->io, entry->startPos)) |
|
368 |
goto UNPK_openRead_failed; |
|
369 |
||
370 |
finfo->curPos = 0; |
|
371 |
finfo->entry = entry; |
|
372 |
||
373 |
memcpy(retval, &UNPK_Io, sizeof (*retval)); |
|
374 |
retval->opaque = finfo; |
|
375 |
return retval; |
|
376 |
||
377 |
UNPK_openRead_failed: |
|
378 |
if (finfo != NULL) |
|
379 |
{ |
|
380 |
if (finfo->io != NULL) |
|
381 |
finfo->io->destroy(finfo->io); |
|
382 |
allocator.Free(finfo); |
|
383 |
} /* if */ |
|
384 |
||
385 |
if (retval != NULL) |
|
386 |
allocator.Free(retval); |
|
387 |
||
388 |
return NULL; |
|
389 |
} /* UNPK_openRead */ |
|
390 |
||
391 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
392 |
PHYSFS_Io *UNPK_openWrite(void *opaque, const char *name) |
7768 | 393 |
{ |
394 |
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, NULL); |
|
395 |
} /* UNPK_openWrite */ |
|
396 |
||
397 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
398 |
PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name) |
7768 | 399 |
{ |
400 |
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, NULL); |
|
401 |
} /* UNPK_openAppend */ |
|
402 |
||
403 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
404 |
int UNPK_remove(void *opaque, const char *name) |
7768 | 405 |
{ |
406 |
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0); |
|
407 |
} /* UNPK_remove */ |
|
408 |
||
409 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
410 |
int UNPK_mkdir(void *opaque, const char *name) |
7768 | 411 |
{ |
412 |
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0); |
|
413 |
} /* UNPK_mkdir */ |
|
414 |
||
415 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
416 |
int UNPK_stat(void *opaque, const char *filename, PHYSFS_Stat *stat) |
7768 | 417 |
{ |
418 |
int isDir = 0; |
|
419 |
const UNPKinfo *info = (const UNPKinfo *) opaque; |
|
420 |
const UNPKentry *entry = findEntry(info, filename, &isDir); |
|
421 |
||
422 |
if (isDir) |
|
423 |
{ |
|
424 |
stat->filetype = PHYSFS_FILETYPE_DIRECTORY; |
|
425 |
stat->filesize = 0; |
|
426 |
} /* if */ |
|
427 |
else if (entry != NULL) |
|
428 |
{ |
|
429 |
stat->filetype = PHYSFS_FILETYPE_REGULAR; |
|
430 |
stat->filesize = entry->size; |
|
431 |
} /* else if */ |
|
432 |
else |
|
433 |
{ |
|
434 |
return 0; |
|
435 |
} /* else */ |
|
436 |
||
437 |
stat->modtime = -1; |
|
438 |
stat->createtime = -1; |
|
439 |
stat->accesstime = -1; |
|
440 |
stat->readonly = 1; |
|
441 |
||
442 |
return 1; |
|
443 |
} /* UNPK_stat */ |
|
444 |
||
445 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
10017
diff
changeset
|
446 |
void *UNPK_openArchive(PHYSFS_Io *io, UNPKentry *e, const PHYSFS_uint32 num) |
7768 | 447 |
{ |
448 |
UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo)); |
|
449 |
if (info == NULL) |
|
450 |
{ |
|
451 |
allocator.Free(e); |
|
452 |
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
|
453 |
} /* if */ |
|
454 |
||
455 |
__PHYSFS_sort(e, (size_t) num, entryCmp, entrySwap); |
|
456 |
info->io = io; |
|
457 |
info->entryCount = num; |
|
458 |
info->entries = e; |
|
459 |
||
460 |
return info; |
|
461 |
} /* UNPK_openArchive */ |
|
462 |
||
463 |
/* end of archiver_unpacked.c ... */ |
|
464 |