author | Ryan C. Gordon <icculus@icculus.org> |
Fri, 10 May 2002 09:28:25 +0000 | |
changeset 216 | d297da72cd4e |
parent 214 | 19846c18071b |
child 220 | 96de4a3cd8fb |
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 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
13 |
#if ((defined __APPLE__) && (defined __MACH__)) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
14 |
# if (!defined __DARWIN__) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
15 |
# define __DARWIN__ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
16 |
# endif |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
17 |
#endif |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
18 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
19 |
#if (defined __STRICT_ANSI__) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
20 |
#define __PHYSFS_DOING_STRICT_ANSI__ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
21 |
#endif |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
22 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
23 |
/* |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
24 |
* We cheat a little: I want the symlink version of stat() (lstat), and |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
25 |
* GCC/Linux will not declare it if compiled with the -ansi flag. |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
26 |
* If you are really lacking symlink support on your platform, |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
27 |
* you should #define __PHYSFS_NO_SYMLINKS__ before compiling this |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
28 |
* file. That will open a security hole, though, if you really DO have |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
29 |
* symlinks on your platform; it renders PHYSFS_permitSymbolicLinks(0) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
30 |
* useless, since every symlink will be reported as a regular file/dir. |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
31 |
*/ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
32 |
#if (defined __PHYSFS_DOING_STRICT_ANSI__) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
33 |
#undef __STRICT_ANSI__ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
34 |
#endif |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
#include <stdio.h> |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
36 |
#if (defined __PHYSFS_DOING_STRICT_ANSI__) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
37 |
#define __STRICT_ANSI__ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
38 |
#endif |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
39 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
#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
|
41 |
#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
|
42 |
#include <ctype.h> |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
#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
|
44 |
#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
|
45 |
#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
|
46 |
#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
|
47 |
#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
|
48 |
#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
|
49 |
#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
|
50 |
#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
|
51 |
#include <errno.h> |
188 | 52 |
|
53 |
#if (!defined __DARWIN__) |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
54 |
#include <mntent.h> |
188 | 55 |
#else |
56 |
#include <sys/ucred.h> |
|
57 |
#endif |
|
58 |
||
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
59 |
#include <sys/mount.h> |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
60 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
#define __PHYSICSFS_INTERNAL__ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
#include "physfs_internal.h" |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
const char *__PHYSFS_platformDirSeparator = "/"; |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
68 |
|
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
69 |
int __PHYSFS_platformInit(void) |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
70 |
{ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
71 |
return(1); /* always succeed. */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
72 |
} /* __PHYSFS_platformInit */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
73 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
74 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
75 |
int __PHYSFS_platformDeinit(void) |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
76 |
{ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
77 |
return(1); /* always succeed. */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
78 |
} /* __PHYSFS_platformDeinit */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
79 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
80 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
81 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
82 |
#if (defined __DARWIN__) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
83 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
84 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
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 |
char **retval = (char **) malloc(sizeof (char *)); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
87 |
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
|
88 |
struct statfs* mntbufp = NULL; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
89 |
int mounts; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
90 |
int ii; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
91 |
|
171
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
92 |
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
|
93 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
94 |
mounts = getmntinfo( &mntbufp, MNT_WAIT ); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
95 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
96 |
for ( ii=0; ii < mounts; ++ii ) { |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
97 |
int add_it = 0; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
98 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
99 |
if ( strcmp( mntbufp[ii].f_fstypename, "iso9660") == 0 ) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
100 |
add_it = 1; |
191 | 101 |
else if ( strcmp( mntbufp[ii].f_fstypename, "cd9660") == 0 ) |
102 |
add_it = 1; |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
103 |
/* !!! other mount types? */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
104 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
105 |
if (add_it) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
106 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
107 |
char **tmp = realloc(retval, sizeof (char *) * cd_count + 1); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
108 |
if (tmp) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
109 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
110 |
retval = tmp; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
111 |
retval[cd_count-1] = (char *) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
112 |
malloc(strlen(mntbufp[ ii ].f_mntonname) + 1); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
113 |
if (retval[cd_count-1]) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
114 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
115 |
strcpy(retval[cd_count-1], mntbufp[ ii ].f_mntonname); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
116 |
cd_count++; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
117 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
118 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
119 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
120 |
} |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
121 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
122 |
free( mntbufp ); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
123 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
124 |
retval[cd_count - 1] = NULL; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
125 |
return(retval); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
126 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
127 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
128 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
129 |
#else /* non-Darwin implementation... */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
130 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
131 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
{ |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
134 |
char **retval = (char **) malloc(sizeof (char *)); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
135 |
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
|
136 |
FILE *mounts = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
137 |
struct mntent *ent = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
138 |
|
171
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
139 |
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
|
140 |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
141 |
*retval = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
142 |
mounts = setmntent("/etc/mtab", "r"); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
143 |
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
|
144 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
145 |
while ( (ent = getmntent(mounts)) != NULL ) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
146 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
147 |
int add_it = 0; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
148 |
if (strcmp(ent->mnt_type, "iso9660") == 0) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
149 |
add_it = 1; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
150 |
/* !!! other mount types? */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
151 |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
152 |
if (add_it) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
153 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
154 |
char **tmp = realloc(retval, sizeof (char *) * cd_count + 1); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
155 |
if (tmp) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
156 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
157 |
retval = tmp; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
158 |
retval[cd_count-1] = (char *) malloc(strlen(ent->mnt_dir) + 1); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
159 |
if (retval[cd_count-1]) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
160 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
161 |
strcpy(retval[cd_count-1], ent->mnt_dir); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
162 |
cd_count++; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
163 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
164 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
165 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
166 |
} /* while */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
167 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
168 |
endmntent(mounts); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
169 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
170 |
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
|
171 |
return(retval); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
172 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
173 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
174 |
#endif |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
177 |
static char *copyEnvironmentVariable(const char *varname) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
178 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
179 |
const char *envr = getenv(varname); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
180 |
char *retval = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
181 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
182 |
if (envr != NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
183 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
184 |
retval = malloc(strlen(envr) + 1); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
185 |
if (retval != NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
186 |
strcpy(retval, envr); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
187 |
} /* if */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
188 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
189 |
return(retval); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
190 |
} /* copyEnvironmentVariable */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
191 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
192 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
193 |
/* !!! this is ugly. */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
194 |
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
|
195 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
196 |
/* 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
|
197 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
198 |
char *retval = NULL; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
199 |
char *envr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
200 |
char *start; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
201 |
char *ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
202 |
char *exe; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
203 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
204 |
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
|
205 |
return(NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
206 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
207 |
envr = copyEnvironmentVariable("PATH"); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
208 |
BAIL_IF_MACRO(!envr, NULL, NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
209 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
210 |
start = envr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
211 |
do |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
212 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
213 |
ptr = strchr(start, ':'); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
214 |
if (ptr) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
215 |
*ptr = '\0'; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
216 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
217 |
exe = (char *) malloc(strlen(start) + strlen(argv0) + 2); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
218 |
if (!exe) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
219 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
220 |
free(envr); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
221 |
BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
222 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
223 |
strcpy(exe, start); |
79
5dbb03944ef0
Fixed base directory determination.
Ryan C. Gordon <icculus@icculus.org>
parents:
70
diff
changeset
|
224 |
if (exe[strlen(exe) - 1] != '/') |
5dbb03944ef0
Fixed base directory determination.
Ryan C. Gordon <icculus@icculus.org>
parents:
70
diff
changeset
|
225 |
strcat(exe, "/"); |
5dbb03944ef0
Fixed base directory determination.
Ryan C. Gordon <icculus@icculus.org>
parents:
70
diff
changeset
|
226 |
strcat(exe, argv0); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
227 |
if (access(exe, X_OK) != 0) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
228 |
free(exe); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
229 |
else |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
230 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
231 |
retval = exe; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
232 |
strcpy(retval, start); /* i'm lazy. piss off. */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
233 |
break; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
234 |
} /* else */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
235 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
236 |
start = ptr + 1; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
237 |
} while (ptr != NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
238 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
239 |
free(envr); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
240 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
241 |
} /* __PHYSFS_platformCalcBaseDir */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
242 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
243 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
244 |
static char *getUserNameByUID(void) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
245 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
246 |
uid_t uid = getuid(); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
247 |
struct passwd *pw; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
248 |
char *retval = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
249 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
250 |
pw = getpwuid(uid); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
251 |
if ((pw != NULL) && (pw->pw_name != NULL)) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
252 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
253 |
retval = malloc(strlen(pw->pw_name) + 1); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
254 |
if (retval != NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
255 |
strcpy(retval, pw->pw_name); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
256 |
} /* if */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
257 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
258 |
return(retval); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
259 |
} /* getUserNameByUID */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
260 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
261 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
262 |
static char *getUserDirByUID(void) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
263 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
264 |
uid_t uid = getuid(); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
265 |
struct passwd *pw; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
266 |
char *retval = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
267 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
268 |
pw = getpwuid(uid); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
269 |
if ((pw != NULL) && (pw->pw_dir != NULL)) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
270 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
271 |
retval = malloc(strlen(pw->pw_dir) + 1); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
272 |
if (retval != NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
273 |
strcpy(retval, pw->pw_dir); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
274 |
} /* if */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
275 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
276 |
return(retval); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
277 |
} /* getUserDirByUID */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
278 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
279 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
char *__PHYSFS_platformGetUserName(void) |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
{ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
282 |
char *retval = getUserNameByUID(); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
283 |
if (retval == NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
284 |
retval = copyEnvironmentVariable("USER"); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
285 |
return(retval); |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
} /* __PHYSFS_platformGetUserName */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
char *__PHYSFS_platformGetUserDir(void) |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
{ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
291 |
char *retval = copyEnvironmentVariable("HOME"); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
292 |
if (retval == NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
293 |
retval = getUserDirByUID(); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
294 |
return(retval); |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
} /* __PHYSFS_platformGetUserDir */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
298 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
{ |
188 | 300 |
return((PHYSFS_uint64) ((PHYSFS_uint32) pthread_self())); |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
} /* __PHYSFS_platformGetThreadID */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
304 |
/* -ansi and -pedantic flags prevent use of strcasecmp() on Linux. */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
305 |
int __PHYSFS_platformStricmp(const char *x, const char *y) |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
{ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
307 |
int ux, uy; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
308 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
309 |
do |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
310 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
311 |
ux = toupper((int) *x); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
312 |
uy = toupper((int) *y); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
313 |
if (ux > uy) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
314 |
return(1); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
315 |
else if (ux < uy) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
316 |
return(-1); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
317 |
x++; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
318 |
y++; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
319 |
} while ((ux) && (uy)); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
320 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
321 |
return(0); |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
} /* __PHYSFS_platformStricmp */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
325 |
int __PHYSFS_platformExists(const char *fname) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
326 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
327 |
struct stat statbuf; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
328 |
return(stat(fname, &statbuf) == 0); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
329 |
} /* __PHYSFS_platformExists */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
330 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
331 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
332 |
int __PHYSFS_platformIsSymLink(const char *fname) |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
{ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
334 |
#if (defined __PHYSFS_NO_SYMLINKS__) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
335 |
return(0); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
336 |
#else |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
337 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
338 |
struct stat statbuf; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
339 |
int retval = 0; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
340 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
341 |
if (lstat(fname, &statbuf) == 0) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
342 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
343 |
if (S_ISLNK(statbuf.st_mode)) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
344 |
retval = 1; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
345 |
} /* if */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
346 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
347 |
return(retval); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
348 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
349 |
#endif |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 |
} /* __PHYSFS_platformIsSymlink */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
int __PHYSFS_platformIsDirectory(const char *fname) |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 |
{ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
355 |
struct stat statbuf; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
356 |
int retval = 0; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
357 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
358 |
if (stat(fname, &statbuf) == 0) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
359 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
360 |
if (S_ISDIR(statbuf.st_mode)) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
361 |
retval = 1; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
362 |
} /* if */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
363 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
364 |
return(retval); |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
} /* __PHYSFS_platformIsDirectory */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
368 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
369 |
const char *dirName, |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
370 |
const char *append) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
371 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
372 |
int len = ((prepend) ? strlen(prepend) : 0) + |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
373 |
((append) ? strlen(append) : 0) + |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
374 |
strlen(dirName) + 1; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
375 |
char *retval = malloc(len); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
376 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
377 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
378 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
379 |
/* platform-independent notation is Unix-style already. :) */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
380 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
381 |
if (prepend) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
382 |
strcpy(retval, prepend); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
383 |
else |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
384 |
retval[0] = '\0'; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
385 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
386 |
strcat(retval, dirName); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
387 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
388 |
if (append) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
389 |
strcat(retval, append); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
390 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
391 |
return(retval); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
392 |
} /* __PHYSFS_platformCvtToDependent */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
393 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
394 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
395 |
/* 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
|
396 |
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
|
397 |
{ |
115
c0671785777b
Changed timeslice implementation to use something more portable (thanks to
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
398 |
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
|
399 |
} /* __PHYSFS_platformTimeslice */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
400 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
401 |
|
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
402 |
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname, |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
403 |
int omitSymLinks) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
404 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
405 |
LinkedStringList *retval = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
406 |
LinkedStringList *l = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
407 |
LinkedStringList *prev = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
408 |
DIR *dir; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
409 |
struct dirent *ent; |
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
410 |
int bufsize = 0; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
411 |
char *buf = NULL; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
412 |
int dlen = 0; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
413 |
|
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
414 |
if (omitSymLinks) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
415 |
{ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
416 |
dlen = strlen(dirname); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
417 |
bufsize = dlen + 256; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
418 |
buf = malloc(bufsize); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
419 |
BAIL_IF_MACRO(buf == NULL, ERR_OUT_OF_MEMORY, NULL); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
420 |
strcpy(buf, dirname); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
421 |
if (buf[dlen - 1] != '/') |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
422 |
{ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
423 |
buf[dlen++] = '/'; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
424 |
buf[dlen] = '\0'; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
425 |
} /* if */ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
426 |
} /* if */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
427 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
428 |
errno = 0; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
429 |
dir = opendir(dirname); |
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
430 |
if (dir == NULL) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
431 |
{ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
432 |
if (buf != NULL) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
433 |
free(buf); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
434 |
BAIL_IF_MACRO(1, strerror(errno), NULL); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
435 |
} /* if */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
436 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
437 |
while (1) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
438 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
439 |
ent = readdir(dir); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
440 |
if (ent == NULL) /* we're done. */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
441 |
break; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
442 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
443 |
if (strcmp(ent->d_name, ".") == 0) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
444 |
continue; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
445 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
446 |
if (strcmp(ent->d_name, "..") == 0) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
447 |
continue; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
448 |
|
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
449 |
if (omitSymLinks) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
450 |
{ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
451 |
char *p; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
452 |
int len = strlen(ent->d_name) + dlen + 1; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
453 |
if (len > bufsize) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
454 |
{ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
455 |
p = realloc(buf, len); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
456 |
if (p == NULL) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
457 |
continue; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
458 |
buf = p; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
459 |
bufsize = len; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
460 |
} /* if */ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
461 |
|
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
462 |
strcpy(buf + dlen, ent->d_name); |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
463 |
if (__PHYSFS_platformIsSymLink(buf)) |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
464 |
continue; |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
465 |
} /* if */ |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
466 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
467 |
l = (LinkedStringList *) malloc(sizeof (LinkedStringList)); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
468 |
if (l == NULL) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
469 |
break; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
470 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
471 |
l->str = (char *) malloc(strlen(ent->d_name) + 1); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
472 |
if (l->str == NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
473 |
{ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
474 |
free(l); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
475 |
break; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
476 |
} /* if */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
477 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
478 |
strcpy(l->str, ent->d_name); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
479 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
480 |
if (retval == NULL) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
481 |
retval = l; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
482 |
else |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
483 |
prev->next = l; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
484 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
485 |
prev = l; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
486 |
l->next = NULL; |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
487 |
} /* while */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
488 |
|
67
5000499d4ee2
Fixed a potential free()ing of a NULL pointer in
Ryan C. Gordon <icculus@icculus.org>
parents:
63
diff
changeset
|
489 |
if (buf != NULL) |
5000499d4ee2
Fixed a potential free()ing of a NULL pointer in
Ryan C. Gordon <icculus@icculus.org>
parents:
63
diff
changeset
|
490 |
free(buf); |
5000499d4ee2
Fixed a potential free()ing of a NULL pointer in
Ryan C. Gordon <icculus@icculus.org>
parents:
63
diff
changeset
|
491 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
492 |
closedir(dir); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
493 |
return(retval); |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
494 |
} /* __PHYSFS_platformEnumerateFiles */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
495 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
496 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
497 |
char *__PHYSFS_platformCurrentDir(void) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
498 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
499 |
int allocSize = 0; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
500 |
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
|
501 |
char *ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
502 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
503 |
do |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
504 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
505 |
allocSize += 100; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
506 |
ptr = (char *) realloc(retval, allocSize); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
507 |
if (ptr == NULL) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
508 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
509 |
if (retval != NULL) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
510 |
free(retval); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
511 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
512 |
} /* if */ |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
513 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
514 |
retval = ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
515 |
ptr = getcwd(retval, allocSize); |
100
d2f04ab4b412
Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents:
79
diff
changeset
|
516 |
} while (ptr == NULL && errno == ERANGE); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
517 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
518 |
if (ptr == NULL && errno) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
519 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
520 |
/* |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
521 |
* getcwd() failed for some reason, for example current |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
522 |
* directory not existing. |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
523 |
*/ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
524 |
if (retval != NULL) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
525 |
free(retval); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
526 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
527 |
} /* if */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
528 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
529 |
return(retval); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
530 |
} /* __PHYSFS_platformCurrentDir */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
531 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
532 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
533 |
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
|
534 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
535 |
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
|
536 |
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
|
537 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
538 |
errno = 0; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
539 |
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
540 |
retval = malloc(strlen(resolved_path) + 1); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
return(retval); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
544 |
} /* __PHYSFS_platformRealPath */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
545 |
|
69
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
546 |
|
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
547 |
int __PHYSFS_platformMkDir(const char *path) |
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
548 |
{ |
70
203efbe2532e
Whoops. Forgot to declare a variable.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
549 |
int rc; |
69
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
550 |
errno = 0; |
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
551 |
rc = mkdir(path, S_IRWXU); |
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
552 |
BAIL_IF_MACRO(rc == -1, strerror(errno), 0); |
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
553 |
return(1); |
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
554 |
} /* __PHYSFS_platformMkDir */ |
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
555 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
556 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
557 |
static void *doOpen(const char *filename, const char *mode) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
558 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
559 |
FILE *retval; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
560 |
errno = 0; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
561 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
562 |
retval = fopen(filename, mode); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
563 |
if (retval == NULL) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
564 |
__PHYSFS_setError(strerror(errno)); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
565 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
566 |
return((void *) retval); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
567 |
} /* doOpen */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
568 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
569 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
570 |
void *__PHYSFS_platformOpenRead(const char *filename) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
571 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
572 |
return(doOpen(filename, "rb")); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
573 |
} /* __PHYSFS_platformOpenRead */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
574 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
575 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
576 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
577 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
578 |
return(doOpen(filename, "wb")); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
579 |
} /* __PHYSFS_platformOpenWrite */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
580 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
581 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
582 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
583 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
584 |
return(doOpen(filename, "wb+")); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
585 |
} /* __PHYSFS_platformOpenAppend */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
586 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
587 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
588 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
589 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
590 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
591 |
FILE *io = (FILE *) opaque; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
592 |
int rc = fread(buffer, size, count, io); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
593 |
if (rc < count) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
594 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
595 |
int err = errno; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
596 |
BAIL_IF_MACRO(ferror(io), strerror(err), rc); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
597 |
BAIL_MACRO(ERR_PAST_EOF, rc); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
598 |
} /* if */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
599 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
600 |
return(rc); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
601 |
} /* __PHYSFS_platformRead */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
602 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
603 |
|
133 | 604 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
605 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
606 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
607 |
FILE *io = (FILE *) opaque; |
133 | 608 |
int rc = fwrite((void *) buffer, size, count, io); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
609 |
if (rc < count) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
610 |
__PHYSFS_setError(strerror(errno)); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
611 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
612 |
return(rc); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
613 |
} /* __PHYSFS_platformWrite */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
614 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
615 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
616 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
617 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
618 |
FILE *io = (FILE *) opaque; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
619 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
620 |
/* !!! FIXME: Use llseek where available. */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
621 |
errno = 0; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
622 |
BAIL_IF_MACRO(fseek(io, pos, SEEK_SET) != 0, strerror(errno), 0); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
623 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
624 |
return(1); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
625 |
} /* __PHYSFS_platformSeek */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
626 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
627 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
628 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
629 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
630 |
FILE *io = (FILE *) opaque; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
631 |
PHYSFS_sint64 retval = ftell(io); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
632 |
BAIL_IF_MACRO(retval == -1, strerror(errno), -1); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
633 |
return(retval); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
634 |
} /* __PHYSFS_platformTell */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
635 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
636 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
637 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
638 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
639 |
FILE *io = (FILE *) opaque; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
640 |
struct stat statbuf; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
641 |
errno = 0; |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
642 |
BAIL_IF_MACRO(fstat(fileno(io), &statbuf) == -1, strerror(errno), -1); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
643 |
return((PHYSFS_sint64) statbuf.st_size); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
644 |
} /* __PHYSFS_platformFileLength */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
645 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
646 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
647 |
int __PHYSFS_platformEOF(void *opaque) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
648 |
{ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
649 |
return(feof((FILE *) opaque)); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
650 |
} /* __PHYSFS_platformEOF */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
651 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
652 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
653 |
int __PHYSFS_platformFlush(void *opaque) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
654 |
{ |
137
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
655 |
errno = 0; |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
656 |
BAIL_IF_MACRO(fflush((FILE *) opaque) == EOF, strerror(errno), 0); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
657 |
return(1); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
658 |
} /* __PHYSFS_platformFlush */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
659 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
660 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
661 |
int __PHYSFS_platformClose(void *opaque) |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
662 |
{ |
137
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
663 |
errno = 0; |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
664 |
BAIL_IF_MACRO(fclose((FILE *) opaque) == EOF, strerror(errno), 0); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
665 |
return(1); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
666 |
} /* __PHYSFS_platformClose */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
667 |
|
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
130
diff
changeset
|
668 |
|
137
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
669 |
int __PHYSFS_platformDelete(const char *path) |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
670 |
{ |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
671 |
errno = 0; |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
672 |
BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0); |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
673 |
return(1); |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
674 |
} /* __PHYSFS_platformDelete */ |
66bddb94b6e0
Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents:
133
diff
changeset
|
675 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
676 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
677 |
void *__PHYSFS_platformCreateMutex(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
678 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
679 |
int rc; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
680 |
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
|
681 |
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
|
682 |
rc = pthread_mutex_init(m, NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
683 |
if (rc != 0) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
684 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
685 |
free(m); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
686 |
BAIL_MACRO(strerror(rc), NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
687 |
} /* if */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
688 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
689 |
return((void *) m); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
690 |
} /* __PHYSFS_platformCreateMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
691 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
692 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
693 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
694 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
695 |
pthread_mutex_destroy((pthread_mutex_t *) mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
696 |
free(mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
697 |
} /* __PHYSFS_platformDestroyMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
698 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
699 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
700 |
int __PHYSFS_platformGrabMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
701 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
702 |
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
|
703 |
} /* __PHYSFS_platformGrabMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
704 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
705 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
706 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
707 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
708 |
pthread_mutex_unlock((pthread_mutex_t *) mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
709 |
} /* __PHYSFS_platformReleaseMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
710 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
711 |
/* end of unix.c ... */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
712 |