Skip to content

Latest commit

 

History

History
783 lines (672 loc) · 29.4 KB

physfs_internal.h

File metadata and controls

783 lines (672 loc) · 29.4 KB
 
Jul 6, 2001
Jul 6, 2001
1
2
3
4
/*
* Internal function/structure declaration. Do NOT include in your
* application.
*
Mar 11, 2007
Mar 11, 2007
5
* Please see the file LICENSE.txt in the source's root directory.
Jul 6, 2001
Jul 6, 2001
6
7
8
9
10
11
12
13
14
15
16
*
* 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
#include "physfs.h"
Sep 6, 2010
Sep 6, 2010
19
20
21
22
/* The holy trinity. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Mar 15, 2007
Mar 15, 2007
23
Mar 19, 2012
Mar 19, 2012
24
25
#include "physfs_platforms.h"
Nov 22, 2002
Nov 22, 2002
26
27
#include <assert.h>
Mar 19, 2007
Mar 19, 2007
28
/* !!! FIXME: remove this when revamping stack allocation code... */
Jul 12, 2007
Jul 12, 2007
29
#if defined(_MSC_VER) || defined(__MINGW32__)
Mar 19, 2007
Mar 19, 2007
30
31
32
#include <malloc.h>
#endif
Mar 20, 2012
Mar 20, 2012
33
#if PHYSFS_PLATFORM_SOLARIS
Apr 8, 2010
Apr 8, 2010
34
35
36
#include <alloca.h>
#endif
Mar 24, 2002
Mar 24, 2002
37
38
39
40
#ifdef __cplusplus
extern "C" {
#endif
Mar 12, 2008
Mar 12, 2008
41
#ifdef __GNUC__
Mar 12, 2008
Mar 12, 2008
42
#define PHYSFS_MINIMUM_GCC_VERSION(major, minor) \
Mar 12, 2008
Mar 12, 2008
43
44
( ((__GNUC__ << 16) + __GNUC_MINOR__) >= (((major) << 16) + (minor)) )
#else
Mar 12, 2008
Mar 12, 2008
45
#define PHYSFS_MINIMUM_GCC_VERSION(major, minor) (0)
Mar 12, 2008
Mar 12, 2008
46
47
#endif
Aug 21, 2010
Aug 21, 2010
48
49
50
51
52
53
54
55
#ifdef __cplusplus
/* C++ always has a real inline keyword. */
#elif (defined macintosh) && !(defined __MWERKS__)
# define inline
#elif (defined _MSC_VER)
# define inline __inline
#endif
Mar 19, 2012
Mar 19, 2012
56
#if PHYSFS_PLATFORM_LINUX && !defined(_FILE_OFFSET_BITS)
Mar 18, 2012
Mar 18, 2012
57
58
59
#define _FILE_OFFSET_BITS 64
#endif
Mar 24, 2007
Mar 24, 2007
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Interface for small allocations. If you need a little scratch space for
* a throwaway buffer or string, use this. It will make small allocations
* on the stack if possible, and use allocator.Malloc() if they are too
* large. This helps reduce malloc pressure.
* There are some rules, though:
* NEVER return a pointer from this, as stack-allocated buffers go away
* when your function returns.
* NEVER allocate in a loop, as stack-allocated pointers will pile up. Call
* a function that uses smallAlloc from your loop, so the allocation can
* free each time.
* NEVER call smallAlloc with any complex expression (it's a macro that WILL
* have side effects...it references the argument multiple times). Use a
* variable or a literal.
* NEVER free a pointer from this with anything but smallFree. It will not
* be a valid pointer to the allocator, regardless of where the memory came
* from.
* NEVER realloc a pointer from this.
* NEVER forget to use smallFree: it may not be a pointer from the stack.
* NEVER forget to check for NULL...allocation can fail here, of course!
*/
Mar 10, 2012
Mar 10, 2012
81
#define __PHYSFS_SMALLALLOCTHRESHOLD 256
Mar 24, 2007
Mar 24, 2007
82
83
84
void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len);
#define __PHYSFS_smallAlloc(bytes) ( \
Mar 12, 2012
Mar 12, 2012
85
86
87
__PHYSFS_initSmallAlloc( \
(((bytes) < __PHYSFS_SMALLALLOCTHRESHOLD) ? \
alloca((size_t)((bytes)+sizeof(void*))) : NULL), (bytes)) \
Mar 24, 2007
Mar 24, 2007
88
89
90
91
92
)
void __PHYSFS_smallFree(void *ptr);
Mar 14, 2005
Mar 14, 2005
93
94
95
96
/* Use the allocation hooks. */
#define malloc(x) Do not use malloc() directly.
#define realloc(x, y) Do not use realloc() directly.
#define free(x) Do not use free() directly.
Mar 19, 2007
Mar 19, 2007
97
/* !!! FIXME: add alloca check here. */
Jul 28, 2002
Jul 28, 2002
98
Mar 23, 2012
Mar 23, 2012
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef PHYSFS_SUPPORTS_ZIP
#define PHYSFS_SUPPORTS_ZIP 1
#endif
#ifndef PHYSFS_SUPPORTS_7Z
#define PHYSFS_SUPPORTS_7Z 0
#endif
#ifndef PHYSFS_SUPPORTS_GRP
#define PHYSFS_SUPPORTS_GRP 0
#endif
#ifndef PHYSFS_SUPPORTS_HOG
#define PHYSFS_SUPPORTS_HOG 0
#endif
#ifndef PHYSFS_SUPPORTS_MVL
#define PHYSFS_SUPPORTS_MVL 0
#endif
#ifndef PHYSFS_SUPPORTS_WAD
#define PHYSFS_SUPPORTS_WAD 0
#endif
#ifndef PHYSFS_SUPPORTS_ISO9660
#define PHYSFS_SUPPORTS_ISO9660 0
#endif
Mar 20, 2012
Mar 20, 2012
121
122
123
124
125
126
127
128
#define DIR_ARCHIVE_DESCRIPTION "Non-archive, direct filesystem I/O"
#define GRP_ARCHIVE_DESCRIPTION "Build engine Groupfile format"
#define HOG_ARCHIVE_DESCRIPTION "Descent I/II HOG file format"
#define MVL_ARCHIVE_DESCRIPTION "Descent II Movielib format"
#define QPAK_ARCHIVE_DESCRIPTION "Quake I/II format"
#define ZIP_ARCHIVE_DESCRIPTION "PkZip/WinZip/Info-Zip compatible"
#define WAD_ARCHIVE_DESCRIPTION "DOOM engine format"
#define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format"
Jul 28, 2002
Jul 28, 2002
129
Jul 8, 2001
Jul 8, 2001
130
Sep 26, 2004
Sep 26, 2004
131
132
133
/* !!! FIXME: find something better than "dvoid" and "fvoid" ... */
/* Opaque data for file and dir handlers... */
typedef void dvoid;
Dec 1, 2002
Dec 1, 2002
134
135
Sep 26, 2004
Sep 26, 2004
136
typedef struct
Jul 6, 2001
Jul 6, 2001
137
{
Jul 6, 2001
Jul 6, 2001
138
/*
Sep 26, 2004
Sep 26, 2004
139
* Basic info about this archiver...
Jul 9, 2001
Jul 9, 2001
140
*/
Sep 26, 2004
Sep 26, 2004
141
const PHYSFS_ArchiveInfo *info;
Jul 9, 2001
Jul 9, 2001
142
Jul 6, 2001
Jul 6, 2001
143
Sep 26, 2004
Sep 26, 2004
144
145
146
147
148
149
/*
* DIRECTORY ROUTINES:
* These functions are for dir handles. Generate a handle with the
* openArchive() method, then pass it as the "opaque" dvoid to the
* others.
*
Sep 5, 2010
Sep 5, 2010
150
151
152
* Symlinks should always be followed (except in stat()); PhysicsFS will
* use the stat() method to check for symlinks and make a judgement on
* whether to continue to call other methods based on that.
Sep 26, 2004
Sep 26, 2004
153
*/
Jul 6, 2001
Jul 6, 2001
154
Jul 6, 2001
Jul 6, 2001
155
/*
Aug 30, 2010
Aug 30, 2010
156
157
158
159
160
* Open a dirhandle for dir/archive data provided by (io).
* (name) is a filename associated with (io), but doesn't necessarily
* map to anything, let alone a real filename. This possibly-
* meaningless name is in platform-dependent notation.
* (forWriting) is non-zero if this is to be used for
Jul 7, 2001
Jul 7, 2001
161
162
* the write directory, and zero if this is to be used for an
* element of the search path.
Mar 20, 2012
Mar 20, 2012
163
* Returns NULL on failure. We ignore any error code you set here.
Sep 26, 2004
Sep 26, 2004
164
165
* Returns non-NULL on success. The pointer returned will be
* passed as the "opaque" parameter for later calls.
Jul 6, 2001
Jul 6, 2001
166
*/
Aug 30, 2010
Aug 30, 2010
167
dvoid *(*openArchive)(PHYSFS_Io *io, const char *name, int forWriting);
Jul 6, 2001
Jul 6, 2001
168
Jul 6, 2001
Jul 6, 2001
169
/*
Sep 29, 2004
Sep 29, 2004
170
171
172
173
174
175
* List all files in (dirname). Each file is passed to (callback),
* where a copy is made if appropriate, so you should dispose of
* it properly upon return from the callback.
* You should omit symlinks if (omitSymLinks) is non-zero.
* If you have a failure, report as much as you can.
* (dirname) is in platform-independent notation.
Jul 6, 2001
Jul 6, 2001
176
*/
Sep 29, 2004
Sep 29, 2004
177
178
179
void (*enumerateFiles)(dvoid *opaque,
const char *dirname,
int omitSymLinks,
Sep 18, 2005
Sep 18, 2005
180
181
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
182
void *callbackdata);
Jul 6, 2001
Jul 6, 2001
183
184
/*
Sep 26, 2004
Sep 26, 2004
185
* Open file for reading.
Jul 6, 2001
Jul 6, 2001
186
* This filename is in platform-independent notation.
Jul 7, 2001
Jul 7, 2001
187
188
* 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
189
* Fail if the file does not exist.
Jul 7, 2001
Jul 7, 2001
190
* Returns NULL on failure, and calls __PHYSFS_setError().
Sep 26, 2004
Sep 26, 2004
191
192
* Returns non-NULL on success. The pointer returned will be
* passed as the "opaque" parameter for later file calls.
Aug 21, 2002
Aug 21, 2002
193
194
195
196
*
* Regardless of success or failure, please set *fileExists to
* non-zero if the file existed (even if it's a broken symlink!),
* zero if it did not.
Jul 6, 2001
Jul 6, 2001
197
*/
Aug 30, 2010
Aug 30, 2010
198
PHYSFS_Io *(*openRead)(dvoid *opaque, const char *fname, int *fileExists);
Jul 6, 2001
Jul 6, 2001
199
200
/*
Sep 26, 2004
Sep 26, 2004
201
* Open file for writing.
Jul 8, 2001
Jul 8, 2001
202
203
204
205
* 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 7, 2001
Jul 7, 2001
206
207
208
* 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().
Sep 26, 2004
Sep 26, 2004
209
210
* Returns non-NULL on success. The pointer returned will be
* passed as the "opaque" parameter for later file calls.
Jul 6, 2001
Jul 6, 2001
211
*/
Aug 30, 2010
Aug 30, 2010
212
PHYSFS_Io *(*openWrite)(dvoid *opaque, const char *filename);
Jul 6, 2001
Jul 6, 2001
213
214
/*
Sep 26, 2004
Sep 26, 2004
215
* Open file for appending.
Jul 8, 2001
Jul 8, 2001
216
217
218
* 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 7, 2001
Jul 7, 2001
219
220
221
* 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().
Sep 26, 2004
Sep 26, 2004
222
223
* Returns non-NULL on success. The pointer returned will be
* passed as the "opaque" parameter for later file calls.
Jul 6, 2001
Jul 6, 2001
224
*/
Aug 30, 2010
Aug 30, 2010
225
PHYSFS_Io *(*openAppend)(dvoid *opaque, const char *filename);
Jul 6, 2001
Jul 6, 2001
226
Jul 7, 2001
Jul 7, 2001
227
228
229
230
231
232
233
/*
* 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().
*/
Sep 26, 2004
Sep 26, 2004
234
int (*remove)(dvoid *opaque, const char *filename);
Jul 7, 2001
Jul 7, 2001
235
236
237
238
239
240
241
242
243
244
245
/*
* 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().
*/
Sep 26, 2004
Sep 26, 2004
246
int (*mkdir)(dvoid *opaque, const char *filename);
Jul 7, 2001
Jul 7, 2001
247
Jul 6, 2001
Jul 6, 2001
248
/*
Sep 26, 2004
Sep 26, 2004
249
* Close directories/archives, and free any associated memory,
Aug 30, 2010
Aug 30, 2010
250
251
252
* including the original PHYSFS_Io and (opaque) itself, if
* applicable. Implementation can assume that it won't be called if
* there are still files open from this archive.
Jul 6, 2001
Jul 6, 2001
253
*/
Sep 26, 2004
Sep 26, 2004
254
255
void (*dirClose)(dvoid *opaque);
Aug 22, 2010
Aug 22, 2010
256
257
258
259
260
261
/*
* Obtain basic file metadata.
* Returns non-zero on success, zero on failure.
* On failure, call __PHYSFS_setError().
*/
int (*stat)(dvoid *opaque, const char *fn, int *exists, PHYSFS_Stat *stat);
Sep 26, 2004
Sep 26, 2004
262
} PHYSFS_Archiver;
Jul 6, 2001
Jul 6, 2001
263
264
265
266
267
268
/*
* 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
269
270
*
* Calling this with a NULL argument is a safe no-op.
Jul 6, 2001
Jul 6, 2001
271
*/
Mar 20, 2012
Mar 20, 2012
272
void __PHYSFS_setError(const PHYSFS_ErrorCode err);
Jul 6, 2001
Jul 6, 2001
273
274
Apr 9, 2004
Apr 9, 2004
275
276
277
278
/* This byteorder stuff was lifted from SDL. http://www.libsdl.org/ */
#define PHYSFS_LIL_ENDIAN 1234
#define PHYSFS_BIG_ENDIAN 4321
Oct 5, 2011
Oct 5, 2011
279
#if defined(__i386__) || defined(__ia64__) || \
Oct 6, 2011
Oct 6, 2011
280
defined(_M_IX86) || defined(_M_IA64) || defined(_M_X64) || \
Apr 9, 2004
Apr 9, 2004
281
282
283
284
285
286
287
288
289
290
291
292
(defined(__alpha__) || defined(__alpha)) || \
defined(__arm__) || defined(ARM) || \
(defined(__mips__) && defined(__MIPSEL__)) || \
defined(__SYMBIAN32__) || \
defined(__x86_64__) || \
defined(__LITTLE_ENDIAN__)
#define PHYSFS_BYTEORDER PHYSFS_LIL_ENDIAN
#else
#define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN
#endif
Aug 20, 2002
Aug 20, 2002
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
* When sorting the entries in an archive, we use a modified QuickSort.
* When there are less then PHYSFS_QUICKSORT_THRESHOLD entries left to sort,
* we switch over to a BubbleSort for the remainder. Tweak to taste.
*
* You can override this setting by defining PHYSFS_QUICKSORT_THRESHOLD
* before #including "physfs_internal.h".
*/
#ifndef PHYSFS_QUICKSORT_THRESHOLD
#define PHYSFS_QUICKSORT_THRESHOLD 4
#endif
/*
* Sort an array (or whatever) of (max) elements. This uses a mixture of
* a QuickSort and BubbleSort internally.
* (cmpfn) is used to determine ordering, and (swapfn) does the actual
* swapping of elements in the list.
*
* See zip.c for an example.
*/
void __PHYSFS_sort(void *entries, PHYSFS_uint32 max,
int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32),
void (*swapfn)(void *, PHYSFS_uint32, PHYSFS_uint32));
Mar 20, 2012
Mar 20, 2012
317
318
319
320
321
/*
* This isn't a formal error code, it's just for BAIL_MACRO.
* It means: there was an error, but someone else already set it for us.
*/
#define ERRPASS PHYSFS_ERR_OK
Jul 23, 2002
Jul 23, 2002
322
Aug 23, 2001
Aug 23, 2001
323
/* These get used all over for lessening code clutter. */
Mar 20, 2012
Mar 20, 2012
324
325
326
327
328
329
330
331
#define BAIL_MACRO(e, r) do { if (e) __PHYSFS_setError(e); return r; } while (0)
#define BAIL_IF_MACRO(c, e, r) do { if (c) { if (e) __PHYSFS_setError(e); return r; } } while (0)
#define BAIL_MACRO_MUTEX(e, m, r) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0)
#define BAIL_IF_MACRO_MUTEX(c, e, m, r) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0)
#define GOTO_MACRO(e, g) do { if (e) __PHYSFS_setError(e); goto g; } while (0)
#define GOTO_IF_MACRO(c, e, g) do { if (c) { if (e) __PHYSFS_setError(e); goto g; } } while (0)
#define GOTO_MACRO_MUTEX(e, m, g) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0)
#define GOTO_IF_MACRO_MUTEX(c, e, m, g) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0)
Jul 6, 2001
Jul 6, 2001
332
Mar 15, 2007
Mar 15, 2007
333
334
#define __PHYSFS_ARRAYLEN(x) ( (sizeof (x)) / (sizeof (x[0])) )
Aug 21, 2010
Aug 21, 2010
335
336
337
338
#ifdef PHYSFS_NO_64BIT_SUPPORT
#define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x))
#define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x))
#elif (defined __GNUC__)
Mar 21, 2007
Mar 21, 2007
339
340
#define __PHYSFS_SI64(x) x##LL
#define __PHYSFS_UI64(x) x##ULL
Mar 21, 2007
Mar 21, 2007
341
342
343
#elif (defined _MSC_VER)
#define __PHYSFS_SI64(x) x##i64
#define __PHYSFS_UI64(x) x##ui64
Jan 1, 2006
Jan 1, 2006
344
#else
Aug 21, 2010
Aug 21, 2010
345
346
#define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x))
#define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x))
Jan 1, 2006
Jan 1, 2006
347
348
#endif
Mar 12, 2008
Mar 12, 2008
349
Jan 1, 2006
Jan 1, 2006
350
351
352
353
354
355
356
357
/*
* Check if a ui64 will fit in the platform's address space.
* The initial sizeof check will optimize this macro out entirely on
* 64-bit (and larger?!) platforms, and the other condition will
* return zero or non-zero if the variable will fit in the platform's
* size_t, suitable to pass to malloc. This is kinda messy, but effective.
*/
#define __PHYSFS_ui64FitsAddressSpace(s) ( \
Aug 24, 2010
Aug 24, 2010
358
359
(sizeof (PHYSFS_uint64) <= sizeof (size_t)) || \
((s) < (__PHYSFS_UI64(0xFFFFFFFFFFFFFFFF) >> (64-(sizeof(size_t)*8)))) \
Jan 1, 2006
Jan 1, 2006
360
)
Jul 6, 2001
Jul 6, 2001
361
Mar 12, 2008
Mar 12, 2008
362
Mar 15, 2007
Mar 15, 2007
363
364
365
366
367
368
369
370
371
372
373
374
/*
* This is a strcasecmp() or stricmp() replacement that expects both strings
* to be in UTF-8 encoding. It will do "case folding" to decide if the
* Unicode codepoints in the strings match.
*
* It will report which string is "greater than" the other, but be aware that
* this doesn't necessarily mean anything: 'a' may be "less than" 'b', but
* a random Kanji codepoint has no meaningful alphabetically relationship to
* a Greek Lambda, but being able to assign a reliable "value" makes sorting
* algorithms possible, if not entirely sane. Most cases should treat the
* return value as "equal" or "not equal".
*/
Mar 22, 2012
Mar 22, 2012
375
int __PHYSFS_utf8stricmp(const char *s1, const char *s2);
Mar 15, 2007
Mar 15, 2007
376
377
/*
Mar 22, 2012
Mar 22, 2012
378
* This works like __PHYSFS_utf8stricmp(), but takes a character (NOT BYTE
Mar 15, 2007
Mar 15, 2007
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
* COUNT) argument, like strcasencmp().
*/
int __PHYSFS_utf8strnicmp(const char *s1, const char *s2, PHYSFS_uint32 l);
/*
* stricmp() that guarantees to only work with low ASCII. The C runtime
* stricmp() might try to apply a locale/codepage/etc, which we don't want.
*/
int __PHYSFS_stricmpASCII(const char *s1, const char *s2);
/*
* strnicmp() that guarantees to only work with low ASCII. The C runtime
* strnicmp() might try to apply a locale/codepage/etc, which we don't want.
*/
int __PHYSFS_strnicmpASCII(const char *s1, const char *s2, PHYSFS_uint32 l);
Sep 23, 2004
Sep 23, 2004
396
/*
Mar 14, 2005
Mar 14, 2005
397
* The current allocator. Not valid before PHYSFS_init is called!
Sep 23, 2004
Sep 23, 2004
398
*/
Mar 14, 2005
Mar 14, 2005
399
extern PHYSFS_Allocator __PHYSFS_AllocatorHooks;
Jul 6, 2001
Jul 6, 2001
400
Mar 14, 2005
Mar 14, 2005
401
402
/* convenience macro to make this less cumbersome internally... */
#define allocator __PHYSFS_AllocatorHooks
Jul 6, 2001
Jul 6, 2001
403
Aug 30, 2010
Aug 30, 2010
404
405
406
407
408
409
410
/*
* Create a PHYSFS_Io for a file in the physical filesystem.
* This path is in platform-dependent notation. (mode) must be 'r', 'w', or
* 'a' for Read, Write, or Append.
*/
PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode);
Aug 30, 2010
Aug 30, 2010
411
412
413
414
415
416
417
418
/*
* Create a PHYSFS_Io for a buffer of memory (READ-ONLY). If you already
* have one of these, just use its duplicate() method, and it'll increment
* its refcount without allocating a copy of the buffer.
*/
PHYSFS_Io *__PHYSFS_createMemoryIo(const void *buf, PHYSFS_uint64 len,
void (*destruct)(void *));
Aug 30, 2010
Aug 30, 2010
419
Mar 9, 2012
Mar 9, 2012
420
421
422
423
424
/*
* Read (len) bytes from (io) into (buf). Returns non-zero on success,
* zero on i/o error. Literally: "return (io->read(io, buf, len) == len);"
*/
int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len);
Sep 6, 2010
Sep 6, 2010
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/* These are shared between some archivers. */
typedef struct
{
char name[32];
PHYSFS_uint32 startPos;
PHYSFS_uint32 size;
} UNPKentry;
void UNPK_dirClose(dvoid *opaque);
dvoid *UNPK_openArchive(PHYSFS_Io *io, UNPKentry *e, const PHYSFS_uint32 num);
void UNPK_enumerateFiles(dvoid *opaque, const char *dname,
int omitSymLinks, PHYSFS_EnumFilesCallback cb,
const char *origdir, void *callbackdata);
PHYSFS_Io *UNPK_openRead(dvoid *opaque, const char *fnm, int *fileExists);
PHYSFS_Io *UNPK_openWrite(dvoid *opaque, const char *name);
PHYSFS_Io *UNPK_openAppend(dvoid *opaque, const char *name);
int UNPK_remove(dvoid *opaque, const char *name);
int UNPK_mkdir(dvoid *opaque, const char *name);
int UNPK_stat(dvoid *opaque, const char *fn, int *exists, PHYSFS_Stat *stat);
Jul 6, 2001
Jul 6, 2001
449
450
451
452
453
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*------------ ----------------*/
/*------------ You MUST implement the following functions ----------------*/
/*------------ if porting to a new platform. ----------------*/
Jul 15, 2001
Jul 15, 2001
454
/*------------ (see platform/unix.c for an example) ----------------*/
Jul 6, 2001
Jul 6, 2001
455
456
457
458
459
460
/*------------ ----------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*
Mar 15, 2012
Mar 15, 2012
461
462
463
* The dir separator; '/' on unix, '\\' on win32, ":" on MacOS, etc...
* Obviously, this isn't a function. If you need more than one char for this,
* you'll need to pull some old pieces of PhysicsFS out of revision control.
Jul 6, 2001
Jul 6, 2001
464
*/
Mar 19, 2012
Mar 19, 2012
465
#if PHYSFS_PLATFORM_WINDOWS
Mar 15, 2012
Mar 15, 2012
466
467
468
469
#define __PHYSFS_platformDirSeparator '\\'
#else
#define __PHYSFS_platformDirSeparator '/'
#endif
Mar 24, 2002
Mar 24, 2002
470
471
472
/*
* Initialize the platform. This is called when PHYSFS_init() is called from
Mar 18, 2012
Mar 18, 2012
473
* the application.
Mar 24, 2002
Mar 24, 2002
474
475
476
477
478
479
*
* 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
480
Mar 24, 2002
Mar 24, 2002
481
482
483
484
485
486
487
488
489
490
/*
* 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
491
Mar 24, 2002
Mar 24, 2002
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
/*
* 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
507
Mar 24, 2002
Mar 24, 2002
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*
* 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
524
Mar 24, 2002
Mar 24, 2002
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/*
* 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);
/*
* Read more data from a platform-specific file handle. (opaque) should be
Aug 21, 2010
Aug 21, 2010
544
545
546
547
548
549
* cast to whatever data type your platform uses. Read a maximum of (len)
* 8-bit bytes to the area pointed to by (buf). If there isn't enough data
* available, return the number of bytes read, and position the file pointer
* immediately after those bytes.
* On success, return (len) and position the file pointer immediately past
* the end of the last read byte. Return (-1) if there is a catastrophic
Mar 24, 2002
Mar 24, 2002
550
* error, and call __PHYSFS_setError() to describe the problem; the file
Aug 21, 2010
Aug 21, 2010
551
552
553
* pointer should not move in such a case. A partial read is success; only
* return (-1) on total failure; presumably, the next read call after a
* partial read will fail as such.
Mar 24, 2002
Mar 24, 2002
554
*/
Aug 21, 2010
Aug 21, 2010
555
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len);
Mar 24, 2002
Mar 24, 2002
556
557
558
/*
* Write more data to a platform-specific file handle. (opaque) should be
Aug 21, 2010
Aug 21, 2010
559
560
561
562
563
564
565
566
* cast to whatever data type your platform uses. Write a maximum of (len)
* 8-bit bytes from the area pointed to by (buffer). If there is a problem,
* return the number of bytes written, and position the file pointer
* immediately after those bytes. 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. A partial write is success; only
* return (-1) on total failure; presumably, the next write call after a
* partial write will fail as such.
Mar 24, 2002
Mar 24, 2002
567
*/
Mar 25, 2002
Mar 25, 2002
568
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
Aug 21, 2010
Aug 21, 2010
569
PHYSFS_uint64 len);
Mar 24, 2002
Mar 24, 2002
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/*
* 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
584
Mar 24, 2002
Mar 24, 2002
585
586
587
588
589
590
591
/*
* 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.
*
Aug 1, 2011
Aug 1, 2011
592
* On error, call __PHYSFS_setError() and return -1. On success, return >= 0.
Mar 24, 2002
Mar 24, 2002
593
594
595
*/
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
May 25, 2002
May 25, 2002
596
Mar 24, 2002
Mar 24, 2002
597
598
599
600
601
602
603
604
605
606
607
/*
* 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);
Feb 15, 2010
Feb 15, 2010
608
609
610
611
612
613
/*
* !!! FIXME: comment me.
*/
int __PHYSFS_platformStat(const char *fn, int *exists, PHYSFS_Stat *stat);
Mar 24, 2002
Mar 24, 2002
614
615
616
617
618
619
620
621
622
623
/*
* 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);
/*
Aug 30, 2010
Aug 30, 2010
624
625
626
* Close file and deallocate resources. (opaque) should be cast to whatever
* data type your platform uses. This should close the file in any scenario:
* flushing is a separate function call, and this function should never fail.
Mar 24, 2002
Mar 24, 2002
627
*
Aug 30, 2010
Aug 30, 2010
628
629
* You should clean up all resources associated with (opaque); the pointer
* will be considered invalid after this call.
Mar 24, 2002
Mar 24, 2002
630
*/
Aug 30, 2010
Aug 30, 2010
631
void __PHYSFS_platformClose(void *opaque);
Mar 24, 2002
Mar 24, 2002
632
Jul 6, 2001
Jul 6, 2001
633
/*
Sep 29, 2004
Sep 29, 2004
634
635
636
637
638
* Platform implementation of PHYSFS_getCdRomDirsCallback()...
* CD directories are discovered and reported to the callback one at a time.
* Pointers passed to the callback are assumed to be invalid to the
* application after the callback returns, so you can free them or whatever.
* Callback does not assume results will be sorted in any meaningful way.
Jul 6, 2001
Jul 6, 2001
639
*/
Sep 29, 2004
Sep 29, 2004
640
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data);
Jul 6, 2001
Jul 6, 2001
641
642
643
644
645
/*
* Calculate the base dir, if your platform needs special consideration.
* Just return NULL if the standard routines will suffice. (see
* calculateBaseDir() in physfs.c ...)
Mar 11, 2012
Mar 11, 2012
646
* Caller will allocator.Free() the retval if it's not NULL.
Jul 6, 2001
Jul 6, 2001
647
*/
Jul 8, 2001
Jul 8, 2001
648
char *__PHYSFS_platformCalcBaseDir(const char *argv0);
Jul 6, 2001
Jul 6, 2001
649
Mar 22, 2012
Mar 22, 2012
650
/*
Jul 6, 2001
Jul 6, 2001
651
* Get the platform-specific user dir.
Mar 11, 2012
Mar 11, 2012
652
653
* Caller will allocator.Free() the retval if it's not NULL. If it's NULL,
* the userdir will default to basedir/username.
Jul 6, 2001
Jul 6, 2001
654
*/
Mar 22, 2012
Mar 22, 2012
655
char *__PHYSFS_platformCalcUserDir(void);
Jul 6, 2001
Jul 6, 2001
656
Mar 22, 2012
Mar 22, 2012
657
658
659
660
661
/* This is the cached version from PHYSFS_init(). This is a fast call. */
const char *__PHYSFS_getUserDir(void); /* not deprecated internal version. */
/*
Mar 22, 2012
Mar 22, 2012
662
663
664
* Get the platform-specific pref dir. You must make sure the string ends
* with a dir separator.
* Caller will allocator.Free() the retval if it's not NULL. If it's NULL,
Mar 22, 2012
Mar 22, 2012
665
666
667
668
669
670
* it's a total failure. Caller will make missing directories if necessary;
* this just reports the final path.
*/
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app);
Jul 6, 2001
Jul 6, 2001
671
/*
Sep 6, 2009
Sep 6, 2009
672
673
* Return a pointer that uniquely identifies the current thread.
* On a platform without threading, (0x1) will suffice. These numbers are
Jul 6, 2001
Jul 6, 2001
674
* arbitrary; the only requirement is that no two threads have the same
Sep 6, 2009
Sep 6, 2009
675
* pointer.
Jul 6, 2001
Jul 6, 2001
676
*/
Sep 6, 2009
Sep 6, 2009
677
void *__PHYSFS_platformGetThreadID(void);
Jul 6, 2001
Jul 6, 2001
678
May 25, 2002
May 25, 2002
679
Jul 8, 2001
Jul 8, 2001
680
681
/*
* Enumerate a directory of files. This follows the rules for the
Sep 26, 2004
Sep 26, 2004
682
* PHYSFS_Archiver->enumerateFiles() method (see above), except that the
Jul 8, 2001
Jul 8, 2001
683
* (dirName) that is passed to this function is converted to
Sep 26, 2004
Sep 26, 2004
684
* platform-DEPENDENT notation by the caller. The PHYSFS_Archiver version
Jul 16, 2001
Jul 16, 2001
685
686
* uses platform-independent notation. Note that ".", "..", and other
* metaentries should always be ignored.
Jul 8, 2001
Jul 8, 2001
687
*/
Sep 29, 2004
Sep 29, 2004
688
689
void __PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks,
Sep 18, 2005
Sep 18, 2005
690
691
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
692
void *callbackdata);
Jul 8, 2001
Jul 8, 2001
693
Aug 23, 2001
Aug 23, 2001
694
695
696
697
698
699
700
/*
* 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
701
Mar 25, 2002
Mar 25, 2002
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
* 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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*
* 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
743
744
745
746
*
* _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
747
748
749
750
751
752
753
754
*/
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
755
756
757
758
*
* _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
759
760
761
*/
void __PHYSFS_platformReleaseMutex(void *mutex);
Sep 23, 2004
Sep 23, 2004
762
/*
Mar 20, 2007
Mar 20, 2007
763
* Called at the start of PHYSFS_init() to prepare the allocator, if the user
Sep 26, 2004
Sep 26, 2004
764
* hasn't selected their own allocator via PHYSFS_setAllocator().
Mar 20, 2007
Mar 20, 2007
765
766
767
768
769
770
771
772
* If the platform has a custom allocator, it should fill in the fields of
* (a) with the proper function pointers and return non-zero.
* If the platform just wants to use malloc()/free()/etc, return zero
* immediately and the higher level will handle it. The Init and Deinit
* fields of (a) are optional...set them to NULL if you don't need them.
* Everything else must be implemented. All rules follow those for
* PHYSFS_setAllocator(). If Init isn't NULL, it will be called shortly
* after this function returns non-zero.
Sep 23, 2004
Sep 23, 2004
773
*/
Mar 20, 2007
Mar 20, 2007
774
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a);
Sep 23, 2004
Sep 23, 2004
775
Jul 6, 2001
Jul 6, 2001
776
#ifdef __cplusplus
Mar 24, 2002
Mar 24, 2002
777
}
Jul 6, 2001
Jul 6, 2001
778
779
780
781
782
#endif
#endif
/* end of physfs_internal.h ... */