physfs_internal.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * Internal function/structure declaration. Do NOT include in your
  3. * application.
  4. *
  5. * Please see the file LICENSE.txt in the source's root directory.
  6. *
  7. * This file written by Ryan C. Gordon.
  8. */
  9. #ifndef _INCLUDE_PHYSFS_INTERNAL_H_
  10. #define _INCLUDE_PHYSFS_INTERNAL_H_
  11. #ifndef __PHYSICSFS_INTERNAL__
  12. #error Do not include this header from your applications.
  13. #endif
  14. #include "physfs.h"
  15. /* The holy trinity. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "physfs_platforms.h"
  20. #include <assert.h>
  21. /* !!! FIXME: remove this when revamping stack allocation code... */
  22. #if defined(_MSC_VER) || defined(__MINGW32__)
  23. #include <malloc.h>
  24. #endif
  25. #if PHYSFS_PLATFORM_SOLARIS
  26. #include <alloca.h>
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #ifdef __GNUC__
  32. #define PHYSFS_MINIMUM_GCC_VERSION(major, minor) \
  33. ( ((__GNUC__ << 16) + __GNUC_MINOR__) >= (((major) << 16) + (minor)) )
  34. #else
  35. #define PHYSFS_MINIMUM_GCC_VERSION(major, minor) (0)
  36. #endif
  37. #ifdef __cplusplus
  38. /* C++ always has a real inline keyword. */
  39. #elif (defined macintosh) && !(defined __MWERKS__)
  40. # define inline
  41. #elif (defined _MSC_VER)
  42. # define inline __inline
  43. #endif
  44. #if PHYSFS_PLATFORM_LINUX && !defined(_FILE_OFFSET_BITS)
  45. #define _FILE_OFFSET_BITS 64
  46. #endif
  47. /*
  48. * Interface for small allocations. If you need a little scratch space for
  49. * a throwaway buffer or string, use this. It will make small allocations
  50. * on the stack if possible, and use allocator.Malloc() if they are too
  51. * large. This helps reduce malloc pressure.
  52. * There are some rules, though:
  53. * NEVER return a pointer from this, as stack-allocated buffers go away
  54. * when your function returns.
  55. * NEVER allocate in a loop, as stack-allocated pointers will pile up. Call
  56. * a function that uses smallAlloc from your loop, so the allocation can
  57. * free each time.
  58. * NEVER call smallAlloc with any complex expression (it's a macro that WILL
  59. * have side effects...it references the argument multiple times). Use a
  60. * variable or a literal.
  61. * NEVER free a pointer from this with anything but smallFree. It will not
  62. * be a valid pointer to the allocator, regardless of where the memory came
  63. * from.
  64. * NEVER realloc a pointer from this.
  65. * NEVER forget to use smallFree: it may not be a pointer from the stack.
  66. * NEVER forget to check for NULL...allocation can fail here, of course!
  67. */
  68. #define __PHYSFS_SMALLALLOCTHRESHOLD 256
  69. void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len);
  70. #define __PHYSFS_smallAlloc(bytes) ( \
  71. __PHYSFS_initSmallAlloc( \
  72. (((bytes) < __PHYSFS_SMALLALLOCTHRESHOLD) ? \
  73. alloca((size_t)((bytes)+sizeof(void*))) : NULL), (bytes)) \
  74. )
  75. void __PHYSFS_smallFree(void *ptr);
  76. /* Use the allocation hooks. */
  77. #define malloc(x) Do not use malloc() directly.
  78. #define realloc(x, y) Do not use realloc() directly.
  79. #define free(x) Do not use free() directly.
  80. /* !!! FIXME: add alloca check here. */
  81. #ifndef PHYSFS_SUPPORTS_ZIP
  82. #define PHYSFS_SUPPORTS_ZIP 1
  83. #endif
  84. #ifndef PHYSFS_SUPPORTS_7Z
  85. #define PHYSFS_SUPPORTS_7Z 0
  86. #endif
  87. #ifndef PHYSFS_SUPPORTS_GRP
  88. #define PHYSFS_SUPPORTS_GRP 0
  89. #endif
  90. #ifndef PHYSFS_SUPPORTS_HOG
  91. #define PHYSFS_SUPPORTS_HOG 0
  92. #endif
  93. #ifndef PHYSFS_SUPPORTS_MVL
  94. #define PHYSFS_SUPPORTS_MVL 0
  95. #endif
  96. #ifndef PHYSFS_SUPPORTS_WAD
  97. #define PHYSFS_SUPPORTS_WAD 0
  98. #endif
  99. #ifndef PHYSFS_SUPPORTS_SLB
  100. #define PHYSFS_SUPPORTS_SLB 0
  101. #endif
  102. #ifndef PHYSFS_SUPPORTS_ISO9660
  103. #define PHYSFS_SUPPORTS_ISO9660 0
  104. #endif
  105. /* The latest supported PHYSFS_Io::version value. */
  106. #define CURRENT_PHYSFS_IO_API_VERSION 0
  107. /* The latest supported PHYSFS_Archiver::version value. */
  108. #define CURRENT_PHYSFS_ARCHIVER_API_VERSION 0
  109. /* !!! FIXME: update this documentation.
  110. * Call this to set the message returned by PHYSFS_getLastError().
  111. * Please only use the ERR_* constants above, or add new constants to the
  112. * above group, but I want these all in one place.
  113. *
  114. * Calling this with a NULL argument is a safe no-op.
  115. */
  116. void __PHYSFS_setError(const PHYSFS_ErrorCode err);
  117. /* This byteorder stuff was lifted from SDL. http://www.libsdl.org/ */
  118. #define PHYSFS_LIL_ENDIAN 1234
  119. #define PHYSFS_BIG_ENDIAN 4321
  120. #if defined(__i386__) || defined(__ia64__) || \
  121. defined(_M_IX86) || defined(_M_IA64) || defined(_M_X64) || \
  122. (defined(__alpha__) || defined(__alpha)) || \
  123. defined(__arm__) || defined(ARM) || \
  124. (defined(__mips__) && defined(__MIPSEL__)) || \
  125. defined(__SYMBIAN32__) || \
  126. defined(__x86_64__) || \
  127. defined(__LITTLE_ENDIAN__)
  128. #define PHYSFS_BYTEORDER PHYSFS_LIL_ENDIAN
  129. #else
  130. #define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN
  131. #endif
  132. /*
  133. * When sorting the entries in an archive, we use a modified QuickSort.
  134. * When there are less then PHYSFS_QUICKSORT_THRESHOLD entries left to sort,
  135. * we switch over to a BubbleSort for the remainder. Tweak to taste.
  136. *
  137. * You can override this setting by defining PHYSFS_QUICKSORT_THRESHOLD
  138. * before #including "physfs_internal.h".
  139. */
  140. #ifndef PHYSFS_QUICKSORT_THRESHOLD
  141. #define PHYSFS_QUICKSORT_THRESHOLD 4
  142. #endif
  143. /*
  144. * Sort an array (or whatever) of (max) elements. This uses a mixture of
  145. * a QuickSort and BubbleSort internally.
  146. * (cmpfn) is used to determine ordering, and (swapfn) does the actual
  147. * swapping of elements in the list.
  148. *
  149. * See zip.c for an example.
  150. */
  151. void __PHYSFS_sort(void *entries, size_t max,
  152. int (*cmpfn)(void *, size_t, size_t),
  153. void (*swapfn)(void *, size_t, size_t));
  154. /*
  155. * This isn't a formal error code, it's just for BAIL_MACRO.
  156. * It means: there was an error, but someone else already set it for us.
  157. */
  158. #define ERRPASS PHYSFS_ERR_OK
  159. /* These get used all over for lessening code clutter. */
  160. #define BAIL_MACRO(e, r) do { if (e) __PHYSFS_setError(e); return r; } while (0)
  161. #define BAIL_IF_MACRO(c, e, r) do { if (c) { if (e) __PHYSFS_setError(e); return r; } } while (0)
  162. #define BAIL_MACRO_MUTEX(e, m, r) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0)
  163. #define BAIL_IF_MACRO_MUTEX(c, e, m, r) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0)
  164. #define GOTO_MACRO(e, g) do { if (e) __PHYSFS_setError(e); goto g; } while (0)
  165. #define GOTO_IF_MACRO(c, e, g) do { if (c) { if (e) __PHYSFS_setError(e); goto g; } } while (0)
  166. #define GOTO_MACRO_MUTEX(e, m, g) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0)
  167. #define GOTO_IF_MACRO_MUTEX(c, e, m, g) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0)
  168. #define __PHYSFS_ARRAYLEN(x) ( (sizeof (x)) / (sizeof (x[0])) )
  169. #ifdef PHYSFS_NO_64BIT_SUPPORT
  170. #define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x))
  171. #define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x))
  172. #elif (defined __GNUC__)
  173. #define __PHYSFS_SI64(x) x##LL
  174. #define __PHYSFS_UI64(x) x##ULL
  175. #elif (defined _MSC_VER)
  176. #define __PHYSFS_SI64(x) x##i64
  177. #define __PHYSFS_UI64(x) x##ui64
  178. #else
  179. #define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x))
  180. #define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x))
  181. #endif
  182. /*
  183. * Check if a ui64 will fit in the platform's address space.
  184. * The initial sizeof check will optimize this macro out entirely on
  185. * 64-bit (and larger?!) platforms, and the other condition will
  186. * return zero or non-zero if the variable will fit in the platform's
  187. * size_t, suitable to pass to malloc. This is kinda messy, but effective.
  188. */
  189. #define __PHYSFS_ui64FitsAddressSpace(s) ( \
  190. (sizeof (PHYSFS_uint64) <= sizeof (size_t)) || \
  191. ((s) < (__PHYSFS_UI64(0xFFFFFFFFFFFFFFFF) >> (64-(sizeof(size_t)*8)))) \
  192. )
  193. /*
  194. * This is a strcasecmp() or stricmp() replacement that expects both strings
  195. * to be in UTF-8 encoding. It will do "case folding" to decide if the
  196. * Unicode codepoints in the strings match.
  197. *
  198. * It will report which string is "greater than" the other, but be aware that
  199. * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but
  200. * a random Kanji codepoint has no meaningful alphabetically relationship to
  201. * a Greek Lambda, but being able to assign a reliable "value" makes sorting
  202. * algorithms possible, if not entirely sane. Most cases should treat the
  203. * return value as "equal" or "not equal".
  204. */
  205. int __PHYSFS_utf8stricmp(const char *s1, const char *s2);
  206. /*
  207. * This works like __PHYSFS_utf8stricmp(), but takes a character (NOT BYTE
  208. * COUNT) argument, like strcasencmp().
  209. */
  210. int __PHYSFS_utf8strnicmp(const char *s1, const char *s2, PHYSFS_uint32 l);
  211. /*
  212. * stricmp() that guarantees to only work with low ASCII. The C runtime
  213. * stricmp() might try to apply a locale/codepage/etc, which we don't want.
  214. */
  215. int __PHYSFS_stricmpASCII(const char *s1, const char *s2);
  216. /*
  217. * strnicmp() that guarantees to only work with low ASCII. The C runtime
  218. * strnicmp() might try to apply a locale/codepage/etc, which we don't want.
  219. */
  220. int __PHYSFS_strnicmpASCII(const char *s1, const char *s2, PHYSFS_uint32 l);
  221. /*
  222. * The current allocator. Not valid before PHYSFS_init is called!
  223. */
  224. extern PHYSFS_Allocator __PHYSFS_AllocatorHooks;
  225. /* convenience macro to make this less cumbersome internally... */
  226. #define allocator __PHYSFS_AllocatorHooks
  227. /*
  228. * Create a PHYSFS_Io for a file in the physical filesystem.
  229. * This path is in platform-dependent notation. (mode) must be 'r', 'w', or
  230. * 'a' for Read, Write, or Append.
  231. */
  232. PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode);
  233. /*
  234. * Create a PHYSFS_Io for a buffer of memory (READ-ONLY). If you already
  235. * have one of these, just use its duplicate() method, and it'll increment
  236. * its refcount without allocating a copy of the buffer.
  237. */
  238. PHYSFS_Io *__PHYSFS_createMemoryIo(const void *buf, PHYSFS_uint64 len,
  239. void (*destruct)(void *));
  240. /*
  241. * Read (len) bytes from (io) into (buf). Returns non-zero on success,
  242. * zero on i/o error. Literally: "return (io->read(io, buf, len) == len);"
  243. */
  244. int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len);
  245. /* These are shared between some archivers. */
  246. typedef struct
  247. {
  248. char name[64];
  249. PHYSFS_uint32 startPos;
  250. PHYSFS_uint32 size;
  251. } UNPKentry;
  252. void UNPK_closeArchive(void *opaque);
  253. void *UNPK_openArchive(PHYSFS_Io *io,UNPKentry *e,const PHYSFS_uint32 n);
  254. void UNPK_enumerateFiles(void *opaque, const char *dname,
  255. PHYSFS_EnumFilesCallback cb,
  256. const char *origdir, void *callbackdata);
  257. PHYSFS_Io *UNPK_openRead(void *opaque, const char *fnm, int *fileExists);
  258. PHYSFS_Io *UNPK_openWrite(void *opaque, const char *name);
  259. PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name);
  260. int UNPK_remove(void *opaque, const char *name);
  261. int UNPK_mkdir(void *opaque, const char *name);
  262. int UNPK_stat(void *opaque, const char *fn, int *exist, PHYSFS_Stat *st);
  263. /*--------------------------------------------------------------------------*/
  264. /*--------------------------------------------------------------------------*/
  265. /*------------ ----------------*/
  266. /*------------ You MUST implement the following functions ----------------*/
  267. /*------------ if porting to a new platform. ----------------*/
  268. /*------------ (see platform/unix.c for an example) ----------------*/
  269. /*------------ ----------------*/
  270. /*--------------------------------------------------------------------------*/
  271. /*--------------------------------------------------------------------------*/
  272. /*
  273. * The dir separator; '/' on unix, '\\' on win32, ":" on MacOS, etc...
  274. * Obviously, this isn't a function. If you need more than one char for this,
  275. * you'll need to pull some old pieces of PhysicsFS out of revision control.
  276. */
  277. #if PHYSFS_PLATFORM_WINDOWS
  278. #define __PHYSFS_platformDirSeparator '\\'
  279. #else
  280. #define __PHYSFS_platformDirSeparator '/'
  281. #endif
  282. /*
  283. * Initialize the platform. This is called when PHYSFS_init() is called from
  284. * the application.
  285. *
  286. * Return zero if there was a catastrophic failure (which prevents you from
  287. * functioning at all), and non-zero otherwise.
  288. */
  289. int __PHYSFS_platformInit(void);
  290. /*
  291. * Deinitialize the platform. This is called when PHYSFS_deinit() is called
  292. * from the application. You can use this to clean up anything you've
  293. * allocated in your platform driver.
  294. *
  295. * Return zero if there was a catastrophic failure (which prevents you from
  296. * functioning at all), and non-zero otherwise.
  297. */
  298. int __PHYSFS_platformDeinit(void);
  299. /*
  300. * Open a file for reading. (filename) is in platform-dependent notation. The
  301. * file pointer should be positioned on the first byte of the file.
  302. *
  303. * The return value will be some platform-specific datatype that is opaque to
  304. * the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32.
  305. *
  306. * The same file can be opened for read multiple times, and each should have
  307. * a unique file handle; this is frequently employed to prevent race
  308. * conditions in the archivers.
  309. *
  310. * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
  311. */
  312. void *__PHYSFS_platformOpenRead(const char *filename);
  313. /*
  314. * Open a file for writing. (filename) is in platform-dependent notation. If
  315. * the file exists, it should be truncated to zero bytes, and if it doesn't
  316. * exist, it should be created as a zero-byte file. The file pointer should
  317. * be positioned on the first byte of the file.
  318. *
  319. * The return value will be some platform-specific datatype that is opaque to
  320. * the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32,
  321. * etc.
  322. *
  323. * Opening a file for write multiple times has undefined results.
  324. *
  325. * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
  326. */
  327. void *__PHYSFS_platformOpenWrite(const char *filename);
  328. /*
  329. * Open a file for appending. (filename) is in platform-dependent notation. If
  330. * the file exists, the file pointer should be place just past the end of the
  331. * file, so that the first write will be one byte after the current end of
  332. * the file. If the file doesn't exist, it should be created as a zero-byte
  333. * file. The file pointer should be positioned on the first byte of the file.
  334. *
  335. * The return value will be some platform-specific datatype that is opaque to
  336. * the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32,
  337. * etc.
  338. *
  339. * Opening a file for append multiple times has undefined results.
  340. *
  341. * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
  342. */
  343. void *__PHYSFS_platformOpenAppend(const char *filename);
  344. /*
  345. * Read more data from a platform-specific file handle. (opaque) should be
  346. * cast to whatever data type your platform uses. Read a maximum of (len)
  347. * 8-bit bytes to the area pointed to by (buf). If there isn't enough data
  348. * available, return the number of bytes read, and position the file pointer
  349. * immediately after those bytes.
  350. * On success, return (len) and position the file pointer immediately past
  351. * the end of the last read byte. Return (-1) if there is a catastrophic
  352. * error, and call __PHYSFS_setError() to describe the problem; the file
  353. * pointer should not move in such a case. A partial read is success; only
  354. * return (-1) on total failure; presumably, the next read call after a
  355. * partial read will fail as such.
  356. */
  357. PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len);
  358. /*
  359. * Write more data to a platform-specific file handle. (opaque) should be
  360. * cast to whatever data type your platform uses. Write a maximum of (len)
  361. * 8-bit bytes from the area pointed to by (buffer). If there is a problem,
  362. * return the number of bytes written, and position the file pointer
  363. * immediately after those bytes. Return (-1) if there is a catastrophic
  364. * error, and call __PHYSFS_setError() to describe the problem; the file
  365. * pointer should not move in such a case. A partial write is success; only
  366. * return (-1) on total failure; presumably, the next write call after a
  367. * partial write will fail as such.
  368. */
  369. PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
  370. PHYSFS_uint64 len);
  371. /*
  372. * Set the file pointer to a new position. (opaque) should be cast to
  373. * whatever data type your platform uses. (pos) specifies the number
  374. * of 8-bit bytes to seek to from the start of the file. Seeking past the
  375. * end of the file is an error condition, and you should check for it.
  376. *
  377. * Not all file types can seek; this is to be expected by the caller.
  378. *
  379. * On error, call __PHYSFS_setError() and return zero. On success, return
  380. * a non-zero value.
  381. */
  382. int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
  383. /*
  384. * Get the file pointer's position, in an 8-bit byte offset from the start of
  385. * the file. (opaque) should be cast to whatever data type your platform
  386. * uses.
  387. *
  388. * Not all file types can "tell"; this is to be expected by the caller.
  389. *
  390. * On error, call __PHYSFS_setError() and return -1. On success, return >= 0.
  391. */
  392. PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
  393. /*
  394. * Determine the current size of a file, in 8-bit bytes, from an open file.
  395. *
  396. * The caller expects that this information may not be available for all
  397. * file types on all platforms.
  398. *
  399. * Return -1 if you can't do it, and call __PHYSFS_setError(). Otherwise,
  400. * return the file length in 8-bit bytes.
  401. */
  402. PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
  403. /*
  404. * !!! FIXME: comment me.
  405. */
  406. int __PHYSFS_platformStat(const char *fn, int *exists, PHYSFS_Stat *stat);
  407. /*
  408. * Flush any pending writes to disk. (opaque) should be cast to whatever data
  409. * type your platform uses. Be sure to check for errors; the caller expects
  410. * that this function can fail if there was a flushing error, etc.
  411. *
  412. * Return zero on failure, non-zero on success.
  413. */
  414. int __PHYSFS_platformFlush(void *opaque);
  415. /*
  416. * Close file and deallocate resources. (opaque) should be cast to whatever
  417. * data type your platform uses. This should close the file in any scenario:
  418. * flushing is a separate function call, and this function should never fail.
  419. *
  420. * You should clean up all resources associated with (opaque); the pointer
  421. * will be considered invalid after this call.
  422. */
  423. void __PHYSFS_platformClose(void *opaque);
  424. /*
  425. * Platform implementation of PHYSFS_getCdRomDirsCallback()...
  426. * CD directories are discovered and reported to the callback one at a time.
  427. * Pointers passed to the callback are assumed to be invalid to the
  428. * application after the callback returns, so you can free them or whatever.
  429. * Callback does not assume results will be sorted in any meaningful way.
  430. */
  431. void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data);
  432. /*
  433. * Calculate the base dir, if your platform needs special consideration.
  434. * Just return NULL if the standard routines will suffice. (see
  435. * calculateBaseDir() in physfs.c ...)
  436. * Your string must end with a dir separator if you don't return NULL.
  437. * Caller will allocator.Free() the retval if it's not NULL.
  438. */
  439. char *__PHYSFS_platformCalcBaseDir(const char *argv0);
  440. /*
  441. * Get the platform-specific user dir.
  442. * As of PhysicsFS 2.1, returning NULL means fatal error.
  443. * Your string must end with a dir separator if you don't return NULL.
  444. * Caller will allocator.Free() the retval if it's not NULL.
  445. */
  446. char *__PHYSFS_platformCalcUserDir(void);
  447. /* This is the cached version from PHYSFS_init(). This is a fast call. */
  448. const char *__PHYSFS_getUserDir(void); /* not deprecated internal version. */
  449. /*
  450. * Get the platform-specific pref dir.
  451. * Returning NULL means fatal error.
  452. * Your string must end with a dir separator if you don't return NULL.
  453. * Caller will allocator.Free() the retval if it's not NULL.
  454. * Caller will make missing directories if necessary; this just reports
  455. * the final path.
  456. */
  457. char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app);
  458. /*
  459. * Return a pointer that uniquely identifies the current thread.
  460. * On a platform without threading, (0x1) will suffice. These numbers are
  461. * arbitrary; the only requirement is that no two threads have the same
  462. * pointer.
  463. */
  464. void *__PHYSFS_platformGetThreadID(void);
  465. /*
  466. * Enumerate a directory of files. This follows the rules for the
  467. * PHYSFS_Archiver::enumerateFiles() method (see above), except that the
  468. * (dirName) that is passed to this function is converted to
  469. * platform-DEPENDENT notation by the caller. The PHYSFS_Archiver version
  470. * uses platform-independent notation. Note that ".", "..", and other
  471. * meta-entries should always be ignored.
  472. */
  473. void __PHYSFS_platformEnumerateFiles(const char *dirname,
  474. PHYSFS_EnumFilesCallback callback,
  475. const char *origdir,
  476. void *callbackdata);
  477. /*
  478. * Make a directory in the actual filesystem. (path) is specified in
  479. * platform-dependent notation. On error, return zero and set the error
  480. * message. Return non-zero on success.
  481. */
  482. int __PHYSFS_platformMkDir(const char *path);
  483. /*
  484. * Remove a file or directory entry in the actual filesystem. (path) is
  485. * specified in platform-dependent notation. Note that this deletes files
  486. * _and_ directories, so you might need to do some determination.
  487. * Non-empty directories should report an error and not delete themselves
  488. * or their contents.
  489. *
  490. * Deleting a symlink should remove the link, not what it points to.
  491. *
  492. * On error, return zero and set the error message. Return non-zero on success.
  493. */
  494. int __PHYSFS_platformDelete(const char *path);
  495. /*
  496. * Create a platform-specific mutex. This can be whatever datatype your
  497. * platform uses for mutexes, but it is cast to a (void *) for abstractness.
  498. *
  499. * Return (NULL) if you couldn't create one. Systems without threads can
  500. * return any arbitrary non-NULL value.
  501. */
  502. void *__PHYSFS_platformCreateMutex(void);
  503. /*
  504. * Destroy a platform-specific mutex, and clean up any resources associated
  505. * with it. (mutex) is a value previously returned by
  506. * __PHYSFS_platformCreateMutex(). This can be a no-op on single-threaded
  507. * platforms.
  508. */
  509. void __PHYSFS_platformDestroyMutex(void *mutex);
  510. /*
  511. * Grab possession of a platform-specific mutex. Mutexes should be recursive;
  512. * that is, the same thread should be able to call this function multiple
  513. * times in a row without causing a deadlock. This function should block
  514. * until a thread can gain possession of the mutex.
  515. *
  516. * Return non-zero if the mutex was grabbed, zero if there was an
  517. * unrecoverable problem grabbing it (this should not be a matter of
  518. * timing out! We're talking major system errors; block until the mutex
  519. * is available otherwise.)
  520. *
  521. * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
  522. * function, you'll cause an infinite recursion. This means you can't
  523. * use the BAIL_*MACRO* macros, either.
  524. */
  525. int __PHYSFS_platformGrabMutex(void *mutex);
  526. /*
  527. * Relinquish possession of the mutex when this method has been called
  528. * once for each time that platformGrabMutex was called. Once possession has
  529. * been released, the next thread in line to grab the mutex (if any) may
  530. * proceed.
  531. *
  532. * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
  533. * function, you'll cause an infinite recursion. This means you can't
  534. * use the BAIL_*MACRO* macros, either.
  535. */
  536. void __PHYSFS_platformReleaseMutex(void *mutex);
  537. /*
  538. * Called at the start of PHYSFS_init() to prepare the allocator, if the user
  539. * hasn't selected their own allocator via PHYSFS_setAllocator().
  540. * If the platform has a custom allocator, it should fill in the fields of
  541. * (a) with the proper function pointers and return non-zero.
  542. * If the platform just wants to use malloc()/free()/etc, return zero
  543. * immediately and the higher level will handle it. The Init and Deinit
  544. * fields of (a) are optional...set them to NULL if you don't need them.
  545. * Everything else must be implemented. All rules follow those for
  546. * PHYSFS_setAllocator(). If Init isn't NULL, it will be called shortly
  547. * after this function returns non-zero.
  548. */
  549. int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a);
  550. #ifdef __cplusplus
  551. }
  552. #endif
  553. #endif
  554. /* end of physfs_internal.h ... */