author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 01 Apr 2007 21:24:19 +0000 | |
changeset 876 | 0d8e41a5c831 |
parent 869 | 1c0138d6ce45 |
child 877 | 99c2fd8e689d |
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 |
* |
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
6 |
* Please see the file LICENSE.txt in the source's root directory. |
5
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 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#include <stdio.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
#include <stdlib.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
#include <string.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
#include "physfs.h" |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
16 |
#define __PHYSICSFS_INTERNAL__ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
17 |
#include "physfs_internal.h" |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
18 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
19 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
20 |
typedef struct __PHYSFS_DIRHANDLE__ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
21 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
22 |
void *opaque; /* Instance data unique to the archiver. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
23 |
char *dirName; /* Path to archive in platform-dependent notation. */ |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
24 |
char *mountPoint; /* Mountpoint in virtual file tree. */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
25 |
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
26 |
struct __PHYSFS_DIRHANDLE__ *next; /* linked list stuff. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
27 |
} DirHandle; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
28 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
29 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
30 |
typedef struct __PHYSFS_FILEHANDLE__ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
31 |
{ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
32 |
void *opaque; /* Instance data unique to the archiver for this file. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
33 |
PHYSFS_uint8 forReading; /* Non-zero if reading, zero if write/append */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
34 |
const DirHandle *dirHandle; /* Archiver instance that created this */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
35 |
const PHYSFS_Archiver *funcs; /* Ptr to archiver info for this handle. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
36 |
PHYSFS_uint8 *buffer; /* Buffer, if set (NULL otherwise). Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
37 |
PHYSFS_uint32 bufsize; /* Bufsize, if set (0 otherwise). Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
38 |
PHYSFS_uint32 buffill; /* Buffer fill size. Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
39 |
PHYSFS_uint32 bufpos; /* Buffer position. Don't touch! */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
40 |
struct __PHYSFS_FILEHANDLE__ *next; /* linked list stuff. */ |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
41 |
} FileHandle; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
42 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
43 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
typedef struct __PHYSFS_ERRMSGTYPE__ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
{ |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
46 |
PHYSFS_uint64 tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
int errorAvailable; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
char errorString[80]; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
struct __PHYSFS_ERRMSGTYPE__ *next; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
} ErrMsg; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
52 |
|
796
5085b2f1213e
Killed some #ifdefs and whitespace.
Ryan C. Gordon <icculus@icculus.org>
parents:
795
diff
changeset
|
53 |
/* The various i/o drivers...some of these may not be compiled in. */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
54 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
55 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_ZIP; |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
56 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
57 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_LZMA; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
58 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
59 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_GRP; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
60 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
61 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
62 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_HOG; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
63 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
64 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_MVL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
65 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
66 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
67 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD; |
796
5085b2f1213e
Killed some #ifdefs and whitespace.
Ryan C. Gordon <icculus@icculus.org>
parents:
795
diff
changeset
|
68 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
69 |
|
453
108de3bb1b6b
Added qpak.c to build systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
70 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
71 |
static const PHYSFS_ArchiveInfo *supported_types[] = |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
74 |
&__PHYSFS_ArchiveInfo_ZIP, |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
#endif |
795
0f10cda58a9a
Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
76 |
#if (defined PHYSFS_SUPPORTS_7Z) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
77 |
&__PHYSFS_ArchiveInfo_LZMA, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
78 |
#endif |
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
79 |
#if (defined PHYSFS_SUPPORTS_GRP) |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
80 |
&__PHYSFS_ArchiveInfo_GRP, |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
81 |
#endif |
582
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
82 |
#if (defined PHYSFS_SUPPORTS_QPAK) |
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
83 |
&__PHYSFS_ArchiveInfo_QPAK, |
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
84 |
#endif |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
85 |
#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
|
86 |
&__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
|
87 |
#endif |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
88 |
#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
|
89 |
&__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
|
90 |
#endif |
609
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
91 |
#if (defined PHYSFS_SUPPORTS_WAD) |
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
92 |
&__PHYSFS_ArchiveInfo_WAD, |
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
93 |
#endif |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
NULL |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
}; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
97 |
static const PHYSFS_Archiver *archivers[] = |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
98 |
{ |
869
1c0138d6ce45
Try the DIR archiver first, since there's no sense in trying to open a
Ryan C. Gordon <icculus@icculus.org>
parents:
867
diff
changeset
|
99 |
&__PHYSFS_Archiver_DIR, |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
100 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
101 |
&__PHYSFS_Archiver_ZIP, |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
102 |
#endif |
795
0f10cda58a9a
Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
103 |
#if (defined PHYSFS_SUPPORTS_7Z) |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
104 |
&__PHYSFS_Archiver_LZMA, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
105 |
#endif |
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
106 |
#if (defined PHYSFS_SUPPORTS_GRP) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
107 |
&__PHYSFS_Archiver_GRP, |
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
108 |
#endif |
582
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
109 |
#if (defined PHYSFS_SUPPORTS_QPAK) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
110 |
&__PHYSFS_Archiver_QPAK, |
582
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
111 |
#endif |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
112 |
#if (defined PHYSFS_SUPPORTS_HOG) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
113 |
&__PHYSFS_Archiver_HOG, |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
114 |
#endif |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
115 |
#if (defined PHYSFS_SUPPORTS_MVL) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
116 |
&__PHYSFS_Archiver_MVL, |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
117 |
#endif |
609
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
118 |
#if (defined PHYSFS_SUPPORTS_WAD) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
119 |
&__PHYSFS_Archiver_WAD, |
609
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
120 |
#endif |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
121 |
NULL |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
122 |
}; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
123 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
126 |
/* General PhysicsFS state ... */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
127 |
static int initialized = 0; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
128 |
static ErrMsg *errorMessages = NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
129 |
static DirHandle *searchPath = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
130 |
static DirHandle *writeDir = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
131 |
static FileHandle *openWriteList = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
132 |
static FileHandle *openReadList = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
133 |
static char *baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
134 |
static char *userDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
135 |
static int allowSymLinks = 0; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
136 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
137 |
/* mutexes ... */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
138 |
static void *errorLock = NULL; /* protects error message list. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
139 |
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
|
140 |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
141 |
/* allocator ... */ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
142 |
static int externalAllocator = 0; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
143 |
PHYSFS_Allocator allocator; |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
144 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
145 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
146 |
/* functions ... */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
148 |
typedef struct |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
149 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
150 |
char **list; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
151 |
PHYSFS_uint32 size; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
152 |
const char *errorstr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
153 |
} EnumStringListCallbackData; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
154 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
155 |
static void enumStringListCallback(void *data, const char *str) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
156 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
157 |
void *ptr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
158 |
char *newstr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
159 |
EnumStringListCallbackData *pecd = (EnumStringListCallbackData *) data; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
160 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
161 |
if (pecd->errorstr) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
162 |
return; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
163 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
164 |
ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *)); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
165 |
newstr = (char *) allocator.Malloc(strlen(str) + 1); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
166 |
if (ptr != NULL) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
167 |
pecd->list = (char **) ptr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
168 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
169 |
if ((ptr == NULL) || (newstr == NULL)) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
170 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
171 |
pecd->errorstr = ERR_OUT_OF_MEMORY; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
172 |
pecd->list[pecd->size] = NULL; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
173 |
PHYSFS_freeList(pecd->list); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
174 |
return; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
175 |
} /* if */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
176 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
177 |
strcpy(newstr, str); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
178 |
pecd->list[pecd->size] = newstr; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
179 |
pecd->size++; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
180 |
} /* enumStringListCallback */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
181 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
182 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
183 |
static char **doEnumStringList(void (*func)(PHYSFS_StringCallback, void *)) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
184 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
185 |
EnumStringListCallbackData ecd; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
186 |
memset(&ecd, '\0', sizeof (ecd)); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
187 |
ecd.list = (char **) allocator.Malloc(sizeof (char *)); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
188 |
BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
189 |
func(enumStringListCallback, &ecd); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
190 |
BAIL_IF_MACRO(ecd.errorstr != NULL, ecd.errorstr, NULL); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
191 |
ecd.list[ecd.size] = NULL; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
192 |
return(ecd.list); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
193 |
} /* doEnumStringList */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
194 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
195 |
|
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
533
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
200 |
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
|
201 |
int sorted; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
202 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
203 |
do |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
204 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
205 |
sorted = 1; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
206 |
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
|
207 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
208 |
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
|
209 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
210 |
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
|
211 |
sorted = 0; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
212 |
} /* if */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
213 |
} /* for */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
214 |
} while (!sorted); |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
215 |
} /* __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
|
216 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
217 |
|
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
533
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
226 |
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
|
227 |
__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
|
228 |
else |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
229 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
230 |
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
|
231 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
236 |
j = hi - 1; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
237 |
swapfn(a, i, j); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
238 |
i = lo; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
239 |
v = j; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
240 |
while (1) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
241 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
break; |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
246 |
swapfn(a, i, j); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
247 |
} /* while */ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
248 |
swapfn(a, i, hi-1); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
249 |
__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
|
250 |
__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
|
251 |
} /* else */ |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
252 |
} /* __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
|
253 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
254 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
259 |
/* |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
260 |
* 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
|
261 |
* 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
|
262 |
*/ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
263 |
__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
|
264 |
} /* __PHYSFS_sort */ |
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 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
static ErrMsg *findErrorForCurrentThread(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
ErrMsg *i; |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
270 |
PHYSFS_uint64 tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
272 |
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
|
273 |
__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
|
274 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
if (errorMessages != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
{ |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
277 |
tid = __PHYSFS_platformGetThreadID(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 |
for (i = errorMessages; i != NULL; i = i->next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
if (i->tid == tid) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
282 |
{ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
283 |
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
|
284 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 |
return(i); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
286 |
} /* if */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
} /* 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
|
289 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
290 |
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
|
291 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
return(NULL); /* no error available. */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
} /* findErrorForCurrentThread */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
297 |
void __PHYSFS_setError(const char *str) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
299 |
ErrMsg *err; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
300 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
301 |
if (str == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
302 |
return; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
303 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
304 |
err = findErrorForCurrentThread(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
if (err == NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
308 |
err = (ErrMsg *) allocator.Malloc(sizeof (ErrMsg)); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
if (err == NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
return; /* uhh...? */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
|
57
1ec888db3df9
Safety memset when creating error information for a new thread.
Ryan C. Gordon <icculus@icculus.org>
parents:
51
diff
changeset
|
312 |
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
|
313 |
err->tid = __PHYSFS_platformGetThreadID(); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
314 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
315 |
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
|
316 |
__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
|
317 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
err->next = errorMessages; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
319 |
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
|
320 |
|
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
321 |
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
|
322 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 |
err->errorAvailable = 1; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
strncpy(err->errorString, str, sizeof (err->errorString)); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
err->errorString[sizeof (err->errorString) - 1] = '\0'; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
328 |
} /* __PHYSFS_setError */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
const char *PHYSFS_getLastError(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
ErrMsg *err = findErrorForCurrentThread(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
if ((err == NULL) || (!err->errorAvailable)) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
return(NULL); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
err->errorAvailable = 0; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
return(err->errorString); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 |
} /* PHYSFS_getLastError */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
343 |
/* 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
|
344 |
static void freeErrorMessages(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
345 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
346 |
ErrMsg *i; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
347 |
ErrMsg *next; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
348 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
349 |
for (i = errorMessages; i != NULL; i = next) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
350 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
351 |
next = i->next; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
352 |
allocator.Free(i); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
353 |
} /* for */ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
354 |
|
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
355 |
errorMessages = NULL; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
356 |
} /* freeErrorMessages */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
357 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
358 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
if (ver != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 |
ver->major = PHYSFS_VER_MAJOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
ver->minor = PHYSFS_VER_MINOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
ver->patch = PHYSFS_VER_PATCH; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
} /* PHYSFS_getLinkedVersion */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
|
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
370 |
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
|
371 |
{ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
372 |
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
|
373 |
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
|
374 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
375 |
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
|
376 |
{ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
377 |
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
|
378 |
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
|
379 |
retval = p; |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
380 |
} /* while */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
381 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
382 |
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
|
383 |
retval++; /* skip '.' */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
384 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
385 |
return(retval); |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
386 |
} /* 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
|
387 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
388 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
389 |
static DirHandle *tryOpenDir(const PHYSFS_Archiver *funcs, |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
390 |
const char *d, int forWriting) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
391 |
{ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
392 |
DirHandle *retval = NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
393 |
if (funcs->isArchive(d, forWriting)) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
394 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
395 |
void *opaque = funcs->openArchive(d, forWriting); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
396 |
if (opaque != NULL) |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
397 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
398 |
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle)); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
399 |
if (retval == NULL) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
400 |
funcs->dirClose(opaque); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
401 |
else |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
402 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
403 |
memset(retval, '\0', sizeof (DirHandle)); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
404 |
retval->mountPoint = NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
405 |
retval->funcs = funcs; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
406 |
retval->opaque = opaque; |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
407 |
} /* else */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
408 |
} /* if */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
409 |
} /* if */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
410 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
411 |
return(retval); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
412 |
} /* tryOpenDir */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
413 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
414 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
415 |
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
|
416 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
417 |
DirHandle *retval = NULL; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
418 |
const PHYSFS_Archiver **i; |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
419 |
const char *ext; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
420 |
|
44
534901592376
Non-existant archives/directories report a more correct error, and a call
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
421 |
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
|
422 |
|
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
423 |
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
|
424 |
if (ext != NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
425 |
{ |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
426 |
/* Look for archivers with matching file extensions first... */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
427 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
428 |
{ |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
821
diff
changeset
|
429 |
if (__PHYSFS_stricmpASCII(ext, (*i)->info->extension) == 0) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
430 |
retval = tryOpenDir(*i, d, forWriting); |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
431 |
} /* for */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
432 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
433 |
/* failing an exact file extension match, try all the others... */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
434 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
435 |
{ |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
821
diff
changeset
|
436 |
if (__PHYSFS_stricmpASCII(ext, (*i)->info->extension) != 0) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
437 |
retval = tryOpenDir(*i, d, forWriting); |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
438 |
} /* for */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
439 |
} /* if */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
440 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
441 |
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
|
442 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
443 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
444 |
retval = tryOpenDir(*i, d, forWriting); |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
445 |
} /* else */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
446 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
447 |
BAIL_IF_MACRO(retval == NULL, ERR_UNSUPPORTED_ARCHIVE, NULL); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
448 |
return(retval); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
449 |
} /* openDirectory */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
450 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
451 |
|
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
452 |
/* |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
453 |
* Make a platform-independent path string sane. Doesn't actually check the |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
454 |
* file hierarchy, it just cleans up the string. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
455 |
* (dst) must be a buffer at least as big as (src), as this is where the |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
456 |
* cleaned up string is deposited. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
457 |
* If there are illegal bits in the path (".." entries, etc) then we |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
458 |
* return zero and (dst) is undefined. Non-zero if the path was sanitized. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
459 |
*/ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
460 |
static int sanitizePlatformIndependentPath(const char *src, char *dst) |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
461 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
462 |
char *prev; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
463 |
char ch; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
464 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
465 |
while (*src == '/') /* skip initial '/' chars... */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
466 |
src++; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
467 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
468 |
prev = dst; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
469 |
do |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
470 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
471 |
ch = *(src++); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
472 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
473 |
if ((ch == ':') || (ch == '\\')) /* illegal chars in a physfs path. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
474 |
BAIL_MACRO(ERR_INSECURE_FNAME, 0); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
475 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
476 |
if (ch == '/') /* path separator. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
477 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
478 |
*dst = '\0'; /* "." and ".." are illegal pathnames. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
479 |
if ((strcmp(prev, ".") == 0) || (strcmp(prev, "..") == 0)) |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
480 |
BAIL_MACRO(ERR_INSECURE_FNAME, 0); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
481 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
482 |
while (*src == '/') /* chop out doubles... */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
483 |
src++; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
484 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
485 |
if (*src == '\0') /* ends with a pathsep? */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
486 |
break; /* we're done, don't add final pathsep to dst. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
487 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
488 |
prev = dst + 1; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
489 |
} /* if */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
490 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
491 |
*(dst++) = ch; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
492 |
} while (ch != '\0'); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
493 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
494 |
return(1); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
495 |
} /* sanitizePlatformIndependentPath */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
496 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
497 |
|
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
498 |
/* |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
499 |
* Figure out if (fname) is part of (h)'s mountpoint. (fname) must be an |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
500 |
* output from sanitizePlatformIndependentPath(), so that it is in a known |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
501 |
* state. |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
502 |
* |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
503 |
* This only finds legitimate segments of a mountpoint. If the mountpoint is |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
504 |
* "/a/b/c" and (fname) is "/a/b/c", "/", or "/a/b/c/d", then the results are |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
505 |
* all zero. "/a/b" will succeed, though. |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
506 |
*/ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
507 |
static int partOfMountPoint(DirHandle *h, char *fname) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
508 |
{ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
509 |
/* !!! FIXME: This code feels gross. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
510 |
int rc; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
511 |
size_t len, mntpntlen; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
512 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
513 |
if (h->mountPoint == NULL) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
514 |
return(0); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
515 |
else if (*fname == '\0') |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
516 |
return(1); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
517 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
518 |
len = strlen(fname); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
519 |
mntpntlen = strlen(h->mountPoint); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
520 |
if (len > mntpntlen) /* can't be a subset of mountpoint. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
521 |
return(0); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
522 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
523 |
/* if true, must be not a match or a complete match, but not a subset. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
524 |
if ((len + 1) == mntpntlen) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
525 |
return(0); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
526 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
527 |
rc = strncmp(fname, h->mountPoint, len); /* !!! FIXME: case insensitive? */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
528 |
if (rc != 0) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
529 |
return(0); /* not a match. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
530 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
531 |
/* make sure /a/b matches /a/b/ and not /a/bc ... */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
532 |
return(h->mountPoint[len] == '/'); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
533 |
} /* partOfMountPoint */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
534 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
535 |
|
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
536 |
static DirHandle *createDirHandle(const char *newDir, |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
537 |
const char *mountPoint, |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
538 |
int forWriting) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
539 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
540 |
DirHandle *dirHandle = NULL; |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
541 |
char *tmpmntpnt = NULL; |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
542 |
|
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
543 |
GOTO_IF_MACRO(!newDir, ERR_INVALID_ARGUMENT, badDirHandle); |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
544 |
if (mountPoint != NULL) |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
545 |
{ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
546 |
const size_t len = strlen(mountPoint) + 1; |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
547 |
tmpmntpnt = (char *) __PHYSFS_smallAlloc(len); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
548 |
GOTO_IF_MACRO(!tmpmntpnt, ERR_OUT_OF_MEMORY, badDirHandle); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
549 |
if (!sanitizePlatformIndependentPath(mountPoint, tmpmntpnt)) |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
550 |
goto badDirHandle; |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
551 |
mountPoint = tmpmntpnt; /* sanitized version. */ |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
552 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
553 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
554 |
dirHandle = openDirectory(newDir, forWriting); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
555 |
GOTO_IF_MACRO(!dirHandle, NULL, badDirHandle); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
556 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
557 |
dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
558 |
GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
559 |
strcpy(dirHandle->dirName, newDir); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
560 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
561 |
if ((mountPoint != NULL) && (*mountPoint != '\0')) |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
562 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
563 |
dirHandle->mountPoint = (char *)allocator.Malloc(strlen(mountPoint)+2); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
564 |
GOTO_IF_MACRO(!dirHandle->mountPoint, ERR_OUT_OF_MEMORY, badDirHandle); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
565 |
strcpy(dirHandle->mountPoint, mountPoint); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
566 |
strcat(dirHandle->mountPoint, "/"); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
567 |
} /* if */ |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
568 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
569 |
__PHYSFS_smallFree(tmpmntpnt); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
570 |
return(dirHandle); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
571 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
572 |
badDirHandle: |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
573 |
if (dirHandle != NULL) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
574 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
575 |
dirHandle->funcs->dirClose(dirHandle->opaque); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
576 |
allocator.Free(dirHandle->dirName); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
577 |
allocator.Free(dirHandle->mountPoint); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
578 |
allocator.Free(dirHandle); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
579 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
580 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
581 |
__PHYSFS_smallFree(tmpmntpnt); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
582 |
return(NULL); |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
583 |
} /* createDirHandle */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
584 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
585 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
586 |
/* MAKE SURE you've got the stateLock held before calling this! */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
587 |
static int freeDirHandle(DirHandle *dh, FileHandle *openList) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
588 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
589 |
FileHandle *i; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
590 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
591 |
if (dh == NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
592 |
return(1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
593 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
594 |
for (i = openList; i != NULL; i = i->next) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
595 |
BAIL_IF_MACRO(i->dirHandle == dh, ERR_FILES_STILL_OPEN, 0); |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
758
diff
changeset
|
596 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
597 |
dh->funcs->dirClose(dh->opaque); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
598 |
allocator.Free(dh->dirName); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
599 |
allocator.Free(dh->mountPoint); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
600 |
allocator.Free(dh); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
601 |
return(1); |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
602 |
} /* freeDirHandle */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
603 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
604 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
605 |
static char *calculateUserDir(void) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
606 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
607 |
char *retval = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
608 |
const char *str = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
609 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
610 |
str = __PHYSFS_platformGetUserDir(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
611 |
if (str != NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
612 |
retval = (char *) str; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
613 |
else |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
614 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
615 |
const char *dirsep = PHYSFS_getDirSeparator(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
616 |
const char *uname = __PHYSFS_platformGetUserName(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
617 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
618 |
str = (uname != NULL) ? uname : "default"; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
619 |
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) + |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
620 |
strlen(dirsep) + 6); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
621 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
622 |
if (retval == NULL) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
623 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
624 |
else |
155
54fee85d9c26
Fixed calculateUserDir() to prevent extra dir separator insertion in default case.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
625 |
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
|
626 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
627 |
allocator.Free((void *) uname); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
628 |
} /* else */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
629 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
630 |
return(retval); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
631 |
} /* calculateUserDir */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
632 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
633 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
634 |
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
|
635 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
636 |
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
|
637 |
char *ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
638 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
639 |
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
|
640 |
return(1); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
641 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
642 |
ptr = (char *) allocator.Realloc(*dir, strlen(*dir) + strlen(dirsep) + 1); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
643 |
if (!ptr) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
644 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
645 |
allocator.Free(*dir); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
646 |
return(0); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
647 |
} /* if */ |
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 |
strcat(ptr, dirsep); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
650 |
*dir = ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
651 |
return(1); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
652 |
} /* appendDirSep */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
653 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
654 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
655 |
static char *calculateBaseDir(const char *argv0) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
656 |
{ |
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
657 |
char *retval = NULL; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
658 |
const char *dirsep = NULL; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
659 |
char *ptr = NULL; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
660 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
661 |
/* Give the platform layer first shot at this. */ |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
662 |
retval = __PHYSFS_platformCalcBaseDir(argv0); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
663 |
if (retval != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
664 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
665 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
666 |
/* We need argv0 to go on. */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
667 |
BAIL_IF_MACRO(argv0 == NULL, ERR_ARGV0_IS_NULL, NULL); |
839
cbb9d603ca71
PHYSFS_init() should fail if argv0 is NULL and we can't do without it.
Ryan C. Gordon <icculus@icculus.org>
parents:
828
diff
changeset
|
668 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
669 |
dirsep = PHYSFS_getDirSeparator(); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
670 |
if (strlen(dirsep) == 1) /* fast path. */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
671 |
ptr = strrchr(argv0, *dirsep); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
672 |
else |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
673 |
{ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
674 |
ptr = strstr(argv0, dirsep); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
675 |
if (ptr != NULL) |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
676 |
{ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
677 |
char *p = ptr; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
678 |
while (p != NULL) |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
679 |
{ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
680 |
ptr = p; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
681 |
p = strstr(p + 1, dirsep); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
682 |
} /* while */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
683 |
} /* if */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
684 |
} /* else */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
685 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
686 |
if (ptr != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
687 |
{ |
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
688 |
size_t size = (size_t) (ptr - argv0); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
689 |
retval = (char *) allocator.Malloc(size + 1); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
690 |
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
|
691 |
memcpy(retval, argv0, size); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
692 |
retval[size] = '\0'; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
693 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
694 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
695 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
696 |
/* argv0 wasn't helpful. */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
697 |
BAIL_MACRO(ERR_INVALID_ARGUMENT, NULL); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
698 |
return(NULL); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
699 |
} /* calculateBaseDir */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
700 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
701 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
702 |
static int initializeMutexes(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
703 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
704 |
errorLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
705 |
if (errorLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
706 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
707 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
708 |
stateLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
709 |
if (stateLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
710 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
711 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
712 |
return(1); /* success. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
713 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
714 |
initializeMutexes_failed: |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
715 |
if (errorLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
716 |
__PHYSFS_platformDestroyMutex(errorLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
717 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
718 |
if (stateLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
719 |
__PHYSFS_platformDestroyMutex(stateLock); |
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 = stateLock = NULL; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
722 |
return(0); /* failed. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
723 |
} /* initializeMutexes */ |
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 |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
726 |
static void setDefaultAllocator(void); |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
727 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
728 |
int PHYSFS_init(const char *argv0) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
729 |
{ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
730 |
char *ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
731 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
732 |
BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
733 |
|
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
734 |
if (!externalAllocator) |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
735 |
setDefaultAllocator(); |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
736 |
|
751
74dc021744de
Some tweaks to PHYSFS_Allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
746
diff
changeset
|
737 |
if (allocator.Init != NULL) |
74dc021744de
Some tweaks to PHYSFS_Allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
746
diff
changeset
|
738 |
BAIL_IF_MACRO(!allocator.Init(), NULL, 0); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
739 |
|
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
126
diff
changeset
|
740 |
BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
741 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
742 |
BAIL_IF_MACRO(!initializeMutexes(), NULL, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
743 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
744 |
baseDir = calculateBaseDir(argv0); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
745 |
BAIL_IF_MACRO(baseDir == NULL, NULL, 0); |
186 | 746 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
747 |
/* !!! FIXME: only call this if we got this from argv0 (unreliable). */ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
748 |
ptr = __PHYSFS_platformRealPath(baseDir); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
749 |
allocator.Free(baseDir); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
750 |
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
|
751 |
baseDir = ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
752 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
753 |
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
754 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
755 |
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
|
756 |
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
|
757 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
758 |
ptr = __PHYSFS_platformRealPath(userDir); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
759 |
allocator.Free(userDir); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
760 |
userDir = ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
761 |
} /* if */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
762 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
763 |
if ((userDir == NULL) || (!appendDirSep(&userDir))) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
764 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
765 |
allocator.Free(baseDir); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
766 |
baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
767 |
return(0); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
768 |
} /* if */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
769 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
770 |
initialized = 1; |
167
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
771 |
|
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
772 |
/* 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
|
773 |
__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
|
774 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
775 |
return(1); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
776 |
} /* PHYSFS_init */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
777 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
778 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
779 |
/* MAKE SURE you hold stateLock before calling this! */ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
780 |
static int closeFileHandleList(FileHandle **list) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
781 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
782 |
FileHandle *i; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
783 |
FileHandle *next = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
784 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
785 |
for (i = *list; i != NULL; i = next) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
786 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
787 |
next = i->next; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
788 |
if (!i->funcs->fileClose(i->opaque)) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
789 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
790 |
*list = i; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
791 |
return(0); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
792 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
793 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
794 |
allocator.Free(i); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
795 |
} /* for */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
796 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
797 |
*list = NULL; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
798 |
return(1); |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
799 |
} /* closeFileHandleList */ |
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 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
802 |
/* 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
|
803 |
static void freeSearchPath(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
804 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
805 |
DirHandle *i; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
806 |
DirHandle *next = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
807 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
808 |
closeFileHandleList(&openReadList); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
809 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
810 |
if (searchPath != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
811 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
812 |
for (i = searchPath; i != NULL; i = next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
813 |
{ |
25
96b32c0fd7f3
Bugfix for infinite loop/touching free()'d memory during PHYSFS_deinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
23
diff
changeset
|
814 |
next = i->next; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
815 |
freeDirHandle(i, openReadList); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
816 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
817 |
searchPath = NULL; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
818 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
819 |
} /* freeSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
820 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
821 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
822 |
int PHYSFS_deinit(void) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
823 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
824 |
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
|
825 |
BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), NULL, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
826 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
827 |
closeFileHandleList(&openWriteList); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
828 |
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
|
829 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
830 |
freeSearchPath(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
831 |
freeErrorMessages(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
832 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
833 |
if (baseDir != NULL) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
834 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
835 |
allocator.Free(baseDir); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
836 |
baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
837 |
} /* if */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
838 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
839 |
if (userDir != NULL) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
840 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
841 |
allocator.Free(userDir); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
842 |
userDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
843 |
} /* if */ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
844 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
845 |
allowSymLinks = 0; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
846 |
initialized = 0; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
847 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
848 |
__PHYSFS_platformDestroyMutex(errorLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
849 |
__PHYSFS_platformDestroyMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
850 |
|
751
74dc021744de
Some tweaks to PHYSFS_Allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
746
diff
changeset
|
851 |
if (allocator.Deinit != NULL) |
74dc021744de
Some tweaks to PHYSFS_Allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
746
diff
changeset
|
852 |
allocator.Deinit(); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
853 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
854 |
errorLock = stateLock = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
855 |
return(1); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
856 |
} /* PHYSFS_deinit */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
857 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
858 |
|
876
0d8e41a5c831
Added PHYSFS_isInit() function.
Ryan C. Gordon <icculus@icculus.org>
parents:
869
diff
changeset
|
859 |
int PHYSFS_isInit(void) |
0d8e41a5c831
Added PHYSFS_isInit() function.
Ryan C. Gordon <icculus@icculus.org>
parents:
869
diff
changeset
|
860 |
{ |
0d8e41a5c831
Added PHYSFS_isInit() function.
Ryan C. Gordon <icculus@icculus.org>
parents:
869
diff
changeset
|
861 |
return(initialized); |
0d8e41a5c831
Added PHYSFS_isInit() function.
Ryan C. Gordon <icculus@icculus.org>
parents:
869
diff
changeset
|
862 |
} /* PHYSFS_isInit */ |
0d8e41a5c831
Added PHYSFS_isInit() function.
Ryan C. Gordon <icculus@icculus.org>
parents:
869
diff
changeset
|
863 |
|
0d8e41a5c831
Added PHYSFS_isInit() function.
Ryan C. Gordon <icculus@icculus.org>
parents:
869
diff
changeset
|
864 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
865 |
const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
866 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
867 |
return(supported_types); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
868 |
} /* PHYSFS_supportedArchiveTypes */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
869 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
870 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
871 |
void PHYSFS_freeList(void *list) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
872 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
873 |
void **i; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
874 |
for (i = (void **) list; *i != NULL; i++) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
875 |
allocator.Free(*i); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
876 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
877 |
allocator.Free(list); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
878 |
} /* PHYSFS_freeList */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
879 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
880 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
881 |
const char *PHYSFS_getDirSeparator(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
882 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
883 |
return(__PHYSFS_platformDirSeparator); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
884 |
} /* PHYSFS_getDirSeparator */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
885 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
886 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
887 |
char **PHYSFS_getCdRomDirs(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
888 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
889 |
return(doEnumStringList(__PHYSFS_platformDetectAvailableCDs)); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
890 |
} /* PHYSFS_getCdRomDirs */ |
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 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
893 |
void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback callback, void *data) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
894 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
895 |
__PHYSFS_platformDetectAvailableCDs(callback, data); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
896 |
} /* PHYSFS_getCdRomDirsCallback */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
897 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
898 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
899 |
const char *PHYSFS_getBaseDir(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(baseDir); /* this is calculated in PHYSFS_init()... */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
902 |
} /* PHYSFS_getBaseDir */ |
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_getUserDir(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
906 |
{ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
907 |
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
|
908 |
} /* PHYSFS_getUserDir */ |
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_getWriteDir(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
912 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
913 |
const char *retval = NULL; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
914 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
915 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
916 |
if (writeDir != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
917 |
retval = writeDir->dirName; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
918 |
__PHYSFS_platformReleaseMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
919 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
920 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
921 |
} /* PHYSFS_getWriteDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
922 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
923 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
924 |
int PHYSFS_setWriteDir(const char *newDir) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
925 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
926 |
int retval = 1; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
927 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
928 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
929 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
930 |
if (writeDir != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
931 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
932 |
BAIL_IF_MACRO_MUTEX(!freeDirHandle(writeDir, openWriteList), NULL, |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
933 |
stateLock, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
934 |
writeDir = NULL; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
935 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
936 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
937 |
if (newDir != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
938 |
{ |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
939 |
writeDir = createDirHandle(newDir, NULL, 1); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
940 |
retval = (writeDir != NULL); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
941 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
942 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
943 |
__PHYSFS_platformReleaseMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
944 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
945 |
return(retval); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
946 |
} /* PHYSFS_setWriteDir */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
947 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
948 |
|
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
949 |
int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
950 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
951 |
DirHandle *dh; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
952 |
DirHandle *prev = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
953 |
DirHandle *i; |
51
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
954 |
|
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
955 |
BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0); |
733
29a0c0bb9a05
Allow a mount point of NULL to mean "/".
Ryan C. Gordon <icculus@icculus.org>
parents:
692
diff
changeset
|
956 |
|
29a0c0bb9a05
Allow a mount point of NULL to mean "/".
Ryan C. Gordon <icculus@icculus.org>
parents:
692
diff
changeset
|
957 |
if (mountPoint == NULL) |
29a0c0bb9a05
Allow a mount point of NULL to mean "/".
Ryan C. Gordon <icculus@icculus.org>
parents:
692
diff
changeset
|
958 |
mountPoint = "/"; |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
959 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
960 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
961 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
962 |
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
|
963 |
{ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
964 |
/* already in search path? */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
965 |
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
|
966 |
prev = i; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
967 |
} /* for */ |
51
42f4befc1d0b
Cleaned up PHYSFS_openRead() a little. PHYSFS_addToSearchPath() now
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
968 |
|
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
969 |
dh = createDirHandle(newDir, mountPoint, 0); |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
970 |
BAIL_IF_MACRO_MUTEX(dh == NULL, NULL, stateLock, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
971 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
972 |
if (appendToPath) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
973 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
974 |
if (prev == NULL) |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
975 |
searchPath = dh; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
976 |
else |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
977 |
prev->next = dh; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
978 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
979 |
else |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
980 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
981 |
dh->next = searchPath; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
982 |
searchPath = dh; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
983 |
} /* else */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
984 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
985 |
__PHYSFS_platformReleaseMutex(stateLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
986 |
return(1); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
987 |
} /* PHYSFS_mount */ |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
988 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
989 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
990 |
int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
991 |
{ |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
992 |
return(PHYSFS_mount(newDir, NULL, appendToPath)); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
993 |
} /* PHYSFS_addToSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
994 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
995 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
996 |
int PHYSFS_removeFromSearchPath(const char *oldDir) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
997 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
998 |
DirHandle *i; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
999 |
DirHandle *prev = NULL; |
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1000 |
DirHandle *next = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1001 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1002 |
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
|
1003 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1004 |
__PHYSFS_platformGrabMutex(stateLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1005 |
for (i = searchPath; i != NULL; i = i->next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1006 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1007 |
if (strcmp(i->dirName, oldDir) == 0) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1008 |
{ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1009 |
next = i->next; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1010 |
BAIL_IF_MACRO_MUTEX(!freeDirHandle(i, openReadList), NULL, |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1011 |
stateLock, 0); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1012 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1013 |
if (prev == NULL) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1014 |
searchPath = next; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1015 |
else |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1016 |
prev->next = next; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1017 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1018 |
BAIL_MACRO_MUTEX(NULL, stateLock, 1); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1019 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1020 |
prev = i; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1021 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1022 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1023 |
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
|
1024 |
} /* PHYSFS_removeFromSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1025 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1026 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1027 |
char **PHYSFS_getSearchPath(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1028 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1029 |
return(doEnumStringList(PHYSFS_getSearchPathCallback)); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1030 |
} /* PHYSFS_getSearchPath */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1031 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1032 |
|
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1033 |
const char *PHYSFS_getMountPoint(const char *dir) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1034 |
{ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1035 |
DirHandle *i; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1036 |
__PHYSFS_platformGrabMutex(stateLock); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1037 |
for (i = searchPath; i != NULL; i = i->next) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1038 |
{ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1039 |
if (strcmp(i->dirName, dir) == 0) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1040 |
{ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1041 |
const char *retval = ((i->mountPoint) ? i->mountPoint : "/"); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1042 |
__PHYSFS_platformReleaseMutex(stateLock); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1043 |
return(retval); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1044 |
} /* if */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1045 |
} /* for */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1046 |
__PHYSFS_platformReleaseMutex(stateLock); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1047 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1048 |
BAIL_MACRO(ERR_NOT_IN_SEARCH_PATH, NULL); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1049 |
} /* PHYSFS_getMountPoint */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1050 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
1051 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1052 |
void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback callback, void *data) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1053 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1054 |
DirHandle *i; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1055 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1056 |
__PHYSFS_platformGrabMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1057 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1058 |
for (i = searchPath; i != NULL; i = i->next) |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1059 |
callback(data, i->dirName); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1060 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1061 |
__PHYSFS_platformReleaseMutex(stateLock); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
1062 |
} /* PHYSFS_getSearchPathCallback */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1063 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1064 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1065 |
/* Split out to avoid stack allocation in a loop. */ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1066 |
static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep, |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1067 |
int archivesFirst) |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1068 |
{ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1069 |
const char *d = PHYSFS_getRealDir(i); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1070 |
const size_t allocsize = strlen(d) + strlen(dirsep) + l + 1; |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1071 |
char *str = (char *) __PHYSFS_smallAlloc(allocsize); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1072 |
if (str != NULL) |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1073 |
{ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1074 |
sprintf(str, "%s%s%s", d, dirsep, i); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1075 |
PHYSFS_addToSearchPath(str, archivesFirst == 0); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1076 |
__PHYSFS_smallFree(str); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1077 |
} /* if */ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1078 |
} /* setSaneCfgAddPath */ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1079 |
|
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1080 |
|
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
1081 |
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
|
1082 |
const char *archiveExt, int includeCdRoms, |
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
1083 |
int archivesFirst) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1084 |
{ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1085 |
const char *basedir = PHYSFS_getBaseDir(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1086 |
const char *userdir = PHYSFS_getUserDir(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1087 |
const char *dirsep = PHYSFS_getDirSeparator(); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1088 |
PHYSFS_uint64 len = 0; |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1089 |
char *str = NULL; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1090 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1091 |
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1092 |
|
746
88780f7156d3
Fixed bug in verifyPath() that was breaking PHYSFS_setSaneConfig() and other
Ryan C. Gordon <icculus@icculus.org>
parents:
736
diff
changeset
|
1093 |
/* set write dir... */ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1094 |
len = (strlen(userdir) + (strlen(organization) * 2) + |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1095 |
(strlen(appName) * 2) + (strlen(dirsep) * 3) + 2); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1096 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1097 |
str = (char *) __PHYSFS_smallAlloc(len); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1098 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1099 |
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
|
1100 |
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
|
1101 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1102 |
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
|
1103 |
{ |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1104 |
int no_write = 0; |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1105 |
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
|
1106 |
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
|
1107 |
(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
|
1108 |
{ |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1109 |
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
|
1110 |
if (!PHYSFS_setWriteDir(str)) |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1111 |
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
|
1112 |
} /* if */ |
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
1113 |
else |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1114 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
1115 |
no_write = 1; |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1116 |
} /* else */ |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1117 |
|
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1118 |
if (no_write) |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1119 |
{ |
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1120 |
PHYSFS_setWriteDir(NULL); /* just in case. */ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1121 |
__PHYSFS_smallFree(str); |
122
402ee2bf165c
Reports trouble setting the write dir in PHYSFS_setSaneConfig().
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
1122 |
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
|
1123 |
} /* if */ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1124 |
} /* if */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1125 |
|
103
cb5f60383994
PHYSFS_setSaneConfig() fixes: set write dir correctly, and put it at start
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
1126 |
/* 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
|
1127 |
PHYSFS_addToSearchPath(str, 0); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
1128 |
__PHYSFS_smallFree(str); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1129 |
|
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
1130 |
/* Put base path on search path... */ |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1131 |
PHYSFS_addToSearchPath(basedir, 1); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1132 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1133 |
/* handle CD-ROMs... */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1134 |
if (includeCdRoms) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1135 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1136 |
char **cds = PHYSFS_getCdRomDirs(); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1137 |
char **i; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1138 |
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
|
1139 |
PHYSFS_addToSearchPath(*i, 1); |
101
bd18e17ad6ad
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
1140 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1141 |
PHYSFS_freeList(cds); |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1142 |
} /* if */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1143 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1144 |
/* Root out archives, and add them to search path... */ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1145 |
if (archiveExt != NULL) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1146 |
{ |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
398
diff
changeset
|
1147 |
char **rc = PHYSFS_enumerateFiles("/"); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1148 |
char **i; |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
1149 |
size_t extlen = strlen(archiveExt); |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1150 |
char *ext; |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1151 |
|
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1152 |
for (i = rc; *i != NULL; i++) |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1153 |
{ |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
74
diff
changeset
|
1154 |
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
|
1155 |
if ((l > extlen) && ((*i)[l - extlen - 1] == '.')) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1156 |
{ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
1157 |
ext = (*i) + (l - extlen); |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. G |