author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 29 Aug 2010 21:36:38 -0400 | |
changeset 1122 | a710d2a325a6 |
parent 1121 | 63800b6cf054 |
child 1123 | 6fdff9f9758d |
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 |
|
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1090
diff
changeset
|
11 |
/* !!! FIXME: ERR_PAST_EOF shouldn't trigger for reads. Just return zero. */ |
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1090
diff
changeset
|
12 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
#include <stdio.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
#include <stdlib.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
#include <string.h> |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
#include "physfs.h" |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
18 |
#define __PHYSICSFS_INTERNAL__ |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
19 |
#include "physfs_internal.h" |
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
20 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
21 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
22 |
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
|
23 |
{ |
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
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
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
|
28 |
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
|
29 |
} 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
|
30 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
31 |
|
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
|
32 |
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
|
33 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
34 |
PHYSFS_Io *io; /* Instance data unique to the archiver for this file. */ |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
} FileHandle; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
43 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
44 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
typedef struct __PHYSFS_ERRMSGTYPE__ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
{ |
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
986
diff
changeset
|
47 |
void *tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
int errorAvailable; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
char errorString[80]; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
struct __PHYSFS_ERRMSGTYPE__ *next; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
} ErrMsg; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
53 |
|
796
5085b2f1213e
Killed some #ifdefs and whitespace.
Ryan C. Gordon <icculus@icculus.org>
parents:
795
diff
changeset
|
54 |
/* 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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD; |
796
5085b2f1213e
Killed some #ifdefs and whitespace.
Ryan C. Gordon <icculus@icculus.org>
parents:
795
diff
changeset
|
69 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR; |
1064
cc4db73e87d1
ISO9660 archiver, compliments of Christoph Nelles.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
70 |
extern const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ISO9660; |
cc4db73e87d1
ISO9660 archiver, compliments of Christoph Nelles.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
71 |
extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
72 |
|
453
108de3bb1b6b
Added qpak.c to build systems.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
73 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
74 |
static const PHYSFS_ArchiveInfo *supported_types[] = |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
77 |
&__PHYSFS_ArchiveInfo_ZIP, |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
#endif |
795
0f10cda58a9a
Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
79 |
#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
|
80 |
&__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
|
81 |
#endif |
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
82 |
#if (defined PHYSFS_SUPPORTS_GRP) |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
83 |
&__PHYSFS_ArchiveInfo_GRP, |
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
84 |
#endif |
582
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
85 |
#if (defined PHYSFS_SUPPORTS_QPAK) |
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
86 |
&__PHYSFS_ArchiveInfo_QPAK, |
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
87 |
#endif |
553
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_HOG) |
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_HOG, |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
90 |
#endif |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
91 |
#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
|
92 |
&__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
|
93 |
#endif |
609
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
94 |
#if (defined PHYSFS_SUPPORTS_WAD) |
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
95 |
&__PHYSFS_ArchiveInfo_WAD, |
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
96 |
#endif |
1066
e1d83e3b5d32
Make ISO9660 archiver optional.
Ryan C. Gordon <icculus@icculus.org>
parents:
1064
diff
changeset
|
97 |
#if (defined PHYSFS_SUPPORTS_ISO9660) |
1064
cc4db73e87d1
ISO9660 archiver, compliments of Christoph Nelles.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
98 |
&__PHYSFS_ArchiveInfo_ISO9660, |
1066
e1d83e3b5d32
Make ISO9660 archiver optional.
Ryan C. Gordon <icculus@icculus.org>
parents:
1064
diff
changeset
|
99 |
#endif |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
NULL |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
}; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
|
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
|
103 |
static const PHYSFS_Archiver *archivers[] = |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
104 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
105 |
#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
|
106 |
&__PHYSFS_Archiver_ZIP, |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
107 |
#endif |
795
0f10cda58a9a
Changed PHYSFS_SUPPORTS_LZMA to PHYSFS_SUPPORTS_7Z.
Ryan C. Gordon <icculus@icculus.org>
parents:
774
diff
changeset
|
108 |
#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
|
109 |
&__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
|
110 |
#endif |
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
111 |
#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
|
112 |
&__PHYSFS_Archiver_GRP, |
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
113 |
#endif |
582
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
114 |
#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
|
115 |
&__PHYSFS_Archiver_QPAK, |
582
d15d27e34a7e
Readded new qpak archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
116 |
#endif |
553
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
117 |
#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
|
118 |
&__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
|
119 |
#endif |
4338d9c0bbcd
Descent I/II HOG and MVL archive support (thanks, Bradley Bell!).
Ryan C. Gordon <icculus@icculus.org>
parents:
550
diff
changeset
|
120 |
#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
|
121 |
&__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
|
122 |
#endif |
609
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
123 |
#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
|
124 |
&__PHYSFS_Archiver_WAD, |
609
3a91332776e0
Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
582
diff
changeset
|
125 |
#endif |
1066
e1d83e3b5d32
Make ISO9660 archiver optional.
Ryan C. Gordon <icculus@icculus.org>
parents:
1064
diff
changeset
|
126 |
#if (defined PHYSFS_SUPPORTS_ISO9660) |
1064
cc4db73e87d1
ISO9660 archiver, compliments of Christoph Nelles.
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
127 |
&__PHYSFS_Archiver_ISO9660, |
1066
e1d83e3b5d32
Make ISO9660 archiver optional.
Ryan C. Gordon <icculus@icculus.org>
parents:
1064
diff
changeset
|
128 |
#endif |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
129 |
NULL |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
130 |
}; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
131 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
134 |
/* General PhysicsFS state ... */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
135 |
static int initialized = 0; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
static FileHandle *openReadList = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
141 |
static char *baseDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
142 |
static char *userDir = NULL; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
143 |
static int allowSymLinks = 0; |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
144 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
145 |
/* mutexes ... */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
146 |
static void *errorLock = NULL; /* protects error message list. */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
147 |
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
|
148 |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
149 |
/* allocator ... */ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
150 |
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
|
151 |
PHYSFS_Allocator allocator; |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
152 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
153 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
154 |
/* PHYSFS_Io implementation for i/o to physical filesystem... */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
155 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
156 |
/* !!! FIXME: maybe refcount the paths in a string pool? */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
157 |
typedef struct __PHYSFS_NativeIoInfo |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
158 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
159 |
void *handle; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
160 |
const char *path; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
161 |
int mode; /* 'r', 'w', or 'a' */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
162 |
} NativeIoInfo; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
163 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
164 |
static PHYSFS_sint64 nativeIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
165 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
166 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
167 |
return __PHYSFS_platformRead(info->handle, buf, len); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
168 |
} /* nativeIo_read */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
169 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
170 |
static PHYSFS_sint64 nativeIo_write(PHYSFS_Io *io, const void *buffer, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
171 |
PHYSFS_uint64 len) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
172 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
173 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
174 |
return __PHYSFS_platformWrite(info->handle, buffer, len); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
175 |
} /* nativeIo_write */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
176 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
177 |
static int nativeIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
178 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
179 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
180 |
return __PHYSFS_platformSeek(info->handle, offset); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
181 |
} /* nativeIo_seek */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
182 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
183 |
static PHYSFS_sint64 nativeIo_tell(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
184 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
185 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
186 |
return __PHYSFS_platformTell(info->handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
187 |
} /* nativeIo_tell */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
188 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
189 |
static PHYSFS_sint64 nativeIo_length(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
190 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
191 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
192 |
return __PHYSFS_platformFileLength(info->handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
193 |
} /* nativeIo_length */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
194 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
195 |
static PHYSFS_Io *nativeIo_duplicate(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
196 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
197 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
198 |
return __PHYSFS_createNativeIo(info->path, info->mode); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
199 |
} /* nativeIo_duplicate */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
200 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
201 |
static int nativeIo_flush(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
202 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
203 |
return __PHYSFS_platformFlush(io->opaque); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
204 |
} /* nativeIo_flush */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
205 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
206 |
static void nativeIo_destroy(PHYSFS_Io *io) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
207 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
208 |
NativeIoInfo *info = (NativeIoInfo *) io->opaque; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
209 |
__PHYSFS_platformClose(info->handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
210 |
allocator.Free((void *) info->path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
211 |
allocator.Free(info); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
212 |
allocator.Free(io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
213 |
} /* nativeIo_destroy */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
214 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
215 |
static const PHYSFS_Io __PHYSFS_nativeIoInterface = |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
216 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
217 |
nativeIo_read, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
218 |
nativeIo_write, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
219 |
nativeIo_seek, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
220 |
nativeIo_tell, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
221 |
nativeIo_length, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
222 |
nativeIo_duplicate, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
223 |
nativeIo_flush, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
224 |
nativeIo_destroy, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
225 |
NULL |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
226 |
}; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
227 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
228 |
PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
229 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
230 |
PHYSFS_Io *io = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
231 |
NativeIoInfo *info = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
232 |
void *handle = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
233 |
char *pathdup = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
234 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
235 |
assert((mode == 'r') || (mode == 'w') || (mode == 'a')); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
236 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
237 |
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
238 |
GOTO_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, createNativeIo_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
239 |
info = (NativeIoInfo *) allocator.Malloc(sizeof (NativeIoInfo)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
240 |
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, createNativeIo_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
241 |
pathdup = (char *) allocator.Malloc(strlen(path) + 1); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
242 |
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, createNativeIo_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
243 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
244 |
if (mode == 'r') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
245 |
handle = __PHYSFS_platformOpenRead(path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
246 |
else if (mode == 'w') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
247 |
handle = __PHYSFS_platformOpenWrite(path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
248 |
else if (mode == 'a') |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
249 |
handle = __PHYSFS_platformOpenAppend(path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
250 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
251 |
GOTO_IF_MACRO(handle == NULL, NULL, createNativeIo_failed); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
252 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
253 |
strcpy(pathdup, path); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
254 |
info->handle = handle; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
255 |
info->path = pathdup; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
256 |
info->mode = mode; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
257 |
memcpy(io, &__PHYSFS_nativeIoInterface, sizeof (*io)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
258 |
io->opaque = info; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
259 |
return io; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
260 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
261 |
createNativeIo_failed: |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
262 |
if (handle != NULL) __PHYSFS_platformClose(handle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
263 |
if (pathdup != NULL) allocator.Free(pathdup); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
264 |
if (info != NULL) allocator.Free(info); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
265 |
if (io != NULL) allocator.Free(io); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
266 |
return NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
267 |
} /* __PHYSFS_createNativeIo */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
268 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
269 |
|
1120
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
270 |
/* PHYSFS_Io implementation for i/o to a memory buffer... */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
271 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
272 |
typedef struct __PHYSFS_MemoryIoInfo |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
273 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
274 |
const PHYSFS_uint8 *buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
275 |
PHYSFS_uint64 len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
276 |
PHYSFS_uint64 pos; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
277 |
PHYSFS_Io *parent; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
278 |
volatile PHYSFS_uint32 refcount; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
279 |
void (*destruct)(void *); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
280 |
} MemoryIoInfo; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
281 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
282 |
static PHYSFS_sint64 memoryIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
283 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
284 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
285 |
const PHYSFS_uint64 avail = info->len - info->pos; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
286 |
assert(avail <= info->len); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
287 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
288 |
if (avail == 0) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
289 |
return 0; /* we're at EOF; nothing to do. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
290 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
291 |
if (len > avail) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
292 |
len = avail; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
293 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
294 |
memcpy(buf, info->buf + info->pos, len); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
295 |
info->pos += len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
296 |
return len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
297 |
} /* memoryIo_read */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
298 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
299 |
static PHYSFS_sint64 memoryIo_write(PHYSFS_Io *io, const void *buffer, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
300 |
PHYSFS_uint64 len) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
301 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
302 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
303 |
} /* memoryIo_write */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
304 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
305 |
static int memoryIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
306 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
307 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
308 |
BAIL_IF_MACRO(offset > info->len, ERR_PAST_EOF, 0); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
309 |
info->pos = offset; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
310 |
return 1; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
311 |
} /* memoryIo_seek */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
312 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
313 |
static PHYSFS_sint64 memoryIo_tell(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
314 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
315 |
const MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
316 |
return (PHYSFS_sint64) info->pos; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
317 |
} /* memoryIo_tell */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
318 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
319 |
static PHYSFS_sint64 memoryIo_length(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
320 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
321 |
const MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
322 |
return (PHYSFS_sint64) info->len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
323 |
} /* memoryIo_length */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
324 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
325 |
static PHYSFS_Io *memoryIo_duplicate(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
326 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
327 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
328 |
MemoryIoInfo *newinfo = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
329 |
PHYSFS_Io *parent = info->parent; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
330 |
PHYSFS_Io *retval = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
331 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
332 |
/* avoid deep copies. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
333 |
assert((!parent) || (!((MemoryIoInfo *) parent->opaque)->parent) ); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
334 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
335 |
/* share the buffer between duplicates. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
336 |
if (parent != NULL) /* dup the parent, increment its refcount. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
337 |
return parent->duplicate(parent); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
338 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
339 |
/* we're the parent. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
340 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
341 |
retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
342 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
343 |
newinfo = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
344 |
if (!newinfo) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
345 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
346 |
allocator.Free(retval); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
347 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
348 |
} /* if */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
349 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
350 |
/* !!! FIXME: want lockless atomic increment. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
351 |
__PHYSFS_platformGrabMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
352 |
info->refcount++; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
353 |
__PHYSFS_platformReleaseMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
354 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
355 |
memset(newinfo, '\0', sizeof (*info)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
356 |
newinfo->buf = info->buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
357 |
newinfo->len = info->len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
358 |
newinfo->pos = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
359 |
newinfo->parent = io; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
360 |
newinfo->refcount = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
361 |
newinfo->destruct = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
362 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
363 |
memcpy(retval, io, sizeof (*retval)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
364 |
retval->opaque = newinfo; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
365 |
return retval; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
366 |
} /* memoryIo_duplicate */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
367 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
368 |
static int memoryIo_flush(PHYSFS_Io *io) { return 1; /* it's read-only. */ } |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
369 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
370 |
static void memoryIo_destroy(PHYSFS_Io *io) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
371 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
372 |
MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
373 |
PHYSFS_Io *parent = info->parent; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
374 |
int should_die = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
375 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
376 |
if (parent != NULL) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
377 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
378 |
assert(info->buf == ((MemoryIoInfo *) info->parent->opaque)->buf); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
379 |
assert(info->len == ((MemoryIoInfo *) info->parent->opaque)->len); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
380 |
assert(info->refcount == 0); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
381 |
assert(info->destruct == NULL); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
382 |
allocator.Free(info); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
383 |
allocator.Free(io); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
384 |
parent->destroy(parent); /* decrements refcount. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
385 |
return; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
386 |
} /* if */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
387 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
388 |
/* we _are_ the parent. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
389 |
assert(info->refcount > 0); /* even in a race, we hold a reference. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
390 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
391 |
/* !!! FIXME: want lockless atomic decrement. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
392 |
__PHYSFS_platformGrabMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
393 |
info->refcount--; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
394 |
should_die = (info->refcount == 0); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
395 |
__PHYSFS_platformReleaseMutex(stateLock); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
396 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
397 |
if (should_die) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
398 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
399 |
void (*destruct)(void *) = info->destruct; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
400 |
void *buf = (void *) info->buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
401 |
io->opaque = NULL; /* kill this here in case of race. */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
402 |
destruct = info->destruct; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
403 |
allocator.Free(info); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
404 |
allocator.Free(io); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
405 |
if (destruct != NULL) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
406 |
destruct(buf); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
407 |
} /* if */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
408 |
} /* memoryIo_destroy */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
409 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
410 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
411 |
static const PHYSFS_Io __PHYSFS_memoryIoInterface = |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
412 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
413 |
memoryIo_read, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
414 |
memoryIo_write, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
415 |
memoryIo_seek, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
416 |
memoryIo_tell, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
417 |
memoryIo_length, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
418 |
memoryIo_duplicate, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
419 |
memoryIo_flush, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
420 |
memoryIo_destroy, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
421 |
NULL |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
422 |
}; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
423 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
424 |
PHYSFS_Io *__PHYSFS_createMemoryIo(const void *buf, PHYSFS_uint64 len, |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
425 |
void (*destruct)(void *)) |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
426 |
{ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
427 |
PHYSFS_Io *io = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
428 |
MemoryIoInfo *info = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
429 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
430 |
io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
431 |
GOTO_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, createMemoryIo_failed); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
432 |
info = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
433 |
GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, createMemoryIo_failed); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
434 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
435 |
memset(info, '\0', sizeof (*info)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
436 |
info->buf = (const PHYSFS_uint8 *) buf; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
437 |
info->len = len; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
438 |
info->pos = 0; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
439 |
info->parent = NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
440 |
info->refcount = 1; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
441 |
info->destruct = destruct; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
442 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
443 |
memcpy(io, &__PHYSFS_memoryIoInterface, sizeof (*io)); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
444 |
io->opaque = info; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
445 |
return io; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
446 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
447 |
createMemoryIo_failed: |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
448 |
if (info != NULL) allocator.Free(info); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
449 |
if (io != NULL) allocator.Free(io); |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
450 |
return NULL; |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
451 |
} /* __PHYSFS_createMemoryIo */ |
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
452 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
453 |
|
67e5e23425a0
Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents:
1119
diff
changeset
|
454 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
455 |
/* functions ... */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
457 |
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
|
458 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
} EnumStringListCallbackData; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
463 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
464 |
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
|
465 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
470 |
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
|
471 |
return; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
472 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
478 |
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
|
479 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
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
|
483 |
return; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
484 |
} /* if */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
485 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
} /* enumStringListCallback */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
490 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
491 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
492 |
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
|
493 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
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
|
499 |
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
|
500 |
ecd.list[ecd.size] = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
501 |
return ecd.list; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
502 |
} /* doEnumStringList */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
503 |
|
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
654
diff
changeset
|
504 |
|
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
533
diff
changeset
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
509 |
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
|
510 |
int sorted; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
511 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
512 |
do |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
513 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
514 |
sorted = 1; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
515 |
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
|
516 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
517 |
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
|
518 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
519 |
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
|
520 |
sorted = 0; |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
521 |
} /* if */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
522 |
} /* for */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
523 |
} while (!sorted); |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
524 |
} /* __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
|
525 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
526 |
|
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
533
diff
changeset
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
531 |
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
|
532 |
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
|
533 |
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
|
534 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
535 |
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
|
536 |
__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
|
537 |
else |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
538 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
539 |
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
|
540 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
545 |
j = hi - 1; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
546 |
swapfn(a, i, j); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
547 |
i = lo; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
548 |
v = j; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
549 |
while (1) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
550 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
551 |
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
|
552 |
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
|
553 |
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
|
554 |
break; |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
555 |
swapfn(a, i, j); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
556 |
} /* while */ |
948
923323444178
Valgrind fix: avoid overlapping memcpy() in sorting routines (thanks, JLM!).
Ryan C. Gordon <icculus@icculus.org>
parents:
901
diff
changeset
|
557 |
if (i != (hi-1)) |
923323444178
Valgrind fix: avoid overlapping memcpy() in sorting routines (thanks, JLM!).
Ryan C. Gordon <icculus@icculus.org>
parents:
901
diff
changeset
|
558 |
swapfn(a, i, hi-1); |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
576
diff
changeset
|
559 |
__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
|
560 |
__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
|
561 |
} /* else */ |
462
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
562 |
} /* __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
|
563 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
564 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
565 |
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
|
566 |
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
|
567 |
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
|
568 |
{ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
569 |
/* |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
570 |
* 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
|
571 |
* 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
|
572 |
*/ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
573 |
__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
|
574 |
} /* __PHYSFS_sort */ |
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
575 |
|
83c60189bc21
Made sorting more generic, moved it here. Added sort profiling code.
Ryan C. Gordon <icculus@icculus.org>
parents:
453
diff
changeset
|
576 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
577 |
static ErrMsg *findErrorForCurrentThread(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
578 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
579 |
ErrMsg *i; |
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
986
diff
changeset
|
580 |
void *tid; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
581 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
582 |
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
|
583 |
__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
|
584 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 |
if (errorMessages != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
586 |
{ |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
160
diff
changeset
|
587 |
tid = __PHYSFS_platformGetThreadID(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
589 |
for (i = errorMessages; i != NULL; i = i->next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
590 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
591 |
if (i->tid == tid) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
592 |
{ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
593 |
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
|
594 |
__PHYSFS_platformReleaseMutex(errorLock); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
595 |
return i; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
596 |
} /* if */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
597 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
598 |
} /* 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
|
599 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
600 |
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
|
601 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
602 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
603 |
return NULL; /* no error available. */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
604 |
} /* findErrorForCurrentThread */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
605 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
606 |
|
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
607 |
void __PHYSFS_setError(const char *str) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
608 |
{ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
609 |
ErrMsg *err; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
610 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
611 |
if (str == NULL) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
612 |
return; |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
613 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
614 |
err = findErrorForCurrentThread(); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
615 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
616 |
if (err == NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
617 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
618 |
err = (ErrMsg *) allocator.Malloc(sizeof (ErrMsg)); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
619 |
if (err == NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
620 |
return; /* uhh...? */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
621 |
|
57
1ec888db3df9
Safety memset when creating error information for a new thread.
Ryan C. Gordon <icculus@icculus.org>
parents:
51
diff
changeset
|
622 |
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
|
623 |
err->tid = __PHYSFS_platformGetThreadID(); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
624 |
|
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
625 |
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
|
626 |
__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
|
627 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
628 |
err->next = errorMessages; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
629 |
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
|
630 |
|
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
631 |
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
|
632 |
__PHYSFS_platformReleaseMutex(errorLock); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
633 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
634 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
635 |
err->errorAvailable = 1; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
636 |
strncpy(err->errorString, str, sizeof (err->errorString)); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
637 |
err->errorString[sizeof (err->errorString) - 1] = '\0'; |
7
07d5e6e8259d
More work. Getting better.
Ryan C. Gordon <icculus@icculus.org>
parents:
5
diff
changeset
|
638 |
} /* __PHYSFS_setError */ |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
639 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
640 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
641 |
const char *PHYSFS_getLastError(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
642 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 |
ErrMsg *err = findErrorForCurrentThread(); |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
644 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
645 |
if ((err == NULL) || (!err->errorAvailable)) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
646 |
return NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
647 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 |
err->errorAvailable = 0; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
649 |
return err->errorString; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
650 |
} /* PHYSFS_getLastError */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
651 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
652 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
653 |
/* 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
|
654 |
static void freeErrorMessages(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
655 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
656 |
ErrMsg *i; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
657 |
ErrMsg *next; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
658 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
659 |
for (i = errorMessages; i != NULL; i = next) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
660 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
661 |
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
|
662 |
allocator.Free(i); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
663 |
} /* for */ |
272
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
664 |
|
470430943851
Fixed a crashbug when calling PHYSFS_deinit() twice in a row.
Ryan C. Gordon <icculus@icculus.org>
parents:
242
diff
changeset
|
665 |
errorMessages = NULL; |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
666 |
} /* freeErrorMessages */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
667 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
668 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
669 |
void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
670 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
671 |
if (ver != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
672 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
673 |
ver->major = PHYSFS_VER_MAJOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
674 |
ver->minor = PHYSFS_VER_MINOR; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
675 |
ver->patch = PHYSFS_VER_PATCH; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
676 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
677 |
} /* PHYSFS_getLinkedVersion */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
678 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
679 |
|
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
680 |
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
|
681 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
682 |
const char *retval = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
683 |
if (fname != NULL) |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
684 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
685 |
retval = strchr(fname, '.'); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
686 |
const char *p = retval; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
687 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
688 |
while (p != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
689 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
690 |
p = strchr(p + 1, '.'); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
691 |
if (p != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
692 |
retval = p; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
693 |
} /* while */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
694 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
695 |
if (retval != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
696 |
retval++; /* skip '.' */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
697 |
} /* if */ |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
698 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
699 |
return retval; |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
700 |
} /* 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
|
701 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
702 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
703 |
static DirHandle *tryOpenDir(PHYSFS_Io *io, const PHYSFS_Archiver *funcs, |
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
|
704 |
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
|
705 |
{ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
706 |
DirHandle *retval = NULL; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
707 |
void *opaque = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
708 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
709 |
if (io != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
710 |
BAIL_IF_MACRO(!io->seek(io, 0), NULL, NULL); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
711 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
712 |
opaque = funcs->openArchive(io, d, forWriting); |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
713 |
if (opaque != NULL) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
714 |
{ |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
715 |
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle)); |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
716 |
if (retval == NULL) |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
717 |
funcs->dirClose(opaque); |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
718 |
else |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
719 |
{ |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
720 |
memset(retval, '\0', sizeof (DirHandle)); |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
721 |
retval->mountPoint = NULL; |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
722 |
retval->funcs = funcs; |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
723 |
retval->opaque = opaque; |
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
724 |
} /* else */ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
725 |
} /* if */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
726 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
727 |
return retval; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
728 |
} /* tryOpenDir */ |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
729 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
730 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
731 |
static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
732 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
733 |
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
|
734 |
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
|
735 |
const char *ext; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
736 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
737 |
assert((io != NULL) || (d != NULL)); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
738 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
739 |
if (io == NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
740 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
741 |
BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
742 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
743 |
/* DIR gets first shot (unlike the rest, it doesn't deal with files). */ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
744 |
retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
745 |
if (retval != NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
746 |
return retval; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
747 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
748 |
io = __PHYSFS_createNativeIo(d, forWriting ? 'w' : 'r'); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
749 |
BAIL_IF_MACRO_MUTEX(io == NULL, NULL, stateLock, 0); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
750 |
} /* if */ |
1113
2136d64bd1ad
Removed PHYSFS_Archiver's isArchive() method.
Ryan C. Gordon <icculus@icculus.org>
parents:
1112
diff
changeset
|
751 |
|
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
752 |
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
|
753 |
if (ext != NULL) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
754 |
{ |
398
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
755 |
/* 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
|
756 |
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
|
757 |
{ |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
821
diff
changeset
|
758 |
if (__PHYSFS_stricmpASCII(ext, (*i)->info->extension) == 0) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
759 |
retval = tryOpenDir(io, *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
|
760 |
} /* for */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
761 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
762 |
/* 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
|
763 |
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
|
764 |
{ |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
821
diff
changeset
|
765 |
if (__PHYSFS_stricmpASCII(ext, (*i)->info->extension) != 0) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
766 |
retval = tryOpenDir(io, *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
|
767 |
} /* for */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
768 |
} /* if */ |
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
769 |
|
aa1e763b09ae
Archivers with matching file extensions get first shot at an archive.
Ryan C. Gordon <icculus@icculus.org>
parents:
393
diff
changeset
|
770 |
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
|
771 |
{ |
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
|
772 |
for (i = archivers; (*i != NULL) && (retval == NULL); i++) |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
773 |
retval = tryOpenDir(io, *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
|
774 |
} /* else */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
775 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
776 |
BAIL_IF_MACRO(retval == NULL, ERR_UNSUPPORTED_ARCHIVE, NULL); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
777 |
return retval; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
778 |
} /* openDirectory */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
779 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
780 |
|
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
781 |
/* |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
782 |
* 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
|
783 |
* 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
|
784 |
* (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
|
785 |
* cleaned up string is deposited. |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
786 |
* 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
|
787 |
* 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
|
788 |
*/ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
789 |
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
|
790 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
791 |
char *prev; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
792 |
char ch; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
793 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
794 |
while (*src == '/') /* skip initial '/' chars... */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
795 |
src++; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
796 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
797 |
prev = dst; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
798 |
do |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
799 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
800 |
ch = *(src++); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
801 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
802 |
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
|
803 |
BAIL_MACRO(ERR_INSECURE_FNAME, 0); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
804 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
805 |
if (ch == '/') /* path separator. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
806 |
{ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
807 |
*dst = '\0'; /* "." and ".." are illegal pathnames. */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
808 |
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
|
809 |
BAIL_MACRO(ERR_INSECURE_FNAME, 0); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
810 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
811 |
while (*src == '/') /* chop out doubles... */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
812 |
src++; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
813 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
814 |
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
|
815 |
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
|
816 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
817 |
prev = dst + 1; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
818 |
} /* if */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
819 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
820 |
*(dst++) = ch; |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
821 |
} while (ch != '\0'); |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
822 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
823 |
return 1; |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
824 |
} /* sanitizePlatformIndependentPath */ |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
825 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
826 |
|
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
827 |
/* |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
828 |
* 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
|
829 |
* 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
|
830 |
* state. |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
831 |
* |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
832 |
* 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
|
833 |
* "/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
|
834 |
* all zero. "/a/b" will succeed, though. |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
835 |
*/ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
836 |
static int partOfMountPoint(DirHandle *h, char *fname) |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
837 |
{ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
838 |
/* !!! FIXME: This code feels gross. */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
839 |
int rc; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
840 |
size_t len, mntpntlen; |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
841 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
842 |
if (h->mountPoint == NULL) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
843 |
return 0; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
844 |
else if (*fname == '\0') |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
845 |
return 1; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
846 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
847 |
len = strlen(fname); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
848 |
mntpntlen = strlen(h->mountPoint); |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
849 |
if (len > mntpntlen) /* can't be a subset of mountpoint. */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
850 |
return 0; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
851 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
852 |
/* 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
|
853 |
if ((len + 1) == mntpntlen) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
854 |
return 0; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
855 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
856 |
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
|
857 |
if (rc != 0) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
858 |
return 0; /* not a match. */ |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
859 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
860 |
/* make sure /a/b matches /a/b/ and not /a/bc ... */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
861 |
return h->mountPoint[len] == '/'; |
687
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
862 |
} /* partOfMountPoint */ |
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
863 |
|
f76dffa43fa2
More mountpoint work and other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
685
diff
changeset
|
864 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
865 |
static DirHandle *createDirHandle(PHYSFS_Io *io, const char *newDir, |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
866 |
const char *mountPoint, int forWriting) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
867 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
868 |
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
|
869 |
char *tmpmntpnt = NULL; |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
870 |
|
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
871 |
if (mountPoint != NULL) |
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
872 |
{ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
873 |
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
|
874 |
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
|
875 |
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
|
876 |
if (!sanitizePlatformIndependentPath(mountPoint, tmpmntpnt)) |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
877 |
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
|
878 |
mountPoint = tmpmntpnt; /* sanitized version. */ |
683
e724adb731df
Split off sanitizePlatformIndependentPath() from verifySecurity(), which makes
Ryan C. Gordon <icculus@icculus.org>
parents:
679
diff
changeset
|
879 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
880 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
881 |
dirHandle = openDirectory(io, newDir, forWriting); |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
882 |
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
|
883 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
884 |
if (newDir == NULL) |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
885 |
dirHandle->dirName = NULL; |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
886 |
else |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
887 |
{ |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
888 |
dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
889 |
GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
890 |
strcpy(dirHandle->dirName, newDir); |
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
891 |
} /* else */ |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
892 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
893 |
if ((mountPoint != NULL) && (*mountPoint != '\0')) |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
894 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
895 |
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
|
896 |
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
|
897 |
strcpy(dirHandle->mountPoint, mountPoint); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
898 |
strcat(dirHandle->mountPoint, "/"); |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
899 |
} /* if */ |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
900 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
901 |
__PHYSFS_smallFree(tmpmntpnt); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
902 |
return dirHandle; |
679
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
903 |
|
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
904 |
badDirHandle: |
ae75b5548364
First chunk of PHYSFS_mount() implementation. Incomplete!
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
905 |
if (dirHandle != NULL) |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
906 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
644
diff
changeset
|
907 |
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
|
908 |
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
|
909 |
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
|
910 |
allocator.Free(dirHandle); |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
911 |
} /* if */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
912 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
913 |
__PHYSFS_smallFree(tmpmntpnt); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
914 |
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
|
915 |
} /* createDirHandle */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
916 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
917 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
918 |
/* 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
|
919 |
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
|
920 |
{ |
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
|
921 |
FileHandle *i; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
922 |
|
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
|
923 |
if (dh == NULL) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
924 |
return 1; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
925 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
926 |
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
|
927 |
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
|
928 |
|
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
|
929 |
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
|
930 |
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
|
931 |
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
|
932 |
allocator.Free(dh); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
933 |
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
|
934 |
} /* freeDirHandle */ |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
935 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
936 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
937 |
static char *calculateUserDir(void) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
938 |
{ |
1072
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
939 |
char *retval = __PHYSFS_platformGetUserDir(); |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
940 |
if (retval != NULL) |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
941 |
{ |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
942 |
/* make sure it really exists and is normalized. */ |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
943 |
char *ptr = __PHYSFS_platformRealPath(retval); |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
944 |
allocator.Free(retval); |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
945 |
retval = ptr; |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
946 |
} /* if */ |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
947 |
|
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
948 |
if (retval == NULL) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
949 |
{ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
950 |
const char *dirsep = PHYSFS_getDirSeparator(); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
951 |
const char *uname = __PHYSFS_platformGetUserName(); |
1072
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
952 |
const char *str = (uname != NULL) ? uname : "default"; |
6d3a91a5029b
If $HOME is invalid, scratch together a different userdir.
Ryan C. Gordon <icculus@icculus.org>
parents:
1066
diff
changeset
|
953 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
954 |
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
|
955 |
strlen(dirsep) + 6); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
956 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
957 |
if (retval == NULL) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
958 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
959 |
else |
155
54fee85d9c26
Fixed calculateUserDir() to prevent extra dir separator insertion in default case.
Ryan C. Gordon <icculus@icculus.org>
parents:
150
diff
changeset
|
960 |
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
|
961 |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
848
diff
changeset
|
962 |
allocator.Free((void *) uname); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
963 |
} /* else */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
964 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
965 |
return retval; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
966 |
} /* calculateUserDir */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
967 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
968 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
969 |
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
|
970 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
971 |
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
|
972 |
char *ptr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
973 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
974 |
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
975 |
return 1; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
976 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
977 |
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
|
978 |
if (!ptr) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
979 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
980 |
allocator.Free(*dir); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
981 |
return 0; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
982 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
983 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
984 |
strcat(ptr, dirsep); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
985 |
*dir = ptr; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
986 |
return 1; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
987 |
} /* appendDirSep */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
988 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
989 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
990 |
static char *calculateBaseDir(const char *argv0) |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
991 |
{ |
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
992 |
char *retval = NULL; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
993 |
const char *dirsep = NULL; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
994 |
char *ptr = NULL; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
995 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
996 |
/* 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
|
997 |
retval = __PHYSFS_platformCalcBaseDir(argv0); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
998 |
if (retval != NULL) |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
999 |
return retval; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1000 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1001 |
/* We need argv0 to go on. */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1002 |
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
|
1003 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1004 |
dirsep = PHYSFS_getDirSeparator(); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1005 |
if (strlen(dirsep) == 1) /* fast path. */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1006 |
ptr = strrchr(argv0, *dirsep); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1007 |
else |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1008 |
{ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1009 |
ptr = strstr(argv0, dirsep); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1010 |
if (ptr != NULL) |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1011 |
{ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1012 |
char *p = ptr; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1013 |
while (p != NULL) |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1014 |
{ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1015 |
ptr = p; |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1016 |
p = strstr(p + 1, dirsep); |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1017 |
} /* while */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1018 |
} /* if */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1019 |
} /* else */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1020 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1021 |
if (ptr != NULL) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1022 |
{ |
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1023 |
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
|
1024 |
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
|
1025 |
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
|
1026 |
memcpy(retval, argv0, size); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1027 |
retval[size] = '\0'; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1028 |
return retval; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1029 |
} /* if */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1030 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1031 |
/* argv0 wasn't helpful. */ |
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1032 |
BAIL_MACRO(ERR_INVALID_ARGUMENT, NULL); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1033 |
} /* calculateBaseDir */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1034 |
|
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1035 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1036 |
static int initializeMutexes(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1037 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1038 |
errorLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1039 |
if (errorLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1040 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1041 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1042 |
stateLock = __PHYSFS_platformCreateMutex(); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1043 |
if (stateLock == NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1044 |
goto initializeMutexes_failed; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1045 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1046 |
return 1; /* success. */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1047 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1048 |
initializeMutexes_failed: |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1049 |
if (errorLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1050 |
__PHYSFS_platformDestroyMutex(errorLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1051 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1052 |
if (stateLock != NULL) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1053 |
__PHYSFS_platformDestroyMutex(stateLock); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1054 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1055 |
errorLock = stateLock = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1056 |
return 0; /* failed. */ |
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1057 |
} /* initializeMutexes */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1058 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1059 |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
1060 |
static void setDefaultAllocator(void); |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
1061 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1062 |
int PHYSFS_init(const char *argv0) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1063 |
{ |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1064 |
char *ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1065 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1066 |
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
|
1067 |
|
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
1068 |
if (!externalAllocator) |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
1069 |
setDefaultAllocator(); |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
634
diff
changeset
|
1070 |
|
751
74dc021744de
Some tweaks to PHYSFS_Allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
746
diff
changeset
|
1071 |
if (allocator.Init != NULL) |
74dc021744de
Some tweaks to PHYSFS_Allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
746
diff
changeset
|
1072 |
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
|
1073 |
|
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
126
diff
changeset
|
1074 |
BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1075 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1076 |
BAIL_IF_MACRO(!initializeMutexes(), NULL, 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1077 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1078 |
baseDir = calculateBaseDir(argv0); |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1079 |
BAIL_IF_MACRO(baseDir == NULL, NULL, 0); |
186 | 1080 |
|
848
963d26edb39b
Cleanups in calculateBaseDir.
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
1081 |
/* !!! 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
|
1082 |
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
|
1083 |
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
|
1084 |
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
|
1085 |
baseDir = ptr; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
1086 |
|
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1087 |
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1088 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1089 |
userDir = calculateUserDir(); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
1090 |
if ((userDir == NULL) || (!appendDirSep(&userDir))) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1091 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1092 |
allocator.Free(baseDir); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1093 |
baseDir = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1094 |
return 0; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1095 |
} /* if */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1096 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1097 |
initialized = 1; |
167
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
1098 |
|
fd695ca50a2c
Error subsystem does basic initialization during PHYSFS_init(), now.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
1099 |
/* 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
|
1100 |
__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
|
1101 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1102 |
return 1; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1103 |
} /* PHYSFS_init */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1104 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1105 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1106 |
/* 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
|
1107 |
static int closeFileHandleList(FileHandle **list) |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1108 |
{ |
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
|
1109 |
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
|
1110 |
FileHandle *next = NULL; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1111 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1112 |
for (i = *list; i != NULL; i = next) |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1113 |
{ |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
1114 |
PHYSFS_Io *io = i->io; |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1115 |
next = i->next; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
1116 |
|
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
1117 |
if (!io->flush(io)) |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1118 |
{ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1119 |
*list = i; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1120 |
return 0; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1121 |
} /* if */ |
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1122 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1113
diff
changeset
|
1123 |
io->destroy(io); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
1124 |
allocator.Free(i); |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1125 |
} /* for */ |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1126 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1127 |
*list = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
1128 |
return 1; |
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1129 |
} /* closeFileHandleList */ |
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1130 |
|
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1131 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
1132 |
/* 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
|
1133 |
static void freeSearchPath(void) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1134 |
{ |
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
|
1135 |
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
|
1136 |
DirHandle *next = NULL; |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1137 |
|
11
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1138 |
closeFileHandleList(&openReadList); |
677e01f5109e
Progress toward complete implementation continues...
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
1139 |
|
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1140 |
if (searchPath != NULL) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1141 |
{ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1142 |
for (i = searchPath; i != NULL; i = next) |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1143 |
{ |
25
96b32c0fd7f3
Bugfix for infinite loop/touching free()'d memory during PHYSFS_deinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
23
diff
changeset
|
1144 |
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
|
1145 |
freeDirHandle(i, openReadList); |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1146 |
} /* for */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1147 |
searchPath = NULL; |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1148 |
} /* if */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1149 |
} /* freeSearchPath */ |
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1150 |
|
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1151 |
|
15
418eacc97ac8
Tons of updates. Mostly implemented. Mostly compiling.
Ryan C. Gordon <icculus@icculus.org>
parents:
12
diff
changeset
|
1152 |
int PHYSFS_deinit(void) |
5
055ddaaabf85
Initial add; not yet completely implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|