physfs_internal.h 23 KB

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