author | alfadur |
Mon, 28 May 2018 19:50:15 -0400 | |
changeset 13407 | 06792533ef91 |
parent 12213 | bb5522e88ab2 |
permissions | -rw-r--r-- |
7768 | 1 |
/* |
2 |
* Standard directory I/O support routines for PhysicsFS. |
|
3 |
* |
|
4 |
* Please see the file LICENSE.txt in the source's root directory. |
|
5 |
* |
|
6 |
* This file written by Ryan C. Gordon. |
|
7 |
*/ |
|
8 |
||
9 |
#define __PHYSICSFS_INTERNAL__ |
|
10 |
#include "physfs_internal.h" |
|
11 |
||
12 |
/* There's no PHYSFS_Io interface here. Use __PHYSFS_createNativeIo(). */ |
|
13 |
||
14 |
||
15 |
||
16 |
static char *cvtToDependent(const char *prepend, const char *path, char *buf) |
|
17 |
{ |
|
18 |
BAIL_IF_MACRO(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
|
19 |
sprintf(buf, "%s%s", prepend ? prepend : "", path); |
|
20 |
||
21 |
if (__PHYSFS_platformDirSeparator != '/') |
|
22 |
{ |
|
23 |
char *p; |
|
24 |
for (p = strchr(buf, '/'); p != NULL; p = strchr(p + 1, '/')) |
|
25 |
*p = __PHYSFS_platformDirSeparator; |
|
26 |
} /* if */ |
|
27 |
||
28 |
return buf; |
|
29 |
} /* cvtToDependent */ |
|
30 |
||
31 |
||
32 |
#define CVT_TO_DEPENDENT(buf, pre, dir) { \ |
|
33 |
const size_t len = ((pre) ? strlen((char *) pre) : 0) + strlen(dir) + 1; \ |
|
34 |
buf = cvtToDependent((char*)pre,dir,(char*)__PHYSFS_smallAlloc(len)); \ |
|
35 |
} |
|
36 |
||
37 |
||
38 |
||
39 |
static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting) |
|
40 |
{ |
|
41 |
PHYSFS_Stat st; |
|
42 |
const char dirsep = __PHYSFS_platformDirSeparator; |
|
43 |
char *retval = NULL; |
|
44 |
const size_t namelen = strlen(name); |
|
45 |
const size_t seplen = 1; |
|
46 |
||
47 |
assert(io == NULL); /* shouldn't create an Io for these. */ |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
48 |
BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &st), ERRPASS, NULL); |
7768 | 49 |
if (st.filetype != PHYSFS_FILETYPE_DIRECTORY) |
50 |
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); |
|
51 |
||
52 |
retval = allocator.Malloc(namelen + seplen + 1); |
|
53 |
BAIL_IF_MACRO(retval == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
|
54 |
||
55 |
strcpy(retval, name); |
|
56 |
||
57 |
/* make sure there's a dir separator at the end of the string */ |
|
58 |
if (retval[namelen - 1] != dirsep) |
|
59 |
{ |
|
60 |
retval[namelen] = dirsep; |
|
61 |
retval[namelen + 1] = '\0'; |
|
62 |
} /* if */ |
|
63 |
||
64 |
return retval; |
|
65 |
} /* DIR_openArchive */ |
|
66 |
||
67 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
68 |
static void DIR_enumerateFiles(void *opaque, const char *dname, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
69 |
PHYSFS_EnumFilesCallback cb, |
7768 | 70 |
const char *origdir, void *callbackdata) |
71 |
{ |
|
72 |
char *d; |
|
73 |
||
74 |
CVT_TO_DEPENDENT(d, opaque, dname); |
|
75 |
if (d != NULL) |
|
76 |
{ |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
77 |
__PHYSFS_platformEnumerateFiles(d, cb, origdir, callbackdata); |
7768 | 78 |
__PHYSFS_smallFree(d); |
79 |
} /* if */ |
|
80 |
} /* DIR_enumerateFiles */ |
|
81 |
||
82 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
83 |
static PHYSFS_Io *doOpen(void *opaque, const char *name, const int mode) |
7768 | 84 |
{ |
85 |
PHYSFS_Io *io = NULL; |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
86 |
char *f = NULL; |
7768 | 87 |
|
88 |
CVT_TO_DEPENDENT(f, opaque, name); |
|
89 |
BAIL_IF_MACRO(!f, ERRPASS, NULL); |
|
90 |
||
91 |
io = __PHYSFS_createNativeIo(f, mode); |
|
92 |
if (io == NULL) |
|
93 |
{ |
|
94 |
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode(); |
|
95 |
PHYSFS_Stat statbuf; |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
96 |
__PHYSFS_platformStat(f, &statbuf); |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
97 |
PHYSFS_setErrorCode(err); |
7768 | 98 |
} /* if */ |
99 |
||
100 |
__PHYSFS_smallFree(f); |
|
101 |
||
102 |
return io; |
|
103 |
} /* doOpen */ |
|
104 |
||
105 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
106 |
static PHYSFS_Io *DIR_openRead(void *opaque, const char *filename) |
7768 | 107 |
{ |
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
108 |
return doOpen(opaque, filename, 'r'); |
7768 | 109 |
} /* DIR_openRead */ |
110 |
||
111 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
112 |
static PHYSFS_Io *DIR_openWrite(void *opaque, const char *filename) |
7768 | 113 |
{ |
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
114 |
return doOpen(opaque, filename, 'w'); |
7768 | 115 |
} /* DIR_openWrite */ |
116 |
||
117 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
118 |
static PHYSFS_Io *DIR_openAppend(void *opaque, const char *filename) |
7768 | 119 |
{ |
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
120 |
return doOpen(opaque, filename, 'a'); |
7768 | 121 |
} /* DIR_openAppend */ |
122 |
||
123 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
124 |
static int DIR_remove(void *opaque, const char *name) |
7768 | 125 |
{ |
126 |
int retval; |
|
127 |
char *f; |
|
128 |
||
129 |
CVT_TO_DEPENDENT(f, opaque, name); |
|
130 |
BAIL_IF_MACRO(!f, ERRPASS, 0); |
|
131 |
retval = __PHYSFS_platformDelete(f); |
|
132 |
__PHYSFS_smallFree(f); |
|
133 |
return retval; |
|
134 |
} /* DIR_remove */ |
|
135 |
||
136 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
137 |
static int DIR_mkdir(void *opaque, const char *name) |
7768 | 138 |
{ |
139 |
int retval; |
|
140 |
char *f; |
|
141 |
||
142 |
CVT_TO_DEPENDENT(f, opaque, name); |
|
143 |
BAIL_IF_MACRO(!f, ERRPASS, 0); |
|
144 |
retval = __PHYSFS_platformMkDir(f); |
|
145 |
__PHYSFS_smallFree(f); |
|
146 |
return retval; |
|
147 |
} /* DIR_mkdir */ |
|
148 |
||
149 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
150 |
static void DIR_closeArchive(void *opaque) |
7768 | 151 |
{ |
152 |
allocator.Free(opaque); |
|
153 |
} /* DIR_closeArchive */ |
|
154 |
||
155 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
156 |
static int DIR_stat(void *opaque, const char *name, PHYSFS_Stat *stat) |
7768 | 157 |
{ |
158 |
int retval = 0; |
|
159 |
char *d; |
|
160 |
||
161 |
CVT_TO_DEPENDENT(d, opaque, name); |
|
162 |
BAIL_IF_MACRO(!d, ERRPASS, 0); |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
163 |
retval = __PHYSFS_platformStat(d, stat); |
7768 | 164 |
__PHYSFS_smallFree(d); |
165 |
return retval; |
|
166 |
} /* DIR_stat */ |
|
167 |
||
168 |
||
169 |
const PHYSFS_Archiver __PHYSFS_Archiver_DIR = |
|
170 |
{ |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
171 |
CURRENT_PHYSFS_ARCHIVER_API_VERSION, |
7768 | 172 |
{ |
173 |
"", |
|
174 |
"Non-archive, direct filesystem I/O", |
|
175 |
"Ryan C. Gordon <icculus@icculus.org>", |
|
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
176 |
"https://icculus.org/physfs/", |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
177 |
1, /* supportsSymlinks */ |
7768 | 178 |
}, |
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
179 |
DIR_openArchive, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
180 |
DIR_enumerateFiles, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
181 |
DIR_openRead, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
182 |
DIR_openWrite, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
183 |
DIR_openAppend, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
184 |
DIR_remove, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
185 |
DIR_mkdir, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
186 |
DIR_stat, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
187 |
DIR_closeArchive |
7768 | 188 |
}; |
189 |
||
12213
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
190 |
/* end of archiver_dir.c ... */ |
7768 | 191 |