author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 15 Jun 2002 10:26:07 +0000 | |
changeset 290 | 1ae98a1e50b9 |
parent 272 | 470430943851 |
child 314 | a156f6155e3c |
permissions | -rw-r--r-- |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/** |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* PhysicsFS; a portable, flexible file i/o abstraction. |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* Documentation is in physfs.h. It's verbose, honest. :) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* Please see the file LICENSE in the source's root directory. |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
* This file written by Ryan C. Gordon. |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
*/ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
193
diff
changeset
|
11 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
193
diff
changeset
|
12 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
193
diff
changeset
|
13 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
193
diff
changeset
|
14 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
#include <stdio.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
#include <stdlib.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
#include <string.h> |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
18 |
#include <fcntl.h> |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
19 |
#include <errno.h> |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
#include <assert.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
#include "physfs.h" |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
23 |
#define __PHYSICSFS_INTERNAL__ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
24 |
#include "physfs_internal.h" |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
25 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
typedef struct __PHYSFS_ERRMSGTYPE__ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
{ |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
28 |
PHYSFS_uint64 tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
int errorAvailable; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
char errorString[80]; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
struct __PHYSFS_ERRMSGTYPE__ *next; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
} ErrMsg; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
34 |
typedef struct __PHYSFS_DIRINFO__ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
char *dirName; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
37 |
DirHandle *dirHandle; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
38 |
struct __PHYSFS_DIRINFO__ *next; |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
39 |
} PhysDirInfo; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
41 |
typedef struct __PHYSFS_FILEHANDLELIST__ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
42 |
{ |
27
e1d3292769b2
Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents:
25
diff
changeset
|
43 |
PHYSFS_file handle; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
44 |
struct __PHYSFS_FILEHANDLELIST__ *next; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
45 |
} FileHandleList; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
47 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
48 |
/* The various i/o drivers... */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
50 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
51 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
52 |
extern const DirFunctions __PHYSFS_DirFunctions_ZIP; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
53 |
#endif |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
54 |
|
22
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
55 |
#if (defined PHYSFS_SUPPORTS_GRP) |
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
56 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP; |
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
57 |
extern const DirFunctions __PHYSFS_DirFunctions_GRP; |
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
58 |
#endif |
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
59 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
60 |
extern const DirFunctions __PHYSFS_DirFunctions_DIR; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
61 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
62 |
static const PHYSFS_ArchiveInfo *supported_types[] = |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
65 |
&__PHYSFS_ArchiveInfo_ZIP, |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
#endif |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
68 |
#if (defined PHYSFS_SUPPORTS_GRP) |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
69 |
&__PHYSFS_ArchiveInfo_GRP, |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
70 |
#endif |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
71 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
NULL |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
}; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
75 |
static const DirFunctions *dirFunctions[] = |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
76 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
77 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
78 |
&__PHYSFS_DirFunctions_ZIP, |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
79 |
#endif |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
80 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
81 |
#if (defined PHYSFS_SUPPORTS_GRP) |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
82 |
&__PHYSFS_DirFunctions_GRP, |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
83 |
#endif |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
84 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
85 |
&__PHYSFS_DirFunctions_DIR, |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
86 |
NULL |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
87 |
}; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
88 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
91 |
/* General PhysicsFS state ... */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
92 |
static int initialized = 0; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
93 |
static ErrMsg *errorMessages = NULL; |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
94 |
static PhysDirInfo *searchPath = NULL; |
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
95 |
static PhysDirInfo *writeDir = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
96 |
static FileHandleList *openWriteList = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
97 |
static FileHandleList *openReadList = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
98 |
static char *baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
99 |
static char *userDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
100 |
static int allowSymLinks = 0; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
101 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
102 |
/* mutexes ... */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
103 |
static void *errorLock = NULL; /* protects error message list. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
104 |
static void *stateLock = NULL; /* protects other PhysFS static state. */ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
105 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
106 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
107 |
/* functions ... */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
static ErrMsg *findErrorForCurrentThread(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
ErrMsg *i; |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
112 |
PHYSFS_uint64 tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
114 |
if (errorLock != NULL) |
193
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
115 |
__PHYSFS_platformGrabMutex(errorLock); |
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
116 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
if (errorMessages != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
{ |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
119 |
tid = __PHYSFS_platformGetThreadID(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
for (i = errorMessages; i != NULL; i = i->next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
if (i->tid == tid) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
124 |
{ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
125 |
if (errorLock != NULL) |
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
126 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
return(i); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
128 |
} /* if */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
} /* if */ |
193
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
131 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
132 |
if (errorLock != NULL) |
193
830c165052a5
Doesn't grab mutex in __PHYSFS_setError() if PHYSFS_init() hasn't been called.
Ryan C. Gordon <icculus@icculus.org>
parents:
186
diff
changeset
|
133 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
return(NULL); /* no error available. */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
} /* findErrorForCurrentThread */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
139 |
void __PHYSFS_setError(const char *str) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
141 |
ErrMsg *err; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
142 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
143 |
if (str == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
144 |
return; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
145 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
146 |
err = findErrorForCurrentThread(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
if (err == NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
err = (ErrMsg *) malloc(sizeof (ErrMsg)); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
if (err == NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
return; /* uhh...? */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
|
57
1ec888db3df9
Safety memset when creating error information for a new thread.
Ryan C. Gordon <icculus@icculus.org>
parents:
51
diff
changeset
|
154 |
memset((void *) err, '\0', sizeof (ErrMsg)); |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
155 |
err->tid = __PHYSFS_platformGetThreadID(); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
156 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
157 |
if (errorLock != NULL) |
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
158 |
__PHYSFS_platformGrabMutex(errorLock); |
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
159 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
err->next = errorMessages; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
161 |
errorMessages = err; |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
162 |
|
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
163 |
if (errorLock != NULL) |
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
164 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
err->errorAvailable = 1; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
strncpy(err->errorString, str, sizeof (err->errorString)); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
err->errorString[sizeof (err->errorString) - 1] = '\0'; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
170 |
} /* __PHYSFS_setError */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
const char *PHYSFS_getLastError(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
ErrMsg *err = findErrorForCurrentThread(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
if ((err == NULL) || (!err->errorAvailable)) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
return(NULL); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 |
err->errorAvailable = 0; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
return(err->errorString); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
} /* PHYSFS_getLastError */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
185 |
/* MAKE SURE that errorLock is held before calling this! */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
186 |
static void freeErrorMessages(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
187 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
188 |
ErrMsg *i; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
189 |
ErrMsg *next; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
190 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
191 |
for (i = errorMessages; i != NULL; i = next) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
192 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
193 |
next = i->next; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
194 |
free(i); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
195 |
} /* for */ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
196 |
|
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
197 |
errorMessages = NULL; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
198 |
} /* freeErrorMessages */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
199 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
200 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 |
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
if (ver != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
ver->major = PHYSFS_VER_MAJOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
ver->minor = PHYSFS_VER_MINOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
ver->patch = PHYSFS_VER_PATCH; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
} /* PHYSFS_getLinkedVersion */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
212 |
static DirHandle *openDirectory(const char *d, int forWriting) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
213 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
214 |
const DirFunctions **i; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
215 |
|
44
534901592376
Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
216 |
BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL); |
534901592376
Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
217 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
218 |
for (i = dirFunctions; *i != NULL; i++) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
219 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
220 |
if ((*i)->isArchive(d, forWriting)) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
221 |
return( (*i)->openArchive(d, forWriting) ); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
222 |
} /* for */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
223 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
224 |
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
225 |
return(NULL); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
226 |
} /* openDirectory */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
227 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
228 |
|
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
229 |
static PhysDirInfo *buildDirInfo(const char *newDir, int forWriting) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
230 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
231 |
DirHandle *dirHandle = NULL; |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
232 |
PhysDirInfo *di = NULL; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
233 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
234 |
BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
235 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
236 |
dirHandle = openDirectory(newDir, forWriting); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
237 |
BAIL_IF_MACRO(dirHandle == NULL, NULL, 0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
238 |
|
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
239 |
di = (PhysDirInfo *) malloc(sizeof (PhysDirInfo)); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
240 |
if (di == NULL) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
241 |
{ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
242 |
dirHandle->funcs->dirClose(dirHandle); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
243 |
BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
244 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
245 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
246 |
di->dirName = (char *) malloc(strlen(newDir) + 1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
247 |
if (di->dirName == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
248 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
249 |
free(di); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
250 |
dirHandle->funcs->dirClose(dirHandle); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
251 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
252 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
253 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
254 |
di->next = NULL; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
255 |
di->dirHandle = dirHandle; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
256 |
strcpy(di->dirName, newDir); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
257 |
return(di); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
258 |
} /* buildDirInfo */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
259 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
260 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
261 |
/* MAKE SURE you've got the stateLock held before calling this! */ |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
262 |
static int freeDirInfo(PhysDirInfo *di, FileHandleList *openList) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
263 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
264 |
FileHandleList *i; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
265 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
266 |
if (di == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
267 |
return(1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
268 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
269 |
for (i = openList; i != NULL; i = i->next) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
270 |
{ |
27
e1d3292769b2
Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents:
25
diff
changeset
|
271 |
const DirHandle *h = ((FileHandle *) &(i->handle.opaque))->dirHandle; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
272 |
BAIL_IF_MACRO(h == di->dirHandle, ERR_FILES_STILL_OPEN, 0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
273 |
} /* for */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
274 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
275 |
di->dirHandle->funcs->dirClose(di->dirHandle); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
276 |
free(di->dirName); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
277 |
free(di); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
278 |
return(1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
279 |
} /* freeDirInfo */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
280 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
281 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
282 |
static char *calculateUserDir(void) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
283 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
284 |
char *retval = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
285 |
const char *str = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
286 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
287 |
str = __PHYSFS_platformGetUserDir(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
288 |
if (str != NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
289 |
retval = (char *) str; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
290 |
else |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
291 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
292 |
const char *dirsep = PHYSFS_getDirSeparator(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
293 |
const char *uname = __PHYSFS_platformGetUserName(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
294 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
295 |
str = (uname != NULL) ? uname : "default"; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
296 |
retval = (char *) malloc(strlen(baseDir) + strlen(str) + |
155
54fee85d9c26
Fixed calculateUserDir() to prevent extra dir separator insertion in default case.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
297 |
strlen(dirsep) + 6); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
298 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
299 |
if (retval == NULL) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
300 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
301 |
else |
155
54fee85d9c26
Fixed calculateUserDir() to prevent extra dir separator insertion in default case.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
302 |
sprintf(retval, "%susers%s%s", baseDir, dirsep, str); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
303 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
304 |
if (uname != NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
305 |
free((void *) uname); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
306 |
} /* else */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
307 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
308 |
return(retval); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
309 |
} /* calculateUserDir */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
310 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
311 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
312 |
static int appendDirSep(char **dir) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
313 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
314 |
const char *dirsep = PHYSFS_getDirSeparator(); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
315 |
char *ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
316 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
317 |
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
318 |
return(1); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
319 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
320 |
ptr = realloc(*dir, strlen(*dir) + strlen(dirsep) + 1); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
321 |
if (!ptr) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
322 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
323 |
free(*dir); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
324 |
return(0); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
325 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
326 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
327 |
strcat(ptr, dirsep); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
328 |
*dir = ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
329 |
return(1); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
330 |
} /* appendDirSep */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
331 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
332 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
333 |
static char *calculateBaseDir(const char *argv0) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
334 |
{ |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
335 |
const char *dirsep = PHYSFS_getDirSeparator(); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
336 |
char *retval; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
337 |
char *ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
338 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
339 |
/* |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
340 |
* See if the platform driver wants to handle this for us... |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
341 |
*/ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
342 |
retval = __PHYSFS_platformCalcBaseDir(argv0); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
343 |
if (retval != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
344 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
345 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
346 |
/* |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
347 |
* Determine if there's a path on argv0. If there is, that's the base dir. |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
348 |
*/ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
349 |
ptr = strstr(argv0, dirsep); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
350 |
if (ptr != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
351 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
352 |
char *p = ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
353 |
size_t size; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
354 |
while (p != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
355 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
356 |
ptr = p; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
357 |
p = strstr(p + 1, dirsep); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
358 |
} /* while */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
359 |
|
225 | 360 |
size = (size_t) (ptr - argv0); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
361 |
retval = (char *) malloc(size + 1); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
362 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
363 |
memcpy(retval, argv0, size); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
364 |
retval[size] = '\0'; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
365 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
366 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
367 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
368 |
/* |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
369 |
* Last ditch effort: it's the current working directory. (*shrug*) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
370 |
*/ |
100
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
371 |
retval = __PHYSFS_platformCurrentDir(); |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
372 |
if(retval != NULL) { |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
373 |
return(retval); |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
374 |
} |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
375 |
|
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
376 |
/* |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
377 |
* Ok, current directory doesn't exist, use the root directory. |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
378 |
* Not a good alternative, but it only happens if the current |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
379 |
* directory was deleted from under the program. |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
380 |
*/ |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
381 |
retval = (char *) malloc(strlen(dirsep) + 1); |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
382 |
strcpy(retval, dirsep); |
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
383 |
return(retval); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
384 |
} /* calculateBaseDir */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
385 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
386 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
387 |
static int initializeMutexes(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
388 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
389 |
errorLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
390 |
if (errorLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
391 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
392 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
393 |
stateLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
394 |
if (stateLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
395 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
396 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
397 |
return(1); /* success. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
398 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
399 |
initializeMutexes_failed: |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
400 |
if (errorLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
401 |
__PHYSFS_platformDestroyMutex(errorLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
402 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
403 |
if (stateLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
404 |
__PHYSFS_platformDestroyMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
405 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
406 |
errorLock = stateLock = NULL; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
407 |
return(0); /* failed. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
408 |
} /* initializeMutexes */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
409 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
410 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
int PHYSFS_init(const char *argv0) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 |
{ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
413 |
char *ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
414 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); |
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
126
diff
changeset
|
416 |
BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
418 |
BAIL_IF_MACRO(!initializeMutexes(), NULL, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
419 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
420 |
baseDir = calculateBaseDir(argv0); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
421 |
BAIL_IF_MACRO(baseDir == NULL, NULL, 0); |
186 | 422 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
423 |
ptr = __PHYSFS_platformRealPath(baseDir); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
424 |
free(baseDir); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
425 |
BAIL_IF_MACRO(ptr == NULL, NULL, 0); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
426 |
baseDir = ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
427 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
428 |
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
429 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
430 |
userDir = calculateUserDir(); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
431 |
if (userDir != NULL) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
432 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
433 |
ptr = __PHYSFS_platformRealPath(userDir); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
434 |
free(userDir); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
435 |
userDir = ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
436 |
} /* if */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
437 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
438 |
if ((userDir == NULL) || (!appendDirSep(&userDir))) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
439 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
440 |
free(baseDir); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
441 |
baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
442 |
return(0); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
443 |
} /* if */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
444 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
initialized = 1; |
167
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
446 |
|
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
447 |
/* This makes sure that the error subsystem is initialized. */ |
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
448 |
__PHYSFS_setError(PHYSFS_getLastError()); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
return(1); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
} /* PHYSFS_init */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
452 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
453 |
/* MAKE SURE you hold stateLock before calling this! */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
454 |
static int closeFileHandleList(FileHandleList **list) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
455 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
456 |
FileHandleList *i; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
457 |
FileHandleList *next = NULL; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
458 |
FileHandle *h; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
459 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
460 |
for (i = *list; i != NULL; i = next) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
461 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
462 |
next = i->next; |
27
e1d3292769b2
Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents:
25
diff
changeset
|
463 |
h = (FileHandle *) (i->handle.opaque); |
e1d3292769b2
Rewrote the file closing routines to not be so gay. Cleaned up the opening
Ryan C. Gordon <icculus@icculus.org>
parents:
25
diff
changeset
|
464 |
if (!h->funcs->fileClose(h)) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
465 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
466 |
*list = i; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
467 |
return(0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
468 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
469 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
470 |
free(i); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
471 |
} /* for */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
472 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
473 |
*list = NULL; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
474 |
return(1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
475 |
} /* closeFileHandleList */ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
476 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
477 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
478 |
/* MAKE SURE you hold the stateLock before calling this! */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
479 |
static void freeSearchPath(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
480 |
{ |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
481 |
PhysDirInfo *i; |
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
482 |
PhysDirInfo *next = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
483 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
484 |
closeFileHandleList(&openReadList); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
485 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
486 |
if (searchPath != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
487 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
488 |
for (i = searchPath; i != NULL; i = next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
489 |
{ |
25
96b32c0fd7f3
Bugfix for infinite loop/touching free()'d memory during PHYSFS_deinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
23
diff
changeset
|
490 |
next = i->next; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
491 |
freeDirInfo(i, openReadList); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
492 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
searchPath = NULL; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
494 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
} /* freeSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
497 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
498 |
int PHYSFS_deinit(void) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
499 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
500 |
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
126
diff
changeset
|
501 |
BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), NULL, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
502 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
503 |
closeFileHandleList(&openWriteList); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
504 |
BAIL_IF_MACRO(!PHYSFS_setWriteDir(NULL), ERR_FILES_STILL_OPEN, 0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
505 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 |
freeSearchPath(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
507 |
freeErrorMessages(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
508 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
509 |
if (baseDir != NULL) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
510 |
{ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
511 |
free(baseDir); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
512 |
baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
513 |
} /* if */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
514 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
515 |
if (userDir != NULL) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
516 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
517 |
free(userDir); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
518 |
userDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
519 |
} /* if */ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
520 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
521 |
allowSymLinks = 0; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
522 |
initialized = 0; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
523 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
524 |
__PHYSFS_platformDestroyMutex(errorLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
525 |
__PHYSFS_platformDestroyMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
526 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
527 |
errorLock = stateLock = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
528 |
return(1); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
529 |
} /* PHYSFS_deinit */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
530 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
532 |
const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
533 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
534 |
return(supported_types); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
535 |
} /* PHYSFS_supportedArchiveTypes */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
536 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
538 |
void PHYSFS_freeList(void *list) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
540 |
void **i; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 |
for (i = (void **) list; *i != NULL; i++) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
542 |
free(*i); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
543 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
544 |
free(list); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
545 |
} /* PHYSFS_freeList */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
546 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
547 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
548 |
const char *PHYSFS_getDirSeparator(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
549 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
550 |
return(__PHYSFS_platformDirSeparator); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
551 |
} /* PHYSFS_getDirSeparator */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
552 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
553 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
554 |
char **PHYSFS_getCdRomDirs(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
555 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
556 |
return(__PHYSFS_platformDetectAvailableCDs()); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
557 |
} /* PHYSFS_getCdRomDirs */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
558 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
559 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
560 |
const char *PHYSFS_getBaseDir(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
561 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
562 |
return(baseDir); /* this is calculated in PHYSFS_init()... */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
563 |
} /* PHYSFS_getBaseDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
564 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
565 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
566 |
const char *PHYSFS_getUserDir(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
567 |
{ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
568 |
return(userDir); /* this is calculated in PHYSFS_init()... */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
569 |
} /* PHYSFS_getUserDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
570 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
571 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
572 |
const char *PHYSFS_getWriteDir(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
573 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
574 |
const char *retval = NULL; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
575 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
576 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
577 |
if (writeDir != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
578 |
retval = writeDir->dirName; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
579 |
__PHYSFS_platformReleaseMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
580 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
581 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
582 |
} /* PHYSFS_getWriteDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
583 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
584 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 |
int PHYSFS_setWriteDir(const char *newDir) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
586 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
587 |
int retval = 1; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
588 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
589 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
590 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
591 |
if (writeDir != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
592 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
593 |
BAIL_IF_MACRO_MUTEX(!freeDirInfo(writeDir, openWriteList), NULL, |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
594 |
stateLock, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
595 |
writeDir = NULL; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
596 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
597 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
598 |
if (newDir != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
599 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
600 |
writeDir = buildDirInfo(newDir, 1); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
601 |
retval = (writeDir != NULL); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
602 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
603 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
604 |
__PHYSFS_platformReleaseMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
605 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
606 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
607 |
} /* PHYSFS_setWriteDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
608 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
609 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
610 |
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
611 |
{ |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
612 |
PhysDirInfo *di; |
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
613 |
PhysDirInfo *prev = NULL; |
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
614 |
PhysDirInfo *i; |
51
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
615 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
616 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
617 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
618 |
for (i = searchPath; i != NULL; i = i->next) |
51
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
619 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
620 |
/* already in search path? */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
621 |
BAIL_IF_MACRO_MUTEX(strcmp(newDir, i->dirName)==0, NULL, stateLock, 1); |
51
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
622 |
prev = i; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
623 |
} /* for */ |
51
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
624 |
|
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
625 |
di = buildDirInfo(newDir, 0); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
626 |
BAIL_IF_MACRO_MUTEX(di == NULL, NULL, stateLock, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
627 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
628 |
if (appendToPath) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
629 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
630 |
di->next = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
631 |
if (prev == NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
632 |
searchPath = di; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
633 |
else |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
634 |
prev->next = di; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
635 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
636 |
else |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
637 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
638 |
di->next = searchPath; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
639 |
searchPath = di; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
640 |
} /* else */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
641 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
642 |
__PHYSFS_platformReleaseMutex(stateLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 |
return(1); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
644 |
} /* PHYSFS_addToSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
645 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
646 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
647 |
int PHYSFS_removeFromSearchPath(const char *oldDir) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 |
{ |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
649 |
PhysDirInfo *i; |
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
650 |
PhysDirInfo *prev = NULL; |
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
651 |
PhysDirInfo *next = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
652 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
653 |
BAIL_IF_MACRO(oldDir == NULL, ERR_INVALID_ARGUMENT, 0); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
654 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
655 |
__PHYSFS_platformGrabMutex(stateLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
656 |
for (i = searchPath; i != NULL; i = i->next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
657 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
658 |
if (strcmp(i->dirName, oldDir) == 0) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
659 |
{ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
660 |
next = i->next; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
661 |
BAIL_IF_MACRO_MUTEX(!freeDirInfo(i, openReadList), NULL, |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
662 |
stateLock, 0); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
663 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
664 |
if (prev == NULL) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
665 |
searchPath = next; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
666 |
else |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
667 |
prev->next = next; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
668 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
669 |
BAIL_MACRO_MUTEX(NULL, stateLock, 1); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
670 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
671 |
prev = i; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
672 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
673 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
674 |
BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
675 |
} /* PHYSFS_removeFromSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
676 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
677 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
678 |
char **PHYSFS_getSearchPath(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
679 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
680 |
int count = 1; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
681 |
int x; |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
682 |
PhysDirInfo *i; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
683 |
char **retval; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
684 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
685 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
686 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
687 |
for (i = searchPath; i != NULL; i = i->next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
688 |
count++; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
689 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
690 |
retval = (char **) malloc(sizeof (char *) * count); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
691 |
BAIL_IF_MACRO_MUTEX(!retval, ERR_OUT_OF_MEMORY, stateLock, NULL); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
692 |
count--; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
693 |
retval[count] = NULL; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
694 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
695 |
for (i = searchPath, x = 0; x < count; i = i->next, x++) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
696 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 |
retval[x] = (char *) malloc(strlen(i->dirName) + 1); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
698 |
if (retval[x] == NULL) /* this is friggin' ugly. */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
699 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
700 |
while (x > 0) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
701 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
702 |
x--; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
703 |
free(retval[x]); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
704 |
} /* while */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
705 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
706 |
free(retval); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
707 |
BAIL_MACRO_MUTEX(ERR_OUT_OF_MEMORY, stateLock, NULL); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
708 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
709 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
710 |
strcpy(retval[x], i->dirName); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
711 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
712 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
713 |
__PHYSFS_platformReleaseMutex(stateLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
714 |
return(retval); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
715 |
} /* PHYSFS_getSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
716 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
717 |
|
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
718 |
int PHYSFS_setSaneConfig(const char *organization, const char *appName, |
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
719 |
const char *archiveExt, int includeCdRoms, |
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
720 |
int archivesFirst) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
721 |
{ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
722 |
const char *basedir = PHYSFS_getBaseDir(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
723 |
const char *userdir = PHYSFS_getUserDir(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
724 |
const char *dirsep = PHYSFS_getDirSeparator(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
725 |
char *str; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
726 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
727 |
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
728 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
729 |
/* set write dir... */ |
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
730 |
str = malloc(strlen(userdir) + (strlen(organization) * 2) + |
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
731 |
(strlen(appName) * 2) + (strlen(dirsep) * 3) + 2); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
732 |
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0); |
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
733 |
sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
734 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
735 |
if (!PHYSFS_setWriteDir(str)) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
736 |
{ |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
737 |
int no_write = 0; |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
738 |
sprintf(str, ".%s/%s", organization, appName); |
103
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
739 |
if ( (PHYSFS_setWriteDir(userdir)) && |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
740 |
(PHYSFS_mkdir(str)) ) |
103
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
741 |
{ |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
742 |
sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName); |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
743 |
if (!PHYSFS_setWriteDir(str)) |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
744 |
no_write = 1; |
103
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
745 |
} /* if */ |
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
746 |
else |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
747 |
{ |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
748 |
no_write = 1; |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
749 |
} /* else */ |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
750 |
|
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
751 |
if (no_write) |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
752 |
{ |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
753 |
PHYSFS_setWriteDir(NULL); /* just in case. */ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
754 |
free(str); |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
755 |
BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0); |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
756 |
} /* if */ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
757 |
} /* if */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
758 |
|
103
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
759 |
/* Put write dir first in search path... */ |
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
760 |
PHYSFS_addToSearchPath(str, 0); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
761 |
free(str); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
762 |
|
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
763 |
/* Put base path on search path... */ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
764 |
PHYSFS_addToSearchPath(basedir, 1); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
765 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
766 |
/* handle CD-ROMs... */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
767 |
if (includeCdRoms) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
768 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
769 |
char **cds = PHYSFS_getCdRomDirs(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
770 |
char **i; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
771 |
for (i = cds; *i != NULL; i++) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
772 |
PHYSFS_addToSearchPath(*i, 1); |
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
773 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
774 |
PHYSFS_freeList(cds); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
775 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
776 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
777 |
/* Root out archives, and add them to search path... */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
778 |
if (archiveExt != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
779 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
780 |
char **rc = PHYSFS_enumerateFiles(""); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
781 |
char **i; |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
782 |
size_t extlen = strlen(archiveExt); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
783 |
char *ext; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
784 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
785 |
for (i = rc; *i != NULL; i++) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
786 |
{ |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
787 |
size_t l = strlen(*i); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
788 |
if ((l > extlen) && ((*i)[l - extlen - 1] == '.')) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
789 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
790 |
ext = (*i) + (l - extlen); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
791 |
if (__PHYSFS_platformStricmp(ext, archiveExt) == 0) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
792 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
793 |
const char *d = PHYSFS_getRealDir(*i); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
794 |
str = malloc(strlen(d) + strlen(dirsep) + l + 1); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
795 |
if (str != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
796 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
797 |
sprintf(str, "%s%s%s", d, dirsep, *i); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
798 |
PHYSFS_addToSearchPath(str, archivesFirst == 0); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
799 |
free(str); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
800 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
801 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
802 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
803 |
} /* for */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
804 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
805 |
PHYSFS_freeList(rc); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
806 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
807 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
808 |
return(1); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
809 |
} /* PHYSFS_setSaneConfig */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
810 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
811 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
812 |
void PHYSFS_permitSymbolicLinks(int allow) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
813 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
814 |
allowSymLinks = allow; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
815 |
} /* PHYSFS_permitSymbolicLinks */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
816 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
817 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
818 |
/* string manipulation in C makes my ass itch. */ |
74
a4a5066fb640
Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents:
66
diff
changeset
|
819 |
char * __PHYSFS_convertToDependent(const char *prepend, |
a4a5066fb640
Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents:
66
diff
changeset
|
820 |
const char *dirName, |
a4a5066fb640
Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents:
66
diff
changeset
|
821 |
const char *append) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
822 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
823 |
const char *dirsep = __PHYSFS_platformDirSeparator; |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
824 |
size_t sepsize = strlen(dirsep); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
825 |
char *str; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
826 |
char *i1; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
827 |
char *i2; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
828 |
size_t allocSize; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
829 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
830 |
while (*dirName == '/') |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
831 |
dirName++; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
832 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
833 |
allocSize = strlen(dirName) + 1; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
834 |
if (prepend != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
835 |
allocSize += strlen(prepend) + sepsize; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
836 |
if (append != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
837 |
allocSize += strlen(append) + sepsize; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
838 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
839 |
/* make sure there's enough space if the dir separator is bigger. */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
840 |
if (sepsize > 1) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
841 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
842 |
str = (char *) dirName; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
843 |
do |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
844 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
845 |
str = strchr(str, '/'); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
846 |
if (str != NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
847 |
{ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
848 |
allocSize += (sepsize - 1); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
849 |
str++; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
850 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
851 |
} while (str != NULL); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
852 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
853 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
854 |
str = (char *) malloc(allocSize); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
855 |
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
856 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
857 |
if (prepend == NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
858 |
*str = '\0'; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
859 |
else |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
860 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
861 |
strcpy(str, prepend); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
862 |
strcat(str, dirsep); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
863 |
} /* else */ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
864 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
865 |
for (i1 = (char *) dirName, i2 = str + strlen(str); *i1; i1++, i2++) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
866 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
867 |
if (*i1 == '/') |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
868 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
869 |
strcpy(i2, dirsep); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
870 |
i2 += sepsize; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
871 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
872 |
else |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
873 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
874 |
*i2 = *i1; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
875 |
} /* else */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
876 |
} /* for */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
877 |
*i2 = '\0'; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
878 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
879 |
if (append) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
880 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
881 |
strcat(str, dirsep); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
882 |
strcpy(str, append); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
883 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
884 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
885 |
return(str); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
886 |
} /* __PHYSFS_convertToDependent */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
887 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
888 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
889 |
int __PHYSFS_verifySecurity(DirHandle *h, const char *fname) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
890 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
891 |
int retval = 1; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
892 |
char *start; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
893 |
char *end; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
894 |
char *str; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
895 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
896 |
start = str = malloc(strlen(fname) + 1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
897 |
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
898 |
strcpy(str, fname); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
899 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
900 |
while (1) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
901 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
902 |
end = strchr(start, '/'); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
903 |
if (end != NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
904 |
*end = '\0'; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
905 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
906 |
if ( (strcmp(start, ".") == 0) || |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
907 |
(strcmp(start, "..") == 0) || |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
19
diff
changeset
|
908 |
(strchr(start, '\\') != NULL) || |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
909 |
(strchr(start, ':') != NULL) ) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
910 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
911 |
__PHYSFS_setError(ERR_INSECURE_FNAME); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
912 |
retval = 0; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
913 |
break; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
914 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
915 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
916 |
if ((!allowSymLinks) && (h->funcs->isSymLink(h, str))) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
917 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
918 |
__PHYSFS_setError(ERR_SYMLINK_DISALLOWED); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
919 |
retval = 0; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
920 |
break; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
921 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
922 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
923 |
if (end == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
924 |
break; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
925 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
926 |
*end = '/'; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
927 |
start = end + 1; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
928 |
} /* while */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
929 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
930 |
free(str); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
931 |
return(retval); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
932 |
} /* __PHYSFS_verifySecurity */ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
933 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
934 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
935 |
int PHYSFS_mkdir(const char *dname) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
936 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
937 |
DirHandle *h; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
938 |
char *str; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
939 |
char *start; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
940 |
char *end; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
941 |
int retval = 0; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
942 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
943 |
BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
944 |
while (*dname == '/') |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
945 |
dname++; |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
946 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
947 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
948 |
BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
949 |
h = writeDir->dirHandle; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
950 |
BAIL_IF_MACRO_MUTEX(!h->funcs->mkdir, ERR_NOT_SUPPORTED, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
951 |
BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, dname), NULL, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
952 |
start = str = malloc(strlen(dname) + 1); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
953 |
BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
954 |
strcpy(str, dname); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
955 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
956 |
while (1) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
957 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
958 |
end = strchr(start, '/'); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
959 |
if (end != NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
960 |
*end = '\0'; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
961 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
962 |
retval = h->funcs->mkdir(h, str); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
963 |
if (!retval) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
964 |
break; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
965 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
966 |
if (end == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
967 |
break; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
968 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
969 |
*end = '/'; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
970 |
start = end + 1; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
971 |
} /* while */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
972 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
973 |
__PHYSFS_platformReleaseMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
974 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
975 |
free(str); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
976 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
977 |
} /* PHYSFS_mkdir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
978 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
979 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
980 |
int PHYSFS_delete(const char *fname) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
981 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
982 |
int retval; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
983 |
DirHandle *h; |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
984 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
985 |
BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
986 |
while (*fname == '/') |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
987 |
fname++; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
988 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
989 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
990 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
991 |
BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
992 |
h = writeDir->dirHandle; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
993 |
BAIL_IF_MACRO_MUTEX(!h->funcs->remove, ERR_NOT_SUPPORTED, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
994 |
BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h, fname), NULL, stateLock, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
995 |
retval = h->funcs->remove(h, fname); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
996 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
997 |
__PHYSFS_platformReleaseMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
998 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
999 |
} /* PHYSFS_delete */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1000 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1001 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1002 |
const char *PHYSFS_getRealDir(const char *filename) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1003 |
{ |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
1004 |
PhysDirInfo *i; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1005 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1006 |
while (*filename == '/') |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1007 |
filename++; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1008 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1009 |
__PHYSFS_platformGrabMutex(stateLock); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1010 |
for (i = searchPath; i != NULL; i = i->next) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1011 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1012 |
DirHandle *h = i->dirHandle; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1013 |
if (__PHYSFS_verifySecurity(h, filename)) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1014 |
{ |
242
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1015 |
if (!h->funcs->exists(h, filename)) |
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1016 |
__PHYSFS_setError(ERR_NO_SUCH_FILE); |
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1017 |
else |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1018 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1019 |
__PHYSFS_platformReleaseMutex(stateLock); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1020 |
return(i->dirName); |
242
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1021 |
} /* else */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1022 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1023 |
} /* for */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1024 |
__PHYSFS_platformReleaseMutex(stateLock); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1025 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1026 |
return(NULL); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1027 |
} /* PHYSFS_getRealDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1028 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1029 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1030 |
static int countList(LinkedStringList *list) |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1031 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1032 |
int retval = 0; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1033 |
LinkedStringList *i; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1034 |
|
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1035 |
for (i = list; i != NULL; i = i->next) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1036 |
retval++; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1037 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1038 |
return(retval); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1039 |
} /* countList */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1040 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1041 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1042 |
static char **convertStringListToPhysFSList(LinkedStringList *finalList) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1043 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1044 |
int i; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1045 |
LinkedStringList *next = NULL; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1046 |
int len = countList(finalList); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1047 |
char **retval = (char **) malloc((len + 1) * sizeof (char *)); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1048 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1049 |
if (retval == NULL) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1050 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1051 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1052 |
for (i = 0; i < len; i++) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1053 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1054 |
next = finalList->next; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1055 |
if (retval == NULL) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1056 |
free(finalList->str); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1057 |
else |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1058 |
retval[i] = finalList->str; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1059 |
free(finalList); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1060 |
finalList = next; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1061 |
} /* for */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1062 |
|
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
1063 |
if (retval != NULL) |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1064 |
retval[i] = NULL; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1065 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1066 |
return(retval); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1067 |
} /* convertStringListToPhysFSList */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1068 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1069 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1070 |
static void insertStringListItem(LinkedStringList **final, |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1071 |
LinkedStringList *item) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1072 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1073 |
LinkedStringList *i; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1074 |
LinkedStringList *prev = NULL; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1075 |
int rc; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1076 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1077 |
for (i = *final; i != NULL; i = i->next) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1078 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1079 |
rc = strcmp(i->str, item->str); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1080 |
if (rc > 0) /* insertion point. */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1081 |
break; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1082 |
else if (rc == 0) /* already in list. */ |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1083 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1084 |
free(item->str); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1085 |
free(item); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1086 |
return; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1087 |
} /* else if */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1088 |
prev = i; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1089 |
} /* for */ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1090 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1091 |
/* |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1092 |
* If we are here, we are either at the insertion point. |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1093 |
* This may be the end of the list, or the list may be empty, too. |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1094 |
*/ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1095 |
if (prev == NULL) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1096 |
*final = item; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1097 |
else |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1098 |
prev->next = item; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1099 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1100 |
item->next = i; |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1101 |
} /* insertStringListItem */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1102 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1103 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1104 |
/* if we run out of memory anywhere in here, we give back what we can. */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1105 |
static void interpolateStringLists(LinkedStringList **final, |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1106 |
LinkedStringList *newList) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1107 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1108 |
LinkedStringList *next = NULL; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1109 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1110 |
while (newList != NULL) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1111 |
{ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1112 |
next = newList->next; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1113 |
insertStringListItem(final, newList); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1114 |
newList = next; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1115 |
} /* while */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1116 |
} /* interpolateStringLists */ |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1117 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1118 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1119 |
char **PHYSFS_enumerateFiles(const char *path) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1120 |
{ |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
1121 |
PhysDirInfo *i; |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1122 |
char **retval = NULL; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1123 |
LinkedStringList *rc; |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1124 |
LinkedStringList *finalList = NULL; |
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
1125 |
int omitSymLinks = !allowSymLinks; |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1126 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1127 |
BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1128 |
while (*path == '/') |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1129 |
path++; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1130 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1131 |
__PHYSFS_platformGrabMutex(stateLock); |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1132 |
for (i = searchPath; i != NULL; i = i->next) |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1133 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1134 |
DirHandle *h = i->dirHandle; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1135 |
if (__PHYSFS_verifySecurity(h, path)) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1136 |
{ |
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
1137 |
rc = h->funcs->enumerateFiles(h, path, omitSymLinks); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1138 |
interpolateStringLists(&finalList, rc); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1139 |
} /* if */ |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1140 |
} /* for */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1141 |
__PHYSFS_platformReleaseMutex(stateLock); |
12
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1142 |
|
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1143 |
retval = convertStringListToPhysFSList(finalList); |
a4041c91d715
Redesign of enumerateFiles code. More efficient and clean, less memory
Ryan C. Gordon <icculus@icculus.org>
parents:
11
diff
changeset
|
1144 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1145 |
} /* PHYSFS_enumerateFiles */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1146 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1147 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1148 |
int PHYSFS_exists(const char *fname) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1149 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1150 |
BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1151 |
while (*fname == '/') |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1152 |
fname++; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1153 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1154 |
return(PHYSFS_getRealDir(fname) != NULL); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1155 |
} /* PHYSFS_exists */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1156 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1157 |
|
240
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1158 |
PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname) |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1159 |
{ |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1160 |
PhysDirInfo *i; |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1161 |
|
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1162 |
BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0); |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1163 |
while (*fname == '/') |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1164 |
fname++; |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1165 |
|
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1166 |
if (*fname == '\0') /* eh...punt if it's the root dir. */ |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1167 |
return(1); |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1168 |
|
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1169 |
__PHYSFS_platformGrabMutex(stateLock); |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1170 |
for (i = searchPath; i != NULL; i = i->next) |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1171 |
{ |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1172 |
DirHandle *h = i->dirHandle; |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1173 |
if (__PHYSFS_verifySecurity(h, fname)) |
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1174 |
{ |
242
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1175 |
if (!h->funcs->exists(h, fname)) |
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1176 |
__PHYSFS_setError(ERR_NO_SUCH_FILE); |
3143cfd544a6
More proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
1177 |
else |
240
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
1178 |
{ |
242 |