Skip to content

Latest commit

 

History

History
740 lines (629 loc) · 26.7 KB

physfs_internal.h

File metadata and controls

740 lines (629 loc) · 26.7 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
Mar 24, 2002
Mar 24, 2002
17
18
19
20
21
22
#include "physfs.h"
#ifdef __cplusplus
extern "C" {
#endif
Jul 7, 2001
Jul 7, 2001
23
struct __PHYSFS_DIRHANDLE__;
Jul 6, 2001
Jul 6, 2001
24
struct __PHYSFS_FILEFUNCTIONS__;
Jul 6, 2001
Jul 6, 2001
25
Jul 8, 2001
Jul 8, 2001
26
27
28
29
30
31
32
33
typedef struct __PHYSFS_LINKEDSTRINGLIST__
{
char *str;
struct __PHYSFS_LINKEDSTRINGLIST__ *next;
} LinkedStringList;
Jul 6, 2001
Jul 6, 2001
34
35
36
37
38
39
40
41
typedef struct __PHYSFS_FILEHANDLE__
{
/*
* This is reserved for the driver to store information.
*/
void *opaque;
/*
Jul 6, 2001
Jul 6, 2001
42
* This should be the DirHandle that created this FileHandle.
Jul 6, 2001
Jul 6, 2001
43
*/
Jul 7, 2001
Jul 7, 2001
44
const struct __PHYSFS_DIRHANDLE__ *dirHandle;
Jul 6, 2001
Jul 6, 2001
45
Jul 6, 2001
Jul 6, 2001
46
47
48
49
50
51
52
53
54
/*
* 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
55
56
/*
* Read more from the file.
Jul 7, 2001
Jul 7, 2001
57
58
59
* 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
60
*/
Mar 24, 2002
Mar 24, 2002
61
62
PHYSFS_sint64 (*read)(FileHandle *handle, void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
Jul 6, 2001
Jul 6, 2001
63
64
65
66
/*
* 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
67
68
69
* 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
70
*/
Mar 24, 2002
Mar 24, 2002
71
72
PHYSFS_sint64 (*write)(FileHandle *handle, const void *buffer,
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
Jul 6, 2001
Jul 6, 2001
73
74
75
76
/*
* Returns non-zero if at end of file.
*/
Jul 6, 2001
Jul 6, 2001
77
int (*eof)(FileHandle *handle);
Jul 6, 2001
Jul 6, 2001
78
79
80
81
/*
* Returns byte offset from start of file.
*/
Mar 24, 2002
Mar 24, 2002
82
PHYSFS_sint64 (*tell)(FileHandle *handle);
Jul 6, 2001
Jul 6, 2001
83
84
85
86
/*
* 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
87
* On failure, call __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
88
*/
Mar 24, 2002
Mar 24, 2002
89
int (*seek)(FileHandle *handle, PHYSFS_uint64 offset);
Jul 6, 2001
Jul 6, 2001
90
Jul 9, 2001
Jul 9, 2001
91
92
93
94
95
/*
* Return number of bytes available in the file, or -1 if you
* aren't able to determine.
* On failure, call __PHYSFS_setError().
*/
Mar 24, 2002
Mar 24, 2002
96
PHYSFS_sint64 (*fileLength)(FileHandle *handle);
Jul 9, 2001
Jul 9, 2001
97
Jul 6, 2001
Jul 6, 2001
98
/*
Jul 6, 2001
Jul 6, 2001
99
* Close the file, and free the FileHandle structure (including "opaque").
Jul 7, 2001
Jul 7, 2001
100
101
* returns non-zero on success, zero if can't close file.
* On failure, call __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
102
*/
Jul 8, 2001
Jul 8, 2001
103
int (*fileClose)(FileHandle *handle);
Jul 6, 2001
Jul 6, 2001
104
} FileFunctions;
Jul 6, 2001
Jul 6, 2001
105
106
Jul 7, 2001
Jul 7, 2001
107
typedef struct __PHYSFS_DIRHANDLE__
Jul 6, 2001
Jul 6, 2001
108
109
110
111
112
113
{
/*
* This is reserved for the driver to store information.
*/
void *opaque;
Jul 6, 2001
Jul 6, 2001
114
/*
Jul 7, 2001
Jul 7, 2001
115
* Pointer to the directory i/o functions for this handle.
Jul 6, 2001
Jul 6, 2001
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
*/
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
131
132
133
* 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
134
*/
Jul 7, 2001
Jul 7, 2001
135
int (*isArchive)(const char *filename, int forWriting);
Jul 6, 2001
Jul 6, 2001
136
137
138
139
/*
* Return a DirHandle for dir/archive (name).
* This filename is in platform-dependent notation.
Jul 7, 2001
Jul 7, 2001
140
141
142
143
* 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
144
*/
Jul 7, 2001
Jul 7, 2001
145
DirHandle *(*openArchive)(const char *name, int forWriting);
Jul 6, 2001
Jul 6, 2001
146
Jul 6, 2001
Jul 6, 2001
147
/*
Jul 6, 2001
Jul 6, 2001
148
149
150
* 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
Jul 16, 2001
Jul 16, 2001
151
* chunk. Omit symlinks if (omitSymLinks) is non-zero.
Jul 6, 2001
Jul 6, 2001
152
* If you have a memory failure, return as much as you can.
Jul 6, 2001
Jul 6, 2001
153
* This dirname is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
154
*/
Jul 16, 2001
Jul 16, 2001
155
156
157
158
LinkedStringList *(*enumerateFiles)(DirHandle *r,
const char *dirname,
int omitSymLinks);
Jul 6, 2001
Jul 6, 2001
159
160
/*
Jul 7, 2001
Jul 7, 2001
161
* Returns non-zero if filename can be opened for reading.
Jul 6, 2001
Jul 6, 2001
162
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
163
*/
Jul 7, 2001
Jul 7, 2001
164
int (*exists)(DirHandle *r, const char *name);
Jul 6, 2001
Jul 6, 2001
165
166
/*
Jul 7, 2001
Jul 7, 2001
167
* Returns non-zero if filename is really a directory.
Jul 6, 2001
Jul 6, 2001
168
* This filename is in platform-independent notation.
Jul 23, 2002
Jul 23, 2002
169
170
* Symlinks should be followed; if what the symlink points
* to is missing, or isn't a directory, then the retval is zero.
Jul 6, 2001
Jul 6, 2001
171
*/
Jul 7, 2001
Jul 7, 2001
172
int (*isDirectory)(DirHandle *r, const char *name);
Jul 6, 2001
Jul 6, 2001
173
174
/*
Jul 7, 2001
Jul 7, 2001
175
* Returns non-zero if filename is really a symlink.
Jul 6, 2001
Jul 6, 2001
176
* This filename is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
177
*/
Jul 7, 2001
Jul 7, 2001
178
int (*isSymLink)(DirHandle *r, const char *name);
Jul 6, 2001
Jul 6, 2001
179
May 25, 2002
May 25, 2002
180
181
182
183
184
185
186
187
/*
* Retrieve the last modification time (mtime) of a file.
* Returns -1 on failure, or the file's mtime in seconds since
* the epoch (Jan 1, 1970) on success.
* This filename is in platform-independent notation.
*/
PHYSFS_sint64 (*getLastModTime)(DirHandle *r, const char *filename);
Jul 6, 2001
Jul 6, 2001
188
189
/*
* Open file for reading, and return a FileHandle.
Jul 6, 2001
Jul 6, 2001
190
* This filename is in platform-independent notation.
Jul 7, 2001
Jul 7, 2001
191
192
* 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
193
* Fail if the file does not exist.
Jul 7, 2001
Jul 7, 2001
194
* Returns NULL on failure, and calls __PHYSFS_setError().
Jul 6, 2001
Jul 6, 2001
195
196
197
198
199
*/
FileHandle *(*openRead)(DirHandle *r, const char *filename);
/*
* Open file for writing, and return a FileHandle.
Jul 8, 2001
Jul 8, 2001
200
201
202
203
* 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
204
* This method may be NULL.
Jul 7, 2001
Jul 7, 2001
205
206
207
* 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
208
209
210
211
212
*/
FileHandle *(*openWrite)(DirHandle *r, const char *filename);
/*
* Open file for appending, and return a FileHandle.
Jul 8, 2001
Jul 8, 2001
213
214
215
* 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
216
* This method may be NULL.
Jul 7, 2001
Jul 7, 2001
217
218
219
* 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
220
*/
Jul 6, 2001
Jul 6, 2001
221
FileHandle *(*openAppend)(DirHandle *r, const char *filename);
Jul 6, 2001
Jul 6, 2001
222
Jul 7, 2001
Jul 7, 2001
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
* 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
244
/*
Jul 6, 2001
Jul 6, 2001
245
* Close directories/archives, and free the handle, including
Jul 6, 2001
Jul 6, 2001
246
* the "opaque" entry. This should assume that it won't be called if
Jul 6, 2001
Jul 6, 2001
247
* there are still files open from this DirHandle.
Jul 6, 2001
Jul 6, 2001
248
*/
Jul 8, 2001
Jul 8, 2001
249
void (*dirClose)(DirHandle *r);
Jul 6, 2001
Jul 6, 2001
250
} DirFunctions;
Jul 6, 2001
Jul 6, 2001
251
252
253
254
255
256
/* 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
257
#define ERR_FILES_STILL_OPEN "Files still open"
Jul 6, 2001
Jul 6, 2001
258
259
260
261
#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
262
#define ERR_UNSUPPORTED_ARCHIVE "Archive type unsupported"
Jul 7, 2001
Jul 7, 2001
263
264
265
266
#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
267
#define ERR_NO_SUCH_FILE "No such file"
Jul 8, 2001
Jul 8, 2001
268
#define ERR_PAST_EOF "Past end of file"
Jul 8, 2001
Jul 8, 2001
269
#define ERR_ARC_IS_READ_ONLY "Archive is read-only"
Jul 15, 2001
Jul 15, 2001
270
#define ERR_IO_ERROR "I/O error"
Jul 23, 2001
Jul 23, 2001
271
#define ERR_CANT_SET_WRITE_DIR "Can't set write directory"
Jul 17, 2002
Jul 17, 2002
272
#define ERR_SYMLINK_LOOP "Infinite symbolic link loop"
Jul 23, 2001
Jul 23, 2001
273
#define ERR_COMPRESSION "(De)compression error"
Apr 1, 2002
Apr 1, 2002
274
#define ERR_NOT_IMPLEMENTED "Not implemented"
Apr 2, 2002
Apr 2, 2002
275
#define ERR_OS_ERROR "Operating system reported error"
Apr 5, 2002
Apr 5, 2002
276
277
278
#define ERR_FILE_EXISTS "File already exists"
#define ERR_NOT_A_DIR "Not a directory"
#define ERR_FILE_NOT_FOUND "File not found"
Jul 13, 2002
Jul 13, 2002
279
280
#define ERR_NOT_AN_ARCHIVE "Not an archive"
#define ERR_CORRUPTED "Corrupted archive"
Jul 6, 2001
Jul 6, 2001
281
May 25, 2002
May 25, 2002
282
Jul 6, 2001
Jul 6, 2001
283
284
285
286
/*
* 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
287
288
*
* Calling this with a NULL argument is a safe no-op.
Jul 6, 2001
Jul 6, 2001
289
290
291
292
*/
void __PHYSFS_setError(const char *err);
Jul 7, 2001
Jul 7, 2001
293
294
295
296
297
/*
* 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
298
* __PHYSFS_convertToDependent("C:\", "my/files", NULL);
Jul 7, 2001
Jul 7, 2001
299
300
301
302
303
304
305
* ...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
306
307
308
char *__PHYSFS_convertToDependent(const char *prepend,
const char *dirName,
const char *append);
Jul 7, 2001
Jul 7, 2001
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
* 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 23, 2002
Jul 23, 2002
322
323
324
325
326
327
328
329
330
331
332
/*
* Use this to build the list that your enumerate function should return.
* See zip.c for an example of proper use.
*/
LinkedStringList *__PHYSFS_addToLinkedStringList(LinkedStringList *retval,
LinkedStringList **prev,
const char *str,
PHYSFS_sint32 len);
Aug 23, 2001
Aug 23, 2001
333
334
/* These get used all over for lessening code clutter. */
#define BAIL_MACRO(e, r) { __PHYSFS_setError(e); return r; }
Jul 7, 2001
Jul 7, 2001
335
#define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return r; }
Mar 30, 2002
Mar 30, 2002
336
337
#define BAIL_MACRO_MUTEX(e, m, r) { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; }
#define BAIL_IF_MACRO_MUTEX(c, e, m, r) if (c) { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; }
Jul 6, 2001
Jul 6, 2001
338
339
340
341
342
343
344
345
346
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*------------ ----------------*/
/*------------ You MUST implement the following functions ----------------*/
/*------------ if porting to a new platform. ----------------*/
Jul 15, 2001
Jul 15, 2001
347
/*------------ (see platform/unix.c for an example) ----------------*/
Jul 6, 2001
Jul 6, 2001
348
349
350
351
352
353
354
355
356
/*------------ ----------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*
* 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
357
extern const char *__PHYSFS_platformDirSeparator;
Jul 6, 2001
Jul 6, 2001
358
Mar 24, 2002
Mar 24, 2002
359
360
361
362
363
364
365
366
367
368
369
/*
* Initialize the platform. This is called when PHYSFS_init() is called from
* the application. You can use this to (for example) determine what version
* of Windows you're running.
*
* Return zero if there was a catastrophic failure (which prevents you from
* functioning at all), and non-zero otherwise.
*/
int __PHYSFS_platformInit(void);
May 25, 2002
May 25, 2002
370
Mar 24, 2002
Mar 24, 2002
371
372
373
374
375
376
377
378
379
380
/*
* Deinitialize the platform. This is called when PHYSFS_deinit() is called
* from the application. You can use this to clean up anything you've
* allocated in your platform driver.
*
* Return zero if there was a catastrophic failure (which prevents you from
* functioning at all), and non-zero otherwise.
*/
int __PHYSFS_platformDeinit(void);
May 25, 2002
May 25, 2002
381
Mar 24, 2002
Mar 24, 2002
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/*
* Open a file for reading. (filename) is in platform-dependent notation. The
* file pointer should be positioned on the first byte of the file.
*
* The return value will be some platform-specific datatype that is opaque to
* the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32.
*
* The same file can be opened for read multiple times, and each should have
* a unique file handle; this is frequently employed to prevent race
* conditions in the archivers.
*
* Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
*/
void *__PHYSFS_platformOpenRead(const char *filename);
May 25, 2002
May 25, 2002
397
Mar 24, 2002
Mar 24, 2002
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
* Open a file for writing. (filename) is in platform-dependent notation. If
* the file exists, it should be truncated to zero bytes, and if it doesn't
* exist, it should be created as a zero-byte file. The file pointer should
* be positioned on the first byte of the file.
*
* The return value will be some platform-specific datatype that is opaque to
* the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32,
* etc.
*
* Opening a file for write multiple times has undefined results.
*
* Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
*/
void *__PHYSFS_platformOpenWrite(const char *filename);
May 25, 2002
May 25, 2002
414
Mar 24, 2002
Mar 24, 2002
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*
* Open a file for appending. (filename) is in platform-dependent notation. If
* the file exists, the file pointer should be place just past the end of the
* file, so that the first write will be one byte after the current end of
* the file. If the file doesn't exist, it should be created as a zero-byte
* file. The file pointer should be positioned on the first byte of the file.
*
* The return value will be some platform-specific datatype that is opaque to
* the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32,
* etc.
*
* Opening a file for append multiple times has undefined results.
*
* Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
*/
void *__PHYSFS_platformOpenAppend(const char *filename);
May 25, 2002
May 25, 2002
432
Mar 24, 2002
Mar 24, 2002
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
* Read more data from a platform-specific file handle. (opaque) should be
* cast to whatever data type your platform uses. Read a maximum of (count)
* objects of (size) 8-bit bytes to the area pointed to by (buffer). If there
* isn't enough data available, return the number of full objects read, and
* position the file pointer at the start of the first incomplete object.
* On success, return (count) and position the file pointer one byte past
* the end of the last read object. Return (-1) if there is a catastrophic
* error, and call __PHYSFS_setError() to describe the problem; the file
* pointer should not move in such a case.
*/
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count);
/*
* Write more data to a platform-specific file handle. (opaque) should be
* cast to whatever data type your platform uses. Write a maximum of (count)
* objects of (size) 8-bit bytes from the area pointed to by (buffer). If
* there isn't enough data available, return the number of full objects
* written, and position the file pointer at the start of the first
* incomplete object. Return (-1) if there is a catastrophic error, and call
* __PHYSFS_setError() to describe the problem; the file pointer should not
* move in such a case.
*/
Mar 25, 2002
Mar 25, 2002
457
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
Mar 24, 2002
Mar 24, 2002
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
PHYSFS_uint32 size, PHYSFS_uint32 count);
/*
* Set the file pointer to a new position. (opaque) should be cast to
* whatever data type your platform uses. (pos) specifies the number
* of 8-bit bytes to seek to from the start of the file. Seeking past the
* end of the file is an error condition, and you should check for it.
*
* Not all file types can seek; this is to be expected by the caller.
*
* On error, call __PHYSFS_setError() and return zero. On success, return
* a non-zero value.
*/
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
May 25, 2002
May 25, 2002
473
Mar 24, 2002
Mar 24, 2002
474
475
476
477
478
479
480
481
482
483
484
485
/*
* Get the file pointer's position, in an 8-bit byte offset from the start of
* the file. (opaque) should be cast to whatever data type your platform
* uses.
*
* Not all file types can "tell"; this is to be expected by the caller.
*
* On error, call __PHYSFS_setError() and return zero. On success, return
* a non-zero value.
*/
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
May 25, 2002
May 25, 2002
486
Mar 24, 2002
Mar 24, 2002
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/*
* Determine the current size of a file, in 8-bit bytes, from an open file.
*
* The caller expects that this information may not be available for all
* file types on all platforms.
*
* Return -1 if you can't do it, and call __PHYSFS_setError(). Otherwise,
* return the file length in 8-bit bytes.
*/
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
/*
* Determine if a file is at EOF. (opaque) should be cast to whatever data
* type your platform uses.
*
* The caller expects that there was a short read before calling this.
*
* Return non-zero if EOF, zero if it is _not_ EOF.
*/
int __PHYSFS_platformEOF(void *opaque);
/*
* Flush any pending writes to disk. (opaque) should be cast to whatever data
* type your platform uses. Be sure to check for errors; the caller expects
* that this function can fail if there was a flushing error, etc.
*
* Return zero on failure, non-zero on success.
*/
int __PHYSFS_platformFlush(void *opaque);
/*
* Flush and close a file. (opaque) should be cast to whatever data type
* your platform uses. Be sure to check for errors when closing; the
* caller expects that this function can fail if there was a flushing
* error, etc.
*
* You should clean up all resources associated with (opaque).
*
* Return zero on failure, non-zero on success.
*/
int __PHYSFS_platformClose(void *opaque);
Jul 6, 2001
Jul 6, 2001
529
530
531
532
533
534
535
536
537
538
539
540
/*
* 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.
*/
Jul 8, 2001
Jul 8, 2001
541
char *__PHYSFS_platformCalcBaseDir(const char *argv0);
Jul 6, 2001
Jul 6, 2001
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*
* 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.
*/
Mar 24, 2002
Mar 24, 2002
563
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void);
Jul 6, 2001
Jul 6, 2001
564
565
566
567
568
569
/*
* 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
570
571
572
573
574
575
576
/*
* 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);
May 25, 2002
May 25, 2002
577
578
579
580
581
582
583
584
585
/*
* Return the last modified time (in seconds since the epoch) of a file.
* Returns -1 on failure. (fname) is in platform-dependent notation.
* Symlinks should be followed; if what the symlink points to is missing,
* then the retval is -1.
*/
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname);
Jul 6, 2001
Jul 6, 2001
586
587
588
/*
* Return non-zero if filename (in platform-dependent notation) is a symlink.
*/
Jul 8, 2001
Jul 8, 2001
589
int __PHYSFS_platformIsSymLink(const char *fname);
Jul 6, 2001
Jul 6, 2001
590
May 25, 2002
May 25, 2002
591
Jul 7, 2001
Jul 7, 2001
592
593
/*
* Return non-zero if filename (in platform-dependent notation) is a symlink.
Jul 8, 2001
Jul 8, 2001
594
595
* 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
596
597
598
*/
int __PHYSFS_platformIsDirectory(const char *fname);
May 25, 2002
May 25, 2002
599
Jul 8, 2001
Jul 8, 2001
600
601
602
603
604
605
606
607
608
609
610
611
612
/*
* 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
Mar 24, 2002
Mar 24, 2002
613
614
* __PHYSFS_convertToDependent() as a passthrough, which may fit the bill
* already.
Jul 8, 2001
Jul 8, 2001
615
616
617
618
619
620
621
*
* Be sure to free() the return value when done with it.
*/
char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append);
May 25, 2002
May 25, 2002
622
Jul 8, 2001
Jul 8, 2001
623
624
625
626
627
628
629
630
631
632
633
634
/*
* 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
Jul 16, 2001
Jul 16, 2001
635
636
* uses platform-independent notation. Note that ".", "..", and other
* metaentries should always be ignored.
Jul 8, 2001
Jul 8, 2001
637
*/
Jul 16, 2001
Jul 16, 2001
638
639
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks);
Jul 8, 2001
Jul 8, 2001
640
Jul 6, 2001
Jul 6, 2001
641
Jul 16, 2001
Jul 16, 2001
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
/*
* Get the current working directory. The return value should be an
* absolute path in platform-dependent notation. The caller will deallocate
* the return value with the standard C runtime free() function when it
* is done with it.
* On error, return NULL and set the error message.
*/
char *__PHYSFS_platformCurrentDir(void);
/*
* Get the real physical path to a file. (path) is specified in
* platform-dependent notation, as should your return value be.
* All relative paths should be removed, leaving you with an absolute
* path. Symlinks should be resolved, too, so that the returned value is
* the most direct path to a file.
* The return value will be deallocated with the standard C runtime free()
* function when the caller is done with it.
* On error, return NULL and set the error message.
*/
char *__PHYSFS_platformRealPath(const char *path);
Aug 23, 2001
Aug 23, 2001
665
666
667
668
669
670
671
/*
* Make a directory in the actual filesystem. (path) is specified in
* platform-dependent notation. On error, return zero and set the error
* message. Return non-zero on success.
*/
int __PHYSFS_platformMkDir(const char *path);
May 25, 2002
May 25, 2002
672
Mar 25, 2002
Mar 25, 2002
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/*
* Remove a file or directory entry in the actual filesystem. (path) is
* specified in platform-dependent notation. Note that this deletes files
* _and_ directories, so you might need to do some determination.
* Non-empty directories should report an error and not delete themselves
* or their contents.
*
* Deleting a symlink should remove the link, not what it points to.
*
* On error, return zero and set the error message. Return non-zero on success.
*/
int __PHYSFS_platformDelete(const char *path);
Mar 30, 2002
Mar 30, 2002
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*
* Create a platform-specific mutex. This can be whatever datatype your
* platform uses for mutexes, but it is cast to a (void *) for abstractness.
*
* Return (NULL) if you couldn't create one. Systems without threads can
* return any arbitrary non-NULL value.
*/
void *__PHYSFS_platformCreateMutex(void);
/*
* Destroy a platform-specific mutex, and clean up any resources associated
* with it. (mutex) is a value previously returned by
* __PHYSFS_platformCreateMutex(). This can be a no-op on single-threaded
* platforms.
*/
void __PHYSFS_platformDestroyMutex(void *mutex);
/*
* Grab possession of a platform-specific mutex. Mutexes should be recursive;
* that is, the same thread should be able to call this function multiple
* times in a row without causing a deadlock. This function should block
* until a thread can gain possession of the mutex.
*
* Return non-zero if the mutex was grabbed, zero if there was an
* unrecoverable problem grabbing it (this should not be a matter of
* timing out! We're talking major system errors; block until the mutex
* is available otherwise.)
Apr 2, 2002
Apr 2, 2002
714
715
716
717
*
* _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
* function, you'll cause an infinite recursion. This means you can't
* use the BAIL_*MACRO* macros, either.
Mar 30, 2002
Mar 30, 2002
718
719
720
721
722
723
724
725
*/
int __PHYSFS_platformGrabMutex(void *mutex);
/*
* Relinquish possession of the mutex when this method has been called
* once for each time that platformGrabMutex was called. Once possession has
* been released, the next thread in line to grab the mutex (if any) may
* proceed.
Apr 2, 2002
Apr 2, 2002
726
727
728
729
*
* _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
* function, you'll cause an infinite recursion. This means you can't
* use the BAIL_*MACRO* macros, either.
Mar 30, 2002
Mar 30, 2002
730
731
732
*/
void __PHYSFS_platformReleaseMutex(void *mutex);
Jul 6, 2001
Jul 6, 2001
733
#ifdef __cplusplus
Mar 24, 2002
Mar 24, 2002
734
}
Jul 6, 2001
Jul 6, 2001
735
736
737
738
739
#endif
#endif
/* end of physfs_internal.h ... */