physfs_internal.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. * Internal function/structure declaration. Do NOT include in your
  3. * application.
  4. *
  5. * Please see the file LICENSE 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. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. struct __PHYSFS_DIRHANDLE__;
  19. struct __PHYSFS_FILEFUNCTIONS__;
  20. typedef struct __PHYSFS_LINKEDSTRINGLIST__
  21. {
  22. char *str;
  23. struct __PHYSFS_LINKEDSTRINGLIST__ *next;
  24. } LinkedStringList;
  25. typedef struct __PHYSFS_FILEHANDLE__
  26. {
  27. /*
  28. * This is reserved for the driver to store information.
  29. */
  30. void *opaque;
  31. /*
  32. * This should be the DirHandle that created this FileHandle.
  33. */
  34. const struct __PHYSFS_DIRHANDLE__ *dirHandle;
  35. /*
  36. * Pointer to the file i/o functions for this filehandle.
  37. */
  38. const struct __PHYSFS_FILEFUNCTIONS__ *funcs;
  39. } FileHandle;
  40. typedef struct __PHYSFS_FILEFUNCTIONS__
  41. {
  42. /*
  43. * Read more from the file.
  44. * Returns number of objects of (objSize) bytes read from file, -1
  45. * if complete failure.
  46. * On failure, call __PHYSFS_setError().
  47. */
  48. PHYSFS_sint64 (*read)(FileHandle *handle, void *buffer,
  49. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  50. /*
  51. * Write more to the file. Archives don't have to implement this.
  52. * (Set it to NULL if not implemented).
  53. * Returns number of objects of (objSize) bytes written to file, -1
  54. * if complete failure.
  55. * On failure, call __PHYSFS_setError().
  56. */
  57. PHYSFS_sint64 (*write)(FileHandle *handle, const void *buffer,
  58. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  59. /*
  60. * Returns non-zero if at end of file.
  61. */
  62. int (*eof)(FileHandle *handle);
  63. /*
  64. * Returns byte offset from start of file.
  65. */
  66. PHYSFS_sint64 (*tell)(FileHandle *handle);
  67. /*
  68. * Move read/write pointer to byte offset from start of file.
  69. * Returns non-zero on success, zero on error.
  70. * On failure, call __PHYSFS_setError().
  71. */
  72. int (*seek)(FileHandle *handle, PHYSFS_uint64 offset);
  73. /*
  74. * Return number of bytes available in the file, or -1 if you
  75. * aren't able to determine.
  76. * On failure, call __PHYSFS_setError().
  77. */
  78. PHYSFS_sint64 (*fileLength)(FileHandle *handle);
  79. /*
  80. * Close the file, and free the FileHandle structure (including "opaque").
  81. * returns non-zero on success, zero if can't close file.
  82. * On failure, call __PHYSFS_setError().
  83. */
  84. int (*fileClose)(FileHandle *handle);
  85. } FileFunctions;
  86. typedef struct __PHYSFS_DIRHANDLE__
  87. {
  88. /*
  89. * This is reserved for the driver to store information.
  90. */
  91. void *opaque;
  92. /*
  93. * Pointer to the directory i/o functions for this handle.
  94. */
  95. const struct __PHYSFS_DIRFUNCTIONS__ *funcs;
  96. } DirHandle;
  97. /*
  98. * Symlinks should always be followed; PhysicsFS will use
  99. * DirFunctions->isSymLink() and make a judgement on whether to
  100. * continue to call other methods based on that.
  101. */
  102. typedef struct __PHYSFS_DIRFUNCTIONS__
  103. {
  104. const PHYSFS_ArchiveInfo *info;
  105. /*
  106. * Returns non-zero if (filename) is a valid archive that this
  107. * driver can handle. This filename is in platform-dependent
  108. * notation. forWriting is non-zero if this is to be used for
  109. * the write directory, and zero if this is to be used for an
  110. * element of the search path.
  111. */
  112. int (*isArchive)(const char *filename, int forWriting);
  113. /*
  114. * Return a DirHandle for dir/archive (name).
  115. * This filename is in platform-dependent notation.
  116. * forWriting is non-zero if this is to be used for
  117. * the write directory, and zero if this is to be used for an
  118. * element of the search path.
  119. * Returns NULL on failure, and calls __PHYSFS_setError().
  120. */
  121. DirHandle *(*openArchive)(const char *name, int forWriting);
  122. /*
  123. * Returns a list of all files in dirname. Each element of this list
  124. * (and its "str" field) will be deallocated with the system's free()
  125. * function by the caller, so be sure to explicitly malloc() each
  126. * chunk. Omit symlinks if (omitSymLinks) is non-zero.
  127. * If you have a memory failure, return as much as you can.
  128. * This dirname is in platform-independent notation.
  129. */
  130. LinkedStringList *(*enumerateFiles)(DirHandle *r,
  131. const char *dirname,
  132. int omitSymLinks);
  133. /*
  134. * Returns non-zero if filename can be opened for reading.
  135. * This filename is in platform-independent notation.
  136. */
  137. int (*exists)(DirHandle *r, const char *name);
  138. /*
  139. * Returns non-zero if filename is really a directory.
  140. * This filename is in platform-independent notation.
  141. * Symlinks should be followed; if what the symlink points
  142. * to is missing, or isn't a directory, then the retval is zero.
  143. */
  144. int (*isDirectory)(DirHandle *r, const char *name);
  145. /*
  146. * Returns non-zero if filename is really a symlink.
  147. * This filename is in platform-independent notation.
  148. */
  149. int (*isSymLink)(DirHandle *r, const char *name);
  150. /*
  151. * Retrieve the last modification time (mtime) of a file.
  152. * Returns -1 on failure, or the file's mtime in seconds since
  153. * the epoch (Jan 1, 1970) on success.
  154. * This filename is in platform-independent notation.
  155. */
  156. PHYSFS_sint64 (*getLastModTime)(DirHandle *r, const char *filename);
  157. /*
  158. * Open file for reading, and return a FileHandle.
  159. * This filename is in platform-independent notation.
  160. * If you can't handle multiple opens of the same file,
  161. * you can opt to fail for the second call.
  162. * Fail if the file does not exist.
  163. * Returns NULL on failure, and calls __PHYSFS_setError().
  164. */
  165. FileHandle *(*openRead)(DirHandle *r, const char *filename);
  166. /*
  167. * Open file for writing, and return a FileHandle.
  168. * If the file does not exist, it should be created. If it exists,
  169. * it should be truncated to zero bytes. The writing
  170. * offset should be the start of the file.
  171. * This filename is in platform-independent notation.
  172. * This method may be NULL.
  173. * If you can't handle multiple opens of the same file,
  174. * you can opt to fail for the second call.
  175. * Returns NULL on failure, and calls __PHYSFS_setError().
  176. */
  177. FileHandle *(*openWrite)(DirHandle *r, const char *filename);
  178. /*
  179. * Open file for appending, and return a FileHandle.
  180. * If the file does not exist, it should be created. The writing
  181. * offset should be the end of the file.
  182. * This filename is in platform-independent notation.
  183. * This method may be NULL.
  184. * If you can't handle multiple opens of the same file,
  185. * you can opt to fail for the second call.
  186. * Returns NULL on failure, and calls __PHYSFS_setError().
  187. */
  188. FileHandle *(*openAppend)(DirHandle *r, const char *filename);
  189. /*
  190. * Delete a file in the archive/directory.
  191. * Return non-zero on success, zero on failure.
  192. * This filename is in platform-independent notation.
  193. * This method may be NULL.
  194. * On failure, call __PHYSFS_setError().
  195. */
  196. int (*remove)(DirHandle *r, const char *filename);
  197. /*
  198. * Create a directory in the archive/directory.
  199. * If the application is trying to make multiple dirs, PhysicsFS
  200. * will split them up into multiple calls before passing them to
  201. * your driver.
  202. * Return non-zero on success, zero on failure.
  203. * This filename is in platform-independent notation.
  204. * This method may be NULL.
  205. * On failure, call __PHYSFS_setError().
  206. */
  207. int (*mkdir)(DirHandle *r, const char *filename);
  208. /*
  209. * Close directories/archives, and free the handle, including
  210. * the "opaque" entry. This should assume that it won't be called if
  211. * there are still files open from this DirHandle.
  212. */
  213. void (*dirClose)(DirHandle *r);
  214. } DirFunctions;
  215. /* error messages... */
  216. #define ERR_IS_INITIALIZED "Already initialized"
  217. #define ERR_NOT_INITIALIZED "Not initialized"
  218. #define ERR_INVALID_ARGUMENT "Invalid argument"
  219. #define ERR_FILES_STILL_OPEN "Files still open"
  220. #define ERR_NO_DIR_CREATE "Failed to create directories"
  221. #define ERR_OUT_OF_MEMORY "Out of memory"
  222. #define ERR_NOT_IN_SEARCH_PATH "No such entry in search path"
  223. #define ERR_NOT_SUPPORTED "Operation not supported"
  224. #define ERR_UNSUPPORTED_ARCHIVE "Archive type unsupported"
  225. #define ERR_NOT_A_HANDLE "Not a file handle"
  226. #define ERR_INSECURE_FNAME "Insecure filename"
  227. #define ERR_SYMLINK_DISALLOWED "Symbolic links are disabled"
  228. #define ERR_NO_WRITE_DIR "Write directory is not set"
  229. #define ERR_NO_SUCH_FILE "No such file"
  230. #define ERR_PAST_EOF "Past end of file"
  231. #define ERR_ARC_IS_READ_ONLY "Archive is read-only"
  232. #define ERR_IO_ERROR "I/O error"
  233. #define ERR_CANT_SET_WRITE_DIR "Can't set write directory"
  234. #define ERR_SYMLINK_LOOP "Infinite symbolic link loop"
  235. #define ERR_COMPRESSION "(De)compression error"
  236. #define ERR_NOT_IMPLEMENTED "Not implemented"
  237. #define ERR_OS_ERROR "Operating system reported error"
  238. #define ERR_FILE_EXISTS "File already exists"
  239. #define ERR_NOT_A_DIR "Not a directory"
  240. #define ERR_FILE_NOT_FOUND "File not found"
  241. #define ERR_NOT_AN_ARCHIVE "Not an archive"
  242. #define ERR_CORRUPTED "Corrupted archive"
  243. #define ERR_SEEK_OUT_OF_RANGE "Seek out of range"
  244. #define ERR_BAD_FILENAME "Bad filename"
  245. /*
  246. * Call this to set the message returned by PHYSFS_getLastError().
  247. * Please only use the ERR_* constants above, or add new constants to the
  248. * above group, but I want these all in one place.
  249. *
  250. * Calling this with a NULL argument is a safe no-op.
  251. */
  252. void __PHYSFS_setError(const char *err);
  253. /*
  254. * Convert (dirName) to platform-dependent notation, then prepend (prepend)
  255. * and append (append) to the converted string.
  256. *
  257. * So, on Win32, calling:
  258. * __PHYSFS_convertToDependent("C:\", "my/files", NULL);
  259. * ...will return the string "C:\my\files".
  260. *
  261. * This is a convenience function; you might want to hack something out that
  262. * is less generic (and therefore more efficient).
  263. *
  264. * Be sure to free() the return value when done with it.
  265. */
  266. char *__PHYSFS_convertToDependent(const char *prepend,
  267. const char *dirName,
  268. const char *append);
  269. /*
  270. * Verify that (fname) (in platform-independent notation), in relation
  271. * to (h) is secure. That means that each element of fname is checked
  272. * for symlinks (if they aren't permitted). Also, elements such as
  273. * ".", "..", or ":" are flagged.
  274. *
  275. * Returns non-zero if string is safe, zero if there's a security issue.
  276. * PHYSFS_getLastError() will specify what was wrong.
  277. */
  278. int __PHYSFS_verifySecurity(DirHandle *h, const char *fname);
  279. /*
  280. * Use this to build the list that your enumerate function should return.
  281. * See zip.c for an example of proper use.
  282. */
  283. LinkedStringList *__PHYSFS_addToLinkedStringList(LinkedStringList *retval,
  284. LinkedStringList **prev,
  285. const char *str,
  286. PHYSFS_sint32 len);
  287. /* These get used all over for lessening code clutter. */
  288. #define BAIL_MACRO(e, r) { __PHYSFS_setError(e); return r; }
  289. #define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return r; }
  290. #define BAIL_MACRO_MUTEX(e, m, r) { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; }
  291. #define BAIL_IF_MACRO_MUTEX(c, e, m, r) if (c) { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; }
  292. /*--------------------------------------------------------------------------*/
  293. /*--------------------------------------------------------------------------*/
  294. /*------------ ----------------*/
  295. /*------------ You MUST implement the following functions ----------------*/
  296. /*------------ if porting to a new platform. ----------------*/
  297. /*------------ (see platform/unix.c for an example) ----------------*/
  298. /*------------ ----------------*/
  299. /*--------------------------------------------------------------------------*/
  300. /*--------------------------------------------------------------------------*/
  301. /*
  302. * The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
  303. * Obviously, this isn't a function, but it IS a null-terminated string.
  304. */
  305. extern const char *__PHYSFS_platformDirSeparator;
  306. /*
  307. * Initialize the platform. This is called when PHYSFS_init() is called from
  308. * the application. You can use this to (for example) determine what version
  309. * of Windows you're running.
  310. *
  311. * Return zero if there was a catastrophic failure (which prevents you from
  312. * functioning at all), and non-zero otherwise.
  313. */
  314. int __PHYSFS_platformInit(void);
  315. /*
  316. * Deinitialize the platform. This is called when PHYSFS_deinit() is called
  317. * from the application. You can use this to clean up anything you've
  318. * allocated in your platform driver.
  319. *
  320. * Return zero if there was a catastrophic failure (which prevents you from
  321. * functioning at all), and non-zero otherwise.
  322. */
  323. int __PHYSFS_platformDeinit(void);
  324. /*
  325. * Open a file for reading. (filename) is in platform-dependent notation. The
  326. * file pointer should be positioned on the first byte of the file.
  327. *
  328. * The return value will be some platform-specific datatype that is opaque to
  329. * the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32.
  330. *
  331. * The same file can be opened for read multiple times, and each should have
  332. * a unique file handle; this is frequently employed to prevent race
  333. * conditions in the archivers.
  334. *
  335. * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
  336. */
  337. void *__PHYSFS_platformOpenRead(const char *filename);
  338. /*
  339. * Open a file for writing. (filename) is in platform-dependent notation. If
  340. * the file exists, it should be truncated to zero bytes, and if it doesn't
  341. * exist, it should be created as a zero-byte file. The file pointer should
  342. * be positioned on the first byte of the file.
  343. *
  344. * The return value will be some platform-specific datatype that is opaque to
  345. * the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32,
  346. * etc.
  347. *
  348. * Opening a file for write multiple times has undefined results.
  349. *
  350. * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
  351. */
  352. void *__PHYSFS_platformOpenWrite(const char *filename);
  353. /*
  354. * Open a file for appending. (filename) is in platform-dependent notation. If
  355. * the file exists, the file pointer should be place just past the end of the
  356. * file, so that the first write will be one byte after the current end of
  357. * the file. If the file doesn't exist, it should be created as a zero-byte
  358. * file. The file pointer should be positioned on the first byte of the file.
  359. *
  360. * The return value will be some platform-specific datatype that is opaque to
  361. * the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under win32,
  362. * etc.
  363. *
  364. * Opening a file for append multiple times has undefined results.
  365. *
  366. * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
  367. */
  368. void *__PHYSFS_platformOpenAppend(const char *filename);
  369. /*
  370. * Read more data from a platform-specific file handle. (opaque) should be
  371. * cast to whatever data type your platform uses. Read a maximum of (count)
  372. * objects of (size) 8-bit bytes to the area pointed to by (buffer). If there
  373. * isn't enough data available, return the number of full objects read, and
  374. * position the file pointer at the start of the first incomplete object.
  375. * On success, return (count) and position the file pointer one byte past
  376. * the end of the last read object. Return (-1) if there is a catastrophic
  377. * error, and call __PHYSFS_setError() to describe the problem; the file
  378. * pointer should not move in such a case.
  379. */
  380. PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
  381. PHYSFS_uint32 size, PHYSFS_uint32 count);
  382. /*
  383. * Write more data to a platform-specific file handle. (opaque) should be
  384. * cast to whatever data type your platform uses. Write a maximum of (count)
  385. * objects of (size) 8-bit bytes from the area pointed to by (buffer). If
  386. * there isn't enough data available, return the number of full objects
  387. * written, and position the file pointer at the start of the first
  388. * incomplete object. Return (-1) if there is a catastrophic error, and call
  389. * __PHYSFS_setError() to describe the problem; the file pointer should not
  390. * move in such a case.
  391. */
  392. PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
  393. PHYSFS_uint32 size, PHYSFS_uint32 count);
  394. /*
  395. * Set the file pointer to a new position. (opaque) should be cast to
  396. * whatever data type your platform uses. (pos) specifies the number
  397. * of 8-bit bytes to seek to from the start of the file. Seeking past the
  398. * end of the file is an error condition, and you should check for it.
  399. *
  400. * Not all file types can seek; this is to be expected by the caller.
  401. *
  402. * On error, call __PHYSFS_setError() and return zero. On success, return
  403. * a non-zero value.
  404. */
  405. int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
  406. /*
  407. * Get the file pointer's position, in an 8-bit byte offset from the start of
  408. * the file. (opaque) should be cast to whatever data type your platform
  409. * uses.
  410. *
  411. * Not all file types can "tell"; this is to be expected by the caller.
  412. *
  413. * On error, call __PHYSFS_setError() and return zero. On success, return
  414. * a non-zero value.
  415. */
  416. PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
  417. /*
  418. * Determine the current size of a file, in 8-bit bytes, from an open file.
  419. *
  420. * The caller expects that this information may not be available for all
  421. * file types on all platforms.
  422. *
  423. * Return -1 if you can't do it, and call __PHYSFS_setError(). Otherwise,
  424. * return the file length in 8-bit bytes.
  425. */
  426. PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
  427. /*
  428. * Determine if a file is at EOF. (opaque) should be cast to whatever data
  429. * type your platform uses.
  430. *
  431. * The caller expects that there was a short read before calling this.
  432. *
  433. * Return non-zero if EOF, zero if it is _not_ EOF.
  434. */
  435. int __PHYSFS_platformEOF(void *opaque);
  436. /*
  437. * Flush any pending writes to disk. (opaque) should be cast to whatever data
  438. * type your platform uses. Be sure to check for errors; the caller expects
  439. * that this function can fail if there was a flushing error, etc.
  440. *
  441. * Return zero on failure, non-zero on success.
  442. */
  443. int __PHYSFS_platformFlush(void *opaque);
  444. /*
  445. * Flush and close a file. (opaque) should be cast to whatever data type
  446. * your platform uses. Be sure to check for errors when closing; the
  447. * caller expects that this function can fail if there was a flushing
  448. * error, etc.
  449. *
  450. * You should clean up all resources associated with (opaque).
  451. *
  452. * Return zero on failure, non-zero on success.
  453. */
  454. int __PHYSFS_platformClose(void *opaque);
  455. /*
  456. * Platform implementation of PHYSFS_getCdRomDirs()...
  457. * See physfs.h. The retval should be freeable via PHYSFS_freeList().
  458. */
  459. char **__PHYSFS_platformDetectAvailableCDs(void);
  460. /*
  461. * Calculate the base dir, if your platform needs special consideration.
  462. * Just return NULL if the standard routines will suffice. (see
  463. * calculateBaseDir() in physfs.c ...)
  464. * Caller will free() the retval if it's not NULL.
  465. */
  466. char *__PHYSFS_platformCalcBaseDir(const char *argv0);
  467. /*
  468. * Get the platform-specific user name.
  469. * Caller will free() the retval if it's not NULL. If it's NULL, the username
  470. * will default to "default".
  471. */
  472. char *__PHYSFS_platformGetUserName(void);
  473. /*
  474. * Get the platform-specific user dir.
  475. * Caller will free() the retval if it's not NULL. If it's NULL, the userdir
  476. * will default to basedir/username.
  477. */
  478. char *__PHYSFS_platformGetUserDir(void);
  479. /*
  480. * Return a number that uniquely identifies the current thread.
  481. * On a platform without threading, (1) will suffice. These numbers are
  482. * arbitrary; the only requirement is that no two threads have the same
  483. * number.
  484. */
  485. PHYSFS_uint64 __PHYSFS_platformGetThreadID(void);
  486. /*
  487. * This is a pass-through to whatever stricmp() is called on your platform.
  488. */
  489. int __PHYSFS_platformStricmp(const char *str1, const char *str2);
  490. /*
  491. * Return non-zero if filename (in platform-dependent notation) exists.
  492. * Symlinks should be followed; if what the symlink points to is missing,
  493. * then the retval is false.
  494. */
  495. int __PHYSFS_platformExists(const char *fname);
  496. /*
  497. * Return the last modified time (in seconds since the epoch) of a file.
  498. * Returns -1 on failure. (fname) is in platform-dependent notation.
  499. * Symlinks should be followed; if what the symlink points to is missing,
  500. * then the retval is -1.
  501. */
  502. PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname);
  503. /*
  504. * Return non-zero if filename (in platform-dependent notation) is a symlink.
  505. */
  506. int __PHYSFS_platformIsSymLink(const char *fname);
  507. /*
  508. * Return non-zero if filename (in platform-dependent notation) is a symlink.
  509. * Symlinks should be followed; if what the symlink points to is missing,
  510. * or isn't a directory, then the retval is false.
  511. */
  512. int __PHYSFS_platformIsDirectory(const char *fname);
  513. /*
  514. * Convert (dirName) to platform-dependent notation, then prepend (prepend)
  515. * and append (append) to the converted string.
  516. *
  517. * So, on Win32, calling:
  518. * __PHYSFS_platformCvtToDependent("C:\", "my/files", NULL);
  519. * ...will return the string "C:\my\files".
  520. *
  521. * This can be implemented in a platform-specific manner, so you can get
  522. * get a speed boost that the default implementation can't, since
  523. * you can make assumptions about the size of strings, etc..
  524. *
  525. * Platforms that choose not to implement this may just call
  526. * __PHYSFS_convertToDependent() as a passthrough, which may fit the bill
  527. * already.
  528. *
  529. * Be sure to free() the return value when done with it.
  530. */
  531. char *__PHYSFS_platformCvtToDependent(const char *prepend,
  532. const char *dirName,
  533. const char *append);
  534. /*
  535. * Make the current thread give up a timeslice. This is called in a loop
  536. * while waiting for various external forces to get back to us.
  537. */
  538. void __PHYSFS_platformTimeslice(void);
  539. /*
  540. * Enumerate a directory of files. This follows the rules for the
  541. * DirFunctions->enumerateFiles() method (see above), except that the
  542. * (dirName) that is passed to this function is converted to
  543. * platform-DEPENDENT notation by the caller. The DirFunctions version
  544. * uses platform-independent notation. Note that ".", "..", and other
  545. * metaentries should always be ignored.
  546. */
  547. LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
  548. int omitSymLinks);
  549. /*
  550. * Get the current working directory. The return value should be an
  551. * absolute path in platform-dependent notation. The caller will deallocate
  552. * the return value with the standard C runtime free() function when it
  553. * is done with it.
  554. * On error, return NULL and set the error message.
  555. */
  556. char *__PHYSFS_platformCurrentDir(void);
  557. /*
  558. * Get the real physical path to a file. (path) is specified in
  559. * platform-dependent notation, as should your return value be.
  560. * All relative paths should be removed, leaving you with an absolute
  561. * path. Symlinks should be resolved, too, so that the returned value is
  562. * the most direct path to a file.
  563. * The return value will be deallocated with the standard C runtime free()
  564. * function when the caller is done with it.
  565. * On error, return NULL and set the error message.
  566. */
  567. char *__PHYSFS_platformRealPath(const char *path);
  568. /*
  569. * Make a directory in the actual filesystem. (path) is specified in
  570. * platform-dependent notation. On error, return zero and set the error
  571. * message. Return non-zero on success.
  572. */
  573. int __PHYSFS_platformMkDir(const char *path);
  574. /*
  575. * Remove a file or directory entry in the actual filesystem. (path) is
  576. * specified in platform-dependent notation. Note that this deletes files
  577. * _and_ directories, so you might need to do some determination.
  578. * Non-empty directories should report an error and not delete themselves
  579. * or their contents.
  580. *
  581. * Deleting a symlink should remove the link, not what it points to.
  582. *
  583. * On error, return zero and set the error message. Return non-zero on success.
  584. */
  585. int __PHYSFS_platformDelete(const char *path);
  586. /*
  587. * Create a platform-specific mutex. This can be whatever datatype your
  588. * platform uses for mutexes, but it is cast to a (void *) for abstractness.
  589. *
  590. * Return (NULL) if you couldn't create one. Systems without threads can
  591. * return any arbitrary non-NULL value.
  592. */
  593. void *__PHYSFS_platformCreateMutex(void);
  594. /*
  595. * Destroy a platform-specific mutex, and clean up any resources associated
  596. * with it. (mutex) is a value previously returned by
  597. * __PHYSFS_platformCreateMutex(). This can be a no-op on single-threaded
  598. * platforms.
  599. */
  600. void __PHYSFS_platformDestroyMutex(void *mutex);
  601. /*
  602. * Grab possession of a platform-specific mutex. Mutexes should be recursive;
  603. * that is, the same thread should be able to call this function multiple
  604. * times in a row without causing a deadlock. This function should block
  605. * until a thread can gain possession of the mutex.
  606. *
  607. * Return non-zero if the mutex was grabbed, zero if there was an
  608. * unrecoverable problem grabbing it (this should not be a matter of
  609. * timing out! We're talking major system errors; block until the mutex
  610. * is available otherwise.)
  611. *
  612. * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
  613. * function, you'll cause an infinite recursion. This means you can't
  614. * use the BAIL_*MACRO* macros, either.
  615. */
  616. int __PHYSFS_platformGrabMutex(void *mutex);
  617. /*
  618. * Relinquish possession of the mutex when this method has been called
  619. * once for each time that platformGrabMutex was called. Once possession has
  620. * been released, the next thread in line to grab the mutex (if any) may
  621. * proceed.
  622. *
  623. * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
  624. * function, you'll cause an infinite recursion. This means you can't
  625. * use the BAIL_*MACRO* macros, either.
  626. */
  627. void __PHYSFS_platformReleaseMutex(void *mutex);
  628. #ifdef __cplusplus
  629. }
  630. #endif
  631. #endif
  632. /* end of physfs_internal.h ... */