author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 11 Mar 2012 03:43:07 -0400 | |
changeset 1211 | 09280603503b |
parent 1199 | fc5cec340d26 |
child 1218 | 643a34fc7c8f |
permissions | -rw-r--r-- |
235 | 1 |
/* |
2 |
* Posix-esque support routines for PhysicsFS. |
|
3 |
* |
|
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
4 |
* Please see the file LICENSE.txt in the source's root directory. |
235 | 5 |
* |
6 |
* This file written by Ryan C. Gordon. |
|
7 |
*/ |
|
8 |
||
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
9 |
#define __PHYSICSFS_INTERNAL__ |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
10 |
#include "physfs_platforms.h" |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
11 |
|
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
12 |
#ifdef PHYSFS_PLATFORM_POSIX |
310
f8bca4a93fd5
Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
292
diff
changeset
|
13 |
|
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
14 |
#include <unistd.h> |
235 | 15 |
#include <ctype.h> |
16 |
#include <sys/types.h> |
|
17 |
#include <sys/stat.h> |
|
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
18 |
#include <pwd.h> |
235 | 19 |
#include <dirent.h> |
20 |
#include <errno.h> |
|
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
21 |
#include <fcntl.h> |
235 | 22 |
|
1173
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
23 |
#if ((!defined PHYSFS_NO_THREAD_SUPPORT) && (!defined PHYSFS_PLATFORM_BEOS)) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
24 |
#include <pthread.h> |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
25 |
#endif |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
26 |
|
259
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
27 |
#ifdef PHYSFS_HAVE_LLSEEK |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
28 |
#include <linux/unistd.h> |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
29 |
#endif |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
30 |
|
235 | 31 |
#include "physfs_internal.h" |
32 |
||
33 |
||
847
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
34 |
const char *__PHYSFS_platformDirSeparator = "/"; |
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
35 |
|
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
36 |
|
235 | 37 |
char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname) |
38 |
{ |
|
39 |
const char *envr = getenv(varname); |
|
40 |
char *retval = NULL; |
|
41 |
||
42 |
if (envr != NULL) |
|
43 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
44 |
retval = (char *) allocator.Malloc(strlen(envr) + 1); |
235 | 45 |
if (retval != NULL) |
46 |
strcpy(retval, envr); |
|
47 |
} /* if */ |
|
48 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
49 |
return retval; |
235 | 50 |
} /* __PHYSFS_platformCopyEnvironmentVariable */ |
51 |
||
52 |
||
53 |
static char *getUserNameByUID(void) |
|
54 |
{ |
|
55 |
uid_t uid = getuid(); |
|
56 |
struct passwd *pw; |
|
57 |
char *retval = NULL; |
|
58 |
||
59 |
pw = getpwuid(uid); |
|
60 |
if ((pw != NULL) && (pw->pw_name != NULL)) |
|
61 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
62 |
retval = (char *) allocator.Malloc(strlen(pw->pw_name) + 1); |
235 | 63 |
if (retval != NULL) |
64 |
strcpy(retval, pw->pw_name); |
|
65 |
} /* if */ |
|
66 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
67 |
return retval; |
235 | 68 |
} /* getUserNameByUID */ |
69 |
||
70 |
||
71 |
static char *getUserDirByUID(void) |
|
72 |
{ |
|
73 |
uid_t uid = getuid(); |
|
74 |
struct passwd *pw; |
|
75 |
char *retval = NULL; |
|
76 |
||
77 |
pw = getpwuid(uid); |
|
78 |
if ((pw != NULL) && (pw->pw_dir != NULL)) |
|
79 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
80 |
retval = (char *) allocator.Malloc(strlen(pw->pw_dir) + 1); |
235 | 81 |
if (retval != NULL) |
82 |
strcpy(retval, pw->pw_dir); |
|
83 |
} /* if */ |
|
84 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
85 |
return retval; |
235 | 86 |
} /* getUserDirByUID */ |
87 |
||
88 |
||
89 |
char *__PHYSFS_platformGetUserName(void) |
|
90 |
{ |
|
91 |
char *retval = getUserNameByUID(); |
|
92 |
if (retval == NULL) |
|
93 |
retval = __PHYSFS_platformCopyEnvironmentVariable("USER"); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
94 |
return retval; |
235 | 95 |
} /* __PHYSFS_platformGetUserName */ |
96 |
||
97 |
||
98 |
char *__PHYSFS_platformGetUserDir(void) |
|
99 |
{ |
|
100 |
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME"); |
|
1073
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
101 |
|
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
102 |
/* if the environment variable was set, make sure it's really a dir. */ |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
103 |
if (retval != NULL) |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
104 |
{ |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
105 |
struct stat statbuf; |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
106 |
if ((stat(retval, &statbuf) == -1) || (S_ISDIR(statbuf.st_mode) == 0)) |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
107 |
{ |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
108 |
allocator.Free(retval); |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
109 |
retval = NULL; |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
110 |
} /* if */ |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
111 |
} /* if */ |
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
112 |
|
235 | 113 |
if (retval == NULL) |
114 |
retval = getUserDirByUID(); |
|
1073
b45193ab2033
See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
115 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
116 |
return retval; |
235 | 117 |
} /* __PHYSFS_platformGetUserDir */ |
118 |
||
119 |
||
120 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
|
121 |
const char *dirName, |
|
122 |
const char *append) |
|
123 |
{ |
|
124 |
int len = ((prepend) ? strlen(prepend) : 0) + |
|
125 |
((append) ? strlen(append) : 0) + |
|
126 |
strlen(dirName) + 1; |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
127 |
char *retval = (char *) allocator.Malloc(len); |
235 | 128 |
|
129 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
130 |
||
131 |
/* platform-independent notation is Unix-style already. :) */ |
|
132 |
||
133 |
if (prepend) |
|
134 |
strcpy(retval, prepend); |
|
135 |
else |
|
136 |
retval[0] = '\0'; |
|
137 |
||
138 |
strcat(retval, dirName); |
|
139 |
||
140 |
if (append) |
|
141 |
strcat(retval, append); |
|
142 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
143 |
return retval; |
235 | 144 |
} /* __PHYSFS_platformCvtToDependent */ |
145 |
||
146 |
||
147 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
148 |
void __PHYSFS_platformEnumerateFiles(const char *dirname, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
149 |
int omitSymLinks, |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
150 |
PHYSFS_EnumFilesCallback callback, |
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
151 |
const char *origdir, |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
152 |
void *callbackdata) |
235 | 153 |
{ |
154 |
DIR *dir; |
|
155 |
struct dirent *ent; |
|
156 |
int bufsize = 0; |
|
157 |
char *buf = NULL; |
|
158 |
int dlen = 0; |
|
159 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
160 |
if (omitSymLinks) /* !!! FIXME: this malloc sucks. */ |
235 | 161 |
{ |
162 |
dlen = strlen(dirname); |
|
163 |
bufsize = dlen + 256; |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
164 |
buf = (char *) allocator.Malloc(bufsize); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
165 |
if (buf == NULL) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
166 |
return; |
235 | 167 |
strcpy(buf, dirname); |
168 |
if (buf[dlen - 1] != '/') |
|
169 |
{ |
|
170 |
buf[dlen++] = '/'; |
|
171 |
buf[dlen] = '\0'; |
|
172 |
} /* if */ |
|
173 |
} /* if */ |
|
174 |
||
175 |
errno = 0; |
|
176 |
dir = opendir(dirname); |
|
177 |
if (dir == NULL) |
|
178 |
{ |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
179 |
allocator.Free(buf); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
180 |
return; |
235 | 181 |
} /* if */ |
182 |
||
362
ac8c846a0a66
Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
183 |
while ((ent = readdir(dir)) != NULL) |
235 | 184 |
{ |
185 |
if (strcmp(ent->d_name, ".") == 0) |
|
186 |
continue; |
|
187 |
||
188 |
if (strcmp(ent->d_name, "..") == 0) |
|
189 |
continue; |
|
190 |
||
191 |
if (omitSymLinks) |
|
192 |
{ |
|
1125
bcff76dbd9fd
Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1118
diff
changeset
|
193 |
PHYSFS_Stat statbuf; |
bcff76dbd9fd
Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1118
diff
changeset
|
194 |
int exists = 0; |
235 | 195 |
char *p; |
196 |
int len = strlen(ent->d_name) + dlen + 1; |
|
197 |
if (len > bufsize) |
|
198 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
199 |
p = (char *) allocator.Realloc(buf, len); |
235 | 200 |
if (p == NULL) |
201 |
continue; |
|
202 |
buf = p; |
|
203 |
bufsize = len; |
|
204 |
} /* if */ |
|
205 |
||
206 |
strcpy(buf + dlen, ent->d_name); |
|
1125
bcff76dbd9fd
Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents:
1118
diff
changeset
|
207 |
|
1199
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
208 |
if (!__PHYSFS_platformStat(buf, &exists, &statbuf)) |
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
209 |
continue; |
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
210 |
else if (!exists) |
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
211 |
continue; /* probably can't happen, but just in case. */ |
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
212 |
else if (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK) |
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
213 |
continue; |
235 | 214 |
} /* if */ |
215 |
||
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
216 |
callback(callbackdata, origdir, ent->d_name); |
235 | 217 |
} /* while */ |
218 |
||
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
219 |
allocator.Free(buf); |
235 | 220 |
closedir(dir); |
221 |
} /* __PHYSFS_platformEnumerateFiles */ |
|
222 |
||
223 |
||
1211
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
224 |
char *__PHYSFS_platformCurrentDir(void) |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
225 |
{ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
226 |
int allocSize = 64; |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
227 |
char *retval = NULL; |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
228 |
char *ptr; |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
229 |
|
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
230 |
do |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
231 |
{ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
232 |
allocSize *= 2; |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
233 |
ptr = (char *) allocator.Realloc(retval, allocSize); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
234 |
if (ptr == NULL) |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
235 |
{ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
236 |
if (retval != NULL) |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
237 |
allocator.Free(retval); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
238 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
239 |
} /* if */ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
240 |
|
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
241 |
retval = ptr; |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
242 |
ptr = getcwd(retval, allocSize); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
243 |
} while (ptr == NULL && errno == ERANGE); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
244 |
|
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
245 |
if (ptr == NULL && errno) |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
246 |
{ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
247 |
/* getcwd() failed , for example current directory not existing... */ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
248 |
if (retval != NULL) |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
249 |
allocator.Free(retval); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
250 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
251 |
} /* if */ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
252 |
|
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
253 |
/* try to shrink buffer... */ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
254 |
ptr = (char *) allocator.Realloc(retval, strlen(retval) + 1); |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
255 |
if (ptr != NULL) |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
256 |
retval = ptr; /* oh well if it failed. */ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
257 |
|
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
258 |
return retval; |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
259 |
} /* __PHYSFS_platformCurrentDir */ |
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
260 |
|
09280603503b
Moved __PHYSFS_platformCurrentDir() from Unix to POSIX sources.
Ryan C. Gordon <icculus@icculus.org>
parents:
1199
diff
changeset
|
261 |
|
235 | 262 |
int __PHYSFS_platformMkDir(const char *path) |
263 |
{ |
|
264 |
int rc; |
|
265 |
errno = 0; |
|
266 |
rc = mkdir(path, S_IRWXU); |
|
267 |
BAIL_IF_MACRO(rc == -1, strerror(errno), 0); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
268 |
return 1; |
235 | 269 |
} /* __PHYSFS_platformMkDir */ |
270 |
||
271 |
||
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
272 |
static void *doOpen(const char *filename, int mode) |
235 | 273 |
{ |
939
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
274 |
const int appending = (mode & O_APPEND); |
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
275 |
int fd; |
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
276 |
int *retval; |
235 | 277 |
errno = 0; |
278 |
||
939
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
279 |
/* O_APPEND doesn't actually behave as we'd like. */ |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
280 |
mode &= ~O_APPEND; |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
281 |
|
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
282 |
fd = open(filename, mode, S_IRUSR | S_IWUSR); |
292
99bf6ef5639a
Patched a bug where doOpen() reported success when the file couldn't be
Ryan C. Gordon <icculus@icculus.org>
parents:
259
diff
changeset
|
283 |
BAIL_IF_MACRO(fd < 0, strerror(errno), NULL); |
235 | 284 |
|
939
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
285 |
if (appending) |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
286 |
{ |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
287 |
if (lseek(fd, 0, SEEK_END) < 0) |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
288 |
{ |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
289 |
close(fd); |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
290 |
BAIL_MACRO(strerror(errno), NULL); |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
291 |
} /* if */ |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
292 |
} /* if */ |
684c583cb586
Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
293 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
294 |
retval = (int *) allocator.Malloc(sizeof (int)); |
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
295 |
if (retval == NULL) |
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
296 |
{ |
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
297 |
close(fd); |
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
298 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
299 |
} /* if */ |
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
300 |
|
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
301 |
*retval = fd; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
302 |
return ((void *) retval); |
235 | 303 |
} /* doOpen */ |
304 |
||
305 |
||
306 |
void *__PHYSFS_platformOpenRead(const char *filename) |
|
307 |
{ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
308 |
return doOpen(filename, O_RDONLY); |
235 | 309 |
} /* __PHYSFS_platformOpenRead */ |
310 |
||
311 |
||
312 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
|
313 |
{ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
314 |
return doOpen(filename, O_WRONLY | O_CREAT | O_TRUNC); |
235 | 315 |
} /* __PHYSFS_platformOpenWrite */ |
316 |
||
317 |
||
318 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
|
319 |
{ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
320 |
return doOpen(filename, O_WRONLY | O_CREAT | O_APPEND); |
235 | 321 |
} /* __PHYSFS_platformOpenAppend */ |
322 |
||
323 |
||
324 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
325 |
PHYSFS_uint64 len) |
235 | 326 |
{ |
1117 | 327 |
const int fd = *((int *) opaque); |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
328 |
ssize_t rc = 0; |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
329 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
330 |
BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); |
235 | 331 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
332 |
rc = read(fd, buffer, (size_t) len); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
333 |
BAIL_IF_MACRO(rc == -1, strerror(errno), (PHYSFS_sint64) rc); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
334 |
assert(rc >= 0); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
335 |
assert(rc <= len); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
336 |
return (PHYSFS_sint64) rc; |
235 | 337 |
} /* __PHYSFS_platformRead */ |
338 |
||
339 |
||
340 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
341 |
PHYSFS_uint64 len) |
235 | 342 |
{ |
1117 | 343 |
const int fd = *((int *) opaque); |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
344 |
ssize_t rc = 0; |
235 | 345 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
346 |
BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
347 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
348 |
rc = write(fd, (void *) buffer, (size_t) len); |
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
349 |
BAIL_IF_MACRO(rc == -1, strerror(errno), rc); |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
350 |
assert(rc >= 0); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
351 |
assert(rc <= len); |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1073
diff
changeset
|
352 |
return (PHYSFS_sint64) rc; |
235 | 353 |
} /* __PHYSFS_platformWrite */ |
354 |
||
355 |
||
356 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
|
357 |
{ |
|
1117 | 358 |
const int fd = *((int *) opaque); |
235 | 359 |
|
259
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
360 |
#ifdef PHYSFS_HAVE_LLSEEK |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
361 |
unsigned long offset_high = ((pos >> 32) & 0xFFFFFFFF); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
362 |
unsigned long offset_low = (pos & 0xFFFFFFFF); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
363 |
loff_t retoffset; |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
364 |
int rc = llseek(fd, offset_high, offset_low, &retoffset, SEEK_SET); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
365 |
BAIL_IF_MACRO(rc == -1, strerror(errno), 0); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
366 |
#else |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
367 |
BAIL_IF_MACRO(lseek(fd, (int) pos, SEEK_SET) == -1, strerror(errno), 0); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
368 |
#endif |
235 | 369 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
370 |
return 1; |
235 | 371 |
} /* __PHYSFS_platformSeek */ |
372 |
||
373 |
||
374 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
|
375 |
{ |
|
1117 | 376 |
const int fd = *((int *) opaque); |
259
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
377 |
PHYSFS_sint64 retval; |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
378 |
|
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
379 |
#ifdef PHYSFS_HAVE_LLSEEK |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
380 |
loff_t retoffset; |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
381 |
int rc = llseek(fd, 0, &retoffset, SEEK_CUR); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
382 |
BAIL_IF_MACRO(rc == -1, strerror(errno), -1); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
383 |
retval = (PHYSFS_sint64) retoffset; |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
384 |
#else |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
385 |
retval = (PHYSFS_sint64) lseek(fd, 0, SEEK_CUR); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
386 |
BAIL_IF_MACRO(retval == -1, strerror(errno), -1); |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
387 |
#endif |
bd65a0d74e9a
64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents:
255
diff
changeset
|
388 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
389 |
return retval; |
235 | 390 |
} /* __PHYSFS_platformTell */ |
391 |
||
392 |
||
393 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
|
394 |
{ |
|
1117 | 395 |
const int fd = *((int *) opaque); |
235 | 396 |
struct stat statbuf; |
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
397 |
BAIL_IF_MACRO(fstat(fd, &statbuf) == -1, strerror(errno), -1); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
398 |
return ((PHYSFS_sint64) statbuf.st_size); |
235 | 399 |
} /* __PHYSFS_platformFileLength */ |
400 |
||
401 |
||
402 |
int __PHYSFS_platformFlush(void *opaque) |
|
403 |
{ |
|
1117 | 404 |
const int fd = *((int *) opaque); |
251
0f4615263e32
Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents:
249
diff
changeset
|
405 |
BAIL_IF_MACRO(fsync(fd) == -1, strerror(errno), 0); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
406 |
return 1; |
235 | 407 |
} /* __PHYSFS_platformFlush */ |
408 |
||
409 |
||
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1117
diff
changeset
|
410 |
void __PHYSFS_platformClose(void *opaque) |
235 | 411 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1117
diff
changeset
|
412 |
const int fd = *((int *) opaque); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1117
diff
changeset
|
413 |
(void) close(fd); /* we don't check this. You should have used flush! */ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
414 |
allocator.Free(opaque); |
235 | 415 |
} /* __PHYSFS_platformClose */ |
416 |
||
417 |
||
418 |
int __PHYSFS_platformDelete(const char *path) |
|
419 |
{ |
|
420 |
BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
421 |
return 1; |
235 | 422 |
} /* __PHYSFS_platformDelete */ |
423 |
||
240
052041af9001
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents:
235
diff
changeset
|
424 |
|
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
425 |
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *st) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
426 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
427 |
struct stat statbuf; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
428 |
|
1199
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
429 |
if (lstat(filename, &statbuf) == -1) |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
430 |
{ |
1199
fc5cec340d26
Cleaned up some __PHYSFS_platformStat() details.
Ryan C. Gordon <icculus@icculus.org>
parents:
1176
diff
changeset
|
431 |
*exists = (errno == ENOENT); |
1106
94c3669d0311
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1098
diff
changeset
|
432 |
BAIL_MACRO(strerror(errno), 0); |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
433 |
} /* if */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
434 |
|
1167
9d84f8652839
POSIX version of __PHYSFS_platformStat() forgot to set *exists properly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
435 |
*exists = 1; |
9d84f8652839
POSIX version of __PHYSFS_platformStat() forgot to set *exists properly.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
436 |
|
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
437 |
if (S_ISREG(statbuf.st_mode)) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
438 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
439 |
st->filetype = PHYSFS_FILETYPE_REGULAR; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
440 |
st->filesize = statbuf.st_size; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
441 |
} /* if */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
442 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
443 |
else if(S_ISDIR(statbuf.st_mode)) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
444 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
445 |
st->filetype = PHYSFS_FILETYPE_DIRECTORY; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
446 |
st->filesize = 0; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
447 |
} /* else if */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
448 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
449 |
else |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
450 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
451 |
st->filetype = PHYSFS_FILETYPE_OTHER; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
452 |
st->filesize = statbuf.st_size; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
453 |
} /* else */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
454 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
455 |
st->modtime = statbuf.st_mtime; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
456 |
st->createtime = statbuf.st_ctime; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
457 |
st->accesstime = statbuf.st_atime; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
458 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
459 |
/* !!! FIXME: maybe we should just report full permissions? */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
460 |
st->readonly = access(filename, W_OK); |
1106
94c3669d0311
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1098
diff
changeset
|
461 |
return 1; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
462 |
} /* __PHYSFS_platformStat */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
463 |
|
1173
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
464 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
465 |
#ifndef PHYSFS_PLATFORM_BEOS /* BeOS has its own code in platform_beos.cpp */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
466 |
#if (defined PHYSFS_NO_THREAD_SUPPORT) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
467 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
468 |
void *__PHYSFS_platformGetThreadID(void) { return ((void *) 0x0001); } |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
469 |
void *__PHYSFS_platformCreateMutex(void) { return ((void *) 0x0001); } |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
470 |
void __PHYSFS_platformDestroyMutex(void *mutex) {} |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
471 |
int __PHYSFS_platformGrabMutex(void *mutex) { return 1; } |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
472 |
void __PHYSFS_platformReleaseMutex(void *mutex) {} |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
473 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
474 |
#else |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
475 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
476 |
typedef struct |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
477 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
478 |
pthread_mutex_t mutex; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
479 |
pthread_t owner; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
480 |
PHYSFS_uint32 count; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
481 |
} PthreadMutex; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
482 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
483 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
484 |
void *__PHYSFS_platformGetThreadID(void) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
485 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
486 |
return ( (void *) ((size_t) pthread_self()) ); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
487 |
} /* __PHYSFS_platformGetThreadID */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
488 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
489 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
490 |
void *__PHYSFS_platformCreateMutex(void) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
491 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
492 |
int rc; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
493 |
PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex)); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
494 |
BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
495 |
rc = pthread_mutex_init(&m->mutex, NULL); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
496 |
if (rc != 0) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
497 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
498 |
allocator.Free(m); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
499 |
BAIL_MACRO(strerror(rc), NULL); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
500 |
} /* if */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
501 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
502 |
m->count = 0; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
503 |
m->owner = (pthread_t) 0xDEADBEEF; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
504 |
return ((void *) m); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
505 |
} /* __PHYSFS_platformCreateMutex */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
506 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
507 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
508 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
509 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
510 |
PthreadMutex *m = (PthreadMutex *) mutex; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
511 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
512 |
/* Destroying a locked mutex is a bug, but we'll try to be helpful. */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
513 |
if ((m->owner == pthread_self()) && (m->count > 0)) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
514 |
pthread_mutex_unlock(&m->mutex); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
515 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
516 |
pthread_mutex_destroy(&m->mutex); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
517 |
allocator.Free(m); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
518 |
} /* __PHYSFS_platformDestroyMutex */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
519 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
520 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
521 |
int __PHYSFS_platformGrabMutex(void *mutex) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
522 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
523 |
PthreadMutex *m = (PthreadMutex *) mutex; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
524 |
pthread_t tid = pthread_self(); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
525 |
if (m->owner != tid) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
526 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
527 |
if (pthread_mutex_lock(&m->mutex) != 0) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
528 |
return 0; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
529 |
m->owner = tid; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
530 |
} /* if */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
531 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
532 |
m->count++; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
533 |
return 1; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
534 |
} /* __PHYSFS_platformGrabMutex */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
535 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
536 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
537 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
538 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
539 |
PthreadMutex *m = (PthreadMutex *) mutex; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
540 |
if (m->owner == pthread_self()) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
541 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
542 |
if (--m->count == 0) |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
543 |
{ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
544 |
m->owner = (pthread_t) 0xDEADBEEF; |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
545 |
pthread_mutex_unlock(&m->mutex); |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
546 |
} /* if */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
547 |
} /* if */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
548 |
} /* __PHYSFS_platformReleaseMutex */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
549 |
|
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
550 |
#endif /* !PHYSFS_NO_THREAD_SUPPORT */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
551 |
#endif /* !PHYSFS_PLATFORM_BEOS */ |
77b2df665bd1
Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents:
1167
diff
changeset
|
552 |
|
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
553 |
#endif /* PHYSFS_PLATFORM_POSIX */ |
310
f8bca4a93fd5
Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
292
diff
changeset
|
554 |
|
235 | 555 |
/* end of posix.c ... */ |
556 |