author | Ryan C. Gordon <icculus@icculus.org> |
Tue, 23 Jul 2002 07:48:08 +0000 | |
changeset 363 | 79f155a51527 |
parent 351 | bc4fa7896225 |
child 381 | b65d27fdc8a9 |
permissions | -rw-r--r-- |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* Unix support routines for PhysicsFS. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* Please see the file LICENSE in the source's root directory. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* This file written by Ryan C. Gordon. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
*/ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
9 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
10 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
11 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
12 |
|
327
76e207c6b4a7
Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
316
diff
changeset
|
13 |
/* BeOS uses beos.cpp and posix.c ... Cygwin and such use win32.c ... */ |
76e207c6b4a7
Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
316
diff
changeset
|
14 |
#if ((!defined __BEOS__) && (!defined WIN32)) |
310
f8bca4a93fd5
Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
273
diff
changeset
|
15 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
#include <stdio.h> |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
#include <stdlib.h> |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
18 |
#include <string.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
19 |
#include <ctype.h> |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
#include <pthread.h> |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
21 |
#include <unistd.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
22 |
#include <sys/types.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
23 |
#include <pwd.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
24 |
#include <sys/stat.h> |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
25 |
#include <sys/param.h> |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
26 |
#include <dirent.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
27 |
#include <time.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
28 |
#include <errno.h> |
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
29 |
#include <sys/mount.h> |
188 | 30 |
|
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
31 |
#ifdef PHYSFS_HAVE_SYS_UCRED_H |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
32 |
# ifdef PHYSFS_HAVE_MNTENT_H |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
33 |
# undef PHYSFS_HAVE_MNTENT_H /* don't do both... */ |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
34 |
# endif |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
35 |
# include <sys/ucred.h> |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
36 |
#endif |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
37 |
|
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
38 |
#ifdef PHYSFS_HAVE_MNTENT_H |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
39 |
#include <mntent.h> |
188 | 40 |
#endif |
41 |
||
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
#define __PHYSICSFS_INTERNAL__ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
#include "physfs_internal.h" |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
const char *__PHYSFS_platformDirSeparator = "/"; |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
48 |
|
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
49 |
int __PHYSFS_platformInit(void) |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
50 |
{ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
51 |
return(1); /* always succeed. */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
52 |
} /* __PHYSFS_platformInit */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
53 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
54 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
55 |
int __PHYSFS_platformDeinit(void) |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
56 |
{ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
57 |
return(1); /* always succeed. */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
58 |
} /* __PHYSFS_platformDeinit */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
59 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
60 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
61 |
|
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
62 |
#ifdef PHYSFS_HAVE_SYS_UCRED_H |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
63 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
64 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
65 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
66 |
char **retval = (char **) malloc(sizeof (char *)); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
67 |
int cd_count = 1; /* We count the NULL entry. */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
68 |
struct statfs* mntbufp = NULL; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
69 |
int mounts; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
70 |
int ii; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
71 |
|
171
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
72 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
73 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
74 |
mounts = getmntinfo( &mntbufp, MNT_WAIT ); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
75 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
76 |
for ( ii=0; ii < mounts; ++ii ) { |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
77 |
int add_it = 0; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
78 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
79 |
if ( strcmp( mntbufp[ii].f_fstypename, "iso9660") == 0 ) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
80 |
add_it = 1; |
191 | 81 |
else if ( strcmp( mntbufp[ii].f_fstypename, "cd9660") == 0 ) |
82 |
add_it = 1; |
|
225 | 83 |
|
84 |
/* add other mount types here */ |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
85 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
86 |
if (add_it) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
87 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
88 |
char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1)); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
89 |
if (tmp) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
90 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
91 |
retval = tmp; |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
92 |
retval[cd_count - 1] = (char *) |
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
93 |
malloc(strlen(mntbufp[ii].f_mntonname) + 1); |
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
94 |
if (retval[cd_count - 1]) |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
95 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
96 |
strcpy(retval[cd_count - 1], mntbufp[ii].f_mntonname); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
97 |
cd_count++; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
98 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
99 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
100 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
101 |
} |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
102 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
103 |
retval[cd_count - 1] = NULL; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
104 |
return(retval); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
105 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
106 |
|
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
107 |
#endif |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
108 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
109 |
|
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
110 |
#ifdef PHYSFS_HAVE_MNTENT_H |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
111 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
{ |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
114 |
char **retval = (char **) malloc(sizeof (char *)); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
115 |
int cd_count = 1; /* We count the NULL entry. */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
116 |
FILE *mounts = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
117 |
struct mntent *ent = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
118 |
|
171
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
119 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
120 |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
121 |
*retval = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
122 |
mounts = setmntent("/etc/mtab", "r"); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
123 |
BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, retval); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
124 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
125 |
while ( (ent = getmntent(mounts)) != NULL ) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
126 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
127 |
int add_it = 0; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
128 |
if (strcmp(ent->mnt_type, "iso9660") == 0) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
129 |
add_it = 1; |
225 | 130 |
|
131 |
/* add other mount types here */ |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
132 |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
133 |
if (add_it) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
134 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
135 |
char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1)); |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
136 |
if (tmp) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
137 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
138 |
retval = tmp; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
139 |
retval[cd_count-1] = (char *) malloc(strlen(ent->mnt_dir) + 1); |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
140 |
if (retval[cd_count - 1]) |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
141 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
142 |
strcpy(retval[cd_count - 1], ent->mnt_dir); |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
143 |
cd_count++; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
144 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
145 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
146 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
147 |
} /* while */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
148 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
149 |
endmntent(mounts); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
150 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
151 |
retval[cd_count - 1] = NULL; |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
152 |
return(retval); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
153 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
154 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
155 |
#endif |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
|
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
158 |
/* this is in posix.c ... */ |
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
159 |
extern char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
160 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
161 |
|
225 | 162 |
/* |
163 |
* See where program (bin) resides in the $PATH specified by (envr). |
|
164 |
* returns a copy of the first element in envr that contains it, or NULL |
|
165 |
* if it doesn't exist or there were other problems. PHYSFS_SetError() is |
|
166 |
* called if we have a problem. |
|
167 |
* |
|
168 |
* (envr) will be scribbled over, and you are expected to free() the |
|
169 |
* return value when you're done with it. |
|
170 |
*/ |
|
171 |
static char *findBinaryInPath(const char *bin, char *envr) |
|
172 |
{ |
|
173 |
size_t alloc_size = 0; |
|
174 |
char *exe = NULL; |
|
175 |
char *start = envr; |
|
176 |
char *ptr; |
|
177 |
||
178 |
BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL); |
|
179 |
BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL); |
|
180 |
||
181 |
do |
|
182 |
{ |
|
183 |
size_t size; |
|
184 |
ptr = strchr(start, ':'); /* find next $PATH separator. */ |
|
185 |
if (ptr) |
|
186 |
*ptr = '\0'; |
|
187 |
||
188 |
size = strlen(start) + strlen(bin) + 2; |
|
189 |
if (size > alloc_size) |
|
190 |
{ |
|
191 |
char *x = (char *) realloc(exe, size); |
|
192 |
if (x == NULL) |
|
193 |
{ |
|
194 |
if (exe != NULL) |
|
195 |
free(exe); |
|
196 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
|
197 |
} /* if */ |
|
198 |
||
199 |
alloc_size = size; |
|
200 |
exe = x; |
|
201 |
} /* if */ |
|
202 |
||
203 |
/* build full binary path... */ |
|
204 |
strcpy(exe, start); |
|
205 |
if (exe[strlen(exe) - 1] != '/') |
|
206 |
strcat(exe, "/"); |
|
207 |
strcat(exe, bin); |
|
208 |
||
209 |
if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */ |
|
210 |
{ |
|
211 |
strcpy(exe, start); /* i'm lazy. piss off. */ |
|
212 |
return(exe); |
|
213 |
} /* if */ |
|
214 |
||
215 |
start = ptr + 1; /* start points to beginning of next element. */ |
|
216 |
} while (ptr != NULL); |
|
217 |
||
218 |
if (exe != NULL) |
|
219 |
free(exe); |
|
220 |
||
221 |
return(NULL); /* doesn't exist in path. */ |
|
222 |
} /* findBinaryInPath */ |
|
223 |
||
224 |
||
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
225 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
226 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
227 |
/* If there isn't a path on argv0, then look through the $PATH for it. */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
228 |
|
225 | 229 |
char *retval; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
230 |
char *envr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
231 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
232 |
if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
233 |
return(NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
234 |
|
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
235 |
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH"); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
236 |
BAIL_IF_MACRO(!envr, NULL, NULL); |
225 | 237 |
retval = findBinaryInPath(argv0, envr); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
238 |
free(envr); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
239 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
240 |
} /* __PHYSFS_platformCalcBaseDir */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
241 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
242 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
243 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
{ |
188 | 245 |
return((PHYSFS_uint64) ((PHYSFS_uint32) pthread_self())); |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
} /* __PHYSFS_platformGetThreadID */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
249 |
/* Much like my college days, try to sleep for 10 milliseconds at a time... */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
250 |
void __PHYSFS_platformTimeslice(void) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
251 |
{ |
115
c0671785777b
Changed timeslice implementation to use something more portable (thanks to
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
252 |
usleep( 10 * 1000 ); /* don't care if it fails. */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
253 |
} /* __PHYSFS_platformTimeslice */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
254 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
255 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
256 |
char *__PHYSFS_platformRealPath(const char *path) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
257 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
258 |
char resolved_path[MAXPATHLEN]; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
259 |
char *retval = NULL; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
260 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
261 |
errno = 0; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
262 |
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL); |
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
263 |
retval = (char *) malloc(strlen(resolved_path) + 1); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
264 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
265 |
strcpy(retval, resolved_path); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
266 |
return(retval); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
267 |
} /* __PHYSFS_platformRealPath */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
268 |
|
69
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
269 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
270 |
void *__PHYSFS_platformCreateMutex(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
271 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
272 |
int rc; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
273 |
pthread_mutex_t *m = (pthread_mutex_t *) malloc(sizeof (pthread_mutex_t)); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
274 |
BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
275 |
rc = pthread_mutex_init(m, NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
276 |
if (rc != 0) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
277 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
278 |
free(m); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
279 |
BAIL_MACRO(strerror(rc), NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
280 |
} /* if */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
281 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
282 |
return((void *) m); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
283 |
} /* __PHYSFS_platformCreateMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
284 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
285 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
286 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
287 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
288 |
pthread_mutex_destroy((pthread_mutex_t *) mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
289 |
free(mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
290 |
} /* __PHYSFS_platformDestroyMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
291 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
292 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
293 |
int __PHYSFS_platformGrabMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
294 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
295 |
return(pthread_mutex_lock((pthread_mutex_t *) mutex) == 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
296 |
} /* __PHYSFS_platformGrabMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
297 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
298 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
299 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
300 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
301 |
pthread_mutex_unlock((pthread_mutex_t *) mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
302 |
} /* __PHYSFS_platformReleaseMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
303 |
|
330 | 304 |
#endif /* !defined __BEOS__ && !defined WIN32 */ |
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
305 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
/* end of unix.c ... */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |