Skip to content

Latest commit

 

History

History
3468 lines (2793 loc) · 98.4 KB

physfs.c

File metadata and controls

3468 lines (2793 loc) · 98.4 KB
 
1
2
3
4
5
/**
* PhysicsFS; a portable, flexible file i/o abstraction.
*
* Documentation is in physfs.h. It's verbose, honest. :)
*
Mar 11, 2007
Mar 11, 2007
6
* Please see the file LICENSE.txt in the source's root directory.
7
8
9
10
*
* This file written by Ryan C. Gordon.
*/
Jul 6, 2001
Jul 6, 2001
11
12
13
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Jul 9, 2017
Jul 9, 2017
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
#if defined(_MSC_VER)
/* this code came from https://stackoverflow.com/a/8712996 */
int __PHYSFS_msvc_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
int __PHYSFS_msvc_snprintf(char *outBuf, size_t size, const char *format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = __PHYSFS_msvc_vsnprintf(outBuf, size, format, ap);
va_end(ap);
return count;
}
#endif
Sep 26, 2004
Sep 26, 2004
41
42
43
typedef struct __PHYSFS_DIRHANDLE__
{
Sep 26, 2004
Sep 26, 2004
44
45
void *opaque; /* Instance data unique to the archiver. */
char *dirName; /* Path to archive in platform-dependent notation. */
Mar 13, 2005
Mar 13, 2005
46
char *mountPoint; /* Mountpoint in virtual file tree. */
Oct 18, 2018
Oct 18, 2018
47
48
char *root; /* subdirectory of archiver to use as root of archive (NULL for actual root) */
size_t rootlen; /* subdirectory of archiver to use as root of archive (NULL for actual root) */
Sep 26, 2004
Sep 26, 2004
49
50
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */
Sep 26, 2004
Sep 26, 2004
51
52
53
} DirHandle;
Sep 26, 2004
Sep 26, 2004
54
55
typedef struct __PHYSFS_FILEHANDLE__
{
Aug 30, 2010
Aug 30, 2010
56
PHYSFS_Io *io; /* Instance data unique to the archiver for this file. */
Sep 26, 2004
Sep 26, 2004
57
58
59
PHYSFS_uint8 forReading; /* Non-zero if reading, zero if write/append */
const DirHandle *dirHandle; /* Archiver instance that created this */
PHYSFS_uint8 *buffer; /* Buffer, if set (NULL otherwise). Don't touch! */
Aug 6, 2017
Aug 6, 2017
60
61
62
size_t bufsize; /* Bufsize, if set (0 otherwise). Don't touch! */
size_t buffill; /* Buffer fill size. Don't touch! */
size_t bufpos; /* Buffer position. Don't touch! */
Sep 26, 2004
Sep 26, 2004
63
64
65
66
struct __PHYSFS_FILEHANDLE__ *next; /* linked list stuff. */
} FileHandle;
Mar 20, 2012
Mar 20, 2012
67
typedef struct __PHYSFS_ERRSTATETYPE__
Sep 6, 2009
Sep 6, 2009
69
void *tid;
Mar 20, 2012
Mar 20, 2012
70
71
72
PHYSFS_ErrorCode code;
struct __PHYSFS_ERRSTATETYPE__ *next;
} ErrState;
Jul 6, 2001
Jul 6, 2001
74
75
76
/* General PhysicsFS state ... */
static int initialized = 0;
Mar 20, 2012
Mar 20, 2012
77
static ErrState *errorStates = NULL;
Sep 26, 2004
Sep 26, 2004
78
79
80
81
static DirHandle *searchPath = NULL;
static DirHandle *writeDir = NULL;
static FileHandle *openWriteList = NULL;
static FileHandle *openReadList = NULL;
Jul 6, 2001
Jul 6, 2001
82
83
static char *baseDir = NULL;
static char *userDir = NULL;
Mar 22, 2012
Mar 22, 2012
84
static char *prefDir = NULL;
Jul 6, 2001
Jul 6, 2001
85
static int allowSymLinks = 0;
Jul 13, 2017
Jul 13, 2017
86
87
static PHYSFS_Archiver **archivers = NULL;
static PHYSFS_ArchiveInfo **archiveInfo = NULL;
Nov 28, 2012
Nov 28, 2012
88
static volatile size_t numArchivers = 0;
Nov 28, 2018
Nov 28, 2018
89
static size_t longest_root = 0;
Jul 6, 2001
Jul 6, 2001
90
Mar 30, 2002
Mar 30, 2002
91
92
93
/* mutexes ... */
static void *errorLock = NULL; /* protects error message list. */
static void *stateLock = NULL; /* protects other PhysFS static state. */
Jul 6, 2001
Jul 6, 2001
94
Sep 23, 2004
Sep 23, 2004
95
96
/* allocator ... */
static int externalAllocator = 0;
Mar 14, 2005
Mar 14, 2005
97
PHYSFS_Allocator allocator;
Sep 23, 2004
Sep 23, 2004
98
Jul 6, 2001
Jul 6, 2001
99
Aug 6, 2017
Aug 6, 2017
100
101
102
103
104
#ifdef PHYSFS_NEED_ATOMIC_OP_FALLBACK
static inline int __PHYSFS_atomicAdd(int *ptrval, const int val)
{
int retval;
__PHYSFS_platformGrabMutex(stateLock);
Sep 29, 2022
Sep 29, 2022
105
*ptrval += val;
Aug 6, 2017
Aug 6, 2017
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
retval = *ptrval;
__PHYSFS_platformReleaseMutex(stateLock);
return retval;
} /* __PHYSFS_atomicAdd */
int __PHYSFS_ATOMIC_INCR(int *ptrval)
{
return __PHYSFS_atomicAdd(ptrval, 1);
} /* __PHYSFS_ATOMIC_INCR */
int __PHYSFS_ATOMIC_DECR(int *ptrval)
{
return __PHYSFS_atomicAdd(ptrval, -1);
} /* __PHYSFS_ATOMIC_DECR */
#endif
Aug 30, 2010
Aug 30, 2010
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
/* PHYSFS_Io implementation for i/o to physical filesystem... */
/* !!! FIXME: maybe refcount the paths in a string pool? */
typedef struct __PHYSFS_NativeIoInfo
{
void *handle;
const char *path;
int mode; /* 'r', 'w', or 'a' */
} NativeIoInfo;
static PHYSFS_sint64 nativeIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_platformRead(info->handle, buf, len);
} /* nativeIo_read */
static PHYSFS_sint64 nativeIo_write(PHYSFS_Io *io, const void *buffer,
PHYSFS_uint64 len)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_platformWrite(info->handle, buffer, len);
} /* nativeIo_write */
static int nativeIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_platformSeek(info->handle, offset);
} /* nativeIo_seek */
static PHYSFS_sint64 nativeIo_tell(PHYSFS_Io *io)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_platformTell(info->handle);
} /* nativeIo_tell */
static PHYSFS_sint64 nativeIo_length(PHYSFS_Io *io)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_platformFileLength(info->handle);
} /* nativeIo_length */
static PHYSFS_Io *nativeIo_duplicate(PHYSFS_Io *io)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_createNativeIo(info->path, info->mode);
} /* nativeIo_duplicate */
static int nativeIo_flush(PHYSFS_Io *io)
{
Sep 25, 2017
Sep 25, 2017
173
174
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
return __PHYSFS_platformFlush(info->handle);
Aug 30, 2010
Aug 30, 2010
175
176
177
178
179
180
181
182
183
184
185
186
187
} /* nativeIo_flush */
static void nativeIo_destroy(PHYSFS_Io *io)
{
NativeIoInfo *info = (NativeIoInfo *) io->opaque;
__PHYSFS_platformClose(info->handle);
allocator.Free((void *) info->path);
allocator.Free(info);
allocator.Free(io);
} /* nativeIo_destroy */
static const PHYSFS_Io __PHYSFS_nativeIoInterface =
{
Mar 25, 2012
Mar 25, 2012
188
CURRENT_PHYSFS_IO_API_VERSION, NULL,
Aug 30, 2010
Aug 30, 2010
189
190
191
192
193
194
195
nativeIo_read,
nativeIo_write,
nativeIo_seek,
nativeIo_tell,
nativeIo_length,
nativeIo_duplicate,
nativeIo_flush,
Mar 25, 2012
Mar 25, 2012
196
nativeIo_destroy
Aug 30, 2010
Aug 30, 2010
197
198
199
200
201
202
203
204
205
206
207
208
};
PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode)
{
PHYSFS_Io *io = NULL;
NativeIoInfo *info = NULL;
void *handle = NULL;
char *pathdup = NULL;
assert((mode == 'r') || (mode == 'w') || (mode == 'a'));
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Jul 6, 2017
Jul 6, 2017
209
GOTO_IF(!io, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed);
Aug 30, 2010
Aug 30, 2010
210
info = (NativeIoInfo *) allocator.Malloc(sizeof (NativeIoInfo));
Jul 6, 2017
Jul 6, 2017
211
GOTO_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed);
Aug 30, 2010
Aug 30, 2010
212
pathdup = (char *) allocator.Malloc(strlen(path) + 1);
Jul 6, 2017
Jul 6, 2017
213
GOTO_IF(!pathdup, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed);
Aug 30, 2010
Aug 30, 2010
214
215
216
217
218
219
220
221
if (mode == 'r')
handle = __PHYSFS_platformOpenRead(path);
else if (mode == 'w')
handle = __PHYSFS_platformOpenWrite(path);
else if (mode == 'a')
handle = __PHYSFS_platformOpenAppend(path);
Jul 6, 2017
Jul 6, 2017
222
GOTO_IF_ERRPASS(!handle, createNativeIo_failed);
Aug 30, 2010
Aug 30, 2010
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
strcpy(pathdup, path);
info->handle = handle;
info->path = pathdup;
info->mode = mode;
memcpy(io, &__PHYSFS_nativeIoInterface, sizeof (*io));
io->opaque = info;
return io;
createNativeIo_failed:
if (handle != NULL) __PHYSFS_platformClose(handle);
if (pathdup != NULL) allocator.Free(pathdup);
if (info != NULL) allocator.Free(info);
if (io != NULL) allocator.Free(io);
return NULL;
} /* __PHYSFS_createNativeIo */
Aug 30, 2010
Aug 30, 2010
241
242
243
244
245
246
247
248
/* PHYSFS_Io implementation for i/o to a memory buffer... */
typedef struct __PHYSFS_MemoryIoInfo
{
const PHYSFS_uint8 *buf;
PHYSFS_uint64 len;
PHYSFS_uint64 pos;
PHYSFS_Io *parent;
Aug 6, 2017
Aug 6, 2017
249
int refcount;
Aug 30, 2010
Aug 30, 2010
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
void (*destruct)(void *);
} MemoryIoInfo;
static PHYSFS_sint64 memoryIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
{
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque;
const PHYSFS_uint64 avail = info->len - info->pos;
assert(avail <= info->len);
if (avail == 0)
return 0; /* we're at EOF; nothing to do. */
if (len > avail)
len = avail;
Mar 10, 2012
Mar 10, 2012
265
memcpy(buf, info->buf + info->pos, (size_t) len);
Aug 30, 2010
Aug 30, 2010
266
267
268
269
270
271
272
info->pos += len;
return len;
} /* memoryIo_read */
static PHYSFS_sint64 memoryIo_write(PHYSFS_Io *io, const void *buffer,
PHYSFS_uint64 len)
{
Jul 6, 2017
Jul 6, 2017
273
BAIL(PHYSFS_ERR_OPEN_FOR_READING, -1);
Aug 30, 2010
Aug 30, 2010
274
275
276
277
278
} /* memoryIo_write */
static int memoryIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
{
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque;
Jul 6, 2017
Jul 6, 2017
279
BAIL_IF(offset > info->len, PHYSFS_ERR_PAST_EOF, 0);
Aug 30, 2010
Aug 30, 2010
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
info->pos = offset;
return 1;
} /* memoryIo_seek */
static PHYSFS_sint64 memoryIo_tell(PHYSFS_Io *io)
{
const MemoryIoInfo *info = (MemoryIoInfo *) io->opaque;
return (PHYSFS_sint64) info->pos;
} /* memoryIo_tell */
static PHYSFS_sint64 memoryIo_length(PHYSFS_Io *io)
{
const MemoryIoInfo *info = (MemoryIoInfo *) io->opaque;
return (PHYSFS_sint64) info->len;
} /* memoryIo_length */
static PHYSFS_Io *memoryIo_duplicate(PHYSFS_Io *io)
{
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque;
MemoryIoInfo *newinfo = NULL;
PHYSFS_Io *parent = info->parent;
PHYSFS_Io *retval = NULL;
/* avoid deep copies. */
assert((!parent) || (!((MemoryIoInfo *) parent->opaque)->parent) );
/* share the buffer between duplicates. */
if (parent != NULL) /* dup the parent, increment its refcount. */
return parent->duplicate(parent);
/* we're the parent. */
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Jul 6, 2017
Jul 6, 2017
313
BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
Aug 30, 2010
Aug 30, 2010
314
315
316
317
newinfo = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo));
if (!newinfo)
{
allocator.Free(retval);
Jul 6, 2017
Jul 6, 2017
318
BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
Aug 30, 2010
Aug 30, 2010
319
320
} /* if */
Aug 4, 2023
Aug 4, 2023
321
(void) __PHYSFS_ATOMIC_INCR(&info->refcount);
Aug 30, 2010
Aug 30, 2010
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
memset(newinfo, '\0', sizeof (*info));
newinfo->buf = info->buf;
newinfo->len = info->len;
newinfo->pos = 0;
newinfo->parent = io;
newinfo->refcount = 0;
newinfo->destruct = NULL;
memcpy(retval, io, sizeof (*retval));
retval->opaque = newinfo;
return retval;
} /* memoryIo_duplicate */
static int memoryIo_flush(PHYSFS_Io *io) { return 1; /* it's read-only. */ }
static void memoryIo_destroy(PHYSFS_Io *io)
{
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque;
PHYSFS_Io *parent = info->parent;
if (parent != NULL)
{
assert(info->buf == ((MemoryIoInfo *) info->parent->opaque)->buf);
assert(info->len == ((MemoryIoInfo *) info->parent->opaque)->len);
assert(info->refcount == 0);
assert(info->destruct == NULL);
allocator.Free(info);
allocator.Free(io);
parent->destroy(parent); /* decrements refcount. */
return;
} /* if */
/* we _are_ the parent. */
assert(info->refcount > 0); /* even in a race, we hold a reference. */
Aug 6, 2017
Aug 6, 2017
358
if (__PHYSFS_ATOMIC_DECR(&info->refcount) == 0)
Aug 30, 2010
Aug 30, 2010
359
360
361
362
363
364
365
{
void (*destruct)(void *) = info->destruct;
void *buf = (void *) info->buf;
io->opaque = NULL; /* kill this here in case of race. */
allocator.Free(info);
allocator.Free(io);
if (destruct != NULL)
Oct 18, 2011
Oct 18, 2011
366
destruct(buf);
Aug 30, 2010
Aug 30, 2010
367
368
369
370
371
372
} /* if */
} /* memoryIo_destroy */
static const PHYSFS_Io __PHYSFS_memoryIoInterface =
{
Mar 25, 2012
Mar 25, 2012
373
CURRENT_PHYSFS_IO_API_VERSION, NULL,
Aug 30, 2010
Aug 30, 2010
374
375
376
377
378
379
380
memoryIo_read,
memoryIo_write,
memoryIo_seek,
memoryIo_tell,
memoryIo_length,
memoryIo_duplicate,
memoryIo_flush,
Mar 25, 2012
Mar 25, 2012
381
memoryIo_destroy
Aug 30, 2010
Aug 30, 2010
382
383
384
385
386
387
388
389
390
};
PHYSFS_Io *__PHYSFS_createMemoryIo(const void *buf, PHYSFS_uint64 len,
void (*destruct)(void *))
{
PHYSFS_Io *io = NULL;
MemoryIoInfo *info = NULL;
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Jul 6, 2017
Jul 6, 2017
391
GOTO_IF(!io, PHYSFS_ERR_OUT_OF_MEMORY, createMemoryIo_failed);
Aug 30, 2010
Aug 30, 2010
392
info = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo));
Jul 6, 2017
Jul 6, 2017
393
GOTO_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, createMemoryIo_failed);
Aug 30, 2010
Aug 30, 2010
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
memset(info, '\0', sizeof (*info));
info->buf = (const PHYSFS_uint8 *) buf;
info->len = len;
info->pos = 0;
info->parent = NULL;
info->refcount = 1;
info->destruct = destruct;
memcpy(io, &__PHYSFS_memoryIoInterface, sizeof (*io));
io->opaque = info;
return io;
createMemoryIo_failed:
if (info != NULL) allocator.Free(info);
if (io != NULL) allocator.Free(io);
return NULL;
} /* __PHYSFS_createMemoryIo */
Aug 30, 2010
Aug 30, 2010
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/* PHYSFS_Io implementation for i/o to a PHYSFS_File... */
static PHYSFS_sint64 handleIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
{
return PHYSFS_readBytes((PHYSFS_File *) io->opaque, buf, len);
} /* handleIo_read */
static PHYSFS_sint64 handleIo_write(PHYSFS_Io *io, const void *buffer,
PHYSFS_uint64 len)
{
return PHYSFS_writeBytes((PHYSFS_File *) io->opaque, buffer, len);
} /* handleIo_write */
static int handleIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
{
return PHYSFS_seek((PHYSFS_File *) io->opaque, offset);
} /* handleIo_seek */
static PHYSFS_sint64 handleIo_tell(PHYSFS_Io *io)
{
return PHYSFS_tell((PHYSFS_File *) io->opaque);
} /* handleIo_tell */
static PHYSFS_sint64 handleIo_length(PHYSFS_Io *io)
{
return PHYSFS_fileLength((PHYSFS_File *) io->opaque);
} /* handleIo_length */
static PHYSFS_Io *handleIo_duplicate(PHYSFS_Io *io)
{
/*
* There's no duplicate at the PHYSFS_File level, so we break the
* abstraction. We're allowed to: we're physfs.c!
*/
FileHandle *origfh = (FileHandle *) io->opaque;
FileHandle *newfh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
PHYSFS_Io *retval = NULL;
Jul 6, 2017
Jul 6, 2017
452
GOTO_IF(!newfh, PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed);
Aug 30, 2010
Aug 30, 2010
453
454
455
memset(newfh, '\0', sizeof (*newfh));
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Jul 6, 2017
Jul 6, 2017
456
GOTO_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed);
Aug 30, 2010
Aug 30, 2010
457
458
459
460
461
#if 0 /* we don't buffer the duplicate, at least not at the moment. */
if (origfh->buffer != NULL)
{
newfh->buffer = (PHYSFS_uint8 *) allocator.Malloc(origfh->bufsize);
Mar 20, 2012
Mar 20, 2012
462
if (!newfh->buffer)
Jul 6, 2017
Jul 6, 2017
463
GOTO(PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed);
Aug 30, 2010
Aug 30, 2010
464
465
466
467
468
newfh->bufsize = origfh->bufsize;
} /* if */
#endif
newfh->io = origfh->io->duplicate(origfh->io);
Jul 6, 2017
Jul 6, 2017
469
GOTO_IF_ERRPASS(!newfh->io, handleIo_dupe_failed);
Aug 30, 2010
Aug 30, 2010
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
newfh->forReading = origfh->forReading;
newfh->dirHandle = origfh->dirHandle;
__PHYSFS_platformGrabMutex(stateLock);
if (newfh->forReading)
{
newfh->next = openReadList;
openReadList = newfh;
} /* if */
else
{
newfh->next = openWriteList;
openWriteList = newfh;
} /* else */
__PHYSFS_platformReleaseMutex(stateLock);
memcpy(retval, io, sizeof (PHYSFS_Io));
retval->opaque = newfh;
return retval;
handleIo_dupe_failed:
if (newfh)
{
if (newfh->io != NULL) newfh->io->destroy(newfh->io);
if (newfh->buffer != NULL) allocator.Free(newfh->buffer);
allocator.Free(newfh);
} /* if */
return NULL;
} /* handleIo_duplicate */
static int handleIo_flush(PHYSFS_Io *io)
{
return PHYSFS_flush((PHYSFS_File *) io->opaque);
} /* handleIo_flush */
static void handleIo_destroy(PHYSFS_Io *io)
{
if (io->opaque != NULL)
PHYSFS_close((PHYSFS_File *) io->opaque);
allocator.Free(io);
} /* handleIo_destroy */
static const PHYSFS_Io __PHYSFS_handleIoInterface =
{
Mar 25, 2012
Mar 25, 2012
516
CURRENT_PHYSFS_IO_API_VERSION, NULL,
Aug 30, 2010
Aug 30, 2010
517
518
519
520
521
522
523
handleIo_read,
handleIo_write,
handleIo_seek,
handleIo_tell,
handleIo_length,
handleIo_duplicate,
handleIo_flush,
Mar 25, 2012
Mar 25, 2012
524
handleIo_destroy
Aug 30, 2010
Aug 30, 2010
525
526
527
528
529
};
static PHYSFS_Io *__PHYSFS_createHandleIo(PHYSFS_File *f)
{
PHYSFS_Io *io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
Jul 6, 2017
Jul 6, 2017
530
BAIL_IF(!io, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
Aug 30, 2010
Aug 30, 2010
531
532
533
534
535
memcpy(io, &__PHYSFS_handleIoInterface, sizeof (*io));
io->opaque = f;
return io;
} /* __PHYSFS_createHandleIo */
Aug 30, 2010
Aug 30, 2010
536
Jul 6, 2001
Jul 6, 2001
537
538
/* functions ... */
Sep 29, 2004
Sep 29, 2004
539
540
541
542
typedef struct
{
char **list;
PHYSFS_uint32 size;
Mar 20, 2012
Mar 20, 2012
543
PHYSFS_ErrorCode errcode;
Sep 29, 2004
Sep 29, 2004
544
545
546
547
548
549
550
551
} EnumStringListCallbackData;
static void enumStringListCallback(void *data, const char *str)
{
void *ptr;
char *newstr;
EnumStringListCallbackData *pecd = (EnumStringListCallbackData *) data;
Mar 20, 2012
Mar 20, 2012
552
if (pecd->errcode)
Sep 29, 2004
Sep 29, 2004
553
554
return;
Mar 14, 2005
Mar 14, 2005
555
556
ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
newstr = (char *) allocator.Malloc(strlen(str) + 1);
Sep 29, 2004
Sep 29, 2004
557
558
559
560
561
if (ptr != NULL)
pecd->list = (char **) ptr;
if ((ptr == NULL) || (newstr == NULL))
{
Mar 20, 2012
Mar 20, 2012
562
pecd->errcode = PHYSFS_ERR_OUT_OF_MEMORY;
Sep 29, 2004
Sep 29, 2004
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
pecd->list[pecd->size] = NULL;
PHYSFS_freeList(pecd->list);
return;
} /* if */
strcpy(newstr, str);
pecd->list[pecd->size] = newstr;
pecd->size++;
} /* enumStringListCallback */
static char **doEnumStringList(void (*func)(PHYSFS_StringCallback, void *))
{
EnumStringListCallbackData ecd;
memset(&ecd, '\0', sizeof (ecd));
Mar 14, 2005
Mar 14, 2005
578
ecd.list = (char **) allocator.Malloc(sizeof (char *));
Jul 6, 2017
Jul 6, 2017
579
BAIL_IF(!ecd.list, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
Sep 29, 2004
Sep 29, 2004
580
func(enumStringListCallback, &ecd);
Mar 20, 2012
Mar 20, 2012
581
582
583
if (ecd.errcode)
{
Nov 30, 2012
Nov 30, 2012
584
PHYSFS_setErrorCode(ecd.errcode);
Mar 20, 2012
Mar 20, 2012
585
586
587
return NULL;
} /* if */
Sep 29, 2004
Sep 29, 2004
588
ecd.list[ecd.size] = NULL;
Jan 28, 2010
Jan 28, 2010
589
return ecd.list;
Sep 29, 2004
Sep 29, 2004
590
591
592
} /* doEnumStringList */
Jun 1, 2012
Jun 1, 2012
593
594
595
static void __PHYSFS_bubble_sort(void *a, size_t lo, size_t hi,
int (*cmpfn)(void *, size_t, size_t),
void (*swapfn)(void *, size_t, size_t))
Aug 20, 2002
Aug 20, 2002
596
{
Jun 1, 2012
Jun 1, 2012
597
size_t i;
Aug 20, 2002
Aug 20, 2002
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
int sorted;
do
{
sorted = 1;
for (i = lo; i < hi; i++)
{
if (cmpfn(a, i, i + 1) > 0)
{
swapfn(a, i, i + 1);
sorted = 0;
} /* if */
} /* for */
} while (!sorted);
} /* __PHYSFS_bubble_sort */
Jun 1, 2012
Jun 1, 2012
615
616
617
static void __PHYSFS_quick_sort(void *a, size_t lo, size_t hi,
int (*cmpfn)(void *, size_t, size_t),
void (*swapfn)(void *, size_t, size_t))
Aug 20, 2002
Aug 20, 2002
618
{
Jun 1, 2012
Jun 1, 2012
619
620
621
size_t i;
size_t j;
size_t v;
Aug 20, 2002
Aug 20, 2002
622
Jul 20, 2003
Jul 20, 2003
623
if ((hi - lo) <= PHYSFS_QUICKSORT_THRESHOLD)
Aug 20, 2002
Aug 20, 2002
624
625
__PHYSFS_bubble_sort(a, lo, hi, cmpfn, swapfn);
else
Jul 20, 2003
Jul 20, 2003
626
627
{
i = (hi + lo) / 2;
Aug 20, 2002
Aug 20, 2002
628
629
if (cmpfn(a, lo, i) > 0) swapfn(a, lo, i);
Jul 20, 2003
Jul 20, 2003
630
631
632
633
634
635
636
637
638
639
640
641
if (cmpfn(a, lo, hi) > 0) swapfn(a, lo, hi);
if (cmpfn(a, i, hi) > 0) swapfn(a, i, hi);
j = hi - 1;
swapfn(a, i, j);
i = lo;
v = j;
while (1)
{
while(cmpfn(a, ++i, v) < 0) { /* do nothing */ }
while(cmpfn(a, --j, v) > 0) { /* do nothing */ }
if (j < i)
Aug 20, 2002
Aug 20, 2002
642
break;
Jul 20, 2003
Jul 20, 2003
643
644
swapfn(a, i, j);
} /* while */
Feb 28, 2009
Feb 28, 2009
645
646
if (i != (hi-1))
swapfn(a, i, hi-1);
Jul 20, 2003
Jul 20, 2003
647
648
649
__PHYSFS_quick_sort(a, lo, j, cmpfn, swapfn);
__PHYSFS_quick_sort(a, i+1, hi, cmpfn, swapfn);
} /* else */
Aug 20, 2002
Aug 20, 2002
650
651
652
} /* __PHYSFS_quick_sort */
Jun 1, 2012
Jun 1, 2012
653
654
655
void __PHYSFS_sort(void *entries, size_t max,
int (*cmpfn)(void *, size_t, size_t),
void (*swapfn)(void *, size_t, size_t))
Aug 20, 2002
Aug 20, 2002
656
657
658
{
/*
* Quicksort w/ Bubblesort fallback algorithm inspired by code from here:
Feb 25, 2016
Feb 25, 2016
659
* https://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html
Aug 20, 2002
Aug 20, 2002
660
*/
Jun 7, 2012
Jun 7, 2012
661
662
if (max > 0)
__PHYSFS_quick_sort(entries, 0, max - 1, cmpfn, swapfn);
Aug 20, 2002
Aug 20, 2002
663
664
665
} /* __PHYSFS_sort */
Mar 20, 2012
Mar 20, 2012
666
static ErrState *findErrorForCurrentThread(void)
Mar 20, 2012
Mar 20, 2012
668
ErrState *i;
Sep 6, 2009
Sep 6, 2009
669
void *tid;
Jun 8, 2002
Jun 8, 2002
671
if (errorLock != NULL)
Apr 8, 2002
Apr 8, 2002
672
673
__PHYSFS_platformGrabMutex(errorLock);
Mar 20, 2012
Mar 20, 2012
674
if (errorStates != NULL)
Apr 3, 2002
Apr 3, 2002
676
tid = __PHYSFS_platformGetThreadID();
Mar 20, 2012
Mar 20, 2012
678
for (i = errorStates; i != NULL; i = i->next)
679
680
{
if (i->tid == tid)
Mar 30, 2002
Mar 30, 2002
681
{
Jun 8, 2002
Jun 8, 2002
682
683
if (errorLock != NULL)
__PHYSFS_platformReleaseMutex(errorLock);
Jan 28, 2010
Jan 28, 2010
684
return i;
Mar 30, 2002
Mar 30, 2002
685
} /* if */
686
687
} /* for */
} /* if */
Apr 8, 2002
Apr 8, 2002
688
Jun 8, 2002
Jun 8, 2002
689
if (errorLock != NULL)
Apr 8, 2002
Apr 8, 2002
690
__PHYSFS_platformReleaseMutex(errorLock);
Jan 28, 2010
Jan 28, 2010
692
return NULL; /* no error available. */
693
694
695
} /* findErrorForCurrentThread */
Nov 30, 2012
Nov 30, 2012
696
697
698
699
700
701
702
703
/* this doesn't reset the error state. */
static inline PHYSFS_ErrorCode currentErrorCode(void)
{
const ErrState *err = findErrorForCurrentThread();
return err ? err->code : PHYSFS_ERR_OK;
} /* currentErrorCode */
Mar 20, 2012
Mar 20, 2012
704
PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
Mar 30, 2002
Mar 30, 2002
705
{
Mar 20, 2012
Mar 20, 2012
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
ErrState *err = findErrorForCurrentThread();
const PHYSFS_ErrorCode retval = (err) ? err->code : PHYSFS_ERR_OK;
if (err)
err->code = PHYSFS_ERR_OK;
return retval;
} /* PHYSFS_getLastErrorCode */
PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code)
{
switch (code)
{
case PHYSFS_ERR_OK: return "no error";
case PHYSFS_ERR_OTHER_ERROR: return "unknown error";
case PHYSFS_ERR_OUT_OF_MEMORY: return "out of memory";
case PHYSFS_ERR_NOT_INITIALIZED: return "not initialized";
case PHYSFS_ERR_IS_INITIALIZED: return "already initialized";
case PHYSFS_ERR_ARGV0_IS_NULL: return "argv[0] is NULL";
case PHYSFS_ERR_UNSUPPORTED: return "unsupported";
case PHYSFS_ERR_PAST_EOF: return "past end of file";
case PHYSFS_ERR_FILES_STILL_OPEN: return "files still open";
case PHYSFS_ERR_INVALID_ARGUMENT: return "invalid argument";
case PHYSFS_ERR_NOT_MOUNTED: return "not mounted";
Nov 28, 2012
Nov 28, 2012
729
case PHYSFS_ERR_NOT_FOUND: return "not found";
Mar 20, 2012
Mar 20, 2012
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
case PHYSFS_ERR_SYMLINK_FORBIDDEN: return "symlinks are forbidden";
case PHYSFS_ERR_NO_WRITE_DIR: return "write directory is not set";
case PHYSFS_ERR_OPEN_FOR_READING: return "file open for reading";
case PHYSFS_ERR_OPEN_FOR_WRITING: return "file open for writing";
case PHYSFS_ERR_NOT_A_FILE: return "not a file";
case PHYSFS_ERR_READ_ONLY: return "read-only filesystem";
case PHYSFS_ERR_CORRUPT: return "corrupted";
case PHYSFS_ERR_SYMLINK_LOOP: return "infinite symbolic link loop";
case PHYSFS_ERR_IO: return "i/o error";
case PHYSFS_ERR_PERMISSION: return "permission denied";
case PHYSFS_ERR_NO_SPACE: return "no space available for writing";
case PHYSFS_ERR_BAD_FILENAME: return "filename is illegal or insecure";
case PHYSFS_ERR_BUSY: return "tried to modify a file the OS needs";
case PHYSFS_ERR_DIR_NOT_EMPTY: return "directory isn't empty";
case PHYSFS_ERR_OS_ERROR: return "OS reported an error";
Nov 28, 2012
Nov 28, 2012
745
case PHYSFS_ERR_DUPLICATE: return "duplicate resource";
Sep 12, 2016
Sep 12, 2016
746
case PHYSFS_ERR_BAD_PASSWORD: return "bad password";
Aug 12, 2017
Aug 12, 2017
747
case PHYSFS_ERR_APP_CALLBACK: return "app callback reported error";
Mar 20, 2012
Mar 20, 2012
748
749
750
751
752
753
} /* switch */
return NULL; /* don't know this error code. */
} /* PHYSFS_getErrorByCode */
Nov 30, 2012
Nov 30, 2012
754
void PHYSFS_setErrorCode(PHYSFS_ErrorCode errcode)
Mar 20, 2012
Mar 20, 2012
755
{
Nov 30, 2012
Nov 30, 2012
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
ErrState *err;
if (!errcode)
return;
err = findErrorForCurrentThread();
if (err == NULL)
{
err = (ErrState *) allocator.Malloc(sizeof (ErrState));
if (err == NULL)
return; /* uhh...? */
memset(err, '\0', sizeof (ErrState));
err->tid = __PHYSFS_platformGetThreadID();
if (errorLock != NULL)
__PHYSFS_platformGrabMutex(errorLock);
err->next = errorStates;
errorStates = err;
if (errorLock != NULL)
__PHYSFS_platformReleaseMutex(errorLock);
} /* if */
err->code = errcode;
Mar 20, 2012
Mar 20, 2012
782
} /* PHYSFS_setErrorCode */
Mar 30, 2002
Mar 30, 2002
783
784
Mar 20, 2012
Mar 20, 2012
785
786
787
788
const char *PHYSFS_getLastError(void)
{
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
return (err) ? PHYSFS_getErrorByCode(err) : NULL;
Mar 30, 2002
Mar 30, 2002
789
790
791
792
} /* PHYSFS_getLastError */
/* MAKE SURE that errorLock is held before calling this! */
Mar 20, 2012
Mar 20, 2012
793
static void freeErrorStates(void)
Jul 7, 2001
Jul 7, 2001
794
{
Mar 20, 2012
Mar 20, 2012
795
796
ErrState *i;
ErrState *next;
Jul 7, 2001
Jul 7, 2001
797
Mar 20, 2012
Mar 20, 2012
798
for (i = errorStates; i != NULL; i = next)
Jul 7, 2001
Jul 7, 2001
799
{
Jul 9, 2001
Jul 9, 2001
800
next = i->next;
Mar 14, 2005
Mar 14, 2005
801
allocator.Free(i);
Jul 7, 2001
Jul 7, 2001
802
} /* for */
Jun 8, 2002
Jun 8, 2002
803
Mar 20, 2012
Mar 20, 2012
804
805
errorStates = NULL;
} /* freeErrorStates */
Jul 7, 2001
Jul 7, 2001
806
807
808
809
810
811
812
813
814
815
816
817
818
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
{
if (ver != NULL)
{
ver->major = PHYSFS_VER_MAJOR;
ver->minor = PHYSFS_VER_MINOR;
ver->patch = PHYSFS_VER_PATCH;
} /* if */
} /* PHYSFS_getLinkedVersion */
Jul 26, 2002
Jul 26, 2002
819
820
static const char *find_filename_extension(const char *fname)
{
Aug 30, 2010
Aug 30, 2010
821
822
const char *retval = NULL;
if (fname != NULL)
Jul 26, 2002
Jul 26, 2002
823
{
Jan 21, 2011
Jan 21, 2011
824
825
const char *p = strchr(fname, '.');
retval = p;
Jul 26, 2002
Jul 26, 2002
826
Aug 30, 2010
Aug 30, 2010
827
828
829
830
831
832
833
834
835
836
while (p != NULL)
{
p = strchr(p + 1, '.');
if (p != NULL)
retval = p;
} /* while */
if (retval != NULL)
retval++; /* skip '.' */
} /* if */
Jul 26, 2002
Jul 26, 2002
837
Jan 28, 2010
Jan 28, 2010
838
return retval;
Jul 26, 2002
Jul 26, 2002
839
840
841
} /* find_filename_extension */
Aug 30, 2010
Aug 30, 2010
842
static DirHandle *tryOpenDir(PHYSFS_Io *io, const PHYSFS_Archiver *funcs,
Aug 14, 2017
Aug 14, 2017
843
const char *d, int forWriting, int *_claimed)
Sep 26, 2004
Sep 26, 2004
844
845
{
DirHandle *retval = NULL;
Aug 30, 2010
Aug 30, 2010
846
847
848
void *opaque = NULL;
if (io != NULL)
Jul 6, 2017
Jul 6, 2017
849
BAIL_IF_ERRPASS(!io->seek(io, 0), NULL);
Aug 30, 2010
Aug 30, 2010
850
Aug 14, 2017
Aug 14, 2017
851
opaque = funcs->openArchive(io, d, forWriting, _claimed);
Aug 24, 2010
Aug 24, 2010
852
if (opaque != NULL)
Sep 26, 2004
Sep 26, 2004
853
{
Aug 24, 2010
Aug 24, 2010
854
855
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
if (retval == NULL)
Mar 24, 2012
Mar 24, 2012
856
funcs->closeArchive(opaque);
Aug 24, 2010
Aug 24, 2010
857
else
Sep 26, 2004
Sep 26, 2004
858
{
Aug 24, 2010
Aug 24, 2010
859
860
861
862
863
memset(retval, '\0', sizeof (DirHandle));
retval->mountPoint = NULL;
retval->funcs = funcs;
retval->opaque = opaque;
} /* else */
Sep 26, 2004
Sep 26, 2004
864
865
} /* if */
Jan 28, 2010
Jan 28, 2010
866
return retval;
Sep 26, 2004
Sep 26, 2004
867
868
869
} /* tryOpenDir */
Aug 30, 2010
Aug 30, 2010
870
static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting)
Jul 7, 2001
Jul 7, 2001
871
{
Sep 26, 2004
Sep 26, 2004
872
DirHandle *retval = NULL;
Jul 13, 2017
Jul 13, 2017
873
PHYSFS_Archiver **i;
Jul 26, 2002
Jul 26, 2002
874
const char *ext;
Aug 19, 2014
Aug 19, 2014
875
int created_io = 0;
Aug 14, 2017
Aug 14, 2017
876
877
int claimed = 0;
PHYSFS_ErrorCode errcode;
Jul 7, 2001
Jul 7, 2001
878
Aug 30, 2010
Aug 30, 2010
879
assert((io != NULL) || (d != NULL));
Jul 23, 2001
Jul 23, 2001
880
Aug 30, 2010
Aug 30, 2010
881
882
if (io == NULL)
{
May 16, 2018
May 16, 2018
883
884
885
886
/* file doesn't exist, etc? Just fail out. */
PHYSFS_Stat statbuf;
BAIL_IF_ERRPASS(!__PHYSFS_platformStat(d, &statbuf, 1), NULL);
Aug 30, 2010
Aug 30, 2010
887
/* DIR gets first shot (unlike the rest, it doesn't deal with files). */
May 16, 2018
May 16, 2018
888
889
890
891
892
893
if (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY)
{
retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting, &claimed);
if (retval || claimed)
return retval;
} /* if */
Aug 30, 2010
Aug 30, 2010
894
895
io = __PHYSFS_createNativeIo(d, forWriting ? 'w' : 'r');
May 16, 2018
May 16, 2018
896
BAIL_IF_ERRPASS(!io, NULL);
Aug 19, 2014
Aug 19, 2014
897
created_io = 1;
Aug 30, 2010
Aug 30, 2010
898
} /* if */
Aug 24, 2010
Aug 24, 2010
899
Jul 26, 2002
Jul 26, 2002
900
901
ext = find_filename_extension(d);
if (ext != NULL)
Jul 7, 2001
Jul 7, 2001
902
{
Jul 26, 2002
Jul 26, 2002
903
/* Look for archivers with matching file extensions first... */
Aug 14, 2017
Aug 14, 2017
904
for (i = archivers; (*i != NULL) && (retval == NULL) && !claimed; i++)
Jul 26, 2002
Jul 26, 2002
905
{
Aug 11, 2017
Aug 11, 2017
906
if (PHYSFS_utf8stricmp(ext, (*i)->info.extension) == 0)
Aug 14, 2017
Aug 14, 2017
907
retval = tryOpenDir(io, *i, d, forWriting, &claimed);
Jul 26, 2002
Jul 26, 2002
908
909
910
} /* for */
/* failing an exact file extension match, try all the others... */
Aug 14, 2017
Aug 14, 2017
911
for (i = archivers; (*i != NULL) && (retval == NULL) && !claimed; i++)
Jul 26, 2002
Jul 26, 2002
912
{
Aug 11, 2017
Aug 11, 2017
913
if (PHYSFS_utf8stricmp(ext, (*i)->info.extension) != 0)
Aug 14, 2017
Aug 14, 2017
914
retval = tryOpenDir(io, *i, d, forWriting, &claimed);
Jul 26, 2002
Jul 26, 2002
915
916
917
918
919
} /* for */
} /* if */
else /* no extension? Try them all. */
{
Aug 14, 2017
Aug 14, 2017
920
921
for (i = archivers; (*i != NULL) && (retval == NULL) && !claimed; i++)
retval = tryOpenDir(io, *i, d, forWriting, &claimed);
Jul 26, 2002
Jul 26, 2002
922
} /* else */
Jul 7, 2001
Jul 7, 2001
923
Jun 15, 2022
Jun 15, 2022
924
errcode = claimed ? currentErrorCode() : PHYSFS_ERR_UNSUPPORTED;
Aug 14, 2017
Aug 14, 2017
925
Aug 19, 2014
Aug 19, 2014
926
927
928
if ((!retval) && (created_io))
io->destroy(io);
Jun 15, 2022
Jun 15, 2022
929
BAIL_IF(!retval, errcode, NULL);
Jan 28, 2010
Jan 28, 2010
930
return retval;
Jul 7, 2001
Jul 7, 2001
931
932
933
} /* openDirectory */
Mar 13, 2005
Mar 13, 2005
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
/*
* Make a platform-independent path string sane. Doesn't actually check the
* file hierarchy, it just cleans up the string.
* (dst) must be a buffer at least as big as (src), as this is where the
* cleaned up string is deposited.
* If there are illegal bits in the path (".." entries, etc) then we
* return zero and (dst) is undefined. Non-zero if the path was sanitized.
*/
static int sanitizePlatformIndependentPath(const char *src, char *dst)
{
char *prev;
char ch;
while (*src == '/') /* skip initial '/' chars... */
src++;
Oct 26, 2017
Oct 26, 2017
950
951
952
953
/* Make sure the entire string isn't "." or ".." */
if ((strcmp(src, ".") == 0) || (strcmp(src, "..") == 0))
BAIL(PHYSFS_ERR_BAD_FILENAME, 0);
Mar 13, 2005
Mar 13, 2005
954
955
956
957
958
959
prev = dst;
do
{
ch = *(src++);
if ((ch == ':') || (ch == '\\')) /* illegal chars in a physfs path. */
Jul 6, 2017
Jul 6, 2017
960
BAIL(PHYSFS_ERR_BAD_FILENAME, 0);
Mar 13, 2005
Mar 13, 2005
961
962
963
964
965
if (ch == '/') /* path separator. */
{
*dst = '\0'; /* "." and ".." are illegal pathnames. */
if ((strcmp(prev, ".") == 0) || (strcmp(prev, "..") == 0))
Jul 6, 2017
Jul 6, 2017
966
BAIL(PHYSFS_ERR_BAD_FILENAME, 0);
Mar 13, 2005
Mar 13, 2005
967
968
969
970
971
972
973
974
975
976
977
978
979
while (*src == '/') /* chop out doubles... */
src++;
if (*src == '\0') /* ends with a pathsep? */
break; /* we're done, don't add final pathsep to dst. */
prev = dst + 1;
} /* if */
*(dst++) = ch;
} while (ch != '\0');
Jan 28, 2010
Jan 28, 2010
980
return 1;
Mar 13, 2005
Mar 13, 2005
981
982
983
} /* sanitizePlatformIndependentPath */
Oct 18, 2018
Oct 18, 2018
984
985
986
987
988
989
990
991
992
993
994
995
static inline size_t dirHandleRootLen(const DirHandle *h)
{
return h ? h->rootlen : 0;
} /* dirHandleRootLen */
static inline int sanitizePlatformIndependentPathWithRoot(const DirHandle *h, const char *src, char *dst)
{
return sanitizePlatformIndependentPath(src, dst + dirHandleRootLen(h));
} /* sanitizePlatformIndependentPathWithRoot */
Mar 14, 2005
Mar 14, 2005
996
997
998
999
1000
/*
* Figure out if (fname) is part of (h)'s mountpoint. (fname) must be an
* output from sanitizePlatformIndependentPath(), so that it is in a known
* state.
*