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