Skip to content

Latest commit

 

History

History
2222 lines (1770 loc) · 60.1 KB

physfs.c

File metadata and controls

2222 lines (1770 loc) · 60.1 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
11
12
13
14
15
*
* This file written by Ryan C. Gordon.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "physfs.h"
Jul 6, 2001
Jul 6, 2001
16
17
18
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
Sep 26, 2004
Sep 26, 2004
19
20
21
typedef struct __PHYSFS_DIRHANDLE__
{
Sep 26, 2004
Sep 26, 2004
22
23
void *opaque; /* Instance data unique to the archiver. */
char *dirName; /* Path to archive in platform-dependent notation. */
Mar 13, 2005
Mar 13, 2005
24
char *mountPoint; /* Mountpoint in virtual file tree. */
Sep 26, 2004
Sep 26, 2004
25
26
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */
Sep 26, 2004
Sep 26, 2004
27
28
29
} DirHandle;
Sep 26, 2004
Sep 26, 2004
30
31
32
33
34
35
36
37
38
39
40
41
42
43
typedef struct __PHYSFS_FILEHANDLE__
{
void *opaque; /* Instance data unique to the archiver for this file. */
PHYSFS_uint8 forReading; /* Non-zero if reading, zero if write/append */
const DirHandle *dirHandle; /* Archiver instance that created this */
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */
PHYSFS_uint8 *buffer; /* Buffer, if set (NULL otherwise). Don't touch! */
PHYSFS_uint32 bufsize; /* Bufsize, if set (0 otherwise). Don't touch! */
PHYSFS_uint32 buffill; /* Buffer fill size. Don't touch! */
PHYSFS_uint32 bufpos; /* Buffer position. Don't touch! */
struct __PHYSFS_FILEHANDLE__ *next; /* linked list stuff. */
} FileHandle;
44
45
typedef struct __PHYSFS_ERRMSGTYPE__
{
Aug 2, 2012
Aug 2, 2012
46
void *tid;
47
48
49
50
51
int errorAvailable;
char errorString[80];
struct __PHYSFS_ERRMSGTYPE__ *next;
} ErrMsg;
Jul 6, 2001
Jul 6, 2001
52
Mar 10, 2007
Mar 10, 2007
53
/* The various i/o drivers...some of these may not be compiled in. */
Sep 26, 2004
Sep 26, 2004
54
55
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP;
extern const PHYSFS_Archiver __PHYSFS_Archiver_ZIP;
Apr 11, 2006
Apr 11, 2006
56
57
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA;
extern const PHYSFS_Archiver __PHYSFS_Archiver_LZMA;
Sep 26, 2004
Sep 26, 2004
58
59
60
61
62
63
64
65
66
67
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP;
extern const PHYSFS_Archiver __PHYSFS_Archiver_GRP;
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK;
extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK;
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG;
extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG;
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL;
extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL;
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD;
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD;
Mar 10, 2007
Mar 10, 2007
68
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR;
Jul 6, 2001
Jul 6, 2001
69
Aug 9, 2002
Aug 9, 2002
70
Jul 6, 2001
Jul 6, 2001
71
static const PHYSFS_ArchiveInfo *supported_types[] =
72
73
{
#if (defined PHYSFS_SUPPORTS_ZIP)
Jul 6, 2001
Jul 6, 2001
74
&__PHYSFS_ArchiveInfo_ZIP,
75
#endif
Mar 9, 2007
Mar 9, 2007
76
#if (defined PHYSFS_SUPPORTS_7Z)
Apr 11, 2006
Apr 11, 2006
77
78
&__PHYSFS_ArchiveInfo_LZMA,
#endif
Jul 8, 2001
Jul 8, 2001
79
80
81
#if (defined PHYSFS_SUPPORTS_GRP)
&__PHYSFS_ArchiveInfo_GRP,
#endif
Jul 21, 2003
Jul 21, 2003
82
83
84
#if (defined PHYSFS_SUPPORTS_QPAK)
&__PHYSFS_ArchiveInfo_QPAK,
#endif
Mar 30, 2003
Mar 30, 2003
85
86
87
88
89
90
#if (defined PHYSFS_SUPPORTS_HOG)
&__PHYSFS_ArchiveInfo_HOG,
#endif
#if (defined PHYSFS_SUPPORTS_MVL)
&__PHYSFS_ArchiveInfo_MVL,
#endif
Dec 15, 2003
Dec 15, 2003
91
92
#if (defined PHYSFS_SUPPORTS_WAD)
&__PHYSFS_ArchiveInfo_WAD,
Apr 9, 2004
Apr 9, 2004
93
#endif
94
95
96
NULL
};
Sep 26, 2004
Sep 26, 2004
97
static const PHYSFS_Archiver *archivers[] =
Jul 6, 2001
Jul 6, 2001
98
{
Mar 31, 2007
Mar 31, 2007
99
&__PHYSFS_Archiver_DIR,
Jul 6, 2001
Jul 6, 2001
100
#if (defined PHYSFS_SUPPORTS_ZIP)
Sep 26, 2004
Sep 26, 2004
101
&__PHYSFS_Archiver_ZIP,
Jul 6, 2001
Jul 6, 2001
102
#endif
Mar 9, 2007
Mar 9, 2007
103
#if (defined PHYSFS_SUPPORTS_7Z)
Apr 11, 2006
Apr 11, 2006
104
105
&__PHYSFS_Archiver_LZMA,
#endif
Jul 8, 2001
Jul 8, 2001
106
#if (defined PHYSFS_SUPPORTS_GRP)
Sep 26, 2004
Sep 26, 2004
107
&__PHYSFS_Archiver_GRP,
Jul 8, 2001
Jul 8, 2001
108
#endif
Jul 21, 2003
Jul 21, 2003
109
#if (defined PHYSFS_SUPPORTS_QPAK)
Sep 26, 2004
Sep 26, 2004
110
&__PHYSFS_Archiver_QPAK,
Jul 21, 2003
Jul 21, 2003
111
#endif
Mar 30, 2003
Mar 30, 2003
112
#if (defined PHYSFS_SUPPORTS_HOG)
Sep 26, 2004
Sep 26, 2004
113
&__PHYSFS_Archiver_HOG,
Mar 30, 2003
Mar 30, 2003
114
115
#endif
#if (defined PHYSFS_SUPPORTS_MVL)
Sep 26, 2004
Sep 26, 2004
116
&__PHYSFS_Archiver_MVL,
Mar 30, 2003
Mar 30, 2003
117
#endif
Dec 15, 2003
Dec 15, 2003
118
#if (defined PHYSFS_SUPPORTS_WAD)
Sep 26, 2004
Sep 26, 2004
119
&__PHYSFS_Archiver_WAD,
Apr 9, 2004
Apr 9, 2004
120
#endif
Jul 6, 2001
Jul 6, 2001
121
122
NULL
};
123
124
125
Jul 6, 2001
Jul 6, 2001
126
127
128
/* General PhysicsFS state ... */
static int initialized = 0;
static ErrMsg *errorMessages = NULL;
Sep 26, 2004
Sep 26, 2004
129
130
131
132
static DirHandle *searchPath = NULL;
static DirHandle *writeDir = NULL;
static FileHandle *openWriteList = NULL;
static FileHandle *openReadList = NULL;
Jul 6, 2001
Jul 6, 2001
133
134
135
136
static char *baseDir = NULL;
static char *userDir = NULL;
static int allowSymLinks = 0;
Mar 30, 2002
Mar 30, 2002
137
138
139
/* mutexes ... */
static void *errorLock = NULL; /* protects error message list. */
static void *stateLock = NULL; /* protects other PhysFS static state. */
Jul 6, 2001
Jul 6, 2001
140
Sep 23, 2004
Sep 23, 2004
141
142
/* allocator ... */
static int externalAllocator = 0;
Mar 14, 2005
Mar 14, 2005
143
PHYSFS_Allocator allocator;
Sep 23, 2004
Sep 23, 2004
144
Jul 6, 2001
Jul 6, 2001
145
146
147
/* functions ... */
Sep 29, 2004
Sep 29, 2004
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
typedef struct
{
char **list;
PHYSFS_uint32 size;
const char *errorstr;
} EnumStringListCallbackData;
static void enumStringListCallback(void *data, const char *str)
{
void *ptr;
char *newstr;
EnumStringListCallbackData *pecd = (EnumStringListCallbackData *) data;
if (pecd->errorstr)
return;
Mar 14, 2005
Mar 14, 2005
164
165
ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
newstr = (char *) allocator.Malloc(strlen(str) + 1);
Sep 29, 2004
Sep 29, 2004
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
if (ptr != NULL)
pecd->list = (char **) ptr;
if ((ptr == NULL) || (newstr == NULL))
{
pecd->errorstr = ERR_OUT_OF_MEMORY;
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
187
ecd.list = (char **) allocator.Malloc(sizeof (char *));
Sep 29, 2004
Sep 29, 2004
188
189
190
191
192
193
194
195
BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
func(enumStringListCallback, &ecd);
BAIL_IF_MACRO(ecd.errorstr != NULL, ecd.errorstr, NULL);
ecd.list[ecd.size] = NULL;
return(ecd.list);
} /* doEnumStringList */
Jan 31, 2003
Jan 31, 2003
196
static void __PHYSFS_bubble_sort(void *a, PHYSFS_uint32 lo, PHYSFS_uint32 hi,
Aug 20, 2002
Aug 20, 2002
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32),
void (*swapfn)(void *, PHYSFS_uint32, PHYSFS_uint32))
{
PHYSFS_uint32 i;
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 */
Jan 31, 2003
Jan 31, 2003
218
static void __PHYSFS_quick_sort(void *a, PHYSFS_uint32 lo, PHYSFS_uint32 hi,
Aug 20, 2002
Aug 20, 2002
219
220
221
222
223
224
225
int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32),
void (*swapfn)(void *, PHYSFS_uint32, PHYSFS_uint32))
{
PHYSFS_uint32 i;
PHYSFS_uint32 j;
PHYSFS_uint32 v;
Jul 20, 2003
Jul 20, 2003
226
if ((hi - lo) <= PHYSFS_QUICKSORT_THRESHOLD)
Aug 20, 2002
Aug 20, 2002
227
228
__PHYSFS_bubble_sort(a, lo, hi, cmpfn, swapfn);
else
Jul 20, 2003
Jul 20, 2003
229
230
{
i = (hi + lo) / 2;
Aug 20, 2002
Aug 20, 2002
231
232
if (cmpfn(a, lo, i) > 0) swapfn(a, lo, i);
Jul 20, 2003
Jul 20, 2003
233
234
235
236
237
238
239
240
241
242
243
244
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
245
break;
Jul 20, 2003
Jul 20, 2003
246
247
swapfn(a, i, j);
} /* while */
Feb 28, 2009
Feb 28, 2009
248
249
if (i != (hi-1))
swapfn(a, i, hi-1);
Jul 20, 2003
Jul 20, 2003
250
251
252
__PHYSFS_quick_sort(a, lo, j, cmpfn, swapfn);
__PHYSFS_quick_sort(a, i+1, hi, cmpfn, swapfn);
} /* else */
Aug 20, 2002
Aug 20, 2002
253
254
255
256
257
258
259
260
261
262
263
} /* __PHYSFS_quick_sort */
void __PHYSFS_sort(void *entries, PHYSFS_uint32 max,
int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32),
void (*swapfn)(void *, PHYSFS_uint32, PHYSFS_uint32))
{
/*
* Quicksort w/ Bubblesort fallback algorithm inspired by code from here:
* http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html
*/
Jun 7, 2012
Jun 7, 2012
264
265
if (max > 0)
__PHYSFS_quick_sort(entries, 0, max - 1, cmpfn, swapfn);
Aug 20, 2002
Aug 20, 2002
266
267
268
} /* __PHYSFS_sort */
269
270
271
static ErrMsg *findErrorForCurrentThread(void)
{
ErrMsg *i;
Aug 2, 2012
Aug 2, 2012
272
void *tid;
Jun 8, 2002
Jun 8, 2002
274
if (errorLock != NULL)
Apr 8, 2002
Apr 8, 2002
275
276
__PHYSFS_platformGrabMutex(errorLock);
277
278
if (errorMessages != NULL)
{
Apr 3, 2002
Apr 3, 2002
279
tid = __PHYSFS_platformGetThreadID();
280
281
282
283
for (i = errorMessages; i != NULL; i = i->next)
{
if (i->tid == tid)
Mar 30, 2002
Mar 30, 2002
284
{
Jun 8, 2002
Jun 8, 2002
285
286
if (errorLock != NULL)
__PHYSFS_platformReleaseMutex(errorLock);
287
return(i);
Mar 30, 2002
Mar 30, 2002
288
} /* if */
289
290
} /* for */
} /* if */
Apr 8, 2002
Apr 8, 2002
291
Jun 8, 2002
Jun 8, 2002
292
if (errorLock != NULL)
Apr 8, 2002
Apr 8, 2002
293
__PHYSFS_platformReleaseMutex(errorLock);
294
295
296
297
298
return(NULL); /* no error available. */
} /* findErrorForCurrentThread */
Jul 6, 2001
Jul 6, 2001
299
void __PHYSFS_setError(const char *str)
Jul 7, 2001
Jul 7, 2001
301
302
303
304
305
306
ErrMsg *err;
if (str == NULL)
return;
err = findErrorForCurrentThread();
307
308
309
if (err == NULL)
{
Mar 14, 2005
Mar 14, 2005
310
err = (ErrMsg *) allocator.Malloc(sizeof (ErrMsg));
311
312
313
if (err == NULL)
return; /* uhh...? */
Aug 1, 2001
Aug 1, 2001
314
memset((void *) err, '\0', sizeof (ErrMsg));
Apr 3, 2002
Apr 3, 2002
315
err->tid = __PHYSFS_platformGetThreadID();
Mar 30, 2002
Mar 30, 2002
316
Jun 8, 2002
Jun 8, 2002
317
318
319
if (errorLock != NULL)
__PHYSFS_platformGrabMutex(errorLock);
Jul 6, 2001
Jul 6, 2001
320
321
err->next = errorMessages;
errorMessages = err;
Jun 8, 2002
Jun 8, 2002
322
323
324
if (errorLock != NULL)
__PHYSFS_platformReleaseMutex(errorLock);
325
326
327
328
329
} /* if */
err->errorAvailable = 1;
strncpy(err->errorString, str, sizeof (err->errorString));
err->errorString[sizeof (err->errorString) - 1] = '\0';
Jul 6, 2001
Jul 6, 2001
330
} /* __PHYSFS_setError */
Mar 30, 2002
Mar 30, 2002
333
334
335
336
337
338
339
340
341
342
343
344
345
const char *PHYSFS_getLastError(void)
{
ErrMsg *err = findErrorForCurrentThread();
if ((err == NULL) || (!err->errorAvailable))
return(NULL);
err->errorAvailable = 0;
return(err->errorString);
} /* PHYSFS_getLastError */
/* MAKE SURE that errorLock is held before calling this! */
Jul 7, 2001
Jul 7, 2001
346
347
348
349
350
351
352
static void freeErrorMessages(void)
{
ErrMsg *i;
ErrMsg *next;
for (i = errorMessages; i != NULL; i = next)
{
Jul 9, 2001
Jul 9, 2001
353
next = i->next;
Mar 14, 2005
Mar 14, 2005
354
allocator.Free(i);
Jul 7, 2001
Jul 7, 2001
355
} /* for */
Jun 8, 2002
Jun 8, 2002
356
357
errorMessages = NULL;
Jul 7, 2001
Jul 7, 2001
358
359
360
} /* freeErrorMessages */
361
362
363
364
365
366
367
368
369
370
371
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
static const char *find_filename_extension(const char *fname)
{
const char *retval = strchr(fname, '.');
const char *p = retval;
while (p != NULL)
{
p = strchr(p + 1, '.');
if (p != NULL)
retval = p;
} /* while */
if (retval != NULL)
retval++; /* skip '.' */
return(retval);
} /* find_filename_extension */
Sep 26, 2004
Sep 26, 2004
391
392
static DirHandle *tryOpenDir(const PHYSFS_Archiver *funcs,
const char *d, int forWriting)
Sep 26, 2004
Sep 26, 2004
393
394
{
DirHandle *retval = NULL;
Sep 26, 2004
Sep 26, 2004
395
if (funcs->isArchive(d, forWriting))
Sep 26, 2004
Sep 26, 2004
396
{
Sep 26, 2004
Sep 26, 2004
397
void *opaque = funcs->openArchive(d, forWriting);
Sep 26, 2004
Sep 26, 2004
398
399
if (opaque != NULL)
{
Mar 14, 2005
Mar 14, 2005
400
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
Sep 26, 2004
Sep 26, 2004
401
if (retval == NULL)
Sep 26, 2004
Sep 26, 2004
402
funcs->dirClose(opaque);
Sep 26, 2004
Sep 26, 2004
403
404
else
{
Sep 26, 2004
Sep 26, 2004
405
memset(retval, '\0', sizeof (DirHandle));
Mar 13, 2005
Mar 13, 2005
406
retval->mountPoint = NULL;
Sep 26, 2004
Sep 26, 2004
407
retval->funcs = funcs;
Sep 26, 2004
Sep 26, 2004
408
409
410
411
412
413
414
415
416
retval->opaque = opaque;
} /* else */
} /* if */
} /* if */
return(retval);
} /* tryOpenDir */
Jul 7, 2001
Jul 7, 2001
417
418
static DirHandle *openDirectory(const char *d, int forWriting)
{
Sep 26, 2004
Sep 26, 2004
419
DirHandle *retval = NULL;
Sep 26, 2004
Sep 26, 2004
420
const PHYSFS_Archiver **i;
Jul 26, 2002
Jul 26, 2002
421
const char *ext;
Jul 7, 2001
Jul 7, 2001
422
Jul 23, 2001
Jul 23, 2001
423
424
BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
Jul 26, 2002
Jul 26, 2002
425
426
ext = find_filename_extension(d);
if (ext != NULL)
Jul 7, 2001
Jul 7, 2001
427
{
Jul 26, 2002
Jul 26, 2002
428
/* Look for archivers with matching file extensions first... */
Sep 26, 2004
Sep 26, 2004
429
for (i = archivers; (*i != NULL) && (retval == NULL); i++)
Jul 26, 2002
Jul 26, 2002
430
{
Mar 15, 2007
Mar 15, 2007
431
if (__PHYSFS_stricmpASCII(ext, (*i)->info->extension) == 0)
Sep 26, 2004
Sep 26, 2004
432
retval = tryOpenDir(*i, d, forWriting);
Jul 26, 2002
Jul 26, 2002
433
434
435
} /* for */
/* failing an exact file extension match, try all the others... */
Sep 26, 2004
Sep 26, 2004
436
for (i = archivers; (*i != NULL) && (retval == NULL); i++)
Jul 26, 2002
Jul 26, 2002
437
{
Mar 15, 2007
Mar 15, 2007
438
if (__PHYSFS_stricmpASCII(ext, (*i)->info->extension) != 0)
Sep 26, 2004
Sep 26, 2004
439
retval = tryOpenDir(*i, d, forWriting);
Jul 26, 2002
Jul 26, 2002
440
441
442
443
444
} /* for */
} /* if */
else /* no extension? Try them all. */
{
Sep 26, 2004
Sep 26, 2004
445
for (i = archivers; (*i != NULL) && (retval == NULL); i++)
Sep 26, 2004
Sep 26, 2004
446
retval = tryOpenDir(*i, d, forWriting);
Jul 26, 2002
Jul 26, 2002
447
} /* else */
Jul 7, 2001
Jul 7, 2001
448
Sep 26, 2004
Sep 26, 2004
449
450
BAIL_IF_MACRO(retval == NULL, ERR_UNSUPPORTED_ARCHIVE, NULL);
return(retval);
Jul 7, 2001
Jul 7, 2001
451
452
453
} /* openDirectory */
Mar 13, 2005
Mar 13, 2005
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
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
/*
* 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++;
prev = dst;
do
{
ch = *(src++);
if ((ch == ':') || (ch == '\\')) /* illegal chars in a physfs path. */
BAIL_MACRO(ERR_INSECURE_FNAME, 0);
if (ch == '/') /* path separator. */
{
*dst = '\0'; /* "." and ".." are illegal pathnames. */
if ((strcmp(prev, ".") == 0) || (strcmp(prev, "..") == 0))
BAIL_MACRO(ERR_INSECURE_FNAME, 0);
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');
return(1);
} /* sanitizePlatformIndependentPath */
Mar 14, 2005
Mar 14, 2005
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/*
* 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.
*
* This only finds legitimate segments of a mountpoint. If the mountpoint is
* "/a/b/c" and (fname) is "/a/b/c", "/", or "/a/b/c/d", then the results are
* all zero. "/a/b" will succeed, though.
*/
static int partOfMountPoint(DirHandle *h, char *fname)
{
/* !!! FIXME: This code feels gross. */
int rc;
size_t len, mntpntlen;
if (h->mountPoint == NULL)
return(0);
else if (*fname == '\0')
return(1);
len = strlen(fname);
mntpntlen = strlen(h->mountPoint);
if (len > mntpntlen) /* can't be a subset of mountpoint. */
return(0);
/* if true, must be not a match or a complete match, but not a subset. */
if ((len + 1) == mntpntlen)
return(0);
rc = strncmp(fname, h->mountPoint, len); /* !!! FIXME: case insensitive? */
if (rc != 0)
return(0); /* not a match. */
/* make sure /a/b matches /a/b/ and not /a/bc ... */
return(h->mountPoint[len] == '/');
} /* partOfMountPoint */
Mar 13, 2005
Mar 13, 2005
538
539
540
static DirHandle *createDirHandle(const char *newDir,
const char *mountPoint,
int forWriting)
Jul 7, 2001
Jul 7, 2001
541
542
{
DirHandle *dirHandle = NULL;
Mar 24, 2007
Mar 24, 2007
543
char *tmpmntpnt = NULL;
Mar 13, 2005
Mar 13, 2005
544
Mar 13, 2005
Mar 13, 2005
545
GOTO_IF_MACRO(!newDir, ERR_INVALID_ARGUMENT, badDirHandle);
Mar 13, 2005
Mar 13, 2005
546
547
if (mountPoint != NULL)
{
Mar 24, 2007
Mar 24, 2007
548
549
550
551
const size_t len = strlen(mountPoint) + 1;
tmpmntpnt = (char *) __PHYSFS_smallAlloc(len);
GOTO_IF_MACRO(!tmpmntpnt, ERR_OUT_OF_MEMORY, badDirHandle);
if (!sanitizePlatformIndependentPath(mountPoint, tmpmntpnt))
Mar 13, 2005
Mar 13, 2005
552
goto badDirHandle;
Mar 24, 2007
Mar 24, 2007
553
mountPoint = tmpmntpnt; /* sanitized version. */
Mar 13, 2005
Mar 13, 2005
554
} /* if */
Jul 7, 2001
Jul 7, 2001
555
556
dirHandle = openDirectory(newDir, forWriting);
Mar 13, 2005
Mar 13, 2005
557
GOTO_IF_MACRO(!dirHandle, NULL, badDirHandle);
Jul 7, 2001
Jul 7, 2001
558
Mar 14, 2005
Mar 14, 2005
559
dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1);
Mar 13, 2005
Mar 13, 2005
560
561
562
563
564
GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle);
strcpy(dirHandle->dirName, newDir);
if ((mountPoint != NULL) && (*mountPoint != '\0'))
{
Mar 14, 2005
Mar 14, 2005
565
dirHandle->mountPoint = (char *)allocator.Malloc(strlen(mountPoint)+2);
Mar 13, 2005
Mar 13, 2005
566
567
568
569
570
GOTO_IF_MACRO(!dirHandle->mountPoint, ERR_OUT_OF_MEMORY, badDirHandle);
strcpy(dirHandle->mountPoint, mountPoint);
strcat(dirHandle->mountPoint, "/");
} /* if */
Mar 24, 2007
Mar 24, 2007
571
__PHYSFS_smallFree(tmpmntpnt);
Mar 13, 2005
Mar 13, 2005
572
573
574
575
return(dirHandle);
badDirHandle:
if (dirHandle != NULL)
Mar 30, 2002
Mar 30, 2002
576
{
Sep 26, 2004
Sep 26, 2004
577
dirHandle->funcs->dirClose(dirHandle->opaque);
Mar 14, 2005
Mar 14, 2005
578
579
580
allocator.Free(dirHandle->dirName);
allocator.Free(dirHandle->mountPoint);
allocator.Free(dirHandle);
Mar 30, 2002
Mar 30, 2002
581
} /* if */
Jul 7, 2001
Jul 7, 2001
582
Mar 24, 2007
Mar 24, 2007
583
__PHYSFS_smallFree(tmpmntpnt);
Mar 13, 2005
Mar 13, 2005
584
return(NULL);
Sep 26, 2004
Sep 26, 2004
585
} /* createDirHandle */
Jul 7, 2001
Jul 7, 2001
586
587
Mar 30, 2002
Mar 30, 2002
588
/* MAKE SURE you've got the stateLock held before calling this! */
Sep 26, 2004
Sep 26, 2004
589
static int freeDirHandle(DirHandle *dh, FileHandle *openList)
Jul 7, 2001
Jul 7, 2001
590
{
Sep 26, 2004
Sep 26, 2004
591
FileHandle *i;
Jul 7, 2001
Jul 7, 2001
592
Sep 26, 2004
Sep 26, 2004
593
if (dh == NULL)
Jul 7, 2001
Jul 7, 2001
594
595
596
return(1);
for (i = openList; i != NULL; i = i->next)
Sep 26, 2004
Sep 26, 2004
597
BAIL_IF_MACRO(i->dirHandle == dh, ERR_FILES_STILL_OPEN, 0);
Apr 11, 2006
Apr 11, 2006
598
Sep 26, 2004
Sep 26, 2004
599
dh->funcs->dirClose(dh->opaque);
Mar 14, 2005
Mar 14, 2005
600
601
602
allocator.Free(dh->dirName);
allocator.Free(dh->mountPoint);
allocator.Free(dh);
Jul 7, 2001
Jul 7, 2001
603
return(1);
Sep 26, 2004
Sep 26, 2004
604
} /* freeDirHandle */
Jul 7, 2001
Jul 7, 2001
605
606
607
static char *calculateUserDir(void)
Jul 6, 2001
Jul 6, 2001
608
{
Mar 21, 2010
Mar 21, 2010
609
610
611
612
613
614
615
616
char *retval = __PHYSFS_platformGetUserDir();
if (retval != NULL)
{
/* make sure it really exists and is normalized. */
char *ptr = __PHYSFS_platformRealPath(retval);
allocator.Free(retval);
retval = ptr;
} /* if */
Jul 6, 2001
Jul 6, 2001
617
Mar 21, 2010
Mar 21, 2010
618
if (retval == NULL)
Jul 6, 2001
Jul 6, 2001
619
620
621
{
const char *dirsep = PHYSFS_getDirSeparator();
const char *uname = __PHYSFS_platformGetUserName();
Mar 21, 2010
Mar 21, 2010
622
const char *str = (uname != NULL) ? uname : "default";
Jul 6, 2001
Jul 6, 2001
623
Mar 14, 2005
Mar 14, 2005
624
625
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
strlen(dirsep) + 6);
Jul 6, 2001
Jul 6, 2001
626
627
628
629
if (retval == NULL)
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
else
Apr 2, 2002
Apr 2, 2002
630
sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
Jul 6, 2001
Jul 6, 2001
631
Mar 24, 2007
Mar 24, 2007
632
allocator.Free((void *) uname);
Jul 6, 2001
Jul 6, 2001
633
634
635
636
637
638
} /* else */
return(retval);
} /* calculateUserDir */
Jul 8, 2001
Jul 8, 2001
639
640
641
642
643
644
645
646
static int appendDirSep(char **dir)
{
const char *dirsep = PHYSFS_getDirSeparator();
char *ptr;
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
return(1);
Mar 14, 2005
Mar 14, 2005
647
ptr = (char *) allocator.Realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
Jul 8, 2001
Jul 8, 2001
648
649
if (!ptr)
{
Mar 14, 2005
Mar 14, 2005
650
allocator.Free(*dir);
Jul 8, 2001
Jul 8, 2001
651
652
653
654
655
656
657
658
659
return(0);
} /* if */
strcat(ptr, dirsep);
*dir = ptr;
return(1);
} /* appendDirSep */
Jul 7, 2001
Jul 7, 2001
660
661
static char *calculateBaseDir(const char *argv0)
{
Mar 21, 2007
Mar 21, 2007
662
663
664
char *retval = NULL;
const char *dirsep = NULL;
char *ptr = NULL;
Jul 8, 2001
Jul 8, 2001
665
Mar 21, 2007
Mar 21, 2007
666
/* Give the platform layer first shot at this. */
Jul 8, 2001
Jul 8, 2001
667
668
669
670
retval = __PHYSFS_platformCalcBaseDir(argv0);
if (retval != NULL)
return(retval);
Mar 21, 2007
Mar 21, 2007
671
672
/* We need argv0 to go on. */
BAIL_IF_MACRO(argv0 == NULL, ERR_ARGV0_IS_NULL, NULL);
Mar 19, 2007
Mar 19, 2007
673
Mar 21, 2007
Mar 21, 2007
674
675
676
677
dirsep = PHYSFS_getDirSeparator();
if (strlen(dirsep) == 1) /* fast path. */
ptr = strrchr(argv0, *dirsep);
else
Jul 8, 2001
Jul 8, 2001
678
{
Mar 21, 2007
Mar 21, 2007
679
680
ptr = strstr(argv0, dirsep);
if (ptr != NULL)
Jul 8, 2001
Jul 8, 2001
681
{
Mar 21, 2007
Mar 21, 2007
682
683
684
685
686
687
688
689
char *p = ptr;
while (p != NULL)
{
ptr = p;
p = strstr(p + 1, dirsep);
} /* while */
} /* if */
} /* else */
Jul 8, 2001
Jul 8, 2001
690
Mar 21, 2007
Mar 21, 2007
691
692
693
if (ptr != NULL)
{
size_t size = (size_t) (ptr - argv0);
Mar 14, 2005
Mar 14, 2005
694
retval = (char *) allocator.Malloc(size + 1);
Jul 8, 2001
Jul 8, 2001
695
696
697
698
699
700
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
memcpy(retval, argv0, size);
retval[size] = '\0';
return(retval);
} /* if */
Mar 21, 2007
Mar 21, 2007
701
702
703
/* argv0 wasn't helpful. */
BAIL_MACRO(ERR_INVALID_ARGUMENT, NULL);
return(NULL);
Jul 7, 2001
Jul 7, 2001
704
705
706
} /* calculateBaseDir */
Mar 30, 2002
Mar 30, 2002
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
static int initializeMutexes(void)
{
errorLock = __PHYSFS_platformCreateMutex();
if (errorLock == NULL)
goto initializeMutexes_failed;
stateLock = __PHYSFS_platformCreateMutex();
if (stateLock == NULL)
goto initializeMutexes_failed;
return(1); /* success. */
initializeMutexes_failed:
if (errorLock != NULL)
__PHYSFS_platformDestroyMutex(errorLock);
if (stateLock != NULL)
__PHYSFS_platformDestroyMutex(stateLock);
errorLock = stateLock = NULL;
return(0); /* failed. */
} /* initializeMutexes */
Sep 23, 2004
Sep 23, 2004
731
732
static void setDefaultAllocator(void);
733
734
int PHYSFS_init(const char *argv0)
{
Jul 16, 2001
Jul 16, 2001
735
736
char *ptr;
737
BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0);
Sep 23, 2004
Sep 23, 2004
738
739
740
741
if (!externalAllocator)
setDefaultAllocator();
Sep 9, 2005
Sep 9, 2005
742
743
if (allocator.Init != NULL)
BAIL_IF_MACRO(!allocator.Init(), NULL, 0);
Sep 26, 2004
Sep 26, 2004
744
Mar 24, 2002
Mar 24, 2002
745
BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
Mar 30, 2002
Mar 30, 2002
747
748
BAIL_IF_MACRO(!initializeMutexes(), NULL, 0);
Jul 6, 2001
Jul 6, 2001
749
baseDir = calculateBaseDir(argv0);
Jul 7, 2001
Jul 7, 2001
750
BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
Apr 6, 2002
Apr 6, 2002
751
Mar 21, 2007
Mar 21, 2007
752
/* !!! FIXME: only call this if we got this from argv0 (unreliable). */
Jul 16, 2001
Jul 16, 2001
753
ptr = __PHYSFS_platformRealPath(baseDir);
Mar 14, 2005
Mar 14, 2005
754
allocator.Free(baseDir);
Jul 16, 2001
Jul 16, 2001
755
756
757
BAIL_IF_MACRO(ptr == NULL, NULL, 0);
baseDir = ptr;
Jul 8, 2001
Jul 8, 2001
758
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
Jul 6, 2001
Jul 6, 2001
759
760
userDir = calculateUserDir();
Jul 8, 2001
Jul 8, 2001
761
if ((userDir == NULL) || (!appendDirSep(&userDir)))
Jul 6, 2001
Jul 6, 2001
762
{
Mar 14, 2005
Mar 14, 2005
763
allocator.Free(baseDir);
Jul 6, 2001
Jul 6, 2001
764
765
766
767
baseDir = NULL;
return(0);
} /* if */
768
initialized = 1;
Apr 4, 2002
Apr 4, 2002
769
770
771
/* This makes sure that the error subsystem is initialized. */
__PHYSFS_setError(PHYSFS_getLastError());
Aug 20, 2002
Aug 20, 2002
772
773
774
775
776
return(1);
} /* PHYSFS_init */
Mar 30, 2002
Mar 30, 2002
777
/* MAKE SURE you hold stateLock before calling this! */
Sep 26, 2004
Sep 26, 2004
778
static int closeFileHandleList(FileHandle **list)
Jul 6, 2001
Jul 6, 2001
779
{
Sep 26, 2004
Sep 26, 2004
780
781
FileHandle *i;
FileHandle *next = NULL;
Jul 6, 2001
Jul 6, 2001
782
783
784
785
for (i = *list; i != NULL; i = next)
{
next = i->next;
Sep 26, 2004
Sep 26, 2004
786
if (!i->funcs->fileClose(i->opaque))
Jul 7, 2001
Jul 7, 2001
787
788
789
790
791
{
*list = i;
return(0);
} /* if */
Mar 14, 2005
Mar 14, 2005
792
allocator.Free(i);
Jul 6, 2001
Jul 6, 2001
793
794
795
} /* for */
*list = NULL;
Jul 7, 2001
Jul 7, 2001
796
797
return(1);
} /* closeFileHandleList */
Jul 6, 2001
Jul 6, 2001
798
799
Mar 30, 2002
Mar 30, 2002
800
/* MAKE SURE you hold the stateLock before calling this! */
801
802
static void freeSearchPath(void)
{
Sep 26, 2004
Sep 26, 2004
803
804
DirHandle *i;
DirHandle *next = NULL;
Jul 6, 2001
Jul 6, 2001
806
807
closeFileHandleList(&openReadList);
808
809
810
811
if (searchPath != NULL)
{
for (i = searchPath; i != NULL; i = next)
{
Jul 9, 2001
Jul 9, 2001
812
next = i->next;
Sep 26, 2004
Sep 26, 2004
813
freeDirHandle(i, openReadList);
814
815
816
817
818
819
} /* for */
searchPath = NULL;
} /* if */
} /* freeSearchPath */
Jul 7, 2001
Jul 7, 2001
820
int PHYSFS_deinit(void)
821
822
{
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
Mar 24, 2002
Mar 24, 2002
823
BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), NULL, 0);
Jul 6, 2001
Jul 6, 2001
825
closeFileHandleList(&openWriteList);
Jul 7, 2001
Jul 7, 2001
826
827
BAIL_IF_MACRO(!PHYSFS_setWriteDir(NULL), ERR_FILES_STILL_OPEN, 0);
828
829
830
freeSearchPath();
freeErrorMessages();
Jul 6, 2001
Jul 6, 2001
831
if (baseDir != NULL)
Jul 6, 2001
Jul 6, 2001
832
{
Mar 14, 2005
Mar 14, 2005
833
allocator.Free(baseDir);
Jul 6, 2001
Jul 6, 2001
834
835
836
837
838
baseDir = NULL;
} /* if */
if (userDir != NULL)
{
Mar 14, 2005
Mar 14, 2005
839
allocator.Free(userDir);
Jul 6, 2001
Jul 6, 2001
840
841
userDir = NULL;
} /* if */
Jul 6, 2001
Jul 6, 2001
842
843
allowSymLinks = 0;
844
initialized = 0;
Mar 30, 2002
Mar 30, 2002
845
846
847
848
__PHYSFS_platformDestroyMutex(errorLock);
__PHYSFS_platformDestroyMutex(stateLock);
Sep 9, 2005
Sep 9, 2005
849
850
if (allocator.Deinit != NULL)
allocator.Deinit();
Sep 26, 2004
Sep 26, 2004
851
Mar 30, 2002
Mar 30, 2002
852
errorLock = stateLock = NULL;
853
854
855
856
return(1);
} /* PHYSFS_deinit */
Apr 1, 2007
Apr 1, 2007
857
858
859
860
861
862
int PHYSFS_isInit(void)
{
return(initialized);
} /* PHYSFS_isInit */
863
864
865
866
867
868
869
870
871
872
const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
{
return(supported_types);
} /* PHYSFS_supportedArchiveTypes */
void PHYSFS_freeList(void *list)
{
void **i;
for (i = (void **) list; *i != NULL; i++)
Mar 14, 2005
Mar 14, 2005
873
allocator.Free(*i);
Mar 14, 2005
Mar 14, 2005
875
allocator.Free(list);
876
877
878
879
880
} /* PHYSFS_freeList */
const char *PHYSFS_getDirSeparator(void)
{
Jul 7, 2001
Jul 7, 2001
881
return(__PHYSFS_platformDirSeparator);
882
883
884
885
886
} /* PHYSFS_getDirSeparator */
char **PHYSFS_getCdRomDirs(void)
{
Sep 29, 2004
Sep 29, 2004
887
return(doEnumStringList(__PHYSFS_platformDetectAvailableCDs));
888
889
890
} /* PHYSFS_getCdRomDirs */
Sep 29, 2004
Sep 29, 2004
891
892
893
894
895
896
void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback callback, void *data)
{
__PHYSFS_platformDetectAvailableCDs(callback, data);
} /* PHYSFS_getCdRomDirsCallback */
897
898
899
900
901
902
903
904
const char *PHYSFS_getBaseDir(void)
{
return(baseDir); /* this is calculated in PHYSFS_init()... */
} /* PHYSFS_getBaseDir */
const char *PHYSFS_getUserDir(void)
{
Jul 6, 2001
Jul 6, 2001
905
return(userDir); /* this is calculated in PHYSFS_init()... */
906
907
908
909
910
} /* PHYSFS_getUserDir */
const char *PHYSFS_getWriteDir(void)
{
Mar 30, 2002
Mar 30, 2002
911
912
913
914
915
916
const char *retval = NULL;
__PHYSFS_platformGrabMutex(stateLock);
if (writeDir != NULL)
retval = writeDir->dirName;
__PHYSFS_platformReleaseMutex(stateLock);
Jul 7, 2001
Jul 7, 2001
917
Mar 30, 2002
Mar 30, 2002
918
return(retval);
919
920
921
922
923
} /* PHYSFS_getWriteDir */
int PHYSFS_setWriteDir(const char *newDir)
{
Mar 30, 2002
Mar 30, 2002
924
925
926
927
int retval = 1;
__PHYSFS_platformGrabMutex(stateLock);
928
929
if (writeDir != NULL)
{
Sep 26, 2004
Sep 26, 2004
930
BAIL_IF_MACRO_MUTEX(!freeDirHandle(writeDir, openWriteList), NULL,
Mar 30, 2002
Mar 30, 2002
931
stateLock, 0);
932
933
934
writeDir = NULL;
} /* if */
Jul 6, 2001
Jul 6, 2001
935
936
if (newDir != NULL)
{
Mar 13, 2005
Mar 13, 2005
937
writeDir = createDirHandle(newDir, NULL, 1);
Mar 30, 2002
Mar 30, 2002
938
retval = (writeDir != NULL);
Jul 6, 2001
Jul 6, 2001
939
} /* if */
Mar 30, 2002
Mar 30, 2002
941
942
943
__PHYSFS_platformReleaseMutex(stateLock);
return(retval);
944
945
946
} /* PHYSFS_setWriteDir */
Mar 13, 2005
Mar 13, 2005
947
int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
Sep 26, 2004
Sep 26, 2004
949
950
951
DirHandle *dh;
DirHandle *prev = NULL;
DirHandle *i;
Jul 23, 2001
Jul 23, 2001
952
Mar 13, 2005
Mar 13, 2005
953
BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0);
Jul 23, 2005
Jul 23, 2005
954
955
956
if (mountPoint == NULL)
mountPoint = "/";
Mar 13, 2005
Mar 13, 2005
957
Mar 30, 2002
Mar 30, 2002
958
__PHYSFS_platformGrabMutex(stateLock);
Jul 23, 2001
Jul 23, 2001
959
Mar 30, 2002
Mar 30, 2002
960
961
962
963
for (i = searchPath; i != NULL; i = i->next)
{
/* already in search path? */
BAIL_IF_MACRO_MUTEX(strcmp(newDir, i->dirName)==0, NULL, stateLock, 1);
Jul 23, 2001
Jul 23, 2001
964
prev = i;
Mar 30, 2002
Mar 30, 2002
965
} /* for */
Jul 23, 2001
Jul 23, 2001
966
Mar 13, 2005
Mar 13, 2005
967
dh = createDirHandle(newDir, mountPoint, 0);
Sep 26, 2004
Sep 26, 2004
968
BAIL_IF_MACRO_MUTEX(dh == NULL, NULL, stateLock, 0);
969
970
971
972
if (appendToPath)
{
if (prev == NULL)
Sep 26, 2004
Sep 26, 2004
973
searchPath = dh;
974
else
Sep 26, 2004
Sep 26, 2004
975
prev->next = dh;
Jul 8, 2001
Jul 8, 2001
976
977
978
} /* if */
else
{
Sep 26, 2004
Sep 26, 2004
979
980
dh->next = searchPath;
searchPath = dh;
981
982
} /* else */
Mar 30, 2002
Mar 30, 2002
983
__PHYSFS_platformReleaseMutex(stateLock);
984
return(1);
Mar 13, 2005
Mar 13, 2005
985
986
987
988
989
} /* PHYSFS_mount */
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
{
Mar 13, 2005
Mar 13, 2005
990
return(PHYSFS_mount(newDir, NULL, appendToPath));
991
992
993
994
995
} /* PHYSFS_addToSearchPath */
int PHYSFS_removeFromSearchPath(const char *oldDir)
{
Sep 26, 2004
Sep 26, 2004
996
997
998
DirHandle *i;
DirHandle *prev = NULL;
DirHandle *next = NULL;
999
1000
BAIL_IF_MACRO(oldDir == NULL, ERR_INVALID_ARGUMENT, 0);