Skip to content

Latest commit

 

History

History
411 lines (347 loc) · 14.1 KB

physfs_internal.h

File metadata and controls

411 lines (347 loc) · 14.1 KB
 
Jul 6, 2001
Jul 6, 2001
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
* Internal function/structure declaration. Do NOT include in your
* application.
*
* Please see the file LICENSE in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
#ifndef _INCLUDE_PHYSFS_INTERNAL_H_
#define _INCLUDE_PHYSFS_INTERNAL_H_
#ifndef __PHYSICSFS_INTERNAL__
#error Do not include this header from your applications.
#endif
Jul 7, 2001
Jul 7, 2001
17
struct __PHYSFS_DIRHANDLE__;
Jul 6, 2001
Jul 6, 2001
18
struct __PHYSFS_FILEFUNCTIONS__;
Jul 6, 2001
Jul 6, 2001
19
Jul 8, 2001
Jul 8, 2001
20
21
22
23
24
25
26
27
typedef struct __PHYSFS_LINKEDSTRINGLIST__
{
char *str;
struct __PHYSFS_LINKEDSTRINGLIST__ *next;
} LinkedStringList;
Jul 6, 2001
Jul 6, 2001
28
29
30
31
32
33
34
35
typedef struct __PHYSFS_FILEHANDLE__
{
/*
* This is reserved for the driver to store information.
*/
void *opaque;
/*
Jul 6, 2001
Jul 6, 2001
36
* This should be the DirHandle that created this FileHandle.
Jul 6, 2001
Jul 6, 2001
37
*/
Jul 7, 2001
Jul 7, 2001
38
const struct __PHYSFS_DIRHANDLE__ *dirHandle;
Jul 6, 2001
Jul 6, 2001
39
Jul 6, 2001
Jul 6, 2001
40
41
42
43
44
45
46
47
48
/*
* Pointer to the file i/o functions for this filehandle.
*/
const struct __PHYSFS_FILEFUNCTIONS__ *funcs;
} FileHandle;
typedef struct __PHYSFS_FILEFUNCTIONS__
{
Jul 6, 2001
Jul 6, 2001
49
50
/*
* Read more from the file.
Jul 7, 2001
Jul 7, 2001
51
52
53
* Returns number of objects of (objSize) bytes read from file, -1
* if complete failure.
* On failure, call __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
54
*/
Jul 6, 2001
Jul 6, 2001
55
int (*read)(FileHandle *handle, void *buffer,
Jul 6, 2001
Jul 6, 2001
56
57
58
59
60
unsigned int objSize, unsigned int objCount);
/*
* Write more to the file. Archives don't have to implement this.
* (Set it to NULL if not implemented).
Jul 7, 2001
Jul 7, 2001
61
62
63
* Returns number of objects of (objSize) bytes written to file, -1
* if complete failure.
* On failure, call __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
64
*/
Jul 6, 2001
Jul 6, 2001
65
int (*write)(FileHandle *handle, void *buffer,
Jul 6, 2001
Jul 6, 2001
66
67
68
69
70
unsigned int objSize, unsigned int objCount);
/*
* Returns non-zero if at end of file.
*/
Jul 6, 2001
Jul 6, 2001
71
int (*eof)(FileHandle *handle);
Jul 6, 2001
Jul 6, 2001
72
73
74
75
/*
* Returns byte offset from start of file.
*/
Jul 6, 2001
Jul 6, 2001
76
int (*tell)(FileHandle *handle);
Jul 6, 2001
Jul 6, 2001
77
78
79
80
/*
* Move read/write pointer to byte offset from start of file.
* Returns non-zero on success, zero on error.
Jul 7, 2001
Jul 7, 2001
81
* On failure, call __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
82
*/
Jul 6, 2001
Jul 6, 2001
83
int (*seek)(FileHandle *handle, int offset);
Jul 6, 2001
Jul 6, 2001
84
85
/*
Jul 6, 2001
Jul 6, 2001
86
* Close the file, and free the FileHandle structure (including "opaque").
Jul 7, 2001
Jul 7, 2001
87
88
* returns non-zero on success, zero if can't close file.
* On failure, call __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
89
*/
Jul 8, 2001
Jul 8, 2001
90
int (*fileClose)(FileHandle *handle);
Jul 6, 2001
Jul 6, 2001
91
} FileFunctions;
Jul 6, 2001
Jul 6, 2001
92
93
Jul 7, 2001
Jul 7, 2001
94
typedef struct __PHYSFS_DIRHANDLE__
Jul 6, 2001
Jul 6, 2001
95
96
97
98
99
100
{
/*
* This is reserved for the driver to store information.
*/
void *opaque;
Jul 6, 2001
Jul 6, 2001
101
/*
Jul 7, 2001
Jul 7, 2001
102
* Pointer to the directory i/o functions for this handle.
Jul 6, 2001
Jul 6, 2001
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
*/
const struct __PHYSFS_DIRFUNCTIONS__ *funcs;
} DirHandle;
/*
* Symlinks should always be followed; PhysicsFS will use
* DirFunctions->isSymLink() and make a judgement on whether to
* continue to call other methods based on that.
*/
typedef struct __PHYSFS_DIRFUNCTIONS__
{
/*
* Returns non-zero if (filename) is a valid archive that this
* driver can handle. This filename is in platform-dependent
Jul 7, 2001
Jul 7, 2001
118
119
120
* notation. forWriting is non-zero if this is to be used for
* the write directory, and zero if this is to be used for an
* element of the search path.
Jul 6, 2001
Jul 6, 2001
121
*/
Jul 7, 2001
Jul 7, 2001
122
int (*isArchive)(const char *filename, int forWriting);
Jul 6, 2001
Jul 6, 2001
123
124
125
126
/*
* Return a DirHandle for dir/archive (name).
* This filename is in platform-dependent notation.
Jul 7, 2001
Jul 7, 2001
127
128
129
130
* forWriting is non-zero if this is to be used for
* the write directory, and zero if this is to be used for an
* element of the search path.
* Returns NULL on failure, and calls __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
131
*/
Jul 7, 2001
Jul 7, 2001
132
DirHandle *(*openArchive)(const char *name, int forWriting);
Jul 6, 2001
Jul 6, 2001
133
Jul 6, 2001
Jul 6, 2001
134
/*
Jul 6, 2001
Jul 6, 2001
135
136
137
138
139
* Returns a list of all files in dirname. Each element of this list
* (and its "str" field) will be deallocated with the system's free()
* function by the caller, so be sure to explicitly malloc() each
* chunk.
* If you have a memory failure, return as much as you can.
Jul 6, 2001
Jul 6, 2001
140
* This dirname is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
141
*/
Jul 7, 2001
Jul 7, 2001
142
LinkedStringList *(*enumerateFiles)(DirHandle *r, const char *dirname);
Jul 6, 2001
Jul 6, 2001
143
144
/*
Jul 7, 2001
Jul 7, 2001
145
* Returns non-zero if filename can be opened for reading.
Jul 6, 2001
Jul 6, 2001
146
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
147
*/
Jul 7, 2001
Jul 7, 2001
148
int (*exists)(DirHandle *r, const char *name);
Jul 6, 2001
Jul 6, 2001
149
150
/*
Jul 7, 2001
Jul 7, 2001
151
* Returns non-zero if filename is really a directory.
Jul 6, 2001
Jul 6, 2001
152
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
153
*/
Jul 7, 2001
Jul 7, 2001
154
int (*isDirectory)(DirHandle *r, const char *name);
Jul 6, 2001
Jul 6, 2001
155
156
/*
Jul 7, 2001
Jul 7, 2001
157
* Returns non-zero if filename is really a symlink.
Jul 6, 2001
Jul 6, 2001
158
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
159
*/
Jul 7, 2001
Jul 7, 2001
160
int (*isSymLink)(DirHandle *r, const char *name);
Jul 6, 2001
Jul 6, 2001
161
162
163
/*
* Open file for reading, and return a FileHandle.
Jul 6, 2001
Jul 6, 2001
164
* This filename is in platform-independent notation.
Jul 7, 2001
Jul 7, 2001
165
166
* If you can't handle multiple opens of the same file,
* you can opt to fail for the second call.
Jul 8, 2001
Jul 8, 2001
167
* Fail if the file does not exist.
Jul 7, 2001
Jul 7, 2001
168
* Returns NULL on failure, and calls __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
169
170
171
172
173
*/
FileHandle *(*openRead)(DirHandle *r, const char *filename);
/*
* Open file for writing, and return a FileHandle.
Jul 8, 2001
Jul 8, 2001
174
175
176
177
* If the file does not exist, it should be created. If it exists,
* it should be truncated to zero bytes. The writing
* offset should be the start of the file.
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
178
* This method may be NULL.
Jul 7, 2001
Jul 7, 2001
179
180
181
* If you can't handle multiple opens of the same file,
* you can opt to fail for the second call.
* Returns NULL on failure, and calls __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
182
183
184
185
186
*/
FileHandle *(*openWrite)(DirHandle *r, const char *filename);
/*
* Open file for appending, and return a FileHandle.
Jul 8, 2001
Jul 8, 2001
187
188
189
* If the file does not exist, it should be created. The writing
* offset should be the end of the file.
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
190
* This method may be NULL.
Jul 7, 2001
Jul 7, 2001
191
192
193
* If you can't handle multiple opens of the same file,
* you can opt to fail for the second call.
* Returns NULL on failure, and calls __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
194
*/
Jul 6, 2001
Jul 6, 2001
195
FileHandle *(*openAppend)(DirHandle *r, const char *filename);
Jul 6, 2001
Jul 6, 2001
196
Jul 7, 2001
Jul 7, 2001
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Delete a file in the archive/directory.
* Return non-zero on success, zero on failure.
* This filename is in platform-independent notation.
* This method may be NULL.
* On failure, call __PHYSFS_setError().
*/
int (*remove)(DirHandle *r, const char *filename);
/*
* Create a directory in the archive/directory.
* If the application is trying to make multiple dirs, PhysicsFS
* will split them up into multiple calls before passing them to
* your driver.
* Return non-zero on success, zero on failure.
* This filename is in platform-independent notation.
* This method may be NULL.
* On failure, call __PHYSFS_setError().
*/
int (*mkdir)(DirHandle *r, const char *filename);
Jul 6, 2001
Jul 6, 2001
218
/*
Jul 6, 2001
Jul 6, 2001
219
* Close directories/archives, and free the handle, including
Jul 6, 2001
Jul 6, 2001
220
* the "opaque" entry. This should assume that it won't be called if
Jul 6, 2001
Jul 6, 2001
221
* there are still files open from this DirHandle.
Jul 6, 2001
Jul 6, 2001
222
*/
Jul 8, 2001
Jul 8, 2001
223
void (*dirClose)(DirHandle *r);
Jul 6, 2001
Jul 6, 2001
224
} DirFunctions;
Jul 6, 2001
Jul 6, 2001
225
226
227
228
229
230
/* error messages... */
#define ERR_IS_INITIALIZED "Already initialized"
#define ERR_NOT_INITIALIZED "Not initialized"
#define ERR_INVALID_ARGUMENT "Invalid argument"
Jul 7, 2001
Jul 7, 2001
231
#define ERR_FILES_STILL_OPEN "Files still open"
Jul 6, 2001
Jul 6, 2001
232
233
234
235
#define ERR_NO_DIR_CREATE "Failed to create directories"
#define ERR_OUT_OF_MEMORY "Out of memory"
#define ERR_NOT_IN_SEARCH_PATH "No such entry in search path"
#define ERR_NOT_SUPPORTED "Operation not supported"
Jul 6, 2001
Jul 6, 2001
236
#define ERR_UNSUPPORTED_ARCHIVE "Archive type unsupported"
Jul 7, 2001
Jul 7, 2001
237
238
239
240
#define ERR_NOT_A_HANDLE "Not a file handle"
#define ERR_INSECURE_FNAME "Insecure filename"
#define ERR_SYMLINK_DISALLOWED "Symbolic links are disabled"
#define ERR_NO_WRITE_DIR "Write directory is not set"
Jul 7, 2001
Jul 7, 2001
241
#define ERR_NO_SUCH_FILE "No such file"
Jul 8, 2001
Jul 8, 2001
242
#define ERR_PAST_EOF "Past end of file"
Jul 6, 2001
Jul 6, 2001
243
244
245
246
247
/*
* Call this to set the message returned by PHYSFS_getLastError().
* Please only use the ERR_* constants above, or add new constants to the
* above group, but I want these all in one place.
Jul 7, 2001
Jul 7, 2001
248
249
*
* Calling this with a NULL argument is a safe no-op.
Jul 6, 2001
Jul 6, 2001
250
251
252
253
*/
void __PHYSFS_setError(const char *err);
Jul 7, 2001
Jul 7, 2001
254
255
256
257
258
/*
* Convert (dirName) to platform-dependent notation, then prepend (prepend)
* and append (append) to the converted string.
*
* So, on Win32, calling:
Jul 8, 2001
Jul 8, 2001
259
* __PHYSFS_convertToDependent("C:\", "my/files", NULL);
Jul 7, 2001
Jul 7, 2001
260
261
262
263
264
265
266
* ...will return the string "C:\my\files".
*
* This is a convenience function; you might want to hack something out that
* is less generic (and therefore more efficient).
*
* Be sure to free() the return value when done with it.
*/
Jul 8, 2001
Jul 8, 2001
267
268
269
char *__PHYSFS_convertToDependent(const char *prepend,
const char *dirName,
const char *append);
Jul 7, 2001
Jul 7, 2001
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
* Verify that (fname) (in platform-independent notation), in relation
* to (h) is secure. That means that each element of fname is checked
* for symlinks (if they aren't permitted). Also, elements such as
* ".", "..", or ":" are flagged.
*
* Returns non-zero if string is safe, zero if there's a security issue.
* PHYSFS_getLastError() will specify what was wrong.
*/
int __PHYSFS_verifySecurity(DirHandle *h, const char *fname);
Jul 6, 2001
Jul 6, 2001
283
/* This gets used all over for lessening code clutter. */
Jul 7, 2001
Jul 7, 2001
284
#define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return r; }
Jul 6, 2001
Jul 6, 2001
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*------------ ----------------*/
/*------------ You MUST implement the following functions ----------------*/
/*------------ if porting to a new platform. ----------------*/
/*------------ (see unix.c for an example) ----------------*/
/*------------ ----------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*
* The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
* Obviously, this isn't a function, but it IS a null-terminated string.
*/
Jul 7, 2001
Jul 7, 2001
304
extern const char *__PHYSFS_platformDirSeparator;
Jul 6, 2001
Jul 6, 2001
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
* Platform implementation of PHYSFS_getCdRomDirs()...
* See physfs.h. The retval should be freeable via PHYSFS_freeList().
*/
char **__PHYSFS_platformDetectAvailableCDs(void);
/*
* Calculate the base dir, if your platform needs special consideration.
* Just return NULL if the standard routines will suffice. (see
* calculateBaseDir() in physfs.c ...)
* Caller will free() the retval if it's not NULL.
*/
char *__PHYSFS_platformCalcBaseDir(char *argv0);
/*
* Get the platform-specific user name.
* Caller will free() the retval if it's not NULL. If it's NULL, the username
* will default to "default".
*/
char *__PHYSFS_platformGetUserName(void);
/*
* Get the platform-specific user dir.
* Caller will free() the retval if it's not NULL. If it's NULL, the userdir
* will default to basedir/username.
*/
char *__PHYSFS_platformGetUserDir(void);
/*
* Return a number that uniquely identifies the current thread.
* On a platform without threading, (1) will suffice. These numbers are
* arbitrary; the only requirement is that no two threads have the same
* number.
*/
int __PHYSFS_platformGetThreadID(void);
/*
* This is a pass-through to whatever stricmp() is called on your platform.
*/
int __PHYSFS_platformStricmp(const char *str1, const char *str2);
Jul 8, 2001
Jul 8, 2001
347
348
349
350
351
352
353
/*
* Return non-zero if filename (in platform-dependent notation) exists.
* Symlinks should be followed; if what the symlink points to is missing,
* then the retval is false.
*/
int __PHYSFS_platformExists(const char *fname);
Jul 6, 2001
Jul 6, 2001
354
355
356
/*
* Return non-zero if filename (in platform-dependent notation) is a symlink.
*/
Jul 8, 2001
Jul 8, 2001
357
int __PHYSFS_platformIsSymLink(const char *fname);
Jul 6, 2001
Jul 6, 2001
358
Jul 7, 2001
Jul 7, 2001
359
360
/*
* Return non-zero if filename (in platform-dependent notation) is a symlink.
Jul 8, 2001
Jul 8, 2001
361
362
* Symlinks should be followed; if what the symlink points to is missing,
* or isn't a directory, then the retval is false.
Jul 7, 2001
Jul 7, 2001
363
364
365
*/
int __PHYSFS_platformIsDirectory(const char *fname);
Jul 8, 2001
Jul 8, 2001
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/*
* Convert (dirName) to platform-dependent notation, then prepend (prepend)
* and append (append) to the converted string.
*
* So, on Win32, calling:
* __PHYSFS_platformCvtToDependent("C:\", "my/files", NULL);
* ...will return the string "C:\my\files".
*
* This can be implemented in a platform-specific manner, so you can get
* get a speed boost that the default implementation can't, since
* you can make assumptions about the size of strings, etc..
*
* Platforms that choose not to implement this may just call
* __PHYSFS_convertToDependent() as a passthrough.
*
* Be sure to free() the return value when done with it.
*/
char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append);
/*
* Make the current thread give up a timeslice. This is called in a loop
* while waiting for various external forces to get back to us.
*/
void __PHYSFS_platformTimeslice(void);
/*
* Enumerate a directory of files. This follows the rules for the
* DirFunctions->enumerateFiles() method (see above), except that the
* (dirName) that is passed to this function is converted to
* platform-DEPENDENT notation by the caller. The DirFunctions version
* uses platform-independent notation.
*/
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname);
Jul 6, 2001
Jul 6, 2001
403
404
405
406
407
408
409
410
#ifdef __cplusplus
extern "C" {
#endif
#endif
/* end of physfs_internal.h ... */