🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3854 lines
158 KiB

  1. /**
  2. * \file physfs.h
  3. *
  4. * Main header file for PhysicsFS.
  5. */
  6. /**
  7. * \mainpage PhysicsFS
  8. *
  9. * The latest version of PhysicsFS can be found at:
  10. * https://icculus.org/physfs/
  11. *
  12. * PhysicsFS; a portable, flexible file i/o abstraction.
  13. *
  14. * This API gives you access to a system file system in ways superior to the
  15. * stdio or system i/o calls. The brief benefits:
  16. *
  17. * - It's portable.
  18. * - It's safe. No file access is permitted outside the specified dirs.
  19. * - It's flexible. Archives (.ZIP files) can be used transparently as
  20. * directory structures.
  21. *
  22. * With PhysicsFS, you have a single writing directory and multiple
  23. * directories (the "search path") for reading. You can think of this as a
  24. * filesystem within a filesystem. If (on Windows) you were to set the
  25. * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
  26. * could touch anything above this directory, including the "C:\MyGame" and
  27. * "C:\" directories. This prevents an application's internal scripting
  28. * language from piddling over c:\\config.sys, for example. If you'd rather
  29. * give PHYSFS full access to the system's REAL file system, set the writing
  30. * dir to "C:\", but that's generally A Bad Thing for several reasons.
  31. *
  32. * Drive letters are hidden in PhysicsFS once you set up your initial paths.
  33. * The search path creates a single, hierarchical directory structure.
  34. * Not only does this lend itself well to general abstraction with archives,
  35. * it also gives better support to operating systems like MacOS and Unix.
  36. * Generally speaking, you shouldn't ever hardcode a drive letter; not only
  37. * does this hurt portability to non-Microsoft OSes, but it limits your win32
  38. * users to a single drive, too. Use the PhysicsFS abstraction functions and
  39. * allow user-defined configuration options, too. When opening a file, you
  40. * specify it like it was on a Unix filesystem: if you want to write to
  41. * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to
  42. * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
  43. * abstraction across all platforms. Specifying a file in this way is termed
  44. * "platform-independent notation" in this documentation. Specifying a
  45. * a filename in a form such as "C:\mydir\myfile" or
  46. * "MacOS hard drive:My Directory:My File" is termed "platform-dependent
  47. * notation". The only time you use platform-dependent notation is when
  48. * setting up your write directory and search path; after that, all file
  49. * access into those directories are done with platform-independent notation.
  50. *
  51. * All files opened for writing are opened in relation to the write directory,
  52. * which is the root of the writable filesystem. When opening a file for
  53. * reading, PhysicsFS goes through the search path. This is NOT the
  54. * same thing as the PATH environment variable. An application using
  55. * PhysicsFS specifies directories to be searched which may be actual
  56. * directories, or archive files that contain files and subdirectories of
  57. * their own. See the end of these docs for currently supported archive
  58. * formats.
  59. *
  60. * Once the search path is defined, you may open files for reading. If you've
  61. * got the following search path defined (to use a win32 example again):
  62. *
  63. * - C:\\mygame
  64. * - C:\\mygame\\myuserfiles
  65. * - D:\\mygamescdromdatafiles
  66. * - C:\\mygame\\installeddatafiles.zip
  67. *
  68. * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory
  69. * separator, lack of drive letter, and lack of dir separator at the start of
  70. * the string; this is platform-independent notation) will check for
  71. * C:\\mygame\\textfiles\\myfile.txt, then
  72. * C:\\mygame\\myuserfiles\\textfiles\\myfile.txt, then
  73. * D:\\mygamescdromdatafiles\\textfiles\\myfile.txt, then, finally, for
  74. * textfiles\\myfile.txt inside of C:\\mygame\\installeddatafiles.zip.
  75. * Remember that most archive types and platform filesystems store their
  76. * filenames in a case-sensitive manner, so you should be careful to specify
  77. * it correctly.
  78. *
  79. * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir
  80. * elements. Not only are these meaningless on MacOS Classic and/or Unix,
  81. * they are a security hole. Also, symbolic links (which can be found in
  82. * some archive types and directly in the filesystem on Unix platforms) are
  83. * NOT followed until you call PHYSFS_permitSymbolicLinks(). That's left to
  84. * your own discretion, as following a symlink can allow for access outside
  85. * the write dir and search paths. For portability, there is no mechanism for
  86. * creating new symlinks in PhysicsFS.
  87. *
  88. * The write dir is not included in the search path unless you specifically
  89. * add it. While you CAN change the write dir as many times as you like,
  90. * you should probably set it once and stick to it. Remember that your
  91. * program will not have permission to write in every directory on Unix and
  92. * NT systems.
  93. *
  94. * All files are opened in binary mode; there is no endline conversion for
  95. * textfiles. Other than that, PhysicsFS has some convenience functions for
  96. * platform-independence. There is a function to tell you the current
  97. * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS),
  98. * which is needed only to set up your search/write paths. There is a
  99. * function to tell you what CD-ROM drives contain accessible discs, and a
  100. * function to recommend a good search path, etc.
  101. *
  102. * A recommended order for the search path is the write dir, then the base dir,
  103. * then the cdrom dir, then any archives discovered. Quake 3 does something
  104. * like this, but moves the archives to the start of the search path. Build
  105. * Engine games, like Duke Nukem 3D and Blood, place the archives last, and
  106. * use the base dir for both searching and writing. There is a helper
  107. * function (PHYSFS_setSaneConfig()) that puts together a basic configuration
  108. * for you, based on a few parameters. Also see the comments on
  109. * PHYSFS_getBaseDir(), and PHYSFS_getPrefDir() for info on what those
  110. * are and how they can help you determine an optimal search path.
  111. *
  112. * PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points
  113. * in the search path. If a zipfile contains "maps/level.map" and you mount
  114. * that archive at "mods/mymod", then you would have to open
  115. * "mods/mymod/maps/level.map" to access the file, even though "mods/mymod"
  116. * isn't actually specified in the .zip file. Unlike the Unix mentality of
  117. * mounting a filesystem, "mods/mymod" doesn't actually have to exist when
  118. * mounting the zipfile. It's a "virtual" directory. The mounting mechanism
  119. * allows the developer to seperate archives in the tree and avoid trampling
  120. * over files when added new archives, such as including mod support in a
  121. * game...keeping external content on a tight leash in this manner can be of
  122. * utmost importance to some applications.
  123. *
  124. * PhysicsFS is mostly thread safe. The errors returned by
  125. * PHYSFS_getLastErrorCode() are unique by thread, and library-state-setting
  126. * functions are mutex'd. For efficiency, individual file accesses are
  127. * not locked, so you can not safely read/write/seek/close/etc the same
  128. * file from two threads at the same time. Other race conditions are bugs
  129. * that should be reported/patched.
  130. *
  131. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  132. * calls, doing so is not recommended, and you can not directly use system
  133. * filehandles with PhysicsFS and vice versa (but as of PhysicsFS 2.1, you
  134. * can wrap them in a PHYSFS_Io interface yourself if you wanted to).
  135. *
  136. * Note that archives need not be named as such: if you have a ZIP file and
  137. * rename it with a .PKG extension, the file will still be recognized as a
  138. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  139. * type where possible.
  140. *
  141. * Currently supported archive types:
  142. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  143. * - .7Z (7zip archives)
  144. * - .ISO (ISO9660 files, CD-ROM images)
  145. * - .GRP (Build Engine groupfile archives)
  146. * - .PAK (Quake I/II archive format)
  147. * - .HOG (Descent I/II HOG file archives)
  148. * - .MVL (Descent II movielib archives)
  149. * - .WAD (DOOM engine archives)
  150. * - .VDF (Gothic I/II engine archives)
  151. * - .SLB (Independence War archives)
  152. *
  153. * String policy for PhysicsFS 2.0 and later:
  154. *
  155. * PhysicsFS 1.0 could only deal with null-terminated ASCII strings. All high
  156. * ASCII chars resulted in undefined behaviour, and there was no Unicode
  157. * support at all. PhysicsFS 2.0 supports Unicode without breaking binary
  158. * compatibility with the 1.0 API by using UTF-8 encoding of all strings
  159. * passed in and out of the library.
  160. *
  161. * All strings passed through PhysicsFS are in null-terminated UTF-8 format.
  162. * This means that if all you care about is English (ASCII characters <= 127)
  163. * then you just use regular C strings. If you care about Unicode (and you
  164. * should!) then you need to figure out what your platform wants, needs, and
  165. * offers. If you are on Windows before Win2000 and build with Unicode
  166. * support, your TCHAR strings are two bytes per character (this is called
  167. * "UCS-2 encoding"). Any modern Windows uses UTF-16, which is two bytes
  168. * per character for most characters, but some characters are four. You
  169. * should convert them to UTF-8 before handing them to PhysicsFS with
  170. * PHYSFS_utf8FromUtf16(), which handles both UTF-16 and UCS-2. If you're
  171. * using Unix or Mac OS X, your wchar_t strings are four bytes per character
  172. * ("UCS-4 encoding", sometimes called "UTF-32"). Use PHYSFS_utf8FromUcs4().
  173. * Mac OS X can give you UTF-8 directly from a CFString or NSString, and many
  174. * Unixes generally give you C strings in UTF-8 format everywhere. If you
  175. * have a single-byte high ASCII charset, like so-many European "codepages"
  176. * you may be out of luck. We'll convert from "Latin1" to UTF-8 only, and
  177. * never back to Latin1. If you're above ASCII 127, all bets are off: move
  178. * to Unicode or use your platform's facilities. Passing a C string with
  179. * high-ASCII data that isn't UTF-8 encoded will NOT do what you expect!
  180. *
  181. * Naturally, there's also PHYSFS_utf8ToUcs2(), PHYSFS_utf8ToUtf16(), and
  182. * PHYSFS_utf8ToUcs4() to get data back into a format you like. Behind the
  183. * scenes, PhysicsFS will use Unicode where possible: the UTF-8 strings on
  184. * Windows will be converted and used with the multibyte Windows APIs, for
  185. * example.
  186. *
  187. * PhysicsFS offers basic encoding conversion support, but not a whole string
  188. * library. Get your stuff into whatever format you can work with.
  189. *
  190. * Most platforms supported by PhysicsFS 2.1 and later fully support Unicode.
  191. * Some older platforms have been dropped (Windows 95, Mac OS 9). Some, like
  192. * OS/2, might be able to convert to a local codepage or will just fail to
  193. * open/create the file. Modern OSes (macOS, Linux, Windows, etc) should all
  194. * be fine.
  195. *
  196. * Many game-specific archivers are seriously unprepared for Unicode (the
  197. * Descent HOG/MVL and Build Engine GRP archivers, for example, only offer a
  198. * DOS 8.3 filename, for example). Nothing can be done for these, but they
  199. * tend to be legacy formats for existing content that was all ASCII (and
  200. * thus, valid UTF-8) anyhow. Other formats, like .ZIP, don't explicitly
  201. * offer Unicode support, but unofficially expect filenames to be UTF-8
  202. * encoded, and thus Just Work. Most everything does the right thing without
  203. * bothering you, but it's good to be aware of these nuances in case they
  204. * don't.
  205. *
  206. *
  207. * Other stuff:
  208. *
  209. * Please see the file LICENSE.txt in the source's root directory for
  210. * licensing and redistribution rights.
  211. *
  212. * Please see the file CREDITS.txt in the source's "docs" directory for
  213. * a more or less complete list of who's responsible for this.
  214. *
  215. * \author Ryan C. Gordon.
  216. */
  217. #ifndef _INCLUDE_PHYSFS_H_
  218. #define _INCLUDE_PHYSFS_H_
  219. #ifdef __cplusplus
  220. extern "C" {
  221. #endif
  222. #if defined(PHYSFS_DECL)
  223. /* do nothing. */
  224. #elif defined(_MSC_VER)
  225. #define PHYSFS_DECL __declspec(dllexport)
  226. #elif defined(__SUNPRO_C)
  227. #define PHYSFS_DECL __global
  228. #elif ((__GNUC__ >= 3) && (!defined(__EMX__)) && (!defined(sun)))
  229. #define PHYSFS_DECL __attribute__((visibility("default")))
  230. #else
  231. #define PHYSFS_DECL
  232. #endif
  233. #if defined(PHYSFS_DEPRECATED)
  234. /* do nothing. */
  235. #elif (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
  236. #define PHYSFS_DEPRECATED __attribute__((deprecated))
  237. #else
  238. #define PHYSFS_DEPRECATED
  239. #endif
  240. #if 0 /* !!! FIXME: look into this later. */
  241. #if defined(PHYSFS_CALL)
  242. /* do nothing. */
  243. #elif defined(__WIN32__) && !defined(__GNUC__)
  244. #define PHYSFS_CALL __cdecl
  245. #elif defined(__OS2__) || defined(OS2) /* should work across all compilers. */
  246. #define PHYSFS_CALL _System
  247. #else
  248. #define PHYSFS_CALL
  249. #endif
  250. #endif
  251. /**
  252. * \typedef PHYSFS_uint8
  253. * \brief An unsigned, 8-bit integer type.
  254. */
  255. typedef unsigned char PHYSFS_uint8;
  256. /**
  257. * \typedef PHYSFS_sint8
  258. * \brief A signed, 8-bit integer type.
  259. */
  260. typedef signed char PHYSFS_sint8;
  261. /**
  262. * \typedef PHYSFS_uint16
  263. * \brief An unsigned, 16-bit integer type.
  264. */
  265. typedef unsigned short PHYSFS_uint16;
  266. /**
  267. * \typedef PHYSFS_sint16
  268. * \brief A signed, 16-bit integer type.
  269. */
  270. typedef signed short PHYSFS_sint16;
  271. /**
  272. * \typedef PHYSFS_uint32
  273. * \brief An unsigned, 32-bit integer type.
  274. */
  275. typedef unsigned int PHYSFS_uint32;
  276. /**
  277. * \typedef PHYSFS_sint32
  278. * \brief A signed, 32-bit integer type.
  279. */
  280. typedef signed int PHYSFS_sint32;
  281. /**
  282. * \typedef PHYSFS_uint64
  283. * \brief An unsigned, 64-bit integer type.
  284. * \warning on platforms without any sort of 64-bit datatype, this is
  285. * equivalent to PHYSFS_uint32!
  286. */
  287. /**
  288. * \typedef PHYSFS_sint64
  289. * \brief A signed, 64-bit integer type.
  290. * \warning on platforms without any sort of 64-bit datatype, this is
  291. * equivalent to PHYSFS_sint32!
  292. */
  293. #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */
  294. typedef PHYSFS_uint32 PHYSFS_uint64;
  295. typedef PHYSFS_sint32 PHYSFS_sint64;
  296. #elif (defined _MSC_VER)
  297. typedef signed __int64 PHYSFS_sint64;
  298. typedef unsigned __int64 PHYSFS_uint64;
  299. #else
  300. typedef unsigned long long PHYSFS_uint64;
  301. typedef signed long long PHYSFS_sint64;
  302. #endif
  303. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  304. /* Make sure the types really have the right sizes */
  305. #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \
  306. typedef int PHYSFS_compile_time_assert_##name[(x) * 2 - 1]
  307. PHYSFS_COMPILE_TIME_ASSERT(uint8IsOneByte, sizeof(PHYSFS_uint8) == 1);
  308. PHYSFS_COMPILE_TIME_ASSERT(sint8IsOneByte, sizeof(PHYSFS_sint8) == 1);
  309. PHYSFS_COMPILE_TIME_ASSERT(uint16IsTwoBytes, sizeof(PHYSFS_uint16) == 2);
  310. PHYSFS_COMPILE_TIME_ASSERT(sint16IsTwoBytes, sizeof(PHYSFS_sint16) == 2);
  311. PHYSFS_COMPILE_TIME_ASSERT(uint32IsFourBytes, sizeof(PHYSFS_uint32) == 4);
  312. PHYSFS_COMPILE_TIME_ASSERT(sint32IsFourBytes, sizeof(PHYSFS_sint32) == 4);
  313. #ifndef PHYSFS_NO_64BIT_SUPPORT
  314. PHYSFS_COMPILE_TIME_ASSERT(uint64IsEightBytes, sizeof(PHYSFS_uint64) == 8);
  315. PHYSFS_COMPILE_TIME_ASSERT(sint64IsEightBytes, sizeof(PHYSFS_sint64) == 8);
  316. #endif
  317. #undef PHYSFS_COMPILE_TIME_ASSERT
  318. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  319. /**
  320. * \struct PHYSFS_File
  321. * \brief A PhysicsFS file handle.
  322. *
  323. * You get a pointer to one of these when you open a file for reading,
  324. * writing, or appending via PhysicsFS.
  325. *
  326. * As you can see from the lack of meaningful fields, you should treat this
  327. * as opaque data. Don't try to manipulate the file handle, just pass the
  328. * pointer you got, unmolested, to various PhysicsFS APIs.
  329. *
  330. * \sa PHYSFS_openRead
  331. * \sa PHYSFS_openWrite
  332. * \sa PHYSFS_openAppend
  333. * \sa PHYSFS_close
  334. * \sa PHYSFS_read
  335. * \sa PHYSFS_write
  336. * \sa PHYSFS_seek
  337. * \sa PHYSFS_tell
  338. * \sa PHYSFS_eof
  339. * \sa PHYSFS_setBuffer
  340. * \sa PHYSFS_flush
  341. */
  342. typedef struct PHYSFS_File
  343. {
  344. void *opaque; /**< That's all you get. Don't touch. */
  345. } PHYSFS_File;
  346. /**
  347. * \def PHYSFS_file
  348. * \brief 1.0 API compatibility define.
  349. *
  350. * PHYSFS_file is identical to PHYSFS_File. This #define is here for backwards
  351. * compatibility with the 1.0 API, which had an inconsistent capitalization
  352. * convention in this case. New code should use PHYSFS_File, as this #define
  353. * may go away someday.
  354. *
  355. * \sa PHYSFS_File
  356. */
  357. #define PHYSFS_file PHYSFS_File
  358. /**
  359. * \struct PHYSFS_ArchiveInfo
  360. * \brief Information on various PhysicsFS-supported archives.
  361. *
  362. * This structure gives you details on what sort of archives are supported
  363. * by this implementation of PhysicsFS. Archives tend to be things like
  364. * ZIP files and such.
  365. *
  366. * \warning Not all binaries are created equal! PhysicsFS can be built with
  367. * or without support for various archives. You can check with
  368. * PHYSFS_supportedArchiveTypes() to see if your archive type is
  369. * supported.
  370. *
  371. * \sa PHYSFS_supportedArchiveTypes
  372. * \sa PHYSFS_registerArchiver
  373. * \sa PHYSFS_deregisterArchiver
  374. */
  375. typedef struct PHYSFS_ArchiveInfo
  376. {
  377. const char *extension; /**< Archive file extension: "ZIP", for example. */
  378. const char *description; /**< Human-readable archive description. */
  379. const char *author; /**< Person who did support for this archive. */
  380. const char *url; /**< URL related to this archive */
  381. int supportsSymlinks; /**< non-zero if archive offers symbolic links. */
  382. } PHYSFS_ArchiveInfo;
  383. /**
  384. * \struct PHYSFS_Version
  385. * \brief Information the version of PhysicsFS in use.
  386. *
  387. * Represents the library's version as three levels: major revision
  388. * (increments with massive changes, additions, and enhancements),
  389. * minor revision (increments with backwards-compatible changes to the
  390. * major revision), and patchlevel (increments with fixes to the minor
  391. * revision).
  392. *
  393. * \sa PHYSFS_VERSION
  394. * \sa PHYSFS_getLinkedVersion
  395. */
  396. typedef struct PHYSFS_Version
  397. {
  398. PHYSFS_uint8 major; /**< major revision */
  399. PHYSFS_uint8 minor; /**< minor revision */
  400. PHYSFS_uint8 patch; /**< patchlevel */
  401. } PHYSFS_Version;
  402. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  403. #define PHYSFS_VER_MAJOR 3
  404. #define PHYSFS_VER_MINOR 0
  405. #define PHYSFS_VER_PATCH 2
  406. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  407. /* PhysicsFS state stuff ... */
  408. /**
  409. * \def PHYSFS_VERSION(x)
  410. * \brief Macro to determine PhysicsFS version program was compiled against.
  411. *
  412. * This macro fills in a PHYSFS_Version structure with the version of the
  413. * library you compiled against. This is determined by what header the
  414. * compiler uses. Note that if you dynamically linked the library, you might
  415. * have a slightly newer or older version at runtime. That version can be
  416. * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION,
  417. * is not a macro.
  418. *
  419. * \param x A pointer to a PHYSFS_Version struct to initialize.
  420. *
  421. * \sa PHYSFS_Version
  422. * \sa PHYSFS_getLinkedVersion
  423. */
  424. #define PHYSFS_VERSION(x) \
  425. { \
  426. (x)->major = PHYSFS_VER_MAJOR; \
  427. (x)->minor = PHYSFS_VER_MINOR; \
  428. (x)->patch = PHYSFS_VER_PATCH; \
  429. }
  430. /**
  431. * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  432. * \brief Get the version of PhysicsFS that is linked against your program.
  433. *
  434. * If you are using a shared library (DLL) version of PhysFS, then it is
  435. * possible that it will be different than the version you compiled against.
  436. *
  437. * This is a real function; the macro PHYSFS_VERSION tells you what version
  438. * of PhysFS you compiled against:
  439. *
  440. * \code
  441. * PHYSFS_Version compiled;
  442. * PHYSFS_Version linked;
  443. *
  444. * PHYSFS_VERSION(&compiled);
  445. * PHYSFS_getLinkedVersion(&linked);
  446. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  447. * compiled.major, compiled.minor, compiled.patch);
  448. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  449. * linked.major, linked.minor, linked.patch);
  450. * \endcode
  451. *
  452. * This function may be called safely at any time, even before PHYSFS_init().
  453. *
  454. * \sa PHYSFS_VERSION
  455. */
  456. PHYSFS_DECL void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  457. /**
  458. * \fn int PHYSFS_init(const char *argv0)
  459. * \brief Initialize the PhysicsFS library.
  460. *
  461. * This must be called before any other PhysicsFS function.
  462. *
  463. * This should be called prior to any attempts to change your process's
  464. * current working directory.
  465. *
  466. * \param argv0 the argv[0] string passed to your program's mainline.
  467. * This may be NULL on most platforms (such as ones without a
  468. * standard main() function), but you should always try to pass
  469. * something in here. Unix-like systems such as Linux _need_ to
  470. * pass argv[0] from main() in here.
  471. * \return nonzero on success, zero on error. Specifics of the error can be
  472. * gleaned from PHYSFS_getLastError().
  473. *
  474. * \sa PHYSFS_deinit
  475. * \sa PHYSFS_isInit
  476. */
  477. PHYSFS_DECL int PHYSFS_init(const char *argv0);
  478. /**
  479. * \fn int PHYSFS_deinit(void)
  480. * \brief Deinitialize the PhysicsFS library.
  481. *
  482. * This closes any files opened via PhysicsFS, blanks the search/write paths,
  483. * frees memory, and invalidates all of your file handles.
  484. *
  485. * Note that this call can FAIL if there's a file open for writing that
  486. * refuses to close (for example, the underlying operating system was
  487. * buffering writes to network filesystem, and the fileserver has crashed,
  488. * or a hard drive has failed, etc). It is usually best to close all write
  489. * handles yourself before calling this function, so that you can gracefully
  490. * handle a specific failure.
  491. *
  492. * Once successfully deinitialized, PHYSFS_init() can be called again to
  493. * restart the subsystem. All default API states are restored at this
  494. * point, with the exception of any custom allocator you might have
  495. * specified, which survives between initializations.
  496. *
  497. * \return nonzero on success, zero on error. Specifics of the error can be
  498. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  499. * undefined, and probably badly screwed up.
  500. *
  501. * \sa PHYSFS_init
  502. * \sa PHYSFS_isInit
  503. */
  504. PHYSFS_DECL int PHYSFS_deinit(void);
  505. /**
  506. * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
  507. * \brief Get a list of supported archive types.
  508. *
  509. * Get a list of archive types supported by this implementation of PhysicFS.
  510. * These are the file formats usable for search path entries. This is for
  511. * informational purposes only. Note that the extension listed is merely
  512. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  513. * with an extension of "XYZ", if you like.
  514. *
  515. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  516. * with a NULL entry to signify the end of the list:
  517. *
  518. * \code
  519. * PHYSFS_ArchiveInfo **i;
  520. *
  521. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  522. * {
  523. * printf("Supported archive: [%s], which is [%s].\n",
  524. * (*i)->extension, (*i)->description);
  525. * }
  526. * \endcode
  527. *
  528. * The return values are pointers to internal memory, and should
  529. * be considered READ ONLY, and never freed. The returned values are
  530. * valid until the next call to PHYSFS_deinit(), PHYSFS_registerArchiver(),
  531. * or PHYSFS_deregisterArchiver().
  532. *
  533. * \return READ ONLY Null-terminated array of READ ONLY structures.
  534. *
  535. * \sa PHYSFS_registerArchiver
  536. * \sa PHYSFS_deregisterArchiver
  537. */
  538. PHYSFS_DECL const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  539. /**
  540. * \fn void PHYSFS_freeList(void *listVar)
  541. * \brief Deallocate resources of lists returned by PhysicsFS.
  542. *
  543. * Certain PhysicsFS functions return lists of information that are
  544. * dynamically allocated. Use this function to free those resources.
  545. *
  546. * It is safe to pass a NULL here, but doing so will cause a crash in versions
  547. * before PhysicsFS 2.1.0.
  548. *
  549. * \param listVar List of information specified as freeable by this function.
  550. * Passing NULL is safe; it is a valid no-op.
  551. *
  552. * \sa PHYSFS_getCdRomDirs
  553. * \sa PHYSFS_enumerateFiles
  554. * \sa PHYSFS_getSearchPath
  555. */
  556. PHYSFS_DECL void PHYSFS_freeList(void *listVar);
  557. /**
  558. * \fn const char *PHYSFS_getLastError(void)
  559. * \brief Get human-readable error information.
  560. *
  561. * \deprecated Use PHYSFS_getLastErrorCode() and PHYSFS_getErrorByCode() instead.
  562. *
  563. * \warning As of PhysicsFS 2.1, this function has been nerfed.
  564. * Before PhysicsFS 2.1, this function was the only way to get
  565. * error details beyond a given function's basic return value.
  566. * This was meant to be a human-readable string in one of several
  567. * languages, and was not useful for application parsing. This was
  568. * a problem, because the developer and not the user chose the
  569. * language at compile time, and the PhysicsFS maintainers had
  570. * to (poorly) maintain a significant amount of localization work.
  571. * The app couldn't parse the strings, even if they counted on a
  572. * specific language, since some were dynamically generated.
  573. * In 2.1 and later, this always returns a static string in
  574. * English; you may use it as a key string for your own
  575. * localizations if you like, as we'll promise not to change
  576. * existing error strings. Also, if your application wants to
  577. * look at specific errors, we now offer a better option:
  578. * use PHYSFS_getLastErrorCode() instead.
  579. *
  580. * Get the last PhysicsFS error message as a human-readable, null-terminated
  581. * string. This will return NULL if there's been no error since the last call
  582. * to this function. The pointer returned by this call points to an internal
  583. * buffer. Each thread has a unique error state associated with it, but each
  584. * time a new error message is set, it will overwrite the previous one
  585. * associated with that thread. It is safe to call this function at anytime,
  586. * even before PHYSFS_init().
  587. *
  588. * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same
  589. * thread-specific error state. Calling one will wipe out the other's
  590. * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that
  591. * value to PHYSFS_getErrorByCode().
  592. *
  593. * As of PhysicsFS 2.1, this function only presents text in the English
  594. * language, but the strings are static, so you can use them as keys into
  595. * your own localization dictionary. These strings are meant to be passed on
  596. * directly to the user.
  597. *
  598. * Generally, applications should only concern themselves with whether a
  599. * given function failed; however, if your code require more specifics, you
  600. * should use PHYSFS_getLastErrorCode() instead of this function.
  601. *
  602. * \return READ ONLY string of last error message.
  603. *
  604. * \sa PHYSFS_getLastErrorCode
  605. * \sa PHYSFS_getErrorByCode
  606. */
  607. PHYSFS_DECL const char *PHYSFS_getLastError(void) PHYSFS_DEPRECATED;
  608. /**
  609. * \fn const char *PHYSFS_getDirSeparator(void)
  610. * \brief Get platform-dependent dir separator string.
  611. *
  612. * This returns "\\" on win32, "/" on Unix, and ":" on MacOS. It may be more
  613. * than one character, depending on the platform, and your code should take
  614. * that into account. Note that this is only useful for setting up the
  615. * search/write paths, since access into those dirs always use '/'
  616. * (platform-independent notation) to separate directories. This is also
  617. * handy for getting platform-independent access when using stdio calls.
  618. *
  619. * \return READ ONLY null-terminated string of platform's dir separator.
  620. */
  621. PHYSFS_DECL const char *PHYSFS_getDirSeparator(void);
  622. /**
  623. * \fn void PHYSFS_permitSymbolicLinks(int allow)
  624. * \brief Enable or disable following of symbolic links.
  625. *
  626. * Some physical filesystems and archives contain files that are just pointers
  627. * to other files. On the physical filesystem, opening such a link will
  628. * (transparently) open the file that is pointed to.
  629. *
  630. * By default, PhysicsFS will check if a file is really a symlink during open
  631. * calls and fail if it is. Otherwise, the link could take you outside the
  632. * write and search paths, and compromise security.
  633. *
  634. * If you want to take that risk, call this function with a non-zero parameter.
  635. * Note that this is more for sandboxing a program's scripting language, in
  636. * case untrusted scripts try to compromise the system. Generally speaking,
  637. * a user could very well have a legitimate reason to set up a symlink, so
  638. * unless you feel there's a specific danger in allowing them, you should
  639. * permit them.
  640. *
  641. * Symlinks are only explicitly checked when dealing with filenames
  642. * in platform-independent notation. That is, when setting up your
  643. * search and write paths, etc, symlinks are never checked for.
  644. *
  645. * Please note that PHYSFS_stat() will always check the path specified; if
  646. * that path is a symlink, it will not be followed in any case. If symlinks
  647. * aren't permitted through this function, PHYSFS_stat() ignores them, and
  648. * would treat the query as if the path didn't exist at all.
  649. *
  650. * Symbolic link permission can be enabled or disabled at any time after
  651. * you've called PHYSFS_init(), and is disabled by default.
  652. *
  653. * \param allow nonzero to permit symlinks, zero to deny linking.
  654. *
  655. * \sa PHYSFS_symbolicLinksPermitted
  656. */
  657. PHYSFS_DECL void PHYSFS_permitSymbolicLinks(int allow);
  658. /**
  659. * \fn char **PHYSFS_getCdRomDirs(void)
  660. * \brief Get an array of paths to available CD-ROM drives.
  661. *
  662. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  663. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  664. * accessible in the drive. So if you've got two drives (D: and E:), and only
  665. * E: has a disc in it, then that's all you get. If the user inserts a disc
  666. * in D: and you call this function again, you get both drives. If, on a
  667. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  668. * call to this function will reflect that change.
  669. *
  670. * This function refers to "CD-ROM" media, but it really means "inserted disc
  671. * media," such as DVD-ROM, HD-DVD, CDRW, and Blu-Ray discs. It looks for
  672. * filesystems, and as such won't report an audio CD, unless there's a
  673. * mounted filesystem track on it.
  674. *
  675. * The returned value is an array of strings, with a NULL entry to signify the
  676. * end of the list:
  677. *
  678. * \code
  679. * char **cds = PHYSFS_getCdRomDirs();
  680. * char **i;
  681. *
  682. * for (i = cds; *i != NULL; i++)
  683. * printf("cdrom dir [%s] is available.\n", *i);
  684. *
  685. * PHYSFS_freeList(cds);
  686. * \endcode
  687. *
  688. * This call may block while drives spin up. Be forewarned.
  689. *
  690. * When you are done with the returned information, you may dispose of the
  691. * resources by calling PHYSFS_freeList() with the returned pointer.
  692. *
  693. * \return Null-terminated array of null-terminated strings.
  694. *
  695. * \sa PHYSFS_getCdRomDirsCallback
  696. */
  697. PHYSFS_DECL char **PHYSFS_getCdRomDirs(void);
  698. /**
  699. * \fn const char *PHYSFS_getBaseDir(void)
  700. * \brief Get the path where the application resides.
  701. *
  702. * Helper function.
  703. *
  704. * Get the "base dir". This is the directory where the application was run
  705. * from, which is probably the installation directory, and may or may not
  706. * be the process's current working directory.
  707. *
  708. * You should probably use the base dir in your search path.
  709. *
  710. * \return READ ONLY string of base dir in platform-dependent notation.
  711. *
  712. * \sa PHYSFS_getPrefDir
  713. */
  714. PHYSFS_DECL const char *PHYSFS_getBaseDir(void);
  715. /**
  716. * \fn const char *PHYSFS_getUserDir(void)
  717. * \brief Get the path where user's home directory resides.
  718. *
  719. * \deprecated As of PhysicsFS 2.1, you probably want PHYSFS_getPrefDir().
  720. *
  721. * Helper function.
  722. *
  723. * Get the "user dir". This is meant to be a suggestion of where a specific
  724. * user of the system can store files. On Unix, this is her home directory.
  725. * On systems with no concept of multiple home directories (MacOS, win95),
  726. * this will default to something like "C:\mybasedir\users\username"
  727. * where "username" will either be the login name, or "default" if the
  728. * platform doesn't support multiple users, either.
  729. *
  730. * \return READ ONLY string of user dir in platform-dependent notation.
  731. *
  732. * \sa PHYSFS_getBaseDir
  733. * \sa PHYSFS_getPrefDir
  734. */
  735. PHYSFS_DECL const char *PHYSFS_getUserDir(void) PHYSFS_DEPRECATED;
  736. /**
  737. * \fn const char *PHYSFS_getWriteDir(void)
  738. * \brief Get path where PhysicsFS will allow file writing.
  739. *
  740. * Get the current write dir. The default write dir is NULL.
  741. *
  742. * \return READ ONLY string of write dir in platform-dependent notation,
  743. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  744. *
  745. * \sa PHYSFS_setWriteDir
  746. */
  747. PHYSFS_DECL const char *PHYSFS_getWriteDir(void);
  748. /**
  749. * \fn int PHYSFS_setWriteDir(const char *newDir)
  750. * \brief Tell PhysicsFS where it may write files.
  751. *
  752. * Set a new write dir. This will override the previous setting.
  753. *
  754. * This call will fail (and fail to change the write dir) if the current
  755. * write dir still has files open in it.
  756. *
  757. * \param newDir The new directory to be the root of the write dir,
  758. * specified in platform-dependent notation. Setting to NULL
  759. * disables the write dir, so no files can be opened for
  760. * writing via PhysicsFS.
  761. * \return non-zero on success, zero on failure. All attempts to open a file
  762. * for writing via PhysicsFS will fail until this call succeeds.
  763. * Use PHYSFS_getLastErrorCode() to obtain the specific error.
  764. *
  765. * \sa PHYSFS_getWriteDir
  766. */
  767. PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
  768. /**
  769. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  770. * \brief Add an archive or directory to the search path.
  771. *
  772. * \deprecated As of PhysicsFS 2.0, use PHYSFS_mount() instead. This
  773. * function just wraps it anyhow.
  774. *
  775. * This function is equivalent to:
  776. *
  777. * \code
  778. * PHYSFS_mount(newDir, NULL, appendToPath);
  779. * \endcode
  780. *
  781. * You must use this and not PHYSFS_mount if binary compatibility with
  782. * PhysicsFS 1.0 is important (which it may not be for many people).
  783. *
  784. * \sa PHYSFS_mount
  785. * \sa PHYSFS_removeFromSearchPath
  786. * \sa PHYSFS_getSearchPath
  787. */
  788. PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  789. PHYSFS_DEPRECATED;
  790. /**
  791. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  792. * \brief Remove a directory or archive from the search path.
  793. *
  794. * \deprecated As of PhysicsFS 2.1, use PHYSFS_unmount() instead. This
  795. * function just wraps it anyhow. There's no functional difference
  796. * except the vocabulary changed from "adding to the search path"
  797. * to "mounting" when that functionality was extended, and thus
  798. * the preferred way to accomplish this function's work is now
  799. * called "unmounting."
  800. *
  801. * This function is equivalent to:
  802. *
  803. * \code
  804. * PHYSFS_unmount(oldDir);
  805. * \endcode
  806. *
  807. * You must use this and not PHYSFS_unmount if binary compatibility with
  808. * PhysicsFS 1.0 is important (which it may not be for many people).
  809. *
  810. * \sa PHYSFS_addToSearchPath
  811. * \sa PHYSFS_getSearchPath
  812. * \sa PHYSFS_unmount
  813. */
  814. PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir)
  815. PHYSFS_DEPRECATED;
  816. /**
  817. * \fn char **PHYSFS_getSearchPath(void)
  818. * \brief Get the current search path.
  819. *
  820. * The default search path is an empty list.
  821. *
  822. * The returned value is an array of strings, with a NULL entry to signify the
  823. * end of the list:
  824. *
  825. * \code
  826. * char **i;
  827. *
  828. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  829. * printf("[%s] is in the search path.\n", *i);
  830. * \endcode
  831. *
  832. * When you are done with the returned information, you may dispose of the
  833. * resources by calling PHYSFS_freeList() with the returned pointer.
  834. *
  835. * \return Null-terminated array of null-terminated strings. NULL if there
  836. * was a problem (read: OUT OF MEMORY).
  837. *
  838. * \sa PHYSFS_getSearchPathCallback
  839. * \sa PHYSFS_addToSearchPath
  840. * \sa PHYSFS_removeFromSearchPath
  841. */
  842. PHYSFS_DECL char **PHYSFS_getSearchPath(void);
  843. /**
  844. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  845. * \brief Set up sane, default paths.
  846. *
  847. * Helper function.
  848. *
  849. * The write dir will be set to the pref dir returned by
  850. * \code PHYSFS_getPrefDir(organization, appName) \endcode, which is
  851. * created if it doesn't exist.
  852. *
  853. * The above is sufficient to make sure your program's configuration directory
  854. * is separated from other clutter, and platform-independent.
  855. *
  856. * The search path will be:
  857. *
  858. * - The Write Dir (created if it doesn't exist)
  859. * - The Base Dir (PHYSFS_getBaseDir())
  860. * - All found CD-ROM dirs (optionally)
  861. *
  862. * These directories are then searched for files ending with the extension
  863. * (archiveExt), which, if they are valid and supported archives, will also
  864. * be added to the search path. If you specified "PKG" for (archiveExt), and
  865. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  866. * can either be appended or prepended to the search path in alphabetical
  867. * order, regardless of which directories they were found in. All archives
  868. * are mounted in the root of the virtual file system ("/").
  869. *
  870. * All of this can be accomplished from the application, but this just does it
  871. * all for you. Feel free to add more to the search path manually, too.
  872. *
  873. * \param organization Name of your company/group/etc to be used as a
  874. * dirname, so keep it small, and no-frills.
  875. *
  876. * \param appName Program-specific name of your program, to separate it
  877. * from other programs using PhysicsFS.
  878. *
  879. * \param archiveExt File extension used by your program to specify an
  880. * archive. For example, Quake 3 uses "pk3", even though
  881. * they are just zipfiles. Specify NULL to not dig out
  882. * archives automatically. Do not specify the '.' char;
  883. * If you want to look for ZIP files, specify "ZIP" and
  884. * not ".ZIP" ... the archive search is case-insensitive.
  885. *
  886. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  887. * (if (archiveExt) != NULL) search them for archives.
  888. * This may cause a significant amount of blocking
  889. * while discs are accessed, and if there are no discs
  890. * in the drive (or even not mounted on Unix systems),
  891. * then they may not be made available anyhow. You may
  892. * want to specify zero and handle the disc setup
  893. * yourself.
  894. *
  895. * \param archivesFirst Non-zero to prepend the archives to the search path.
  896. * Zero to append them. Ignored if !(archiveExt).
  897. *
  898. * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode()
  899. * to obtain the specific error.
  900. */
  901. PHYSFS_DECL int PHYSFS_setSaneConfig(const char *organization,
  902. const char *appName,
  903. const char *archiveExt,
  904. int includeCdRoms,
  905. int archivesFirst);
  906. /* Directory management stuff ... */
  907. /**
  908. * \fn int PHYSFS_mkdir(const char *dirName)
  909. * \brief Create a directory.
  910. *
  911. * This is specified in platform-independent notation in relation to the
  912. * write dir. All missing parent directories are also created if they
  913. * don't exist.
  914. *
  915. * So if you've got the write dir set to "C:\mygame\writedir" and call
  916. * PHYSFS_mkdir("downloads/maps") then the directories
  917. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  918. * will be created if possible. If the creation of "maps" fails after we
  919. * have successfully created "downloads", then the function leaves the
  920. * created directory behind and reports failure.
  921. *
  922. * \param dirName New dir to create.
  923. * \return nonzero on success, zero on error. Use
  924. * PHYSFS_getLastErrorCode() to obtain the specific error.
  925. *
  926. * \sa PHYSFS_delete
  927. */
  928. PHYSFS_DECL int PHYSFS_mkdir(const char *dirName);
  929. /**
  930. * \fn int PHYSFS_delete(const char *filename)
  931. * \brief Delete a file or directory.
  932. *
  933. * (filename) is specified in platform-independent notation in relation to the
  934. * write dir.
  935. *
  936. * A directory must be empty before this call can delete it.
  937. *
  938. * Deleting a symlink will remove the link, not what it points to, regardless
  939. * of whether you "permitSymLinks" or not.
  940. *
  941. * So if you've got the write dir set to "C:\mygame\writedir" and call
  942. * PHYSFS_delete("downloads/maps/level1.map") then the file
  943. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  944. * physical filesystem, if it exists and the operating system permits the
  945. * deletion.
  946. *
  947. * Note that on Unix systems, deleting a file may be successful, but the
  948. * actual file won't be removed until all processes that have an open
  949. * filehandle to it (including your program) close their handles.
  950. *
  951. * Chances are, the bits that make up the file still exist, they are just
  952. * made available to be written over at a later point. Don't consider this
  953. * a security method or anything. :)
  954. *
  955. * \param filename Filename to delete.
  956. * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode()
  957. * to obtain the specific error.
  958. */
  959. PHYSFS_DECL int PHYSFS_delete(const char *filename);
  960. /**
  961. * \fn const char *PHYSFS_getRealDir(const char *filename)
  962. * \brief Figure out where in the search path a file resides.
  963. *
  964. * The file is specified in platform-independent notation. The returned
  965. * filename will be the element of the search path where the file was found,
  966. * which may be a directory, or an archive. Even if there are multiple
  967. * matches in different parts of the search path, only the first one found
  968. * is used, just like when opening a file.
  969. *
  970. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  971. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  972. *
  973. * If a any part of a match is a symbolic link, and you've not explicitly
  974. * permitted symlinks, then it will be ignored, and the search for a match
  975. * will continue.
  976. *
  977. * If you specify a fake directory that only exists as a mount point, it'll
  978. * be associated with the first archive mounted there, even though that
  979. * directory isn't necessarily contained in a real archive.
  980. *
  981. * \warning This will return NULL if there is no real directory associated
  982. * with (filename). Specifically, PHYSFS_mountIo(),
  983. * PHYSFS_mountMemory(), and PHYSFS_mountHandle() will return NULL
  984. * even if the filename is found in the search path. Plan accordingly.
  985. *
  986. * \param filename file to look for.
  987. * \return READ ONLY string of element of search path containing the
  988. * the file in question. NULL if not found.
  989. */
  990. PHYSFS_DECL const char *PHYSFS_getRealDir(const char *filename);
  991. /**
  992. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  993. * \brief Get a file listing of a search path's directory.
  994. *
  995. * \warning In PhysicsFS versions prior to 2.1, this function would return
  996. * as many items as it could in the face of a failure condition
  997. * (out of memory, disk i/o error, etc). Since this meant apps
  998. * couldn't distinguish between complete success and partial failure,
  999. * and since the function could always return NULL to report
  1000. * catastrophic failures anyway, in PhysicsFS 2.1 this function's
  1001. * policy changed: it will either return a list of complete results
  1002. * or it will return NULL for any failure of any kind, so we can
  1003. * guarantee that the enumeration ran to completion and has no gaps
  1004. * in its results.
  1005. *
  1006. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  1007. * search path and contains a directory "savegames" that contains "x.sav",
  1008. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  1009. * that has a "savegames" subdirectory with "w.sav", then the following code:
  1010. *
  1011. * \code
  1012. * char **rc = PHYSFS_enumerateFiles("savegames");
  1013. * char **i;
  1014. *
  1015. * for (i = rc; *i != NULL; i++)
  1016. * printf(" * We've got [%s].\n", *i);
  1017. *
  1018. * PHYSFS_freeList(rc);
  1019. * \endcode
  1020. *
  1021. * \...will print:
  1022. *
  1023. * \verbatim
  1024. * We've got [x.sav].
  1025. * We've got [y.sav].
  1026. * We've got [z.sav].
  1027. * We've got [w.sav].\endverbatim
  1028. *
  1029. * Feel free to sort the list however you like. However, the returned data
  1030. * will always contain no duplicates, and will be always sorted in alphabetic
  1031. * (rather: case-sensitive Unicode) order for you.
  1032. *
  1033. * Don't forget to call PHYSFS_freeList() with the return value from this
  1034. * function when you are done with it.
  1035. *
  1036. * \param dir directory in platform-independent notation to enumerate.
  1037. * \return Null-terminated array of null-terminated strings, or NULL for
  1038. * failure cases.
  1039. *
  1040. * \sa PHYSFS_enumerate
  1041. */
  1042. PHYSFS_DECL char **PHYSFS_enumerateFiles(const char *dir);
  1043. /**
  1044. * \fn int PHYSFS_exists(const char *fname)
  1045. * \brief Determine if a file exists in the search path.
  1046. *
  1047. * Reports true if there is an entry anywhere in the search path by the
  1048. * name of (fname).
  1049. *
  1050. * Note that entries that are symlinks are ignored if
  1051. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  1052. * might end up further down in the search path than expected.
  1053. *
  1054. * \param fname filename in platform-independent notation.
  1055. * \return non-zero if filename exists. zero otherwise.
  1056. */
  1057. PHYSFS_DECL int PHYSFS_exists(const char *fname);
  1058. /**
  1059. * \fn int PHYSFS_isDirectory(const char *fname)
  1060. * \brief Determine if a file in the search path is really a directory.
  1061. *
  1062. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1063. * function just wraps it anyhow.
  1064. *
  1065. * Determine if the first occurence of (fname) in the search path is
  1066. * really a directory entry.
  1067. *
  1068. * Note that entries that are symlinks are ignored if
  1069. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  1070. * might end up further down in the search path than expected.
  1071. *
  1072. * \param fname filename in platform-independent notation.
  1073. * \return non-zero if filename exists and is a directory. zero otherwise.
  1074. *
  1075. * \sa PHYSFS_stat
  1076. * \sa PHYSFS_exists
  1077. */
  1078. PHYSFS_DECL int PHYSFS_isDirectory(const char *fname) PHYSFS_DEPRECATED;
  1079. /**
  1080. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  1081. * \brief Determine if a file in the search path is really a symbolic link.
  1082. *
  1083. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1084. * function just wraps it anyhow.
  1085. *
  1086. * Determine if the first occurence of (fname) in the search path is
  1087. * really a symbolic link.
  1088. *
  1089. * Note that entries that are symlinks are ignored if
  1090. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  1091. * this function will always return 0 in that case.
  1092. *
  1093. * \param fname filename in platform-independent notation.
  1094. * \return non-zero if filename exists and is a symlink. zero otherwise.
  1095. *
  1096. * \sa PHYSFS_stat
  1097. * \sa PHYSFS_exists
  1098. */
  1099. PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname) PHYSFS_DEPRECATED;
  1100. /**
  1101. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1102. * \brief Get the last modification time of a file.
  1103. *
  1104. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1105. * function just wraps it anyhow.
  1106. *
  1107. * The modtime is returned as a number of seconds since the Unix epoch
  1108. * (midnight, Jan 1, 1970). The exact derivation and accuracy of this time
  1109. * depends on the particular archiver. If there is no reasonable way to
  1110. * obtain this information for a particular archiver, or there was some sort
  1111. * of error, this function returns (-1).
  1112. *
  1113. * You must use this and not PHYSFS_stat() if binary compatibility with
  1114. * PhysicsFS 2.0 is important (which it may not be for many people).
  1115. *
  1116. * \param filename filename to check, in platform-independent notation.
  1117. * \return last modified time of the file. -1 if it can't be determined.
  1118. *
  1119. * \sa PHYSFS_stat
  1120. */
  1121. PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1122. PHYSFS_DEPRECATED;
  1123. /* i/o stuff... */
  1124. /**
  1125. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  1126. * \brief Open a file for writing.
  1127. *
  1128. * Open a file for writing, in platform-independent notation and in relation
  1129. * to the write dir as the root of the writable filesystem. The specified
  1130. * file is created if it doesn't exist. If it does exist, it is truncated to
  1131. * zero bytes, and the writing offset is set to the start.
  1132. *
  1133. * Note that entries that are symlinks are ignored if
  1134. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1135. * symlink with this function will fail in such a case.
  1136. *
  1137. * \param filename File to open.
  1138. * \return A valid PhysicsFS filehandle on success, NULL on error. Use
  1139. * PHYSFS_getLastErrorCode() to obtain the specific error.
  1140. *
  1141. * \sa PHYSFS_openRead
  1142. * \sa PHYSFS_openAppend
  1143. * \sa PHYSFS_write
  1144. * \sa PHYSFS_close
  1145. */
  1146. PHYSFS_DECL PHYSFS_File *PHYSFS_openWrite(const char *filename);
  1147. /**
  1148. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  1149. * \brief Open a file for appending.
  1150. *
  1151. * Open a file for writing, in platform-independent notation and in relation
  1152. * to the write dir as the root of the writable filesystem. The specified
  1153. * file is created if it doesn't exist. If it does exist, the writing offset
  1154. * is set to the end of the file, so the first write will be the byte after
  1155. * the end.
  1156. *
  1157. * Note that entries that are symlinks are ignored if
  1158. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1159. * symlink with this function will fail in such a case.
  1160. *
  1161. * \param filename File to open.
  1162. * \return A valid PhysicsFS filehandle on success, NULL on error. Use
  1163. * PHYSFS_getLastErrorCode() to obtain the specific error.
  1164. *
  1165. * \sa PHYSFS_openRead
  1166. * \sa PHYSFS_openWrite
  1167. * \sa PHYSFS_write
  1168. * \sa PHYSFS_close
  1169. */
  1170. PHYSFS_DECL PHYSFS_File *PHYSFS_openAppend(const char *filename);
  1171. /**
  1172. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  1173. * \brief Open a file for reading.
  1174. *
  1175. * Open a file for reading, in platform-independent notation. The search path
  1176. * is checked one at a time until a matching file is found, in which case an
  1177. * abstract filehandle is associated with it, and reading may be done.
  1178. * The reading offset is set to the first byte of the file.
  1179. *
  1180. * Note that entries that are symlinks are ignored if
  1181. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1182. * symlink with this function will fail in such a case.
  1183. *
  1184. * \param filename File to open.
  1185. * \return A valid PhysicsFS filehandle on success, NULL on error.
  1186. * Use PHYSFS_getLastErrorCode() to obtain the specific error.
  1187. *
  1188. * \sa PHYSFS_openWrite
  1189. * \sa PHYSFS_openAppend
  1190. * \sa PHYSFS_read
  1191. * \sa PHYSFS_close
  1192. */
  1193. PHYSFS_DECL PHYSFS_File *PHYSFS_openRead(const char *filename);
  1194. /**
  1195. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1196. * \brief Close a PhysicsFS filehandle.
  1197. *
  1198. * This call is capable of failing if the operating system was buffering
  1199. * writes to the physical media, and, now forced to write those changes to
  1200. * physical media, can not store the data for some reason. In such a case,
  1201. * the filehandle stays open. A well-written program should ALWAYS check the
  1202. * return value from the close call in addition to every writing call!
  1203. *
  1204. * \param handle handle returned from PHYSFS_open*().
  1205. * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode()
  1206. * to obtain the specific error.
  1207. *
  1208. * \sa PHYSFS_openRead
  1209. * \sa PHYSFS_openWrite
  1210. * \sa PHYSFS_openAppend
  1211. */
  1212. PHYSFS_DECL int PHYSFS_close(PHYSFS_File *handle);
  1213. /**
  1214. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1215. * \brief Read data from a PhysicsFS filehandle
  1216. *
  1217. * The file must be opened for reading.
  1218. *
  1219. * \deprecated As of PhysicsFS 2.1, use PHYSFS_readBytes() instead. This
  1220. * function just wraps it anyhow. This function never clarified
  1221. * what would happen if you managed to read a partial object, so
  1222. * working at the byte level makes this cleaner for everyone,
  1223. * especially now that PHYSFS_Io interfaces can be supplied by the
  1224. * application.
  1225. *
  1226. * \param handle handle returned from PHYSFS_openRead().
  1227. * \param buffer buffer to store read data into.
  1228. * \param objSize size in bytes of objects being read from (handle).
  1229. * \param objCount number of (objSize) objects to read from (handle).
  1230. * \return number of objects read. PHYSFS_getLastErrorCode() can shed light
  1231. * on the reason this might be < (objCount), as can PHYSFS_eof().
  1232. * -1 if complete failure.
  1233. *
  1234. * \sa PHYSFS_readBytes
  1235. * \sa PHYSFS_eof
  1236. */
  1237. PHYSFS_DECL PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1238. void *buffer,
  1239. PHYSFS_uint32 objSize,
  1240. PHYSFS_uint32 objCount)
  1241. PHYSFS_DEPRECATED;
  1242. /**
  1243. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1244. * \brief Write data to a PhysicsFS filehandle
  1245. *
  1246. * The file must be opened for writing.
  1247. *
  1248. * \deprecated As of PhysicsFS 2.1, use PHYSFS_writeBytes() instead. This
  1249. * function just wraps it anyhow. This function never clarified
  1250. * what would happen if you managed to write a partial object, so
  1251. * working at the byte level makes this cleaner for everyone,
  1252. * especially now that PHYSFS_Io interfaces can be supplied by the
  1253. * application.
  1254. *
  1255. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1256. * \param buffer buffer of bytes to write to (handle).
  1257. * \param objSize size in bytes of objects being written to (handle).
  1258. * \param objCount number of (objSize) objects to write to (handle).
  1259. * \return number of objects written. PHYSFS_getLastErrorCode() can shed
  1260. * light on the reason this might be < (objCount). -1 if complete
  1261. * failure.
  1262. *
  1263. * \sa PHYSFS_writeBytes
  1264. */
  1265. PHYSFS_DECL PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1266. const void *buffer,
  1267. PHYSFS_uint32 objSize,
  1268. PHYSFS_uint32 objCount)
  1269. PHYSFS_DEPRECATED;
  1270. /* File position stuff... */
  1271. /**
  1272. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1273. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1274. *
  1275. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1276. *
  1277. * \param handle handle returned from PHYSFS_openRead().
  1278. * \return nonzero if EOF, zero if not.
  1279. *
  1280. * \sa PHYSFS_read
  1281. * \sa PHYSFS_tell
  1282. */
  1283. PHYSFS_DECL int PHYSFS_eof(PHYSFS_File *handle);
  1284. /**
  1285. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1286. * \brief Determine current position within a PhysicsFS filehandle.
  1287. *
  1288. * \param handle handle returned from PHYSFS_open*().
  1289. * \return offset in bytes from start of file. -1 if error occurred.
  1290. * Use PHYSFS_getLastErrorCode() to obtain the specific error.
  1291. *
  1292. * \sa PHYSFS_seek
  1293. */
  1294. PHYSFS_DECL PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1295. /**
  1296. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1297. * \brief Seek to a new position within a PhysicsFS filehandle.
  1298. *
  1299. * The next read or write will occur at that place. Seeking past the
  1300. * beginning or end of the file is not allowed, and causes an error.
  1301. *
  1302. * \param handle handle returned from PHYSFS_open*().
  1303. * \param pos number of bytes from start of file to seek to.
  1304. * \return nonzero on success, zero on error. Use PHYSFS_getLastErrorCode()
  1305. * to obtain the specific error.
  1306. *
  1307. * \sa PHYSFS_tell
  1308. */
  1309. PHYSFS_DECL int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1310. /**
  1311. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1312. * \brief Get total length of a file in bytes.
  1313. *
  1314. * Note that if another process/thread is writing to this file at the same
  1315. * time, then the information this function supplies could be incorrect
  1316. * before you get it. Use with caution, or better yet, don't use at all.
  1317. *
  1318. * \param handle handle returned from PHYSFS_open*().
  1319. * \return size in bytes of the file. -1 if can't be determined.
  1320. *
  1321. * \sa PHYSFS_tell
  1322. * \sa PHYSFS_seek
  1323. */
  1324. PHYSFS_DECL PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1325. /* Buffering stuff... */
  1326. /**
  1327. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1328. * \brief Set up buffering for a PhysicsFS file handle.
  1329. *
  1330. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1331. * will be allocated and associated with (handle).
  1332. *
  1333. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1334. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1335. * from this buffer until it is empty, and then refill it for more reading.
  1336. * Note that compressed files, like ZIP archives, will decompress while
  1337. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1338. * The buffer isn't filled until you do your next read.
  1339. *
  1340. * For files opened for writing, data will be buffered to memory until the
  1341. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1342. * causes a flush...check your return values!
  1343. *
  1344. * Seeking, etc transparently accounts for buffering.
  1345. *
  1346. * You can resize an existing buffer by calling this function more than once
  1347. * on the same file. Setting the buffer size to zero will free an existing
  1348. * buffer.
  1349. *
  1350. * PhysicsFS file handles are unbuffered by default.
  1351. *
  1352. * Please check the return value of this function! Failures can include
  1353. * not being able to seek backwards in a read-only file when removing the
  1354. * buffer, not being able to allocate the buffer, and not being able to
  1355. * flush the buffer to disk, among other unexpected problems.
  1356. *
  1357. * \param handle handle returned from PHYSFS_open*().
  1358. * \param bufsize size, in bytes, of buffer to allocate.
  1359. * \return nonzero if successful, zero on error.
  1360. *
  1361. * \sa PHYSFS_flush
  1362. * \sa PHYSFS_read
  1363. * \sa PHYSFS_write
  1364. * \sa PHYSFS_close
  1365. */
  1366. PHYSFS_DECL int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1367. /**
  1368. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1369. * \brief Flush a buffered PhysicsFS file handle.
  1370. *
  1371. * For buffered files opened for writing, this will put the current contents
  1372. * of the buffer to disk and flag the buffer as empty if possible.
  1373. *
  1374. * For buffered files opened for reading or unbuffered files, this is a safe
  1375. * no-op, and will report success.
  1376. *
  1377. * \param handle handle returned from PHYSFS_open*().
  1378. * \return nonzero if successful, zero on error.
  1379. *
  1380. * \sa PHYSFS_setBuffer
  1381. * \sa PHYSFS_close
  1382. */
  1383. PHYSFS_DECL int PHYSFS_flush(PHYSFS_File *handle);
  1384. /* Byteorder stuff... */
  1385. /**
  1386. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1387. * \brief Swap littleendian signed 16 to platform's native byte order.
  1388. *
  1389. * Take a 16-bit signed value in littleendian format and convert it to
  1390. * the platform's native byte order.
  1391. *
  1392. * \param val value to convert
  1393. * \return converted value.
  1394. */
  1395. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1396. /**
  1397. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1398. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1399. *
  1400. * Take a 16-bit unsigned value in littleendian format and convert it to
  1401. * the platform's native byte order.
  1402. *
  1403. * \param val value to convert
  1404. * \return converted value.
  1405. */
  1406. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1407. /**
  1408. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1409. * \brief Swap littleendian signed 32 to platform's native byte order.
  1410. *
  1411. * Take a 32-bit signed value in littleendian format and convert it to
  1412. * the platform's native byte order.
  1413. *
  1414. * \param val value to convert
  1415. * \return converted value.
  1416. */
  1417. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1418. /**
  1419. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1420. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1421. *
  1422. * Take a 32-bit unsigned value in littleendian format and convert it to
  1423. * the platform's native byte order.
  1424. *
  1425. * \param val value to convert
  1426. * \return converted value.
  1427. */
  1428. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1429. /**
  1430. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1431. * \brief Swap littleendian signed 64 to platform's native byte order.
  1432. *
  1433. * Take a 64-bit signed value in littleendian format and convert it to
  1434. * the platform's native byte order.
  1435. *
  1436. * \param val value to convert
  1437. * \return converted value.
  1438. *
  1439. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1440. * any sort of 64-bit support.
  1441. */
  1442. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1443. /**
  1444. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1445. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1446. *
  1447. * Take a 64-bit unsigned value in littleendian format and convert it to
  1448. * the platform's native byte order.
  1449. *
  1450. * \param val value to convert
  1451. * \return converted value.
  1452. *
  1453. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1454. * any sort of 64-bit support.
  1455. */
  1456. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1457. /**
  1458. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1459. * \brief Swap bigendian signed 16 to platform's native byte order.
  1460. *
  1461. * Take a 16-bit signed value in bigendian format and convert it to
  1462. * the platform's native byte order.
  1463. *
  1464. * \param val value to convert
  1465. * \return converted value.
  1466. */
  1467. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1468. /**
  1469. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1470. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1471. *
  1472. * Take a 16-bit unsigned value in bigendian format and convert it to
  1473. * the platform's native byte order.
  1474. *
  1475. * \param val value to convert
  1476. * \return converted value.
  1477. */
  1478. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1479. /**
  1480. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1481. * \brief Swap bigendian signed 32 to platform's native byte order.
  1482. *
  1483. * Take a 32-bit signed value in bigendian format and convert it to
  1484. * the platform's native byte order.
  1485. *
  1486. * \param val value to convert
  1487. * \return converted value.
  1488. */
  1489. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1490. /**
  1491. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1492. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1493. *
  1494. * Take a 32-bit unsigned value in bigendian format and convert it to
  1495. * the platform's native byte order.
  1496. *
  1497. * \param val value to convert
  1498. * \return converted value.
  1499. */
  1500. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1501. /**
  1502. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1503. * \brief Swap bigendian signed 64 to platform's native byte order.
  1504. *
  1505. * Take a 64-bit signed value in bigendian format and convert it to
  1506. * the platform's native byte order.
  1507. *
  1508. * \param val value to convert
  1509. * \return converted value.
  1510. *
  1511. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1512. * any sort of 64-bit support.
  1513. */
  1514. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1515. /**
  1516. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1517. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1518. *
  1519. * Take a 64-bit unsigned value in bigendian format and convert it to
  1520. * the platform's native byte order.
  1521. *
  1522. * \param val value to convert
  1523. * \return converted value.
  1524. *
  1525. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1526. * any sort of 64-bit support.
  1527. */
  1528. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1529. /**
  1530. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1531. * \brief Read and convert a signed 16-bit littleendian value.
  1532. *
  1533. * Convenience function. Read a signed 16-bit littleendian value from a
  1534. * file and convert it to the platform's native byte order.
  1535. *
  1536. * \param file PhysicsFS file handle from which to read.
  1537. * \param val pointer to where value should be stored.
  1538. * \return zero on failure, non-zero on success. If successful, (*val) will
  1539. * store the result. On failure, you can find out what went wrong
  1540. * from PHYSFS_getLastErrorCode().
  1541. */
  1542. PHYSFS_DECL int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1543. /**
  1544. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1545. * \brief Read and convert an unsigned 16-bit littleendian value.
  1546. *
  1547. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1548. * file and convert it to the platform's native byte order.
  1549. *
  1550. * \param file PhysicsFS file handle from which to read.
  1551. * \param val pointer to where value should be stored.
  1552. * \return zero on failure, non-zero on success. If successful, (*val) will
  1553. * store the result. On failure, you can find out what went wrong
  1554. * from PHYSFS_getLastErrorCode().
  1555. *
  1556. */
  1557. PHYSFS_DECL int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1558. /**
  1559. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1560. * \brief Read and convert a signed 16-bit bigendian value.
  1561. *
  1562. * Convenience function. Read a signed 16-bit bigendian value from a
  1563. * file and convert it to the platform's native byte order.
  1564. *
  1565. * \param file PhysicsFS file handle from which to read.
  1566. * \param val pointer to where value should be stored.
  1567. * \return zero on failure, non-zero on success. If successful, (*val) will
  1568. * store the result. On failure, you can find out what went wrong
  1569. * from PHYSFS_getLastErrorCode().
  1570. */
  1571. PHYSFS_DECL int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1572. /**
  1573. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1574. * \brief Read and convert an unsigned 16-bit bigendian value.
  1575. *
  1576. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1577. * file and convert it to the platform's native byte order.
  1578. *
  1579. * \param file PhysicsFS file handle from which to read.
  1580. * \param val pointer to where value should be stored.
  1581. * \return zero on failure, non-zero on success. If successful, (*val) will
  1582. * store the result. On failure, you can find out what went wrong
  1583. * from PHYSFS_getLastErrorCode().
  1584. *
  1585. */
  1586. PHYSFS_DECL int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1587. /**
  1588. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1589. * \brief Read and convert a signed 32-bit littleendian value.
  1590. *
  1591. * Convenience function. Read a signed 32-bit littleendian value from a
  1592. * file and convert it to the platform's native byte order.
  1593. *
  1594. * \param file PhysicsFS file handle from which to read.
  1595. * \param val pointer to where value should be stored.
  1596. * \return zero on failure, non-zero on success. If successful, (*val) will
  1597. * store the result. On failure, you can find out what went wrong
  1598. * from PHYSFS_getLastErrorCode().
  1599. */
  1600. PHYSFS_DECL int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1601. /**
  1602. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1603. * \brief Read and convert an unsigned 32-bit littleendian value.
  1604. *
  1605. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1606. * file and convert it to the platform's native byte order.
  1607. *
  1608. * \param file PhysicsFS file handle from which to read.
  1609. * \param val pointer to where value should be stored.
  1610. * \return zero on failure, non-zero on success. If successful, (*val) will
  1611. * store the result. On failure, you can find out what went wrong
  1612. * from PHYSFS_getLastErrorCode().
  1613. *
  1614. */
  1615. PHYSFS_DECL int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1616. /**
  1617. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1618. * \brief Read and convert a signed 32-bit bigendian value.
  1619. *
  1620. * Convenience function. Read a signed 32-bit bigendian value from a
  1621. * file and convert it to the platform's native byte order.
  1622. *
  1623. * \param file PhysicsFS file handle from which to read.
  1624. * \param val pointer to where value should be stored.
  1625. * \return zero on failure, non-zero on success. If successful, (*val) will
  1626. * store the result. On failure, you can find out what went wrong
  1627. * from PHYSFS_getLastErrorCode().
  1628. */
  1629. PHYSFS_DECL int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1630. /**
  1631. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1632. * \brief Read and convert an unsigned 32-bit bigendian value.
  1633. *
  1634. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1635. * file and convert it to the platform's native byte order.
  1636. *
  1637. * \param file PhysicsFS file handle from which to read.
  1638. * \param val pointer to where value should be stored.
  1639. * \return zero on failure, non-zero on success. If successful, (*val) will
  1640. * store the result. On failure, you can find out what went wrong
  1641. * from PHYSFS_getLastErrorCode().
  1642. *
  1643. */
  1644. PHYSFS_DECL int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1645. /**
  1646. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1647. * \brief Read and convert a signed 64-bit littleendian value.
  1648. *
  1649. * Convenience function. Read a signed 64-bit littleendian value from a
  1650. * file and convert it to the platform's native byte order.
  1651. *
  1652. * \param file PhysicsFS file handle from which to read.
  1653. * \param val pointer to where value should be stored.
  1654. * \return zero on failure, non-zero on success. If successful, (*val) will
  1655. * store the result. On failure, you can find out what went wrong
  1656. * from PHYSFS_getLastErrorCode().
  1657. *
  1658. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1659. * any sort of 64-bit support.
  1660. */
  1661. PHYSFS_DECL int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1662. /**
  1663. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1664. * \brief Read and convert an unsigned 64-bit littleendian value.
  1665. *
  1666. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1667. * file and convert it to the platform's native byte order.
  1668. *
  1669. * \param file PhysicsFS file handle from which to read.
  1670. * \param val pointer to where value should be stored.
  1671. * \return zero on failure, non-zero on success. If successful, (*val) will
  1672. * store the result. On failure, you can find out what went wrong
  1673. * from PHYSFS_getLastErrorCode().
  1674. *
  1675. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1676. * any sort of 64-bit support.
  1677. */
  1678. PHYSFS_DECL int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1679. /**
  1680. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1681. * \brief Read and convert a signed 64-bit bigendian value.
  1682. *
  1683. * Convenience function. Read a signed 64-bit bigendian value from a
  1684. * file and convert it to the platform's native byte order.
  1685. *
  1686. * \param file PhysicsFS file handle from which to read.
  1687. * \param val pointer to where value should be stored.
  1688. * \return zero on failure, non-zero on success. If successful, (*val) will
  1689. * store the result. On failure, you can find out what went wrong
  1690. * from PHYSFS_getLastErrorCode().
  1691. *
  1692. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1693. * any sort of 64-bit support.
  1694. */
  1695. PHYSFS_DECL int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1696. /**
  1697. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1698. * \brief Read and convert an unsigned 64-bit bigendian value.
  1699. *
  1700. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1701. * file and convert it to the platform's native byte order.
  1702. *
  1703. * \param file PhysicsFS file handle from which to read.
  1704. * \param val pointer to where value should be stored.
  1705. * \return zero on failure, non-zero on success. If successful, (*val) will
  1706. * store the result. On failure, you can find out what went wrong
  1707. * from PHYSFS_getLastErrorCode().
  1708. *
  1709. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1710. * any sort of 64-bit support.
  1711. */
  1712. PHYSFS_DECL int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1713. /**
  1714. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1715. * \brief Convert and write a signed 16-bit littleendian value.
  1716. *
  1717. * Convenience function. Convert a signed 16-bit value from the platform's
  1718. * native byte order to littleendian and write it to a file.
  1719. *
  1720. * \param file PhysicsFS file handle to which to write.
  1721. * \param val Value to convert and write.
  1722. * \return zero on failure, non-zero on success. On failure, you can
  1723. * find out what went wrong from PHYSFS_getLastErrorCode().
  1724. */
  1725. PHYSFS_DECL int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1726. /**
  1727. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1728. * \brief Convert and write an unsigned 16-bit littleendian value.
  1729. *
  1730. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1731. * native byte order to littleendian and write it to a file.
  1732. *
  1733. * \param file PhysicsFS file handle to which to write.
  1734. * \param val Value to convert and write.
  1735. * \return zero on failure, non-zero on success. On failure, you can
  1736. * find out what went wrong from PHYSFS_getLastErrorCode().
  1737. */
  1738. PHYSFS_DECL int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1739. /**
  1740. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1741. * \brief Convert and write a signed 16-bit bigendian value.
  1742. *
  1743. * Convenience function. Convert a signed 16-bit value from the platform's
  1744. * native byte order to bigendian and write it to a file.
  1745. *
  1746. * \param file PhysicsFS file handle to which to write.
  1747. * \param val Value to convert and write.
  1748. * \return zero on failure, non-zero on success. On failure, you can
  1749. * find out what went wrong from PHYSFS_getLastErrorCode().
  1750. */
  1751. PHYSFS_DECL int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1752. /**
  1753. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1754. * \brief Convert and write an unsigned 16-bit bigendian value.
  1755. *
  1756. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1757. * native byte order to bigendian and write it to a file.
  1758. *
  1759. * \param file PhysicsFS file handle to which to write.
  1760. * \param val Value to convert and write.
  1761. * \return zero on failure, non-zero on success. On failure, you can
  1762. * find out what went wrong from PHYSFS_getLastErrorCode().
  1763. */
  1764. PHYSFS_DECL int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1765. /**
  1766. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1767. * \brief Convert and write a signed 32-bit littleendian value.
  1768. *
  1769. * Convenience function. Convert a signed 32-bit value from the platform's
  1770. * native byte order to littleendian and write it to a file.
  1771. *
  1772. * \param file PhysicsFS file handle to which to write.
  1773. * \param val Value to convert and write.
  1774. * \return zero on failure, non-zero on success. On failure, you can
  1775. * find out what went wrong from PHYSFS_getLastErrorCode().
  1776. */
  1777. PHYSFS_DECL int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1778. /**
  1779. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1780. * \brief Convert and write an unsigned 32-bit littleendian value.
  1781. *
  1782. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1783. * native byte order to littleendian and write it to a file.
  1784. *
  1785. * \param file PhysicsFS file handle to which to write.
  1786. * \param val Value to convert and write.
  1787. * \return zero on failure, non-zero on success. On failure, you can
  1788. * find out what went wrong from PHYSFS_getLastErrorCode().
  1789. */
  1790. PHYSFS_DECL int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1791. /**
  1792. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1793. * \brief Convert and write a signed 32-bit bigendian value.
  1794. *
  1795. * Convenience function. Convert a signed 32-bit value from the platform's
  1796. * native byte order to bigendian and write it to a file.
  1797. *
  1798. * \param file PhysicsFS file handle to which to write.
  1799. * \param val Value to convert and write.
  1800. * \return zero on failure, non-zero on success. On failure, you can
  1801. * find out what went wrong from PHYSFS_getLastErrorCode().
  1802. */
  1803. PHYSFS_DECL int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1804. /**
  1805. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1806. * \brief Convert and write an unsigned 32-bit bigendian value.
  1807. *
  1808. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1809. * native byte order to bigendian and write it to a file.
  1810. *
  1811. * \param file PhysicsFS file handle to which to write.
  1812. * \param val Value to convert and write.
  1813. * \return zero on failure, non-zero on success. On failure, you can
  1814. * find out what went wrong from PHYSFS_getLastErrorCode().
  1815. */
  1816. PHYSFS_DECL int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1817. /**
  1818. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1819. * \brief Convert and write a signed 64-bit littleendian value.
  1820. *
  1821. * Convenience function. Convert a signed 64-bit value from the platform's
  1822. * native byte order to littleendian and write it to a file.
  1823. *
  1824. * \param file PhysicsFS file handle to which to write.
  1825. * \param val Value to convert and write.
  1826. * \return zero on failure, non-zero on success. On failure, you can
  1827. * find out what went wrong from PHYSFS_getLastErrorCode().
  1828. *
  1829. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1830. * any sort of 64-bit support.
  1831. */
  1832. PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1833. /**
  1834. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1835. * \brief Convert and write an unsigned 64-bit littleendian value.
  1836. *
  1837. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1838. * native byte order to littleendian and write it to a file.
  1839. *
  1840. * \param file PhysicsFS file handle to which to write.
  1841. * \param val Value to convert and write.
  1842. * \return zero on failure, non-zero on success. On failure, you can
  1843. * find out what went wrong from PHYSFS_getLastErrorCode().
  1844. *
  1845. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1846. * any sort of 64-bit support.
  1847. */
  1848. PHYSFS_DECL int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1849. /**
  1850. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1851. * \brief Convert and write a signed 64-bit bigending value.
  1852. *
  1853. * Convenience function. Convert a signed 64-bit value from the platform's
  1854. * native byte order to bigendian and write it to a file.
  1855. *
  1856. * \param file PhysicsFS file handle to which to write.
  1857. * \param val Value to convert and write.
  1858. * \return zero on failure, non-zero on success. On failure, you can
  1859. * find out what went wrong from PHYSFS_getLastErrorCode().
  1860. *
  1861. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1862. * any sort of 64-bit support.
  1863. */
  1864. PHYSFS_DECL int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1865. /**
  1866. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1867. * \brief Convert and write an unsigned 64-bit bigendian value.
  1868. *
  1869. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1870. * native byte order to bigendian and write it to a file.
  1871. *
  1872. * \param file PhysicsFS file handle to which to write.
  1873. * \param val Value to convert and write.
  1874. * \return zero on failure, non-zero on success. On failure, you can
  1875. * find out what went wrong from PHYSFS_getLastErrorCode().
  1876. *
  1877. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1878. * any sort of 64-bit support.
  1879. */
  1880. PHYSFS_DECL int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1881. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1882. /**
  1883. * \fn int PHYSFS_isInit(void)
  1884. * \brief Determine if the PhysicsFS library is initialized.
  1885. *
  1886. * Once PHYSFS_init() returns successfully, this will return non-zero.
  1887. * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns
  1888. * successfully, this will return zero. This function is safe to call at
  1889. * any time.
  1890. *
  1891. * \return non-zero if library is initialized, zero if library is not.
  1892. *
  1893. * \sa PHYSFS_init
  1894. * \sa PHYSFS_deinit
  1895. */
  1896. PHYSFS_DECL int PHYSFS_isInit(void);
  1897. /**
  1898. * \fn int PHYSFS_symbolicLinksPermitted(void)
  1899. * \brief Determine if the symbolic links are permitted.
  1900. *
  1901. * This reports the setting from the last call to PHYSFS_permitSymbolicLinks().
  1902. * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was
  1903. * last initialized, symbolic links are implicitly disabled.
  1904. *
  1905. * \return non-zero if symlinks are permitted, zero if not.
  1906. *
  1907. * \sa PHYSFS_permitSymbolicLinks
  1908. */
  1909. PHYSFS_DECL int PHYSFS_symbolicLinksPermitted(void);
  1910. /**
  1911. * \struct PHYSFS_Allocator
  1912. * \brief PhysicsFS allocation function pointers.
  1913. *
  1914. * (This is for limited, hardcore use. If you don't immediately see a need
  1915. * for it, you can probably ignore this forever.)
  1916. *
  1917. * You create one of these structures for use with PHYSFS_setAllocator.
  1918. * Allocators are assumed to be reentrant by the caller; please mutex
  1919. * accordingly.
  1920. *
  1921. * Allocations are always discussed in 64-bits, for future expansion...we're
  1922. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1923. * gigabytes like it's nothing sooner or later, and I don't want to change
  1924. * this again at that point. If you're on a 32-bit platform and have to
  1925. * downcast, it's okay to return NULL if the allocation is greater than
  1926. * 4 gigabytes, since you'd have to do so anyhow.
  1927. *
  1928. * \sa PHYSFS_setAllocator
  1929. */
  1930. typedef struct PHYSFS_Allocator
  1931. {
  1932. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1933. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1934. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1935. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1936. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1937. } PHYSFS_Allocator;
  1938. /**
  1939. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1940. * \brief Hook your own allocation routines into PhysicsFS.
  1941. *
  1942. * (This is for limited, hardcore use. If you don't immediately see a need
  1943. * for it, you can probably ignore this forever.)
  1944. *
  1945. * By default, PhysicsFS will use whatever is reasonable for a platform
  1946. * to manage dynamic memory (usually ANSI C malloc/realloc/free, but
  1947. * some platforms might use something else), but in some uncommon cases, the
  1948. * app might want more control over the library's memory management. This
  1949. * lets you redirect PhysicsFS to use your own allocation routines instead.
  1950. * You can only call this function before PHYSFS_init(); if the library is
  1951. * initialized, it'll reject your efforts to change the allocator mid-stream.
  1952. * You may call this function after PHYSFS_deinit() if you are willing to
  1953. * shut down the library and restart it with a new allocator; this is a safe
  1954. * and supported operation. The allocator remains intact between deinit/init
  1955. * calls. If you want to return to the platform's default allocator, pass a
  1956. * NULL in here.
  1957. *
  1958. * If you aren't immediately sure what to do with this function, you can
  1959. * safely ignore it altogether.
  1960. *
  1961. * \param allocator Structure containing your allocator's entry points.
  1962. * \return zero on failure, non-zero on success. This call only fails
  1963. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1964. */
  1965. PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1966. /**
  1967. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
  1968. * \brief Add an archive or directory to the search path.
  1969. *
  1970. * If this is a duplicate, the entry is not added again, even though the
  1971. * function succeeds. You may not add the same archive to two different
  1972. * mountpoints: duplicate checking is done against the archive and not the
  1973. * mountpoint.
  1974. *
  1975. * When you mount an archive, it is added to a virtual file system...all files
  1976. * in all of the archives are interpolated into a single hierachical file
  1977. * tree. Two archives mounted at the same place (or an archive with files
  1978. * overlapping another mountpoint) may have overlapping files: in such a case,
  1979. * the file earliest in the search path is selected, and the other files are
  1980. * inaccessible to the application. This allows archives to be used to
  1981. * override previous revisions; you can use the mounting mechanism to place
  1982. * archives at a specific point in the file tree and prevent overlap; this
  1983. * is useful for downloadable mods that might trample over application data
  1984. * or each other, for example.
  1985. *
  1986. * The mountpoint does not need to exist prior to mounting, which is different
  1987. * than those familiar with the Unix concept of "mounting" may expect.
  1988. * As well, more than one archive can be mounted to the same mountpoint, or
  1989. * mountpoints and archive contents can overlap...the interpolation mechanism
  1990. * still functions as usual.
  1991. *
  1992. * Specifying a symbolic link to an archive or directory is allowed here,
  1993. * regardless of the state of PHYSFS_permitSymbolicLinks(). That function
  1994. * only deals with symlinks inside the mounted directory or archive.
  1995. *
  1996. * \param newDir directory or archive to add to the path, in
  1997. * platform-dependent notation.
  1998. * \param mountPoint Location in the interpolated tree that this archive
  1999. * will be "mounted", in platform-independent notation.
  2000. * NULL or "" is equivalent to "/".
  2001. * \param appendToPath nonzero to append to search path, zero to prepend.
  2002. * \return nonzero if added to path, zero on failure (bogus archive, dir
  2003. * missing, etc). Use PHYSFS_getLastErrorCode() to obtain
  2004. * the specific error.
  2005. *
  2006. * \sa PHYSFS_removeFromSearchPath
  2007. * \sa PHYSFS_getSearchPath
  2008. * \sa PHYSFS_getMountPoint
  2009. * \sa PHYSFS_mountIo
  2010. */
  2011. PHYSFS_DECL int PHYSFS_mount(const char *newDir,
  2012. const char *mountPoint,
  2013. int appendToPath);
  2014. /**
  2015. * \fn int PHYSFS_getMountPoint(const char *dir)
  2016. * \brief Determine a mounted archive's mountpoint.
  2017. *
  2018. * You give this function the name of an archive or dir you successfully
  2019. * added to the search path, and it reports the location in the interpolated
  2020. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  2021. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  2022. * and valid until the archive is removed from the search path.
  2023. *
  2024. * \param dir directory or archive previously added to the path, in
  2025. * platform-dependent notation. This must match the string
  2026. * used when adding, even if your string would also reference
  2027. * the same file with a different string of characters.
  2028. * \return READ-ONLY string of mount point if added to path, NULL on failure
  2029. * (bogus archive, etc). Use PHYSFS_getLastErrorCode() to obtain the
  2030. * specific error.
  2031. *
  2032. * \sa PHYSFS_removeFromSearchPath
  2033. * \sa PHYSFS_getSearchPath
  2034. * \sa PHYSFS_getMountPoint
  2035. */
  2036. PHYSFS_DECL const char *PHYSFS_getMountPoint(const char *dir);
  2037. /**
  2038. * \typedef PHYSFS_StringCallback
  2039. * \brief Function signature for callbacks that report strings.
  2040. *
  2041. * These are used to report a list of strings to an original caller, one
  2042. * string per callback. All strings are UTF-8 encoded. Functions should not
  2043. * try to modify or free the string's memory.
  2044. *
  2045. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  2046. * functions that would return lists that need to be cleaned up with
  2047. * PHYSFS_freeList(). The callback means that the library doesn't need to
  2048. * allocate an entire list and all the strings up front.
  2049. *
  2050. * Be aware that promises data ordering in the list versions are not
  2051. * necessarily so in the callback versions. Check the documentation on
  2052. * specific APIs, but strings may not be sorted as you expect.
  2053. *
  2054. * \param data User-defined data pointer, passed through from the API
  2055. * that eventually called the callback.
  2056. * \param str The string data about which the callback is meant to inform.
  2057. *
  2058. * \sa PHYSFS_getCdRomDirsCallback
  2059. * \sa PHYSFS_getSearchPathCallback
  2060. */
  2061. typedef void (*PHYSFS_StringCallback)(void *data, const char *str);
  2062. /**
  2063. * \typedef PHYSFS_EnumFilesCallback
  2064. * \brief Function signature for callbacks that enumerate files.
  2065. *
  2066. * \warning As of PhysicsFS 2.1, Use PHYSFS_EnumerateCallback with
  2067. * PHYSFS_enumerate() instead; it gives you more control over the process.
  2068. *
  2069. * These are used to report a list of directory entries to an original caller,
  2070. * one file/dir/symlink per callback. All strings are UTF-8 encoded.
  2071. * Functions should not try to modify or free any string's memory.
  2072. *
  2073. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  2074. * functions that would return lists that need to be cleaned up with
  2075. * PHYSFS_freeList(). The callback means that the library doesn't need to
  2076. * allocate an entire list and all the strings up front.
  2077. *
  2078. * Be aware that promised data ordering in the list versions are not
  2079. * necessarily so in the callback versions. Check the documentation on
  2080. * specific APIs, but strings may not be sorted as you expect and you might
  2081. * get duplicate strings.
  2082. *
  2083. * \param data User-defined data pointer, passed through from the API
  2084. * that eventually called the callback.
  2085. * \param origdir A string containing the full path, in platform-independent
  2086. * notation, of the directory containing this file. In most
  2087. * cases, this is the directory on which you requested
  2088. * enumeration, passed in the callback for your convenience.
  2089. * \param fname The filename that is being enumerated. It may not be in
  2090. * alphabetical order compared to other callbacks that have
  2091. * fired, and it will not contain the full path. You can
  2092. * recreate the fullpath with $origdir/$fname ... The file
  2093. * can be a subdirectory, a file, a symlink, etc.
  2094. *
  2095. * \sa PHYSFS_enumerateFilesCallback
  2096. */
  2097. typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir,
  2098. const char *fname);
  2099. /**
  2100. * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d)
  2101. * \brief Enumerate CD-ROM directories, using an application-defined callback.
  2102. *
  2103. * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds
  2104. * a list before returning to the application, so functionality is identical
  2105. * except for how the information is represented to the application.
  2106. *
  2107. * Unlike PHYSFS_getCdRomDirs(), this function does not return an array.
  2108. * Rather, it calls a function specified by the application once per
  2109. * detected disc:
  2110. *
  2111. * \code
  2112. *
  2113. * static void foundDisc(void *data, const char *cddir)
  2114. * {
  2115. * printf("cdrom dir [%s] is available.\n", cddir);
  2116. * }
  2117. *
  2118. * // ...
  2119. * PHYSFS_getCdRomDirsCallback(foundDisc, NULL);
  2120. * \endcode
  2121. *
  2122. * This call may block while drives spin up. Be forewarned.
  2123. *
  2124. * \param c Callback function to notify about detected drives.
  2125. * \param d Application-defined data passed to callback. Can be NULL.
  2126. *
  2127. * \sa PHYSFS_StringCallback
  2128. * \sa PHYSFS_getCdRomDirs
  2129. */
  2130. PHYSFS_DECL void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  2131. /**
  2132. * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d)
  2133. * \brief Enumerate the search path, using an application-defined callback.
  2134. *
  2135. * Internally, PHYSFS_getSearchPath() just calls this function and then builds
  2136. * a list before returning to the application, so functionality is identical
  2137. * except for how the information is represented to the application.
  2138. *
  2139. * Unlike PHYSFS_getSearchPath(), this function does not return an array.
  2140. * Rather, it calls a function specified by the application once per
  2141. * element of the search path:
  2142. *
  2143. * \code
  2144. *
  2145. * static void printSearchPath(void *data, const char *pathItem)
  2146. * {
  2147. * printf("[%s] is in the search path.\n", pathItem);
  2148. * }
  2149. *
  2150. * // ...
  2151. * PHYSFS_getSearchPathCallback(printSearchPath, NULL);
  2152. * \endcode
  2153. *
  2154. * Elements of the search path are reported in order search priority, so the
  2155. * first archive/dir that would be examined when looking for a file is the
  2156. * first element passed through the callback.
  2157. *
  2158. * \param c Callback function to notify about search path elements.
  2159. * \param d Application-defined data passed to callback. Can be NULL.
  2160. *
  2161. * \sa PHYSFS_StringCallback
  2162. * \sa PHYSFS_getSearchPath
  2163. */
  2164. PHYSFS_DECL void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  2165. /**
  2166. * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d)
  2167. * \brief Get a file listing of a search path's directory, using an application-defined callback.
  2168. *
  2169. * \deprecated As of PhysicsFS 2.1, use PHYSFS_enumerate() instead. This
  2170. * function has no way to report errors (or to have the callback signal an
  2171. * error or request a stop), so if data will be lost, your callback has no
  2172. * way to direct the process, and your calling app has no way to know.
  2173. *
  2174. * As of PhysicsFS 2.1, this function just wraps PHYSFS_enumerate() and
  2175. * ignores errors. Consider using PHYSFS_enumerate() or
  2176. * PHYSFS_enumerateFiles() instead.
  2177. *
  2178. * \sa PHYSFS_enumerate
  2179. * \sa PHYSFS_enumerateFiles
  2180. * \sa PHYSFS_EnumFilesCallback
  2181. */
  2182. PHYSFS_DECL void PHYSFS_enumerateFilesCallback(const char *dir,
  2183. PHYSFS_EnumFilesCallback c,
  2184. void *d) PHYSFS_DEPRECATED;
  2185. /**
  2186. * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
  2187. * \brief Convert a UCS-4 string to a UTF-8 string.
  2188. *
  2189. * \warning This function will not report an error if there are invalid UCS-4
  2190. * values in the source string. It will replace them with a '?'
  2191. * character and continue on.
  2192. *
  2193. * UCS-4 (aka UTF-32) strings are 32-bits per character: \c wchar_t on Unix.
  2194. *
  2195. * To ensure that the destination buffer is large enough for the conversion,
  2196. * please allocate a buffer that is the same size as the source buffer. UTF-8
  2197. * never uses more than 32-bits per character, so while it may shrink a UCS-4
  2198. * string, it will never expand it.
  2199. *
  2200. * Strings that don't fit in the destination buffer will be truncated, but
  2201. * will always be null-terminated and never have an incomplete UTF-8
  2202. * sequence at the end. If the buffer length is 0, this function does nothing.
  2203. *
  2204. * \param src Null-terminated source string in UCS-4 format.
  2205. * \param dst Buffer to store converted UTF-8 string.
  2206. * \param len Size, in bytes, of destination buffer.
  2207. */
  2208. PHYSFS_DECL void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst,
  2209. PHYSFS_uint64 len);
  2210. /**
  2211. * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
  2212. * \brief Convert a UTF-8 string to a UCS-4 string.
  2213. *
  2214. * \warning This function will not report an error if there are invalid UTF-8
  2215. * sequences in the source string. It will replace them with a '?'
  2216. * character and continue on.
  2217. *
  2218. * UCS-4 (aka UTF-32) strings are 32-bits per character: \c wchar_t on Unix.
  2219. *
  2220. * To ensure that the destination buffer is large enough for the conversion,
  2221. * please allocate a buffer that is four times the size of the source buffer.
  2222. * UTF-8 uses from one to four bytes per character, but UCS-4 always uses
  2223. * four, so an entirely low-ASCII string will quadruple in size!
  2224. *
  2225. * Strings that don't fit in the destination buffer will be truncated, but
  2226. * will always be null-terminated and never have an incomplete UCS-4
  2227. * sequence at the end. If the buffer length is 0, this function does nothing.
  2228. *
  2229. * \param src Null-terminated source string in UTF-8 format.
  2230. * \param dst Buffer to store converted UCS-4 string.
  2231. * \param len Size, in bytes, of destination buffer.
  2232. */
  2233. PHYSFS_DECL void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst,
  2234. PHYSFS_uint64 len);
  2235. /**
  2236. * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2237. * \brief Convert a UCS-2 string to a UTF-8 string.
  2238. *
  2239. * \warning you almost certainly should use PHYSFS_utf8FromUtf16(), which
  2240. * became available in PhysicsFS 2.1, unless you know what you're doing.
  2241. *
  2242. * \warning This function will not report an error if there are invalid UCS-2
  2243. * values in the source string. It will replace them with a '?'
  2244. * character and continue on.
  2245. *
  2246. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2247. * with Unicode support. Please note that modern versions of Windows use
  2248. * UTF-16, which is an extended form of UCS-2, and not UCS-2 itself. You
  2249. * almost certainly want PHYSFS_utf8FromUtf16() instead.
  2250. *
  2251. * To ensure that the destination buffer is large enough for the conversion,
  2252. * please allocate a buffer that is double the size of the source buffer.
  2253. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2254. * a UCS-2 string, it may also expand it.
  2255. *
  2256. * Strings that don't fit in the destination buffer will be truncated, but
  2257. * will always be null-terminated and never have an incomplete UTF-8
  2258. * sequence at the end. If the buffer length is 0, this function does nothing.
  2259. *
  2260. * \param src Null-terminated source string in UCS-2 format.
  2261. * \param dst Buffer to store converted UTF-8 string.
  2262. * \param len Size, in bytes, of destination buffer.
  2263. *
  2264. * \sa PHYSFS_utf8FromUtf16
  2265. */
  2266. PHYSFS_DECL void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst,
  2267. PHYSFS_uint64 len);
  2268. /**
  2269. * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2270. * \brief Convert a UTF-8 string to a UCS-2 string.
  2271. *
  2272. * \warning you almost certainly should use PHYSFS_utf8ToUtf16(), which
  2273. * became available in PhysicsFS 2.1, unless you know what you're doing.
  2274. *
  2275. * \warning This function will not report an error if there are invalid UTF-8
  2276. * sequences in the source string. It will replace them with a '?'
  2277. * character and continue on.
  2278. *
  2279. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2280. * with Unicode support. Please note that modern versions of Windows use
  2281. * UTF-16, which is an extended form of UCS-2, and not UCS-2 itself. You
  2282. * almost certainly want PHYSFS_utf8ToUtf16() instead, but you need to
  2283. * understand how that changes things, too.
  2284. *
  2285. * To ensure that the destination buffer is large enough for the conversion,
  2286. * please allocate a buffer that is double the size of the source buffer.
  2287. * UTF-8 uses from one to four bytes per character, but UCS-2 always uses
  2288. * two, so an entirely low-ASCII string will double in size!
  2289. *
  2290. * Strings that don't fit in the destination buffer will be truncated, but
  2291. * will always be null-terminated and never have an incomplete UCS-2
  2292. * sequence at the end. If the buffer length is 0, this function does nothing.
  2293. *
  2294. * \param src Null-terminated source string in UTF-8 format.
  2295. * \param dst Buffer to store converted UCS-2 string.
  2296. * \param len Size, in bytes, of destination buffer.
  2297. *
  2298. * \sa PHYSFS_utf8ToUtf16
  2299. */
  2300. PHYSFS_DECL void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst,
  2301. PHYSFS_uint64 len);
  2302. /**
  2303. * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
  2304. * \brief Convert a UTF-8 string to a Latin1 string.
  2305. *
  2306. * Latin1 strings are 8-bits per character: a popular "high ASCII" encoding.
  2307. *
  2308. * To ensure that the destination buffer is large enough for the conversion,
  2309. * please allocate a buffer that is double the size of the source buffer.
  2310. * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string
  2311. * may grow in some cases.
  2312. *
  2313. * Strings that don't fit in the destination buffer will be truncated, but
  2314. * will always be null-terminated and never have an incomplete UTF-8
  2315. * sequence at the end. If the buffer length is 0, this function does nothing.
  2316. *
  2317. * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  2318. * can't express most Unicode codepoints. It's a legacy encoding; you should
  2319. * be converting away from it at all times.
  2320. *
  2321. * \param src Null-terminated source string in Latin1 format.
  2322. * \param dst Buffer to store converted UTF-8 string.
  2323. * \param len Size, in bytes, of destination buffer.
  2324. */
  2325. PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst,
  2326. PHYSFS_uint64 len);
  2327. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  2328. /**
  2329. * \fn int PHYSFS_caseFold(const PHYSFS_uint32 from, PHYSFS_uint32 *to)
  2330. * \brief "Fold" a Unicode codepoint to a lowercase equivalent.
  2331. *
  2332. * (This is for limited, hardcore use. If you don't immediately see a need
  2333. * for it, you can probably ignore this forever.)
  2334. *
  2335. * This will convert a Unicode codepoint into its lowercase equivalent.
  2336. * Bogus codepoints and codepoints without a lowercase equivalent will
  2337. * be returned unconverted.
  2338. *
  2339. * Note that you might get multiple codepoints in return! The German Eszett,
  2340. * for example, will fold down to two lowercase latin 's' codepoints. The
  2341. * theory is that if you fold two strings, one with an Eszett and one with
  2342. * "SS" down, they will match.
  2343. *
  2344. * \warning Anyone that is a student of Unicode knows about the "Turkish I"
  2345. * problem. This API does not handle it. Assume this one letter
  2346. * in all of Unicode will definitely fold sort of incorrectly. If
  2347. * you don't know what this is about, you can probably ignore this
  2348. * problem for most of the planet, but perfection is impossible.
  2349. *
  2350. * \param from The codepoint to fold.
  2351. * \param to Buffer to store the folded codepoint values into. This should
  2352. * point to space for at least 3 PHYSFS_uint32 slots.
  2353. * \return The number of codepoints the folding produced. Between 1 and 3.
  2354. */
  2355. PHYSFS_DECL int PHYSFS_caseFold(const PHYSFS_uint32 from, PHYSFS_uint32 *to);
  2356. /**
  2357. * \fn int PHYSFS_utf8stricmp(const char *str1, const char *str2)
  2358. * \brief Case-insensitive compare of two UTF-8 strings.
  2359. *
  2360. * This is a strcasecmp/stricmp replacement that expects both strings
  2361. * to be in UTF-8 encoding. It will do "case folding" to decide if the
  2362. * Unicode codepoints in the strings match.
  2363. *
  2364. * If both strings are exclusively low-ASCII characters, this will do the
  2365. * right thing, as that is also valid UTF-8. If there are any high-ASCII
  2366. * chars, this will not do what you expect!
  2367. *
  2368. * It will report which string is "greater than" the other, but be aware that
  2369. * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but
  2370. * a Japanese kuten has no meaningful alphabetically relationship to
  2371. * a Greek lambda, but being able to assign a reliable "value" makes sorting
  2372. * algorithms possible, if not entirely sane. Most cases should treat the
  2373. * return value as "equal" or "not equal".
  2374. *
  2375. * Like stricmp, this expects both strings to be NULL-terminated.
  2376. *
  2377. * \param str1 First string to compare.
  2378. * \param str2 Second string to compare.
  2379. * \return -1 if str1 is "less than" str2, 1 if "greater than", 0 if equal.
  2380. */
  2381. PHYSFS_DECL int PHYSFS_utf8stricmp(const char *str1, const char *str2);
  2382. /**
  2383. * \fn int PHYSFS_utf16stricmp(const PHYSFS_uint16 *str1, const PHYSFS_uint16 *str2)
  2384. * \brief Case-insensitive compare of two UTF-16 strings.
  2385. *
  2386. * This is a strcasecmp/stricmp replacement that expects both strings
  2387. * to be in UTF-16 encoding. It will do "case folding" to decide if the
  2388. * Unicode codepoints in the strings match.
  2389. *
  2390. * It will report which string is "greater than" the other, but be aware that
  2391. * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but
  2392. * a Japanese kuten has no meaningful alphabetically relationship to
  2393. * a Greek lambda, but being able to assign a reliable "value" makes sorting
  2394. * algorithms possible, if not entirely sane. Most cases should treat the
  2395. * return value as "equal" or "not equal".
  2396. *
  2397. * Like stricmp, this expects both strings to be NULL-terminated.
  2398. *
  2399. * \param str1 First string to compare.
  2400. * \param str2 Second string to compare.
  2401. * \return -1 if str1 is "less than" str2, 1 if "greater than", 0 if equal.
  2402. */
  2403. PHYSFS_DECL int PHYSFS_utf16stricmp(const PHYSFS_uint16 *str1,
  2404. const PHYSFS_uint16 *str2);
  2405. /**
  2406. * \fn int PHYSFS_ucs4stricmp(const PHYSFS_uint32 *str1, const PHYSFS_uint32 *str2)
  2407. * \brief Case-insensitive compare of two UCS-4 strings.
  2408. *
  2409. * This is a strcasecmp/stricmp replacement that expects both strings
  2410. * to be in UCS-4 (aka UTF-32) encoding. It will do "case folding" to decide
  2411. * if the Unicode codepoints in the strings match.
  2412. *
  2413. * It will report which string is "greater than" the other, but be aware that
  2414. * this doesn't necessarily mean anything: 'a' may be "less than" 'b', but
  2415. * a Japanese kuten has no meaningful alphabetically relationship to
  2416. * a Greek lambda, but being able to assign a reliable "value" makes sorting
  2417. * algorithms possible, if not entirely sane. Most cases should treat the
  2418. * return value as "equal" or "not equal".
  2419. *
  2420. * Like stricmp, this expects both strings to be NULL-terminated.
  2421. *
  2422. * \param str1 First string to compare.
  2423. * \param str2 Second string to compare.
  2424. * \return -1 if str1 is "less than" str2, 1 if "greater than", 0 if equal.
  2425. */
  2426. PHYSFS_DECL int PHYSFS_ucs4stricmp(const PHYSFS_uint32 *str1,
  2427. const PHYSFS_uint32 *str2);
  2428. /**
  2429. * \typedef PHYSFS_EnumerateCallback
  2430. * \brief Possible return values from PHYSFS_EnumerateCallback.
  2431. *
  2432. * These values dictate if an enumeration callback should continue to fire,
  2433. * or stop (and why it is stopping).
  2434. *
  2435. * \sa PHYSFS_EnumerateCallback
  2436. * \sa PHYSFS_enumerate
  2437. */
  2438. typedef enum PHYSFS_EnumerateCallbackResult
  2439. {
  2440. PHYSFS_ENUM_ERROR = -1, /**< Stop enumerating, report error to app. */
  2441. PHYSFS_ENUM_STOP = 0, /**< Stop enumerating, report success to app. */
  2442. PHYSFS_ENUM_OK = 1 /**< Keep enumerating, no problems */
  2443. } PHYSFS_EnumerateCallbackResult;
  2444. /**
  2445. * \typedef PHYSFS_EnumerateCallback
  2446. * \brief Function signature for callbacks that enumerate and return results.
  2447. *
  2448. * This is the same thing as PHYSFS_EnumFilesCallback from PhysicsFS 2.0,
  2449. * except it can return a result from the callback: namely: if you're looking
  2450. * for something specific, once you find it, you can tell PhysicsFS to stop
  2451. * enumerating further. This is used with PHYSFS_enumerate(), which we
  2452. * hopefully got right this time. :)
  2453. *
  2454. * \param data User-defined data pointer, passed through from the API
  2455. * that eventually called the callback.
  2456. * \param origdir A string containing the full path, in platform-independent
  2457. * notation, of the directory containing this file. In most
  2458. * cases, this is the directory on which you requested
  2459. * enumeration, passed in the callback for your convenience.
  2460. * \param fname The filename that is being enumerated. It may not be in
  2461. * alphabetical order compared to other callbacks that have
  2462. * fired, and it will not contain the full path. You can
  2463. * recreate the fullpath with $origdir/$fname ... The file
  2464. * can be a subdirectory, a file, a symlink, etc.
  2465. * \return A value from PHYSFS_EnumerateCallbackResult.
  2466. * All other values are (currently) undefined; don't use them.
  2467. *
  2468. * \sa PHYSFS_enumerate
  2469. * \sa PHYSFS_EnumerateCallbackResult
  2470. */
  2471. typedef PHYSFS_EnumerateCallbackResult (*PHYSFS_EnumerateCallback)(void *data,
  2472. const char *origdir, const char *fname);
  2473. /**
  2474. * \fn int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c, void *d)
  2475. * \brief Get a file listing of a search path's directory, using an application-defined callback, with errors reported.
  2476. *
  2477. * Internally, PHYSFS_enumerateFiles() just calls this function and then builds
  2478. * a list before returning to the application, so functionality is identical
  2479. * except for how the information is represented to the application.
  2480. *
  2481. * Unlike PHYSFS_enumerateFiles(), this function does not return an array.
  2482. * Rather, it calls a function specified by the application once per
  2483. * element of the search path:
  2484. *
  2485. * \code
  2486. *
  2487. * static int printDir(void *data, const char *origdir, const char *fname)
  2488. * {
  2489. * printf(" * We've got [%s] in [%s].\n", fname, origdir);
  2490. * return 1; // give me more data, please.
  2491. * }
  2492. *
  2493. * // ...
  2494. * PHYSFS_enumerate("/some/path", printDir, NULL);
  2495. * \endcode
  2496. *
  2497. * Items sent to the callback are not guaranteed to be in any order whatsoever.
  2498. * There is no sorting done at this level, and if you need that, you should
  2499. * probably use PHYSFS_enumerateFiles() instead, which guarantees
  2500. * alphabetical sorting. This form reports whatever is discovered in each
  2501. * archive before moving on to the next. Even within one archive, we can't
  2502. * guarantee what order it will discover data. <em>Any sorting you find in
  2503. * these callbacks is just pure luck. Do not rely on it.</em> As this walks
  2504. * the entire list of archives, you may receive duplicate filenames.
  2505. *
  2506. * This API and the callbacks themselves are capable of reporting errors.
  2507. * Prior to this API, callbacks had to accept every enumerated item, even if
  2508. * they were only looking for a specific thing and wanted to stop after that,
  2509. * or had a serious error and couldn't alert anyone. Furthermore, if
  2510. * PhysicsFS itself had a problem (disk error or whatnot), it couldn't report
  2511. * it to the calling app, it would just have to skip items or stop
  2512. * enumerating outright, and the caller wouldn't know it had lost some data
  2513. * along the way.
  2514. *
  2515. * Now the caller can be sure it got a complete data set, and its callback has
  2516. * control if it wants enumeration to stop early. See the documentation for
  2517. * PHYSFS_EnumerateCallback for details on how your callback should behave.
  2518. *
  2519. * \param dir Directory, in platform-independent notation, to enumerate.
  2520. * \param c Callback function to notify about search path elements.
  2521. * \param d Application-defined data passed to callback. Can be NULL.
  2522. * \return non-zero on success, zero on failure. Use
  2523. * PHYSFS_getLastErrorCode() to obtain the specific error. If the
  2524. * callback returns PHYSFS_ENUM_STOP to stop early, this will be
  2525. * considered success. Callbacks returning PHYSFS_ENUM_ERROR will
  2526. * make this function return zero and set the error code to
  2527. * PHYSFS_ERR_APP_CALLBACK.
  2528. *
  2529. * \sa PHYSFS_EnumerateCallback
  2530. * \sa PHYSFS_enumerateFiles
  2531. */
  2532. PHYSFS_DECL int PHYSFS_enumerate(const char *dir, PHYSFS_EnumerateCallback c,
  2533. void *d);
  2534. /**
  2535. * \fn int PHYSFS_unmount(const char *oldDir)
  2536. * \brief Remove a directory or archive from the search path.
  2537. *
  2538. * This is functionally equivalent to PHYSFS_removeFromSearchPath(), but that
  2539. * function is deprecated to keep the vocabulary paired with PHYSFS_mount().
  2540. *
  2541. * This must be a (case-sensitive) match to a dir or archive already in the
  2542. * search path, specified in platform-dependent notation.
  2543. *
  2544. * This call will fail (and fail to remove from the path) if the element still
  2545. * has files open in it.
  2546. *
  2547. * \warning This function wants the path to the archive or directory that was
  2548. * mounted (the same string used for the "newDir" argument of
  2549. * PHYSFS_addToSearchPath or any of the mount functions), not the
  2550. * path where it is mounted in the tree (the "mountPoint" argument
  2551. * to any of the mount functions).
  2552. *
  2553. * \param oldDir dir/archive to remove.
  2554. * \return nonzero on success, zero on failure. Use
  2555. * PHYSFS_getLastErrorCode() to obtain the specific error.
  2556. *
  2557. * \sa PHYSFS_getSearchPath
  2558. * \sa PHYSFS_mount
  2559. */
  2560. PHYSFS_DECL int PHYSFS_unmount(const char *oldDir);
  2561. /**
  2562. * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void)
  2563. * \brief Discover the current allocator.
  2564. *
  2565. * (This is for limited, hardcore use. If you don't immediately see a need
  2566. * for it, you can probably ignore this forever.)
  2567. *
  2568. * This function exposes the function pointers that make up the currently used
  2569. * allocator. This can be useful for apps that want to access PhysicsFS's
  2570. * internal, default allocation routines, as well as for external code that
  2571. * wants to share the same allocator, even if the application specified their
  2572. * own.
  2573. *
  2574. * This call is only valid between PHYSFS_init() and PHYSFS_deinit() calls;
  2575. * it will return NULL if the library isn't initialized. As we can't
  2576. * guarantee the state of the internal allocators unless the library is
  2577. * initialized, you shouldn't use any allocator returned here after a call
  2578. * to PHYSFS_deinit().
  2579. *
  2580. * Do not call the returned allocator's Init() or Deinit() methods under any
  2581. * circumstances.
  2582. *
  2583. * If you aren't immediately sure what to do with this function, you can
  2584. * safely ignore it altogether.
  2585. *
  2586. * \return Current allocator, as set by PHYSFS_setAllocator(), or PhysicsFS's
  2587. * internal, default allocator if no application defined allocator
  2588. * is currently set. Will return NULL if the library is not
  2589. * initialized.
  2590. *
  2591. * \sa PHYSFS_Allocator
  2592. * \sa PHYSFS_setAllocator
  2593. */
  2594. PHYSFS_DECL const PHYSFS_Allocator *PHYSFS_getAllocator(void);
  2595. /**
  2596. * \enum PHYSFS_FileType
  2597. * \brief Type of a File
  2598. *
  2599. * Possible types of a file.
  2600. *
  2601. * \sa PHYSFS_stat
  2602. */
  2603. typedef enum PHYSFS_FileType
  2604. {
  2605. PHYSFS_FILETYPE_REGULAR, /**< a normal file */
  2606. PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
  2607. PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
  2608. PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
  2609. } PHYSFS_FileType;
  2610. /**
  2611. * \struct PHYSFS_Stat
  2612. * \brief Meta data for a file or directory
  2613. *
  2614. * Container for various meta data about a file in the virtual file system.
  2615. * PHYSFS_stat() uses this structure for returning the information. The time
  2616. * data will be either the number of seconds since the Unix epoch (midnight,
  2617. * Jan 1, 1970), or -1 if the information isn't available or applicable.
  2618. * The (filesize) field is measured in bytes.
  2619. * The (readonly) field tells you whether the archive thinks a file is
  2620. * not writable, but tends to be only an estimate (for example, your write
  2621. * dir might overlap with a .zip file, meaning you _can_ successfully open
  2622. * that path for writing, as it gets created elsewhere.
  2623. *
  2624. * \sa PHYSFS_stat
  2625. * \sa PHYSFS_FileType
  2626. */
  2627. typedef struct PHYSFS_Stat
  2628. {
  2629. PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
  2630. PHYSFS_sint64 modtime; /**< last modification time */
  2631. PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
  2632. PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
  2633. PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
  2634. int readonly; /**< non-zero if read only, zero if writable. */
  2635. } PHYSFS_Stat;
  2636. /**
  2637. * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
  2638. * \brief Get various information about a directory or a file.
  2639. *
  2640. * Obtain various information about a file or directory from the meta data.
  2641. *
  2642. * This function will never follow symbolic links. If you haven't enabled
  2643. * symlinks with PHYSFS_permitSymbolicLinks(), stat'ing a symlink will be
  2644. * treated like stat'ing a non-existant file. If symlinks are enabled,
  2645. * stat'ing a symlink will give you information on the link itself and not
  2646. * what it points to.
  2647. *
  2648. * \param fname filename to check, in platform-indepedent notation.
  2649. * \param stat pointer to structure to fill in with data about (fname).
  2650. * \return non-zero on success, zero on failure. On failure, (stat)'s
  2651. * contents are undefined.
  2652. *
  2653. * \sa PHYSFS_Stat
  2654. */
  2655. PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
  2656. /**
  2657. * \fn void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2658. * \brief Convert a UTF-16 string to a UTF-8 string.
  2659. *
  2660. * \warning This function will not report an error if there are invalid UTF-16
  2661. * sequences in the source string. It will replace them with a '?'
  2662. * character and continue on.
  2663. *
  2664. * UTF-16 strings are 16-bits per character (except some chars, which are
  2665. * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern
  2666. * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but
  2667. * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that
  2668. * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you
  2669. * aren't sure, you should be using UTF-16 at this point on Windows.
  2670. *
  2671. * To ensure that the destination buffer is large enough for the conversion,
  2672. * please allocate a buffer that is double the size of the source buffer.
  2673. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2674. * a UTF-16 string, it may also expand it.
  2675. *
  2676. * Strings that don't fit in the destination buffer will be truncated, but
  2677. * will always be null-terminated and never have an incomplete UTF-8
  2678. * sequence at the end. If the buffer length is 0, this function does nothing.
  2679. *
  2680. * \param src Null-terminated source string in UTF-16 format.
  2681. * \param dst Buffer to store converted UTF-8 string.
  2682. * \param len Size, in bytes, of destination buffer.
  2683. */
  2684. PHYSFS_DECL void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst,
  2685. PHYSFS_uint64 len);
  2686. /**
  2687. * \fn PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2688. * \brief Convert a UTF-8 string to a UTF-16 string.
  2689. *
  2690. * \warning This function will not report an error if there are invalid UTF-8
  2691. * sequences in the source string. It will replace them with a '?'
  2692. * character and continue on.
  2693. *
  2694. * UTF-16 strings are 16-bits per character (except some chars, which are
  2695. * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern
  2696. * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but
  2697. * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that
  2698. * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you
  2699. * aren't sure, you should be using UTF-16 at this point on Windows.
  2700. *
  2701. * To ensure that the destination buffer is large enough for the conversion,
  2702. * please allocate a buffer that is double the size of the source buffer.
  2703. * UTF-8 uses from one to four bytes per character, but UTF-16 always uses
  2704. * two to four, so an entirely low-ASCII string will double in size! The
  2705. * UTF-16 characters that would take four bytes also take four bytes in UTF-8,
  2706. * so you don't need to allocate 4x the space just in case: double will do.
  2707. *
  2708. * Strings that don't fit in the destination buffer will be truncated, but
  2709. * will always be null-terminated and never have an incomplete UTF-16
  2710. * surrogate pair at the end. If the buffer length is 0, this function does
  2711. * nothing.
  2712. *
  2713. * \param src Null-terminated source string in UTF-8 format.
  2714. * \param dst Buffer to store converted UTF-16 string.
  2715. * \param len Size, in bytes, of destination buffer.
  2716. *
  2717. * \sa PHYSFS_utf8ToUtf16
  2718. */
  2719. PHYSFS_DECL void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst,
  2720. PHYSFS_uint64 len);
  2721. /**
  2722. * \fn PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer, PHYSFS_uint64 len)
  2723. * \brief Read bytes from a PhysicsFS filehandle
  2724. *
  2725. * The file must be opened for reading.
  2726. *
  2727. * \param handle handle returned from PHYSFS_openRead().
  2728. * \param buffer buffer of at least (len) bytes to store read data into.
  2729. * \param len number of bytes being read from (handle).
  2730. * \return number of bytes read. This may be less than (len); this does not
  2731. * signify an error, necessarily (a short read may mean EOF).
  2732. * PHYSFS_getLastErrorCode() can shed light on the reason this might
  2733. * be < (len), as can PHYSFS_eof(). -1 if complete failure.
  2734. *
  2735. * \sa PHYSFS_eof
  2736. */
  2737. PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
  2738. PHYSFS_uint64 len);
  2739. /**
  2740. * \fn PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle, const void *buffer, PHYSFS_uint64 len)
  2741. * \brief Write data to a PhysicsFS filehandle
  2742. *
  2743. * The file must be opened for writing.
  2744. *
  2745. * Please note that while (len) is an unsigned 64-bit integer, you are limited
  2746. * to 63 bits (9223372036854775807 bytes), so we can return a negative value
  2747. * on error. If length is greater than 0x7FFFFFFFFFFFFFFF, this function will
  2748. * immediately fail. For systems without a 64-bit datatype, you are limited
  2749. * to 31 bits (0x7FFFFFFF, or 2147483647 bytes). We trust most things won't
  2750. * need to do multiple gigabytes of i/o in one call anyhow, but why limit
  2751. * things?
  2752. *
  2753. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  2754. * \param buffer buffer of (len) bytes to write to (handle).
  2755. * \param len number of bytes being written to (handle).
  2756. * \return number of bytes written. This may be less than (len); in the case
  2757. * of an error, the system may try to write as many bytes as possible,
  2758. * so an incomplete write might occur. PHYSFS_getLastErrorCode() can
  2759. * shed light on the reason this might be < (len). -1 if complete
  2760. * failure.
  2761. */
  2762. PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
  2763. const void *buffer,
  2764. PHYSFS_uint64 len);
  2765. /**
  2766. * \struct PHYSFS_Io
  2767. * \brief An abstract i/o interface.
  2768. *
  2769. * \warning This is advanced, hardcore stuff. You don't need this unless you
  2770. * really know what you're doing. Most apps will not need this.
  2771. *
  2772. * Historically, PhysicsFS provided access to the physical filesystem and
  2773. * archives within that filesystem. However, sometimes you need more power
  2774. * than this. Perhaps you need to provide an archive that is entirely
  2775. * contained in RAM, or you need to bridge some other file i/o API to
  2776. * PhysicsFS, or you need to translate the bits (perhaps you have a
  2777. * a standard .zip file that's encrypted, and you need to decrypt on the fly
  2778. * for the unsuspecting zip archiver).
  2779. *
  2780. * A PHYSFS_Io is the interface that Archivers use to get archive data.
  2781. * Historically, this has mapped to file i/o to the physical filesystem, but
  2782. * as of PhysicsFS 2.1, applications can provide their own i/o implementations
  2783. * at runtime.
  2784. *
  2785. * This interface isn't necessarily a good universal fit for i/o. There are a
  2786. * few requirements of note:
  2787. *
  2788. * - They only do blocking i/o (at least, for now).
  2789. * - They need to be able to duplicate. If you have a file handle from
  2790. * fopen(), you need to be able to create a unique clone of it (so we
  2791. * have two handles to the same file that can both seek/read/etc without
  2792. * stepping on each other).
  2793. * - They need to know the size of their entire data set.
  2794. * - They need to be able to seek and rewind on demand.
  2795. *
  2796. * ...in short, you're probably not going to write an HTTP implementation.
  2797. *
  2798. * Thread safety: PHYSFS_Io implementations are not guaranteed to be thread
  2799. * safe in themselves. Under the hood where PhysicsFS uses them, the library
  2800. * provides its own locks. If you plan to use them directly from separate
  2801. * threads, you should either use mutexes to protect them, or don't use the
  2802. * same PHYSFS_Io from two threads at the same time.
  2803. *
  2804. * \sa PHYSFS_mountIo
  2805. */
  2806. typedef struct PHYSFS_Io
  2807. {
  2808. /**
  2809. * \brief Binary compatibility information.
  2810. *
  2811. * This must be set to zero at this time. Future versions of this
  2812. * struct will increment this field, so we know what a given
  2813. * implementation supports. We'll presumably keep supporting older
  2814. * versions as we offer new features, though.
  2815. */
  2816. PHYSFS_uint32 version;
  2817. /**
  2818. * \brief Instance data for this struct.
  2819. *
  2820. * Each instance has a pointer associated with it that can be used to
  2821. * store anything it likes. This pointer is per-instance of the stream,
  2822. * so presumably it will change when calling duplicate(). This can be
  2823. * deallocated during the destroy() method.
  2824. */
  2825. void *opaque;
  2826. /**
  2827. * \brief Read more data.
  2828. *
  2829. * Read (len) bytes from the interface, at the current i/o position, and
  2830. * store them in (buffer). The current i/o position should move ahead
  2831. * by the number of bytes successfully read.
  2832. *
  2833. * You don't have to implement this; set it to NULL if not implemented.
  2834. * This will only be used if the file is opened for reading. If set to
  2835. * NULL, a default implementation that immediately reports failure will
  2836. * be used.
  2837. *
  2838. * \param io The i/o instance to read from.
  2839. * \param buf The buffer to store data into. It must be at least
  2840. * (len) bytes long and can't be NULL.
  2841. * \param len The number of bytes to read from the interface.
  2842. * \return number of bytes read from file, 0 on EOF, -1 if complete
  2843. * failure.
  2844. */
  2845. PHYSFS_sint64 (*read)(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len);
  2846. /**
  2847. * \brief Write more data.
  2848. *
  2849. * Write (len) bytes from (buffer) to the interface at the current i/o
  2850. * position. The current i/o position should move ahead by the number of
  2851. * bytes successfully written.
  2852. *
  2853. * You don't have to implement this; set it to NULL if not implemented.
  2854. * This will only be used if the file is opened for writing. If set to
  2855. * NULL, a default implementation that immediately reports failure will
  2856. * be used.
  2857. *
  2858. * You are allowed to buffer; a write can succeed here and then later
  2859. * fail when flushing. Note that PHYSFS_setBuffer() may be operating a
  2860. * level above your i/o, so you should usually not implement your
  2861. * own buffering routines.
  2862. *
  2863. * \param io The i/o instance to write to.
  2864. * \param buffer The buffer to read data from. It must be at least
  2865. * (len) bytes long and can't be NULL.
  2866. * \param len The number of bytes to read from (buffer).
  2867. * \return number of bytes written to file, -1 if complete failure.
  2868. */
  2869. PHYSFS_sint64 (*write)(struct PHYSFS_Io *io, const void *buffer,
  2870. PHYSFS_uint64 len);
  2871. /**
  2872. * \brief Move i/o position to a given byte offset from start.
  2873. *
  2874. * This method moves the i/o position, so the next read/write will
  2875. * be of the byte at (offset) offset. Seeks past the end of file should
  2876. * be treated as an error condition.
  2877. *
  2878. * \param io The i/o instance to seek.
  2879. * \param offset The new byte offset for the i/o position.
  2880. * \return non-zero on success, zero on error.
  2881. */
  2882. int (*seek)(struct PHYSFS_Io *io, PHYSFS_uint64 offset);
  2883. /**
  2884. * \brief Report current i/o position.
  2885. *
  2886. * Return bytes offset, or -1 if you aren't able to determine. A failure
  2887. * will almost certainly be fatal to further use of this stream, so you
  2888. * may not leave this unimplemented.
  2889. *
  2890. * \param io The i/o instance to query.
  2891. * \return The current byte offset for the i/o position, -1 if unknown.
  2892. */
  2893. PHYSFS_sint64 (*tell)(struct PHYSFS_Io *io);
  2894. /**
  2895. * \brief Determine size of the i/o instance's dataset.
  2896. *
  2897. * Return number of bytes available in the file, or -1 if you
  2898. * aren't able to determine. A failure will almost certainly be fatal
  2899. * to further use of this stream, so you may not leave this unimplemented.
  2900. *
  2901. * \param io The i/o instance to query.
  2902. * \return Total size, in bytes, of the dataset.
  2903. */
  2904. PHYSFS_sint64 (*length)(struct PHYSFS_Io *io);
  2905. /**
  2906. * \brief Duplicate this i/o instance.
  2907. *
  2908. * This needs to result in a full copy of this PHYSFS_Io, that can live
  2909. * completely independently. The copy needs to be able to perform all
  2910. * its operations without altering the original, including either object
  2911. * being destroyed separately (so, for example: they can't share a file
  2912. * handle; they each need their own).
  2913. *
  2914. * If you can't duplicate a handle, it's legal to return NULL, but you
  2915. * almost certainly need this functionality if you want to use this to
  2916. * PHYSFS_Io to back an archive.
  2917. *
  2918. * \param io The i/o instance to duplicate.
  2919. * \return A new value for a stream's (opaque) field, or NULL on error.
  2920. */
  2921. struct PHYSFS_Io *(*duplicate)(struct PHYSFS_Io *io);
  2922. /**
  2923. * \brief Flush resources to media, or wherever.
  2924. *
  2925. * This is the chance to report failure for writes that had claimed
  2926. * success earlier, but still had a chance to actually fail. This method
  2927. * can be NULL if flushing isn't necessary.
  2928. *
  2929. * This function may be called before destroy(), as it can report failure
  2930. * and destroy() can not. It may be called at other times, too.
  2931. *
  2932. * \param io The i/o instance to flush.
  2933. * \return Zero on error, non-zero on success.
  2934. */
  2935. int (*flush)(struct PHYSFS_Io *io);
  2936. /**
  2937. * \brief Cleanup and deallocate i/o instance.
  2938. *
  2939. * Free associated resources, including (opaque) if applicable.
  2940. *
  2941. * This function must always succeed: as such, it returns void. The
  2942. * system may call your flush() method before this. You may report
  2943. * failure there if necessary. This method may still be called if
  2944. * flush() fails, in which case you'll have to abandon unflushed data
  2945. * and other failing conditions and clean up.
  2946. *
  2947. * Once this method is called for a given instance, the system will assume
  2948. * it is unsafe to touch that instance again and will discard any
  2949. * references to it.
  2950. *
  2951. * \param s The i/o instance to destroy.
  2952. */
  2953. void (*destroy)(struct PHYSFS_Io *io);
  2954. } PHYSFS_Io;
  2955. /**
  2956. * \fn int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir, const char *mountPoint, int appendToPath)
  2957. * \brief Add an archive, built on a PHYSFS_Io, to the search path.
  2958. *
  2959. * \warning Unless you have some special, low-level need, you should be using
  2960. * PHYSFS_mount() instead of this.
  2961. *
  2962. * This function operates just like PHYSFS_mount(), but takes a PHYSFS_Io
  2963. * instead of a pathname. Behind the scenes, PHYSFS_mount() calls this
  2964. * function with a physical-filesystem-based PHYSFS_Io.
  2965. *
  2966. * (newDir) must be a unique string to identify this archive. It is used
  2967. * to optimize archiver selection (if you name it XXXXX.zip, we might try
  2968. * the ZIP archiver first, for example, or directly choose an archiver that
  2969. * can only trust the data is valid by filename extension). It doesn't
  2970. * need to refer to a real file at all. If the filename extension isn't
  2971. * helpful, the system will try every archiver until one works or none
  2972. * of them do. This filename must be unique, as the system won't allow you
  2973. * to have two archives with the same name.
  2974. *
  2975. * (io) must remain until the archive is unmounted. When the archive is
  2976. * unmounted, the system will call (io)->destroy(io), which will give you
  2977. * a chance to free your resources.
  2978. *
  2979. * If this function fails, (io)->destroy(io) is not called.
  2980. *
  2981. * \param io i/o instance for archive to add to the path.
  2982. * \param newDir Filename that can represent this stream.
  2983. * \param mountPoint Location in the interpolated tree that this archive
  2984. * will be "mounted", in platform-independent notation.
  2985. * NULL or "" is equivalent to "/".
  2986. * \param appendToPath nonzero to append to search path, zero to prepend.
  2987. * \return nonzero if added to path, zero on failure (bogus archive, stream
  2988. * i/o issue, etc). Use PHYSFS_getLastErrorCode() to obtain
  2989. * the specific error.
  2990. *
  2991. * \sa PHYSFS_unmount
  2992. * \sa PHYSFS_getSearchPath
  2993. * \sa PHYSFS_getMountPoint
  2994. */
  2995. PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *newDir,
  2996. const char *mountPoint, int appendToPath);
  2997. /**
  2998. * \fn int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *), const char *newDir, const char *mountPoint, int appendToPath)
  2999. * \brief Add an archive, contained in a memory buffer, to the search path.
  3000. *
  3001. * \warning Unless you have some special, low-level need, you should be using
  3002. * PHYSFS_mount() instead of this.
  3003. *
  3004. * This function operates just like PHYSFS_mount(), but takes a memory buffer
  3005. * instead of a pathname. This buffer contains all the data of the archive,
  3006. * and is used instead of a real file in the physical filesystem.
  3007. *
  3008. * (newDir) must be a unique string to identify this archive. It is used
  3009. * to optimize archiver selection (if you name it XXXXX.zip, we might try
  3010. * the ZIP archiver first, for example, or directly choose an archiver that
  3011. * can only trust the data is valid by filename extension). It doesn't
  3012. * need to refer to a real file at all. If the filename extension isn't
  3013. * helpful, the system will try every archiver until one works or none
  3014. * of them do. This filename must be unique, as the system won't allow you
  3015. * to have two archives with the same name.
  3016. *
  3017. * (ptr) must remain until the archive is unmounted. When the archive is
  3018. * unmounted, the system will call (del)(ptr), which will notify you that
  3019. * the system is done with the buffer, and give you a chance to free your
  3020. * resources. (del) can be NULL, in which case the system will make no
  3021. * attempt to free the buffer.
  3022. *
  3023. * If this function fails, (del) is not called.
  3024. *
  3025. * \param buf Address of the memory buffer containing the archive data.
  3026. * \param len Size of memory buffer, in bytes.
  3027. * \param del A callback that triggers upon unmount. Can be NULL.
  3028. * \param newDir Filename that can represent this stream.
  3029. * \param mountPoint Location in the interpolated tree that this archive
  3030. * will be "mounted", in platform-independent notation.
  3031. * NULL or "" is equivalent to "/".
  3032. * \param appendToPath nonzero to append to search path, zero to prepend.
  3033. * \return nonzero if added to path, zero on failure (bogus archive, etc).
  3034. * Use PHYSFS_getLastErrorCode() to obtain the specific error.
  3035. *
  3036. * \sa PHYSFS_unmount
  3037. * \sa PHYSFS_getSearchPath
  3038. * \sa PHYSFS_getMountPoint
  3039. */
  3040. PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len,
  3041. void (*del)(void *), const char *newDir,
  3042. const char *mountPoint, int appendToPath);
  3043. /**
  3044. * \fn int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir, const char *mountPoint, int appendToPath)
  3045. * \brief Add an archive, contained in a PHYSFS_File handle, to the search path.
  3046. *
  3047. * \warning Unless you have some special, low-level need, you should be using
  3048. * PHYSFS_mount() instead of this.
  3049. *
  3050. * \warning Archives-in-archives may be very slow! While a PHYSFS_File can
  3051. * seek even when the data is compressed, it may do so by rewinding
  3052. * to the start and decompressing everything before the seek point.
  3053. * Normal archive usage may do a lot of seeking behind the scenes.
  3054. * As such, you might find normal archive usage extremely painful
  3055. * if mounted this way. Plan accordingly: if you, say, have a
  3056. * self-extracting .zip file, and want to mount something in it,
  3057. * compress the contents of the inner archive and make sure the outer
  3058. * .zip file doesn't compress the inner archive too.
  3059. *
  3060. * This function operates just like PHYSFS_mount(), but takes a PHYSFS_File
  3061. * handle instead of a pathname. This handle contains all the data of the
  3062. * archive, and is used instead of a real file in the physical filesystem.
  3063. * The PHYSFS_File may be backed by a real file in the physical filesystem,
  3064. * but isn't necessarily. The most popular use for this is likely to mount
  3065. * archives stored inside other archives.
  3066. *
  3067. * (newDir) must be a unique string to identify this archive. It is used
  3068. * to optimize archiver selection (if you name it XXXXX.zip, we might try
  3069. * the ZIP archiver first, for example, or directly choose an archiver that
  3070. * can only trust the data is valid by filename extension). It doesn't
  3071. * need to refer to a real file at all. If the filename extension isn't
  3072. * helpful, the system will try every archiver until one works or none
  3073. * of them do. This filename must be unique, as the system won't allow you
  3074. * to have two archives with the same name.
  3075. *
  3076. * (file) must remain until the archive is unmounted. When the archive is
  3077. * unmounted, the system will call PHYSFS_close(file). If you need this
  3078. * handle to survive, you will have to wrap this in a PHYSFS_Io and use
  3079. * PHYSFS_mountIo() instead.
  3080. *
  3081. * If this function fails, PHYSFS_close(file) is not called.
  3082. *
  3083. * \param file The PHYSFS_File handle containing archive data.
  3084. * \param newDir Filename that can represent this stream.
  3085. * \param mountPoint Location in the interpolated tree that this archive
  3086. * will be "mounted", in platform-independent notation.
  3087. * NULL or "" is equivalent to "/".
  3088. * \param appendToPath nonzero to append to search path, zero to prepend.
  3089. * \return nonzero if added to path, zero on failure (bogus archive, etc).
  3090. * Use PHYSFS_getLastErrorCode() to obtain the specific error.
  3091. *
  3092. * \sa PHYSFS_unmount
  3093. * \sa PHYSFS_getSearchPath
  3094. * \sa PHYSFS_getMountPoint
  3095. */
  3096. PHYSFS_DECL int PHYSFS_mountHandle(PHYSFS_File *file, const char *newDir,
  3097. const char *mountPoint, int appendToPath);
  3098. /**
  3099. * \enum PHYSFS_ErrorCode
  3100. * \brief Values that represent specific causes of failure.
  3101. *
  3102. * Most of the time, you should only concern yourself with whether a given
  3103. * operation failed or not, but there may be occasions where you plan to
  3104. * handle a specific failure case gracefully, so we provide specific error
  3105. * codes.
  3106. *
  3107. * Most of these errors are a little vague, and most aren't things you can
  3108. * fix...if there's a permission error, for example, all you can really do
  3109. * is pass that information on to the user and let them figure out how to
  3110. * handle it. In most these cases, your program should only care that it
  3111. * failed to accomplish its goals, and not care specifically why.
  3112. *
  3113. * \sa PHYSFS_getLastErrorCode
  3114. * \sa PHYSFS_getErrorByCode
  3115. */
  3116. typedef enum PHYSFS_ErrorCode
  3117. {
  3118. PHYSFS_ERR_OK, /**< Success; no error. */
  3119. PHYSFS_ERR_OTHER_ERROR, /**< Error not otherwise covered here. */
  3120. PHYSFS_ERR_OUT_OF_MEMORY, /**< Memory allocation failed. */
  3121. PHYSFS_ERR_NOT_INITIALIZED, /**< PhysicsFS is not initialized. */
  3122. PHYSFS_ERR_IS_INITIALIZED, /**< PhysicsFS is already initialized. */
  3123. PHYSFS_ERR_ARGV0_IS_NULL, /**< Needed argv[0], but it is NULL. */
  3124. PHYSFS_ERR_UNSUPPORTED, /**< Operation or feature unsupported. */
  3125. PHYSFS_ERR_PAST_EOF, /**< Attempted to access past end of file. */
  3126. PHYSFS_ERR_FILES_STILL_OPEN, /**< Files still open. */
  3127. PHYSFS_ERR_INVALID_ARGUMENT, /**< Bad parameter passed to an function. */
  3128. PHYSFS_ERR_NOT_MOUNTED, /**< Requested archive/dir not mounted. */
  3129. PHYSFS_ERR_NOT_FOUND, /**< File (or whatever) not found. */
  3130. PHYSFS_ERR_SYMLINK_FORBIDDEN,/**< Symlink seen when not permitted. */
  3131. PHYSFS_ERR_NO_WRITE_DIR, /**< No write dir has been specified. */
  3132. PHYSFS_ERR_OPEN_FOR_READING, /**< Wrote to a file opened for reading. */
  3133. PHYSFS_ERR_OPEN_FOR_WRITING, /**< Read from a file opened for writing. */
  3134. PHYSFS_ERR_NOT_A_FILE, /**< Needed a file, got a directory (etc). */
  3135. PHYSFS_ERR_READ_ONLY, /**< Wrote to a read-only filesystem. */
  3136. PHYSFS_ERR_CORRUPT, /**< Corrupted data encountered. */
  3137. PHYSFS_ERR_SYMLINK_LOOP, /**< Infinite symbolic link loop. */
  3138. PHYSFS_ERR_IO, /**< i/o error (hardware failure, etc). */
  3139. PHYSFS_ERR_PERMISSION, /**< Permission denied. */
  3140. PHYSFS_ERR_NO_SPACE, /**< No space (disk full, over quota, etc) */
  3141. PHYSFS_ERR_BAD_FILENAME, /**< Filename is bogus/insecure. */
  3142. PHYSFS_ERR_BUSY, /**< Tried to modify a file the OS needs. */
  3143. PHYSFS_ERR_DIR_NOT_EMPTY, /**< Tried to delete dir with files in it. */
  3144. PHYSFS_ERR_OS_ERROR, /**< Unspecified OS-level error. */
  3145. PHYSFS_ERR_DUPLICATE, /**< Duplicate entry. */
  3146. PHYSFS_ERR_BAD_PASSWORD, /**< Bad password. */
  3147. PHYSFS_ERR_APP_CALLBACK /**< Application callback reported error. */
  3148. } PHYSFS_ErrorCode;
  3149. /**
  3150. * \fn PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
  3151. * \brief Get machine-readable error information.
  3152. *
  3153. * Get the last PhysicsFS error message as an integer value. This will return
  3154. * PHYSFS_ERR_OK if there's been no error since the last call to this
  3155. * function. Each thread has a unique error state associated with it, but
  3156. * each time a new error message is set, it will overwrite the previous one
  3157. * associated with that thread. It is safe to call this function at anytime,
  3158. * even before PHYSFS_init().
  3159. *
  3160. * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same
  3161. * thread-specific error state. Calling one will wipe out the other's
  3162. * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that
  3163. * value to PHYSFS_getErrorByCode().
  3164. *
  3165. * Generally, applications should only concern themselves with whether a
  3166. * given function failed; however, if you require more specifics, you can
  3167. * try this function to glean information, if there's some specific problem
  3168. * you're expecting and plan to handle. But with most things that involve
  3169. * file systems, the best course of action is usually to give up, report the
  3170. * problem to the user, and let them figure out what should be done about it.
  3171. * For that, you might prefer PHYSFS_getErrorByCode() instead.
  3172. *
  3173. * \return Enumeration value that represents last reported error.
  3174. *
  3175. * \sa PHYSFS_getErrorByCode
  3176. */
  3177. PHYSFS_DECL PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void);
  3178. /**
  3179. * \fn const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code)
  3180. * \brief Get human-readable description string for a given error code.
  3181. *
  3182. * Get a static string, in UTF-8 format, that represents an English
  3183. * description of a given error code.
  3184. *
  3185. * This string is guaranteed to never change (although we may add new strings
  3186. * for new error codes in later versions of PhysicsFS), so you can use it
  3187. * for keying a localization dictionary.
  3188. *
  3189. * It is safe to call this function at anytime, even before PHYSFS_init().
  3190. *
  3191. * These strings are meant to be passed on directly to the user.
  3192. * Generally, applications should only concern themselves with whether a
  3193. * given function failed, but not care about the specifics much.
  3194. *
  3195. * Do not attempt to free the returned strings; they are read-only and you
  3196. * don't own their memory pages.
  3197. *
  3198. * \param code Error code to convert to a string.
  3199. * \return READ ONLY string of requested error message, NULL if this
  3200. * is not a valid PhysicsFS error code. Always check for NULL if
  3201. * you might be looking up an error code that didn't exist in an
  3202. * earlier version of PhysicsFS.
  3203. *
  3204. * \sa PHYSFS_getLastErrorCode
  3205. */
  3206. PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code);
  3207. /**
  3208. * \fn void PHYSFS_setErrorCode(PHYSFS_ErrorCode code)
  3209. * \brief Set the current thread's error code.
  3210. *
  3211. * This lets you set the value that will be returned by the next call to
  3212. * PHYSFS_getLastErrorCode(). This will replace any existing error code,
  3213. * whether set by your application or internally by PhysicsFS.
  3214. *
  3215. * Error codes are stored per-thread; what you set here will not be
  3216. * accessible to another thread.
  3217. *
  3218. * Any call into PhysicsFS may change the current error code, so any code you
  3219. * set here is somewhat fragile, and thus you shouldn't build any serious
  3220. * error reporting framework on this function. The primary goal of this
  3221. * function is to allow PHYSFS_Io implementations to set the error state,
  3222. * which generally will be passed back to your application when PhysicsFS
  3223. * makes a PHYSFS_Io call that fails internally.
  3224. *
  3225. * This function doesn't care if the error code is a value known to PhysicsFS
  3226. * or not (but PHYSFS_getErrorByCode() will return NULL for unknown values).
  3227. * The value will be reported unmolested by PHYSFS_getLastErrorCode().
  3228. *
  3229. * \param code Error code to become the current thread's new error state.
  3230. *
  3231. * \sa PHYSFS_getLastErrorCode
  3232. * \sa PHYSFS_getErrorByCode
  3233. */
  3234. PHYSFS_DECL void PHYSFS_setErrorCode(PHYSFS_ErrorCode code);
  3235. /**
  3236. * \fn const char *PHYSFS_getPrefDir(const char *org, const char *app)
  3237. * \brief Get the user-and-app-specific path where files can be written.
  3238. *
  3239. * Helper function.
  3240. *
  3241. * Get the "pref dir". This is meant to be where users can write personal
  3242. * files (preferences and save games, etc) that are specific to your
  3243. * application. This directory is unique per user, per application.
  3244. *
  3245. * This function will decide the appropriate location in the native filesystem,
  3246. * create the directory if necessary, and return a string in
  3247. * platform-dependent notation, suitable for passing to PHYSFS_setWriteDir().
  3248. *
  3249. * On Windows, this might look like:
  3250. * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name"
  3251. *
  3252. * On Linux, this might look like:
  3253. * "/home/bob/.local/share/My Program Name"
  3254. *
  3255. * On Mac OS X, this might look like:
  3256. * "/Users/bob/Library/Application Support/My Program Name"
  3257. *
  3258. * (etc.)
  3259. *
  3260. * You should probably use the pref dir for your write dir, and also put it
  3261. * near the beginning of your search path. Older versions of PhysicsFS
  3262. * offered only PHYSFS_getUserDir() and left you to figure out where the
  3263. * files should go under that tree. This finds the correct location
  3264. * for whatever platform, which not only changes between operating systems,
  3265. * but also versions of the same operating system.
  3266. *
  3267. * You specify the name of your organization (if it's not a real organization,
  3268. * your name or an Internet domain you own might do) and the name of your
  3269. * application. These should be proper names.
  3270. *
  3271. * Both the (org) and (app) strings may become part of a directory name, so
  3272. * please follow these rules:
  3273. *
  3274. * - Try to use the same org string (including case-sensitivity) for
  3275. * all your applications that use this function.
  3276. * - Always use a unique app string for each one, and make sure it never
  3277. * changes for an app once you've decided on it.
  3278. * - Unicode characters are legal, as long as it's UTF-8 encoded, but...
  3279. * - ...only use letters, numbers, and spaces. Avoid punctuation like
  3280. * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
  3281. *
  3282. * The pointer returned by this function remains valid until you call this
  3283. * function again, or call PHYSFS_deinit(). This is not necessarily a fast
  3284. * call, though, so you should call this once at startup and copy the string
  3285. * if you need it.
  3286. *
  3287. * You should assume the path returned by this function is the only safe
  3288. * place to write files (and that PHYSFS_getUserDir() and PHYSFS_getBaseDir(),
  3289. * while they might be writable, or even parents of the returned path, aren't
  3290. * where you should be writing things).
  3291. *
  3292. * \param org The name of your organization.
  3293. * \param app The name of your application.
  3294. * \return READ ONLY string of user dir in platform-dependent notation. NULL
  3295. * if there's a problem (creating directory failed, etc).
  3296. *
  3297. * \sa PHYSFS_getBaseDir
  3298. * \sa PHYSFS_getUserDir
  3299. */
  3300. PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app);
  3301. /**
  3302. * \struct PHYSFS_Archiver
  3303. * \brief Abstract interface to provide support for user-defined archives.
  3304. *
  3305. * \warning This is advanced, hardcore stuff. You don't need this unless you
  3306. * really know what you're doing. Most apps will not need this.
  3307. *
  3308. * Historically, PhysicsFS provided a means to mount various archive file
  3309. * formats, and physical directories in the native filesystem. However,
  3310. * applications have been limited to the file formats provided by the
  3311. * library. This interface allows an application to provide their own
  3312. * archive file types.
  3313. *
  3314. * Conceptually, a PHYSFS_Archiver provides directory entries, while
  3315. * PHYSFS_Io provides data streams for those directory entries. The most
  3316. * obvious use of PHYSFS_Archiver is to provide support for an archive
  3317. * file type that isn't provided by PhysicsFS directly: perhaps some
  3318. * proprietary format that only your application needs to understand.
  3319. *
  3320. * Internally, all the built-in archive support uses this interface, so the
  3321. * best examples for building a PHYSFS_Archiver is the source code to
  3322. * PhysicsFS itself.
  3323. *
  3324. * An archiver is added to the system with PHYSFS_registerArchiver(), and then
  3325. * it will be available for use automatically with PHYSFS_mount(); if a
  3326. * given archive can be handled with your archiver, it will be given control
  3327. * as appropriate.
  3328. *
  3329. * These methods deal with dir handles. You have one instance of your
  3330. * archiver, and it generates a unique, opaque handle for each opened
  3331. * archive in its openArchive() method. Since the lifetime of an Archiver
  3332. * (not an archive) is generally the entire lifetime of the process, and it's
  3333. * assumed to be a singleton, we do not provide any instance data for the
  3334. * archiver itself; the app can just use some static variables if necessary.
  3335. *
  3336. * Symlinks should always be followed (except in stat()); PhysicsFS will
  3337. * use the stat() method to check for symlinks and make a judgement on
  3338. * whether to continue to call other methods based on that.
  3339. *
  3340. * Archivers, when necessary, should set the PhysicsFS error state with
  3341. * PHYSFS_setErrorCode() before returning. PhysicsFS will pass these errors
  3342. * back to the application unmolested in most cases.
  3343. *
  3344. * Thread safety: PHYSFS_Archiver implementations are not guaranteed to be
  3345. * thread safe in themselves. PhysicsFS provides thread safety when it calls
  3346. * into a given archiver inside the library, but it does not promise that
  3347. * using the same PHYSFS_File from two threads at once is thread-safe; as
  3348. * such, your PHYSFS_Archiver can assume that locking is handled for you
  3349. * so long as the PHYSFS_Io you return from PHYSFS_open* doesn't change any
  3350. * of your Archiver state, as the PHYSFS_Io won't be as aggressively
  3351. * protected.
  3352. *
  3353. * \sa PHYSFS_registerArchiver
  3354. * \sa PHYSFS_deregisterArchiver
  3355. * \sa PHYSFS_supportedArchiveTypes
  3356. */
  3357. typedef struct PHYSFS_Archiver
  3358. {
  3359. /**
  3360. * \brief Binary compatibility information.
  3361. *
  3362. * This must be set to zero at this time. Future versions of this
  3363. * struct will increment this field, so we know what a given
  3364. * implementation supports. We'll presumably keep supporting older
  3365. * versions as we offer new features, though.
  3366. */
  3367. PHYSFS_uint32 version;
  3368. /**
  3369. * \brief Basic info about this archiver.
  3370. *
  3371. * This is used to identify your archive, and is returned in
  3372. * PHYSFS_supportedArchiveTypes().
  3373. */
  3374. PHYSFS_ArchiveInfo info;
  3375. /**
  3376. * \brief Open an archive provided by (io).
  3377. *
  3378. * This is where resources are allocated and data is parsed when mounting
  3379. * an archive.
  3380. * (name) is a filename associated with (io), but doesn't necessarily
  3381. * map to anything, let alone a real filename. This possibly-
  3382. * meaningless name is in platform-dependent notation.
  3383. * (forWrite) is non-zero if this is to be used for
  3384. * the write directory, and zero if this is to be used for an
  3385. * element of the search path.
  3386. * (claimed) should be set to 1 if this is definitely an archive your
  3387. * archiver implementation can handle, even if it fails. We use to
  3388. * decide if we should stop trying other archivers if you fail to open
  3389. * it. For example: the .zip archiver will set this to 1 for something
  3390. * that's got a .zip file signature, even if it failed because the file
  3391. * was also truncated. No sense in trying other archivers here, we
  3392. * already tried to handle it with the appropriate implementation!.
  3393. * Return NULL on failure and set (claimed) appropriately. If no archiver
  3394. * opened the archive or set (claimed), PHYSFS_mount() will report
  3395. * PHYSFS_ERR_UNSUPPORTED. Otherwise, it will report the error from the
  3396. * archiver that claimed the data through (claimed).
  3397. * Return non-NULL on success. The pointer returned will be
  3398. * passed as the "opaque" parameter for later calls.
  3399. */
  3400. void *(*openArchive)(PHYSFS_Io *io, const char *name,
  3401. int forWrite, int *claimed);
  3402. /**
  3403. * \brief List all files in (dirname).
  3404. *
  3405. * Each file is passed to (cb), where a copy is made if appropriate, so
  3406. * you can dispose of it upon return from the callback. (dirname) is in
  3407. * platform-independent notation.
  3408. * If you have a failure, call PHYSFS_SetErrorCode() with whatever code
  3409. * seem appropriate and return PHYSFS_ENUM_ERROR.
  3410. * If the callback returns PHYSFS_ENUM_ERROR, please call
  3411. * PHYSFS_SetErrorCode(PHYSFS_ERR_APP_CALLBACK) and then return
  3412. * PHYSFS_ENUM_ERROR as well. Don't call the callback again in any
  3413. * circumstances.
  3414. * If the callback returns PHYSFS_ENUM_STOP, stop enumerating and return
  3415. * PHYSFS_ENUM_STOP as well. Don't call the callback again in any
  3416. * circumstances. Don't set an error code in this case.
  3417. * Callbacks are only supposed to return a value from
  3418. * PHYSFS_EnumerateCallbackResult. Any other result has undefined
  3419. * behavior.
  3420. * As long as the callback returned PHYSFS_ENUM_OK and you haven't
  3421. * experienced any errors of your own, keep enumerating until you're done
  3422. * and then return PHYSFS_ENUM_OK without setting an error code.
  3423. *
  3424. * \warning PHYSFS_enumerate returns zero or non-zero (success or failure),
  3425. * so be aware this function pointer returns different values!
  3426. */
  3427. PHYSFS_EnumerateCallbackResult (*enumerate)(void *opaque,
  3428. const char *dirname, PHYSFS_EnumerateCallback cb,
  3429. const char *origdir, void *callbackdata);
  3430. /**
  3431. * \brief Open a file in this archive for reading.
  3432. *
  3433. * This filename, (fnm), is in platform-independent notation.
  3434. * Fail if the file does not exist.
  3435. * Returns NULL on failure, and calls PHYSFS_setErrorCode().
  3436. * Returns non-NULL on success. The pointer returned will be
  3437. * passed as the "opaque" parameter for later file calls.
  3438. */
  3439. PHYSFS_Io *(*openRead)(void *opaque, const char *fnm);
  3440. /**
  3441. * \brief Open a file in this archive for writing.
  3442. *
  3443. * If the file does not exist, it should be created. If it exists,
  3444. * it should be truncated to zero bytes. The writing offset should
  3445. * be the start of the file.
  3446. * If the archive is read-only, this operation should fail.
  3447. * This filename is in platform-independent notation.
  3448. * Returns NULL on failure, and calls PHYSFS_setErrorCode().
  3449. * Returns non-NULL on success. The pointer returned will be
  3450. * passed as the "opaque" parameter for later file calls.
  3451. */
  3452. PHYSFS_Io *(*openWrite)(void *opaque, const char *filename);
  3453. /**
  3454. * \brief Open a file in this archive for appending.
  3455. *
  3456. * If the file does not exist, it should be created. The writing
  3457. * offset should be the end of the file.
  3458. * If the archive is read-only, this operation should fail.
  3459. * This filename is in platform-independent notation.
  3460. * Returns NULL on failure, and calls PHYSFS_setErrorCode().
  3461. * Returns non-NULL on success. The pointer returned will be
  3462. * passed as the "opaque" parameter for later file calls.
  3463. */
  3464. PHYSFS_Io *(*openAppend)(void *opaque, const char *filename);
  3465. /**
  3466. * \brief Delete a file or directory in the archive.
  3467. *
  3468. * This same call is used for both files and directories; there is not a
  3469. * separate rmdir() call. Directories are only meant to be removed if
  3470. * they are empty.
  3471. * If the archive is read-only, this operation should fail.
  3472. *
  3473. * Return non-zero on success, zero on failure.
  3474. * This filename is in platform-independent notation.
  3475. * On failure, call PHYSFS_setErrorCode().
  3476. */
  3477. int (*remove)(void *opaque, const char *filename);
  3478. /**
  3479. * \brief Create a directory in the archive.
  3480. *
  3481. * If the application is trying to make multiple dirs, PhysicsFS
  3482. * will split them up into multiple calls before passing them to
  3483. * your driver.
  3484. * If the archive is read-only, this operation should fail.
  3485. * Return non-zero on success, zero on failure.
  3486. * This filename is in platform-independent notation.
  3487. * On failure, call PHYSFS_setErrorCode().
  3488. */
  3489. int (*mkdir)(void *opaque, const char *filename);
  3490. /**
  3491. * \brief Obtain basic file metadata.
  3492. *
  3493. * On success, fill in all the fields in (stat), using
  3494. * reasonable defaults for fields that apply to your archive.
  3495. *
  3496. * Returns non-zero on success, zero on failure.
  3497. * This filename is in platform-independent notation.
  3498. * On failure, call PHYSFS_setErrorCode().
  3499. */
  3500. int (*stat)(void *opaque, const char *fn, PHYSFS_Stat *stat);
  3501. /**
  3502. * \brief Destruct a previously-opened archive.
  3503. *
  3504. * Close this archive, and free any associated memory,
  3505. * including the original PHYSFS_Io and (opaque) itself, if
  3506. * applicable. Implementation can assume that it won't be called if
  3507. * there are still files open from this archive.
  3508. */
  3509. void (*closeArchive)(void *opaque);
  3510. } PHYSFS_Archiver;
  3511. /**
  3512. * \fn int PHYSFS_registerArchiver(const PHYSFS_Archiver *archiver)
  3513. * \brief Add a new archiver to the system.
  3514. *
  3515. * \warning This is advanced, hardcore stuff. You don't need this unless you
  3516. * really know what you're doing. Most apps will not need this.
  3517. *
  3518. * If you want to provide your own archiver (for example, a custom archive
  3519. * file format, or some virtual thing you want to make look like a filesystem
  3520. * that you can access through the usual PhysicsFS APIs), this is where you
  3521. * start. Once an archiver is successfully registered, then you can use
  3522. * PHYSFS_mount() to add archives that your archiver supports to the
  3523. * search path, or perhaps use it as the write dir. Internally, PhysicsFS
  3524. * uses this function to register its own built-in archivers, like .zip
  3525. * support, etc.
  3526. *
  3527. * You may not have two archivers that handle the same extension. If you are
  3528. * going to have a clash, you can deregister the other archiver (including
  3529. * built-in ones) with PHYSFS_deregisterArchiver().
  3530. *
  3531. * The data in (archiver) is copied; you may free this pointer when this
  3532. * function returns.
  3533. *
  3534. * Once this function returns successfully, PhysicsFS will be able to support
  3535. * archives of this type until you deregister the archiver again.
  3536. *
  3537. * \param archiver The archiver to register.
  3538. * \return Zero on error, non-zero on success.
  3539. *
  3540. * \sa PHYSFS_Archiver
  3541. * \sa PHYSFS_deregisterArchiver
  3542. */
  3543. PHYSFS_DECL int PHYSFS_registerArchiver(const PHYSFS_Archiver *archiver);
  3544. /**
  3545. * \fn int PHYSFS_deregisterArchiver(const char *ext)
  3546. * \brief Remove an archiver from the system.
  3547. *
  3548. * If for some reason, you only need your previously-registered archiver to
  3549. * live for a portion of your app's lifetime, you can remove it from the
  3550. * system once you're done with it through this function.
  3551. *
  3552. * This fails if there are any archives still open that use this archiver.
  3553. *
  3554. * This function can also remove internally-supplied archivers, like .zip
  3555. * support or whatnot. This could be useful in some situations, like
  3556. * disabling support for them outright or overriding them with your own
  3557. * implementation. Once an internal archiver is disabled like this,
  3558. * PhysicsFS provides no mechanism to recover them, short of calling
  3559. * PHYSFS_deinit() and PHYSFS_init() again.
  3560. *
  3561. * PHYSFS_deinit() will automatically deregister all archivers, so you don't
  3562. * need to explicitly deregister yours if you otherwise shut down cleanly.
  3563. *
  3564. * \param ext Filename extension that the archiver handles.
  3565. * \return Zero on error, non-zero on success.
  3566. *
  3567. * \sa PHYSFS_Archiver
  3568. * \sa PHYSFS_registerArchiver
  3569. */
  3570. PHYSFS_DECL int PHYSFS_deregisterArchiver(const char *ext);
  3571. /* Everything above this line is part of the PhysicsFS 2.1 API. */
  3572. #ifdef __cplusplus
  3573. }
  3574. #endif
  3575. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  3576. /* end of physfs.h ... */