Skip to content

Latest commit

 

History

History
741 lines (629 loc) · 27.6 KB

physfs_internal.h

File metadata and controls

741 lines (629 loc) · 27.6 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
Jul 12, 2017
Jul 12, 2017
17
18
19
20
21
/* Turn off MSVC warnings that are aggressively anti-portability. */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS 1
#endif
Mar 24, 2002
Mar 24, 2002
22
23
#include "physfs.h"
Sep 6, 2010
Sep 6, 2010
24
25
26
27
/* The holy trinity. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Mar 15, 2007
Mar 15, 2007
28
Mar 19, 2012
Mar 19, 2012
29
30
#include "physfs_platforms.h"
Nov 22, 2002
Nov 22, 2002
31
32
#include <assert.h>
Aug 6, 2017
Aug 6, 2017
33
34
35
#define __PHYSFS_COMPILE_TIME_ASSERT(name, x) \
typedef int __PHYSFS_compile_time_assert_##name[(x) * 2 - 1]
Mar 19, 2007
Mar 19, 2007
36
/* !!! FIXME: remove this when revamping stack allocation code... */
Jul 6, 2017
Jul 6, 2017
37
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__WATCOMC__)
Mar 19, 2007
Mar 19, 2007
38
39
40
#include <malloc.h>
#endif
Jul 24, 2017
Jul 24, 2017
41
#ifdef PHYSFS_PLATFORM_SOLARIS
Apr 8, 2010
Apr 8, 2010
42
43
44
#include <alloca.h>
#endif
Mar 24, 2002
Mar 24, 2002
45
46
47
48
#ifdef __cplusplus
extern "C" {
#endif
Mar 12, 2008
Mar 12, 2008
49
#ifdef __GNUC__
Mar 12, 2008
Mar 12, 2008
50
#define PHYSFS_MINIMUM_GCC_VERSION(major, minor) \
Mar 12, 2008
Mar 12, 2008
51
52
( ((__GNUC__ << 16) + __GNUC_MINOR__) >= (((major) << 16) + (minor)) )
#else
Mar 12, 2008
Mar 12, 2008
53
#define PHYSFS_MINIMUM_GCC_VERSION(major, minor) (0)
Mar 12, 2008
Mar 12, 2008
54
55
#endif
Aug 21, 2010
Aug 21, 2010
56
57
58
59
60
61
62
63
#ifdef __cplusplus
/* C++ always has a real inline keyword. */
#elif (defined macintosh) && !(defined __MWERKS__)
# define inline
#elif (defined _MSC_VER)
# define inline __inline
#endif
Jul 24, 2017
Jul 24, 2017
64
#if defined(PHYSFS_PLATFORM_LINUX) && !defined(_FILE_OFFSET_BITS)
Mar 18, 2012
Mar 18, 2012
65
66
#define _FILE_OFFSET_BITS 64
#endif
Jul 9, 2017
Jul 9, 2017
67
Jul 12, 2017
Jul 12, 2017
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* All public APIs need to be in physfs.h with a PHYSFS_DECL.
All file-private symbols need to be marked "static".
Everything shared between PhysicsFS sources needs to be in this
file between the visibility pragma blocks. */
#if PHYSFS_MINIMUM_GCC_VERSION(4,0) || defined(__clang__)
#define PHYSFS_HAVE_PRAGMA_VISIBILITY 1
#endif
#if PHYSFS_HAVE_PRAGMA_VISIBILITY
#pragma GCC visibility push(hidden)
#endif
/* These are the build-in archivers. We list them all as "extern" here without
#ifdefs to keep it tidy, but obviously you need to make sure these are
wrapped in PHYSFS_SUPPORTS_* checks before actually referencing them. */
extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR;
extern const PHYSFS_Archiver __PHYSFS_Archiver_ZIP;
Jul 22, 2017
Jul 22, 2017
85
extern const PHYSFS_Archiver __PHYSFS_Archiver_7Z;
Jul 12, 2017
Jul 12, 2017
86
87
88
89
90
91
92
93
94
extern const PHYSFS_Archiver __PHYSFS_Archiver_GRP;
extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK;
extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG;
extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL;
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD;
extern const PHYSFS_Archiver __PHYSFS_Archiver_SLB;
extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660;
extern const PHYSFS_Archiver __PHYSFS_Archiver_VDF;
Jul 9, 2017
Jul 9, 2017
95
96
97
98
99
100
101
102
/* a real C99-compliant snprintf() is in Visual Studio 2015,
but just use this everywhere for binary compatibility. */
#if defined(_MSC_VER)
int __PHYSFS_msvc_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap);
int __PHYSFS_msvc_snprintf(char *outBuf, size_t size, const char *format, ...);
#define vsnprintf __PHYSFS_msvc_vsnprintf
#define snprintf __PHYSFS_msvc_snprintf
#endif
Mar 18, 2012
Mar 18, 2012
103
Jul 24, 2017
Jul 24, 2017
104
105
106
107
108
109
/* Some simple wrappers around WinRT C++ interfaces we can call from C. */
#ifdef PHYSFS_PLATFORM_WINRT
const void *__PHYSFS_winrtCalcBaseDir(void);
const void *__PHYSFS_winrtCalcPrefDir(void);
#endif
Aug 6, 2017
Aug 6, 2017
110
111
112
/* atomic operations. */
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#include <intrin.h>
Aug 6, 2017
Aug 6, 2017
113
__PHYSFS_COMPILE_TIME_ASSERT(LongEqualsInt, sizeof (int) == sizeof (long));
Aug 6, 2017
Aug 6, 2017
114
#define __PHYSFS_ATOMIC_INCR(ptrval) _InterlockedIncrement((long*)(ptrval))
Aug 6, 2017
Aug 6, 2017
115
#define __PHYSFS_ATOMIC_DECR(ptrval) _InterlockedDecrement((long*)(ptrval))
Aug 6, 2017
Aug 6, 2017
116
117
118
119
120
121
122
123
124
125
#elif defined(__clang__) || (defined(__GNUC__) && (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100)) >= 40100))
#define __PHYSFS_ATOMIC_INCR(ptrval) __sync_fetch_and_add(ptrval, 1)
#define __PHYSFS_ATOMIC_DECR(ptrval) __sync_fetch_and_add(ptrval, -1)
#else
#define PHYSFS_NEED_ATOMIC_OP_FALLBACK 1
int __PHYSFS_ATOMIC_INCR(int *ptrval);
int __PHYSFS_ATOMIC_DECR(int *ptrval);
#endif
Mar 24, 2007
Mar 24, 2007
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* 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
147
#define __PHYSFS_SMALLALLOCTHRESHOLD 256
Mar 24, 2007
Mar 24, 2007
148
149
150
void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len);
#define __PHYSFS_smallAlloc(bytes) ( \
Mar 12, 2012
Mar 12, 2012
151
152
153
__PHYSFS_initSmallAlloc( \
(((bytes) < __PHYSFS_SMALLALLOCTHRESHOLD) ? \
alloca((size_t)((bytes)+sizeof(void*))) : NULL), (bytes)) \
Mar 24, 2007
Mar 24, 2007
154
155
156
157
158
)
void __PHYSFS_smallFree(void *ptr);
Mar 14, 2005
Mar 14, 2005
159
160
161
162
/* 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
163
/* !!! FIXME: add alloca check here. */
Jul 28, 2002
Jul 28, 2002
164
Mar 23, 2012
Mar 23, 2012
165
166
167
168
#ifndef PHYSFS_SUPPORTS_ZIP
#define PHYSFS_SUPPORTS_ZIP 1
#endif
#ifndef PHYSFS_SUPPORTS_7Z
Jul 17, 2017
Jul 17, 2017
169
#define PHYSFS_SUPPORTS_7Z 1
Mar 23, 2012
Mar 23, 2012
170
171
#endif
#ifndef PHYSFS_SUPPORTS_GRP
Jul 8, 2017
Jul 8, 2017
172
#define PHYSFS_SUPPORTS_GRP 1
Mar 23, 2012
Mar 23, 2012
173
174
#endif
#ifndef PHYSFS_SUPPORTS_HOG
Jul 8, 2017
Jul 8, 2017
175
#define PHYSFS_SUPPORTS_HOG 1
Mar 23, 2012
Mar 23, 2012
176
177
#endif
#ifndef PHYSFS_SUPPORTS_MVL
Jul 8, 2017
Jul 8, 2017
178
#define PHYSFS_SUPPORTS_MVL 1
Mar 23, 2012
Mar 23, 2012
179
180
#endif
#ifndef PHYSFS_SUPPORTS_WAD
Jul 8, 2017
Jul 8, 2017
181
#define PHYSFS_SUPPORTS_WAD 1
Mar 23, 2012
Mar 23, 2012
182
#endif
Jul 16, 2017
Jul 16, 2017
183
184
185
#ifndef PHYSFS_SUPPORTS_QPAK
#define PHYSFS_SUPPORTS_QPAK 1
#endif
Nov 12, 2012
Nov 12, 2012
186
#ifndef PHYSFS_SUPPORTS_SLB
Jul 8, 2017
Jul 8, 2017
187
#define PHYSFS_SUPPORTS_SLB 1
Nov 12, 2012
Nov 12, 2012
188
#endif
Mar 23, 2012
Mar 23, 2012
189
#ifndef PHYSFS_SUPPORTS_ISO9660
Jul 8, 2017
Jul 8, 2017
190
#define PHYSFS_SUPPORTS_ISO9660 1
Mar 23, 2012
Mar 23, 2012
191
#endif
Jun 20, 2017
Jun 20, 2017
192
#ifndef PHYSFS_SUPPORTS_VDF
Jul 8, 2017
Jul 8, 2017
193
#define PHYSFS_SUPPORTS_VDF 1
Jun 20, 2017
Jun 20, 2017
194
#endif
Mar 23, 2012
Mar 23, 2012
195
Mar 25, 2012
Mar 25, 2012
196
197
/* The latest supported PHYSFS_Io::version value. */
#define CURRENT_PHYSFS_IO_API_VERSION 0
Jul 8, 2001
Jul 8, 2001
198
Nov 28, 2012
Nov 28, 2012
199
200
/* The latest supported PHYSFS_Archiver::version value. */
#define CURRENT_PHYSFS_ARCHIVER_API_VERSION 0
Dec 1, 2002
Dec 1, 2002
201
Feb 25, 2016
Feb 25, 2016
202
/* This byteorder stuff was lifted from SDL. https://www.libsdl.org/ */
Apr 9, 2004
Apr 9, 2004
203
204
205
#define PHYSFS_LIL_ENDIAN 1234
#define PHYSFS_BIG_ENDIAN 4321
Feb 25, 2016
Feb 25, 2016
206
207
208
209
210
211
212
213
214
215
#ifdef __linux__
#include <endian.h>
#define PHYSFS_BYTEORDER __BYTE_ORDER
#else /* __linux__ */
#if defined(__hppa__) || \
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
(defined(__MIPS__) && defined(__MISPEB__)) || \
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
defined(__sparc__)
#define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN
Apr 9, 2004
Apr 9, 2004
216
#else
Feb 25, 2016
Feb 25, 2016
217
#define PHYSFS_BYTEORDER PHYSFS_LIL_ENDIAN
Apr 9, 2004
Apr 9, 2004
218
#endif
Feb 25, 2016
Feb 25, 2016
219
#endif /* __linux__ */
Apr 9, 2004
Apr 9, 2004
220
221
Aug 20, 2002
Aug 20, 2002
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* 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.
*/
Jun 1, 2012
Jun 1, 2012
240
241
242
void __PHYSFS_sort(void *entries, size_t max,
int (*cmpfn)(void *, size_t, size_t),
void (*swapfn)(void *, size_t, size_t));
Aug 20, 2002
Aug 20, 2002
243
Aug 23, 2001
Aug 23, 2001
244
/* These get used all over for lessening code clutter. */
Jul 6, 2017
Jul 6, 2017
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* "ERRPASS" means "something else just set the error state for us" and is
just to make it clear where the responsibility for the error state lays. */
#define BAIL(e, r) do { if (e) PHYSFS_setErrorCode(e); return r; } while (0)
#define BAIL_ERRPASS(r) do { return r; } while (0)
#define BAIL_IF(c, e, r) do { if (c) { if (e) PHYSFS_setErrorCode(e); return r; } } while (0)
#define BAIL_IF_ERRPASS(c, r) do { if (c) { return r; } } while (0)
#define BAIL_MUTEX(e, m, r) do { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0)
#define BAIL_MUTEX_ERRPASS(m, r) do { __PHYSFS_platformReleaseMutex(m); return r; } while (0)
#define BAIL_IF_MUTEX(c, e, m, r) do { if (c) { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0)
#define BAIL_IF_MUTEX_ERRPASS(c, m, r) do { if (c) { __PHYSFS_platformReleaseMutex(m); return r; } } while (0)
#define GOTO(e, g) do { if (e) PHYSFS_setErrorCode(e); goto g; } while (0)
#define GOTO_ERRPASS(g) do { goto g; } while (0)
#define GOTO_IF(c, e, g) do { if (c) { if (e) PHYSFS_setErrorCode(e); goto g; } } while (0)
#define GOTO_IF_ERRPASS(c, g) do { if (c) { goto g; } } while (0)
#define GOTO_MUTEX(e, m, g) do { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0)
#define GOTO_MUTEX_ERRPASS(m, g) do { __PHYSFS_platformReleaseMutex(m); goto g; } while (0)
#define GOTO_IF_MUTEX(c, e, m, g) do { if (c) { if (e) PHYSFS_setErrorCode(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0)
#define GOTO_IF_MUTEX_ERRPASS(c, m, g) do { if (c) { __PHYSFS_platformReleaseMutex(m); goto g; } } while (0)
Jul 6, 2001
Jul 6, 2001
263
Mar 15, 2007
Mar 15, 2007
264
265
#define __PHYSFS_ARRAYLEN(x) ( (sizeof (x)) / (sizeof (x[0])) )
Aug 21, 2010
Aug 21, 2010
266
267
268
269
#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
270
271
#define __PHYSFS_SI64(x) x##LL
#define __PHYSFS_UI64(x) x##ULL
Mar 21, 2007
Mar 21, 2007
272
273
274
#elif (defined _MSC_VER)
#define __PHYSFS_SI64(x) x##i64
#define __PHYSFS_UI64(x) x##ui64
Jan 1, 2006
Jan 1, 2006
275
#else
Aug 21, 2010
Aug 21, 2010
276
277
#define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x))
#define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x))
Jan 1, 2006
Jan 1, 2006
278
279
#endif
Mar 12, 2008
Mar 12, 2008
280
Jan 1, 2006
Jan 1, 2006
281
282
283
284
285
286
287
288
/*
* 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
289
290
(sizeof (PHYSFS_uint64) <= sizeof (size_t)) || \
((s) < (__PHYSFS_UI64(0xFFFFFFFFFFFFFFFF) >> (64-(sizeof(size_t)*8)))) \
Jan 1, 2006
Jan 1, 2006
291
)
Jul 6, 2001
Jul 6, 2001
292
Mar 12, 2008
Mar 12, 2008
293
Mar 15, 2007
Mar 15, 2007
294
295
296
297
298
299
300
301
302
303
304
305
/*
* 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
306
int __PHYSFS_utf8stricmp(const char *s1, const char *s2);
Mar 15, 2007
Mar 15, 2007
307
308
/*
Mar 22, 2012
Mar 22, 2012
309
* This works like __PHYSFS_utf8stricmp(), but takes a character (NOT BYTE
Mar 15, 2007
Mar 15, 2007
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
* 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);
Feb 25, 2016
Feb 25, 2016
326
327
328
329
330
/*
* Like strdup(), but uses the current PhysicsFS allocator.
*/
char *__PHYSFS_strdup(const char *str);
Feb 25, 2016
Feb 25, 2016
331
332
333
334
335
/*
* Give a hash value for a C string (uses djb's xor hashing algorithm).
*/
PHYSFS_uint32 __PHYSFS_hashString(const char *str, size_t len);
Mar 15, 2007
Mar 15, 2007
336
Sep 23, 2004
Sep 23, 2004
337
/*
Mar 14, 2005
Mar 14, 2005
338
* The current allocator. Not valid before PHYSFS_init is called!
Sep 23, 2004
Sep 23, 2004
339
*/
Mar 14, 2005
Mar 14, 2005
340
extern PHYSFS_Allocator __PHYSFS_AllocatorHooks;
Jul 6, 2001
Jul 6, 2001
341
Mar 14, 2005
Mar 14, 2005
342
343
/* convenience macro to make this less cumbersome internally... */
#define allocator __PHYSFS_AllocatorHooks
Jul 6, 2001
Jul 6, 2001
344
Aug 30, 2010
Aug 30, 2010
345
346
347
348
349
350
351
/*
* 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
352
353
354
355
356
357
358
359
/*
* 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
360
Mar 9, 2012
Mar 9, 2012
361
362
363
364
365
/*
* 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
366
367
368
369
/* These are shared between some archivers. */
Jul 21, 2017
Jul 21, 2017
370
void UNPK_abandonArchive(void *opaque);
Nov 28, 2012
Nov 28, 2012
371
void UNPK_closeArchive(void *opaque);
Jul 21, 2017
Jul 21, 2017
372
void *UNPK_openArchive(PHYSFS_Io *io);
Jul 16, 2017
Jul 16, 2017
373
void *UNPK_addEntry(void *opaque, char *name, const int isdir,
Jul 22, 2017
Jul 22, 2017
374
const PHYSFS_sint64 ctime, const PHYSFS_sint64 mtime,
Jul 16, 2017
Jul 16, 2017
375
const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
Nov 30, 2012
Nov 30, 2012
376
PHYSFS_Io *UNPK_openRead(void *opaque, const char *name);
Nov 28, 2012
Nov 28, 2012
377
378
379
380
PHYSFS_Io *UNPK_openWrite(void *opaque, const char *name);
PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name);
int UNPK_remove(void *opaque, const char *name);
int UNPK_mkdir(void *opaque, const char *name);
Nov 30, 2012
Nov 30, 2012
381
int UNPK_stat(void *opaque, const char *fn, PHYSFS_Stat *st);
Jul 16, 2017
Jul 16, 2017
382
#define UNPK_enumerateFiles __PHYSFS_DirTreeEnumerateFiles
Sep 6, 2010
Sep 6, 2010
383
384
Jul 15, 2017
Jul 15, 2017
385
386
/* Optional API many archivers use this to manage their directory tree. */
Aug 6, 2017
Aug 6, 2017
387
/* !!! FIXME-3.0: document this better. */
Jul 15, 2017
Jul 15, 2017
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
typedef struct __PHYSFS_DirTreeEntry
{
char *name; /* Full path in archive. */
struct __PHYSFS_DirTreeEntry *hashnext; /* next item in hash bucket. */
struct __PHYSFS_DirTreeEntry *children; /* linked list of kids, if dir. */
struct __PHYSFS_DirTreeEntry *sibling; /* next item in same dir. */
int isdir;
} __PHYSFS_DirTreeEntry;
typedef struct __PHYSFS_DirTree
{
__PHYSFS_DirTreeEntry *root; /* root of directory tree. */
__PHYSFS_DirTreeEntry **hash; /* all entries hashed for fast lookup. */
size_t hashBuckets; /* number of buckets in hash. */
size_t entrylen; /* size in bytes of entries (including subclass). */
} __PHYSFS_DirTree;
Jul 21, 2017
Jul 21, 2017
407
int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen);
Jul 15, 2017
Jul 15, 2017
408
409
410
411
412
413
414
415
416
void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
void __PHYSFS_DirTreeEnumerateFiles(void *opaque, const char *dname,
PHYSFS_EnumFilesCallback cb,
const char *origdir, void *callbackdata);
void __PHYSFS_DirTreeDeinit(__PHYSFS_DirTree *dt);
Jul 6, 2001
Jul 6, 2001
417
418
419
420
421
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*------------ ----------------*/
/*------------ You MUST implement the following functions ----------------*/
/*------------ if porting to a new platform. ----------------*/
Jul 15, 2001
Jul 15, 2001
422
/*------------ (see platform/unix.c for an example) ----------------*/
Jul 6, 2001
Jul 6, 2001
423
424
425
426
427
428
/*------------ ----------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*
Mar 15, 2012
Mar 15, 2012
429
430
431
* 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
432
*/
Jul 24, 2017
Jul 24, 2017
433
#if defined(PHYSFS_PLATFORM_WINDOWS) || defined(PHYSFS_PLATFORM_OS2)
Mar 15, 2012
Mar 15, 2012
434
435
436
437
#define __PHYSFS_platformDirSeparator '\\'
#else
#define __PHYSFS_platformDirSeparator '/'
#endif
Mar 24, 2002
Mar 24, 2002
438
439
440
/*
* Initialize the platform. This is called when PHYSFS_init() is called from
Mar 18, 2012
Mar 18, 2012
441
* the application.
Mar 24, 2002
Mar 24, 2002
442
443
444
445
446
447
*
* 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
448
Mar 24, 2002
Mar 24, 2002
449
450
451
452
453
/*
* 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.
*/
Aug 6, 2017
Aug 6, 2017
454
void __PHYSFS_platformDeinit(void);
Mar 24, 2002
Mar 24, 2002
455
May 25, 2002
May 25, 2002
456
Mar 24, 2002
Mar 24, 2002
457
458
459
460
461
462
463
464
465
466
467
/*
* 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.
*
Nov 30, 2012
Nov 30, 2012
468
* Call PHYSFS_setErrorCode() and return (NULL) if the file can't be opened.
Mar 24, 2002
Mar 24, 2002
469
470
471
*/
void *__PHYSFS_platformOpenRead(const char *filename);
May 25, 2002
May 25, 2002
472
Mar 24, 2002
Mar 24, 2002
473
474
475
476
477
478
479
480
481
482
483
484
/*
* 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.
*
Nov 30, 2012
Nov 30, 2012
485
* Call PHYSFS_setErrorCode() and return (NULL) if the file can't be opened.
Mar 24, 2002
Mar 24, 2002
486
487
488
*/
void *__PHYSFS_platformOpenWrite(const char *filename);
May 25, 2002
May 25, 2002
489
Mar 24, 2002
Mar 24, 2002
490
491
492
493
494
495
496
497
498
499
500
501
502
/*
* 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.
*
Nov 30, 2012
Nov 30, 2012
503
* Call PHYSFS_setErrorCode() and return (NULL) if the file can't be opened.
Mar 24, 2002
Mar 24, 2002
504
505
506
507
508
*/
void *__PHYSFS_platformOpenAppend(const char *filename);
/*
* Read more data from a platform-specific file handle. (opaque) should be
Aug 21, 2010
Aug 21, 2010
509
510
511
512
513
514
* 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
Nov 30, 2012
Nov 30, 2012
515
* error, and call PHYSFS_setErrorCode() to describe the problem; the file
Aug 21, 2010
Aug 21, 2010
516
517
518
* 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
519
*/
Aug 21, 2010
Aug 21, 2010
520
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len);
Mar 24, 2002
Mar 24, 2002
521
522
523
/*
* Write more data to a platform-specific file handle. (opaque) should be
Aug 21, 2010
Aug 21, 2010
524
525
526
527
* 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
Nov 30, 2012
Nov 30, 2012
528
* error, and call PHYSFS_setErrorCode() to describe the problem; the file
Aug 21, 2010
Aug 21, 2010
529
530
531
* 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
532
*/
Mar 25, 2002
Mar 25, 2002
533
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
Aug 21, 2010
Aug 21, 2010
534
PHYSFS_uint64 len);
Mar 24, 2002
Mar 24, 2002
535
536
537
538
539
540
541
542
543
/*
* 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.
*
Nov 30, 2012
Nov 30, 2012
544
* On error, call PHYSFS_setErrorCode() and return zero. On success, return
Mar 24, 2002
Mar 24, 2002
545
546
547
548
* a non-zero value.
*/
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
May 25, 2002
May 25, 2002
549
Mar 24, 2002
Mar 24, 2002
550
551
552
553
554
555
556
/*
* 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.
*
Nov 30, 2012
Nov 30, 2012
557
* On error, call PHYSFS_setErrorCode() and return -1. On success, return >= 0.
Mar 24, 2002
Mar 24, 2002
558
559
560
*/
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
May 25, 2002
May 25, 2002
561
Mar 24, 2002
Mar 24, 2002
562
563
564
565
566
567
/*
* 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.
*
Nov 30, 2012
Nov 30, 2012
568
* Return -1 if you can't do it, and call PHYSFS_setErrorCode(). Otherwise,
Mar 24, 2002
Mar 24, 2002
569
570
571
572
* return the file length in 8-bit bytes.
*/
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
Feb 15, 2010
Feb 15, 2010
573
574
/*
Aug 6, 2017
Aug 6, 2017
575
* !!! FIXME-3.0: comment me.
Feb 15, 2010
Feb 15, 2010
576
*/
Nov 30, 2012
Nov 30, 2012
577
int __PHYSFS_platformStat(const char *fn, PHYSFS_Stat *stat);
Feb 15, 2010
Feb 15, 2010
578
Mar 24, 2002
Mar 24, 2002
579
580
581
582
583
584
585
586
587
588
/*
* 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
589
590
591
* 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
592
*
Aug 30, 2010
Aug 30, 2010
593
594
* You should clean up all resources associated with (opaque); the pointer
* will be considered invalid after this call.
Mar 24, 2002
Mar 24, 2002
595
*/
Aug 30, 2010
Aug 30, 2010
596
void __PHYSFS_platformClose(void *opaque);
Mar 24, 2002
Mar 24, 2002
597
Jul 6, 2001
Jul 6, 2001
598
/*
Sep 29, 2004
Sep 29, 2004
599
600
601
602
603
* 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
604
*/
Sep 29, 2004
Sep 29, 2004
605
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data);
Jul 6, 2001
Jul 6, 2001
606
607
608
609
610
/*
* 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 23, 2012
Mar 23, 2012
611
* Your string must end with a dir separator if you don't return NULL.
Mar 11, 2012
Mar 11, 2012
612
* Caller will allocator.Free() the retval if it's not NULL.
Jul 6, 2001
Jul 6, 2001
613
*/
Jul 8, 2001
Jul 8, 2001
614
char *__PHYSFS_platformCalcBaseDir(const char *argv0);
Jul 6, 2001
Jul 6, 2001
615
Mar 22, 2012
Mar 22, 2012
616
/*
Jul 6, 2001
Jul 6, 2001
617
* Get the platform-specific user dir.
Mar 24, 2012
Mar 24, 2012
618
619
620
* As of PhysicsFS 2.1, returning NULL means fatal error.
* Your string must end with a dir separator if you don't return NULL.
* Caller will allocator.Free() the retval if it's not NULL.
Jul 6, 2001
Jul 6, 2001
621
*/
Mar 22, 2012
Mar 22, 2012
622
char *__PHYSFS_platformCalcUserDir(void);
Jul 6, 2001
Jul 6, 2001
623
Mar 22, 2012
Mar 22, 2012
624
625
626
627
/* This is the cached version from PHYSFS_init(). This is a fast call. */
const char *__PHYSFS_getUserDir(void); /* not deprecated internal version. */
Mar 24, 2012
Mar 24, 2012
628
Mar 22, 2012
Mar 22, 2012
629
/*
Mar 24, 2012
Mar 24, 2012
630
631
632
633
634
635
* Get the platform-specific pref dir.
* Returning NULL means fatal error.
* Your string must end with a dir separator if you don't return NULL.
* Caller will allocator.Free() the retval if it's not NULL.
* Caller will make missing directories if necessary; this just reports
* the final path.
Mar 22, 2012
Mar 22, 2012
636
637
638
639
*/
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app);
Jul 6, 2001
Jul 6, 2001
640
/*
Sep 6, 2009
Sep 6, 2009
641
642
* 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
643
* arbitrary; the only requirement is that no two threads have the same
Sep 6, 2009
Sep 6, 2009
644
* pointer.
Jul 6, 2001
Jul 6, 2001
645
*/
Sep 6, 2009
Sep 6, 2009
646
void *__PHYSFS_platformGetThreadID(void);
Jul 6, 2001
Jul 6, 2001
647
May 25, 2002
May 25, 2002
648
Jul 8, 2001
Jul 8, 2001
649
650
/*
* Enumerate a directory of files. This follows the rules for the
Feb 25, 2016
Feb 25, 2016
651
* PHYSFS_Archiver::enumerateFiles() method, except that the
Jul 8, 2001
Jul 8, 2001
652
* (dirName) that is passed to this function is converted to
Sep 26, 2004
Sep 26, 2004
653
* platform-DEPENDENT notation by the caller. The PHYSFS_Archiver version
Jul 16, 2001
Jul 16, 2001
654
* uses platform-independent notation. Note that ".", "..", and other
Nov 29, 2012
Nov 29, 2012
655
* meta-entries should always be ignored.
Jul 8, 2001
Jul 8, 2001
656
*/
Sep 29, 2004
Sep 29, 2004
657
void __PHYSFS_platformEnumerateFiles(const char *dirname,
Sep 18, 2005
Sep 18, 2005
658
659
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
660
void *callbackdata);
Jul 8, 2001
Jul 8, 2001
661
Aug 23, 2001
Aug 23, 2001
662
663
664
665
666
667
668
/*
* 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
669
Mar 25, 2002
Mar 25, 2002
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/*
* 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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
/*
* 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
711
*
Nov 30, 2012
Nov 30, 2012
712
* _DO NOT_ call PHYSFS_setErrorCode() in here! Since setErrorCode calls this
Apr 2, 2002
Apr 2, 2002
713
714
* function, you'll cause an infinite recursion. This means you can't
* use the BAIL_*MACRO* macros, either.
Mar 30, 2002
Mar 30, 2002
715
716
717
718
719
720
721
722
*/
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
723
*
Nov 30, 2012
Nov 30, 2012
724
* _DO NOT_ call PHYSFS_setErrorCode() in here! Since setErrorCode calls this
Apr 2, 2002
Apr 2, 2002
725
726
* function, you'll cause an infinite recursion. This means you can't
* use the BAIL_*MACRO* macros, either.
Mar 30, 2002
Mar 30, 2002
727
728
729
*/
void __PHYSFS_platformReleaseMutex(void *mutex);
Jul 12, 2017
Jul 12, 2017
730
731
732
733
#if PHYSFS_HAVE_PRAGMA_VISIBILITY
#pragma GCC visibility pop
#endif
Jul 6, 2001
Jul 6, 2001
734
#ifdef __cplusplus
Mar 24, 2002
Mar 24, 2002
735
}
Jul 6, 2001
Jul 6, 2001
736
737
738
739
740
#endif
#endif
/* end of physfs_internal.h ... */