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