physfs.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /**
  2. * PhysicsFS; a portable, flexible file i/o abstraction.
  3. *
  4. * This API gives you access to a system file system in ways superior to the
  5. * stdio or system i/o calls. The brief benefits:
  6. *
  7. * - It's portable.
  8. * - It's safe. No file access is permitted outside the specified dirs.
  9. * - It's flexible. Archives (.ZIP files) can be used transparently as
  10. * directory structures.
  11. *
  12. * This system is largely inspired by Quake 3's PK3 files and the related
  13. * fs_* cvars. If you've ever tinkered with these, then this API will be
  14. * familiar to you.
  15. *
  16. * With PhysicsFS, you have a single writing directory and multiple
  17. * directories (the "search path") for reading. You can think of this as a
  18. * filesystem within a filesystem. If (on Windows) you were to set the
  19. * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
  20. * could touch anything above this directory, including the "C:\MyGame" and
  21. * "C:\" directories. This prevents an application's internal scripting
  22. * language from piddling over c:\config.sys, for example. If you'd rather
  23. * give PHYSFS full access to the system's REAL file system, set the writing
  24. * dir to "C:\", but that's generally A Bad Thing for several reasons.
  25. *
  26. * Drive letters are hidden in PhysicsFS once you set up your initial paths.
  27. * The search path creates a single, hierarchical directory structure.
  28. * Not only does this lend itself well to general abstraction with archives,
  29. * it also gives better support to operating systems like MacOS and Unix.
  30. * Generally speaking, you shouldn't ever hardcode a drive letter; not only
  31. * does this hurt portability to non-Microsoft OSes, but it limits your win32
  32. * users to a single drive, too. Use the PhysicsFS abstraction functions and
  33. * allow user-defined configuration options, too. When opening a file, you
  34. * specify it like it was on a Unix filesystem: if you want to write to
  35. * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to
  36. * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
  37. * abstraction across all platforms. Specifying a file in this way is termed
  38. * "platform-independent notation" in this documentation. Specifying a
  39. * a filename in a form such as "C:\mydir\myfile" or
  40. * "MacOS hard drive:My Directory:My File" is termed "platform-dependent
  41. * notation". The only time you use platform-dependent notation is when
  42. * setting up your write directory and search path; after that, all file
  43. * access into those directories are done with platform-independent notation.
  44. *
  45. * All files opened for writing are opened in relation to the write directory,
  46. * which is the root of the writable filesystem. When opening a file for
  47. * reading, PhysicsFS goes through the search path. This is NOT the
  48. * same thing as the PATH environment variable. An application using
  49. * PhysicsFS specifies directories to be searched which may be actual
  50. * directories, or archive files that contain files and subdirectories of
  51. * their own. See the end of these docs for currently supported archive
  52. * formats.
  53. *
  54. * Once the search path is defined, you may open files for reading. If you've
  55. * got the following search path defined (to use a win32 example again):
  56. *
  57. * C:\mygame
  58. * C:\mygame\myuserfiles
  59. * D:\mygamescdromdatafiles
  60. * C:\mygame\installeddatafiles.zip
  61. *
  62. * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory
  63. * separator, lack of drive letter, and lack of dir separator at the start of
  64. * the string; this is platform-independent notation) will check for
  65. * C:\mygame\textfiles\myfile.txt, then
  66. * C:\mygame\myuserfiles\textfiles\myfile.txt, then
  67. * D:\mygamescdromdatafiles\textfiles\myfile.txt, then, finally, for
  68. * textfiles\myfile.txt inside of C:\mygame\installeddatafiles.zip. Remember
  69. * that most archive types and platform filesystems store their filenames in
  70. * a case-sensitive manner, so you should be careful to specify it correctly.
  71. *
  72. * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir
  73. * elements. Not only are these meaningless on MacOS and/or Unix, they are a
  74. * security hole. Also, symbolic links (which can be found in some archive
  75. * types and directly in the filesystem on Unix platforms) are NOT followed
  76. * until you call PHYSFS_permitSymbolicLinks(). That's left to your own
  77. * discretion, as following a symlink can allow for access outside the write
  78. * dir and search paths. There is no mechanism for creating new symlinks in
  79. * PhysicsFS.
  80. *
  81. * The write dir is not included in the search path unless you specifically
  82. * add it. While you CAN change the write dir as many times as you like,
  83. * you should probably set it once and stick to it. Remember that your
  84. * program will not have permission to write in every directory on Unix and
  85. * NT systems.
  86. *
  87. * All files are opened in binary mode; there is no endline conversion for
  88. * textfiles. Other than that, PhysicsFS has some convenience functions for
  89. * platform-independence. There is a function to tell you the current
  90. * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS),
  91. * which is needed only to set up your search/write paths. There is a
  92. * function to tell you what CD-ROM drives contain accessible discs, and a
  93. * function to recommend a good search path, etc.
  94. *
  95. * A recommended order for the search path is the write dir, then the base dir,
  96. * then the cdrom dir, then any archives discovered. Quake 3 does something
  97. * like this, but moves the archives to the start of the search path. Build
  98. * Engine games, like Duke Nukem 3D and Blood, place the archives last, and
  99. * use the base dir for both searching and writing. There is a helper
  100. * function (PHYSFS_setSaneConfig()) that puts together a basic configuration
  101. * for you, based on a few parameters. Also see the comments on
  102. * PHYSFS_getBaseDir(), and PHYSFS_getUserDir() for info on what those
  103. * are and how they can help you determine an optimal search path.
  104. *
  105. * PhysicsFS is mostly thread safe. The error messages returned by
  106. * PHYSFS_getLastError are unique by thread, and library-state-setting
  107. * functions are mutex'd. For efficiency, individual file accesses are
  108. * not locked, so you can not safely read/write/seek/close/etc the same
  109. * file from two threads at the same time. Other race conditions are bugs
  110. * that should be reported/patched.
  111. *
  112. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  113. * calls, doing so is not recommended, and you can not use system
  114. * filehandles with PhysicsFS and vice versa.
  115. *
  116. * Note that archives need not be named as such: if you have a ZIP file and
  117. * rename it with a .PKG extension, the file will still be recognized as a
  118. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  119. * type.
  120. *
  121. * Currently supported archive types:
  122. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  123. *
  124. * Please see the file LICENSE in the source's root directory.
  125. *
  126. * This file written by Ryan C. Gordon.
  127. */
  128. #ifndef _INCLUDE_PHYSFS_H_
  129. #define _INCLUDE_PHYSFS_H_
  130. #ifdef __cplusplus
  131. extern "C" {
  132. #endif
  133. #if (defined _MSC_VER)
  134. #define __EXPORT__ __declspec(dllexport)
  135. #else
  136. #define __EXPORT__
  137. #endif
  138. /* !!! FIXME: This is not universal. */
  139. typedef unsigned char PHYSFS_uint8;
  140. typedef signed char PHYSFS_sint8;
  141. typedef unsigned short PHYSFS_uint16;
  142. typedef signed short PHYSFS_sint16;
  143. typedef unsigned int PHYSFS_uint32;
  144. typedef signed int PHYSFS_sint32;
  145. #ifdef PHYSFS_NO_64BIT_SUPPORT /* oh well. */
  146. typedef PHYSFS_uint32 PHYSFS_uint64;
  147. typedef PHYSFS_sint32 PHYSFS_sint64;
  148. #else
  149. typedef unsigned long long PHYSFS_uint64;
  150. typedef signed long long PHYSFS_sint64;
  151. #endif
  152. /* Make sure the types really have the right sizes */
  153. #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \
  154. typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1]
  155. PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1);
  156. PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1);
  157. PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2);
  158. PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2);
  159. PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4);
  160. PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4);
  161. #ifndef PHYSFS_NO_64BIT_SUPPORT
  162. PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8);
  163. PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8);
  164. #endif
  165. #undef PHYSFS_COMPILE_TIME_ASSERT
  166. typedef struct __PHYSFS_FILE__
  167. {
  168. void *opaque;
  169. } PHYSFS_file;
  170. typedef struct __PHYSFS_ARCHIVEINFO__
  171. {
  172. const char *extension;
  173. const char *description;
  174. const char *author;
  175. const char *url;
  176. } PHYSFS_ArchiveInfo;
  177. /* functions... */
  178. typedef struct __PHYSFS_VERSION__
  179. {
  180. PHYSFS_uint8 major;
  181. PHYSFS_uint8 minor;
  182. PHYSFS_uint8 patch;
  183. } PHYSFS_Version;
  184. #define PHYSFS_VER_MAJOR 0
  185. #define PHYSFS_VER_MINOR 1
  186. #define PHYSFS_VER_PATCH 4
  187. #define PHYSFS_VERSION(x) { \
  188. (x)->major = PHYSFS_VER_MAJOR; \
  189. (x)->minor = PHYSFS_VER_MINOR; \
  190. (x)->patch = PHYSFS_VER_PATCH; \
  191. }
  192. /**
  193. * Get the version of PhysicsFS that is linked against your program. If you
  194. * are using a shared library (DLL) version of PhysFS, then it is possible
  195. * that it will be different than the version you compiled against.
  196. *
  197. * This is a real function; the macro PHYSFS_VERSION tells you what version
  198. * of PhysFS you compiled against:
  199. *
  200. * PHYSFS_Version compiled;
  201. * PHYSFS_Version linked;
  202. *
  203. * PHYSFS_VERSION(&compiled);
  204. * PHYSFS_getLinkedVersion(&linked);
  205. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  206. * compiled.major, compiled.minor, compiled.patch);
  207. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  208. * linked.major, linked.minor, linked.patch);
  209. *
  210. * This function may be called safely at any time, even before PHYSFS_init().
  211. */
  212. __EXPORT__ void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  213. /**
  214. * Initialize PhysicsFS. This must be called before any other PhysicsFS
  215. * function.
  216. *
  217. * This should be called prior to any attempts to change your process's
  218. * current working directory.
  219. *
  220. * @param argv0 the argv[0] string passed to your program's mainline.
  221. * @return nonzero on success, zero on error. Specifics of the error can be
  222. * gleaned from PHYSFS_getLastError().
  223. */
  224. __EXPORT__ int PHYSFS_init(const char *argv0);
  225. /**
  226. * Shutdown PhysicsFS. This closes any files opened via PhysicsFS, blanks the
  227. * search/write paths, frees memory, and invalidates all of your handles.
  228. *
  229. * Note that this call can FAIL if there's a file open for writing that
  230. * refuses to close (for example, the underlying operating system was
  231. * buffering writes to network filesystem, and the fileserver has crashed,
  232. * or a hard drive has failed, etc). It is usually best to close all write
  233. * handles yourself before calling this function, so that you can gracefully
  234. * handle a specific failure.
  235. *
  236. * Once successfully deinitialized, PHYSFS_init() can be called again to
  237. * restart the subsystem. All defaults API states are restored at this
  238. * point.
  239. *
  240. * @return nonzero on success, zero on error. Specifics of the error can be
  241. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  242. * undefined, and probably badly screwed up.
  243. */
  244. __EXPORT__ int PHYSFS_deinit(void);
  245. /**
  246. * Get a list of archive types supported by this implementation of PhysicFS.
  247. * These are the file formats usable for search path entries. This is for
  248. * informational purposes only. Note that the extension listed is merely
  249. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  250. * with an extension of "XYZ", if you like.
  251. *
  252. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  253. * with a NULL entry to signify the end of the list:
  254. *
  255. * PHYSFS_ArchiveInfo **i;
  256. *
  257. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  258. * {
  259. * printf("Supported archive: [%s], which is [%s].\n",
  260. * i->extension, i->description);
  261. * }
  262. *
  263. * The return values are pointers to static internal memory, and should
  264. * be considered READ ONLY, and never freed.
  265. *
  266. * @return READ ONLY Null-terminated array of READ ONLY structures.
  267. */
  268. __EXPORT__ const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  269. /**
  270. * Certain PhysicsFS functions return lists of information that are
  271. * dynamically allocated. Use this function to free those resources.
  272. *
  273. * @param list List of information specified as freeable by this function.
  274. */
  275. __EXPORT__ void PHYSFS_freeList(void *listVar);
  276. /**
  277. * Get the last PhysicsFS error message as a null-terminated string.
  278. * This will be NULL if there's been no error since the last call to this
  279. * function. The pointer returned by this call points to an internal buffer.
  280. * Each thread has a unique error state associated with it, but each time
  281. * a new error message is set, it will overwrite the previous one associated
  282. * with that thread. It is safe to call this function at anytime, even
  283. * before PHYSFS_init().
  284. *
  285. * @return READ ONLY string of last error message.
  286. */
  287. __EXPORT__ const char *PHYSFS_getLastError(void);
  288. /**
  289. * Get a platform-dependent dir separator. This is "\\" on win32, "/" on Unix,
  290. * and ":" on MacOS. It may be more than one character, depending on the
  291. * platform, and your code should take that into account. Note that this is
  292. * only useful for setting up the search/write paths, since access into those
  293. * dirs always use '/' (platform-independent notation) to separate
  294. * directories. This is also handy for getting platform-independent access
  295. * when using stdio calls.
  296. *
  297. * @return READ ONLY null-terminated string of platform's dir separator.
  298. */
  299. __EXPORT__ const char *PHYSFS_getDirSeparator(void);
  300. /**
  301. * Enable symbolic links. Some physical filesystems and archives contain
  302. * files that are just pointers to other files. On the physical filesystem,
  303. * opening such a link will (transparently) open the file that is pointed to.
  304. *
  305. * By default, PhysicsFS will check if a file is really a symlink during open
  306. * calls and fail if it is. Otherwise, the link could take you outside the
  307. * write and search paths, and compromise security.
  308. *
  309. * If you want to take that risk, call this function with a non-zero parameter.
  310. * Note that this is more for sandboxing a program's scripting language, in
  311. * case untrusted scripts try to compromise the system. Generally speaking,
  312. * a user could very well have a legitimate reason to set up a symlink, so
  313. * unless you feel there's a specific danger in allowing them, you should
  314. * permit them.
  315. *
  316. * Symlinks are only explicitly checked when dealing with filenames
  317. * in platform-independent notation. That is, when setting up your
  318. * search and write paths, etc, symlinks are never checked for.
  319. *
  320. * Symbolic link permission can be enabled or disabled at any time, and is
  321. * disabled by default.
  322. *
  323. * @param allow nonzero to permit symlinks, zero to deny linking.
  324. */
  325. __EXPORT__ void PHYSFS_permitSymbolicLinks(int allow);
  326. /**
  327. * Get an array of dirs to available CD-ROM drives.
  328. *
  329. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  330. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  331. * accessible in the drive. So if you've got two drives (D: and E:), and only
  332. * E: has a disc in it, then that's all you get. If the user inserts a disc
  333. * in D: and you call this function again, you get both drives. If, on a
  334. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  335. * call to this function will reflect that change. Fun.
  336. *
  337. * The returned value is an array of strings, with a NULL entry to signify the
  338. * end of the list:
  339. *
  340. * char **cds = PHYSFS_getCdRomDirs();
  341. * char **i;
  342. *
  343. * for (i = cds; *i != NULL; i++)
  344. * printf("cdrom dir [%s] is available.\n", *i);
  345. *
  346. * PHYSFS_freeList(cds);
  347. *
  348. * This call may block while drives spin up. Be forewarned.
  349. *
  350. * When you are done with the returned information, you may dispose of the
  351. * resources by calling PHYSFS_freeList() with the returned pointer.
  352. *
  353. * @return Null-terminated array of null-terminated strings.
  354. */
  355. __EXPORT__ char **PHYSFS_getCdRomDirs(void);
  356. /**
  357. * Helper function.
  358. *
  359. * Get the "base dir". This is the directory where the application was run
  360. * from, which is probably the installation directory, and may or may not
  361. * be the process's current working directory.
  362. *
  363. * You should probably use the base dir in your search path.
  364. *
  365. * @return READ ONLY string of base dir in platform-dependent notation.
  366. */
  367. __EXPORT__ const char *PHYSFS_getBaseDir(void);
  368. /**
  369. * Helper function.
  370. *
  371. * Get the "user dir". This is meant to be a suggestion of where a specific
  372. * user of the system can store files. On Unix, this is her home directory.
  373. * On systems with no concept of multiple home directories (MacOS, win95),
  374. * this will default to something like "C:\mybasedir\users\username"
  375. * where "username" will either be the login name, or "default" if the
  376. * platform doesn't support multiple users, either.
  377. *
  378. * You should probably use the user dir as the basis for your write dir, and
  379. * also put it near the beginning of your search path.
  380. *
  381. * @return READ ONLY string of user dir in platform-dependent notation.
  382. */
  383. __EXPORT__ const char *PHYSFS_getUserDir(void);
  384. /**
  385. * Get the current write dir. The default write dir is NULL.
  386. *
  387. * @return READ ONLY string of write dir in platform-dependent notation,
  388. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  389. */
  390. __EXPORT__ const char *PHYSFS_getWriteDir(void);
  391. /**
  392. * Set a new write dir. This will override the previous setting. If the
  393. * directory or a parent directory doesn't exist in the physical filesystem,
  394. * PhysicsFS will attempt to create them as needed.
  395. *
  396. * This call will fail (and fail to change the write dir) if the current
  397. * write dir still has files open in it.
  398. *
  399. * @param newDir The new directory to be the root of the write dir,
  400. * specified in platform-dependent notation. Setting to NULL
  401. * disables the write dir, so no files can be opened for
  402. * writing via PhysicsFS.
  403. * @return non-zero on success, zero on failure. All attempts to open a file
  404. * for writing via PhysicsFS will fail until this call succeeds.
  405. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  406. *
  407. */
  408. __EXPORT__ int PHYSFS_setWriteDir(const char *newDir);
  409. /**
  410. * Add a directory or archive to the search path. If this is a duplicate, the
  411. * entry is not added again, even though the function succeeds.
  412. *
  413. * @param newDir directory or archive to add to the path, in
  414. * platform-dependent notation.
  415. * @param appendToPath nonzero to append to search path, zero to prepend.
  416. * @return nonzero if added to path, zero on failure (bogus archive, dir
  417. * missing, etc). Specifics of the error can be
  418. * gleaned from PHYSFS_getLastError().
  419. */
  420. __EXPORT__ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  421. /**
  422. * Remove a directory or archive from the search path.
  423. *
  424. * This must be a (case-sensitive) match to a dir or archive already in the
  425. * search path, specified in platform-dependent notation.
  426. *
  427. * This call will fail (and fail to remove from the path) if the element still
  428. * has files open in it.
  429. *
  430. * @param oldDir dir/archive to remove.
  431. * @return nonzero on success, zero on failure.
  432. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  433. */
  434. __EXPORT__ int PHYSFS_removeFromSearchPath(const char *oldDir);
  435. /**
  436. * Get the current search path. The default search path is an empty list.
  437. *
  438. * The returned value is an array of strings, with a NULL entry to signify the
  439. * end of the list:
  440. *
  441. * char **i;
  442. *
  443. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  444. * printf("[%s] is in the search path.\n", *i);
  445. *
  446. * When you are done with the returned information, you may dispose of the
  447. * resources by calling PHYSFS_freeList() with the returned pointer.
  448. *
  449. * @return Null-terminated array of null-terminated strings. NULL if there
  450. * was a problem (read: OUT OF MEMORY).
  451. */
  452. __EXPORT__ char **PHYSFS_getSearchPath(void);
  453. /**
  454. * Helper function.
  455. *
  456. * Set up sane, default paths. The write dir will be set to
  457. * "userdir/.organization/appName", which is created if it doesn't exist.
  458. *
  459. * The above is sufficient to make sure your program's configuration directory
  460. * is separated from other clutter, and platform-independent. The period
  461. * before "mygame" even hides the directory on Unix systems.
  462. *
  463. * The search path will be:
  464. *
  465. * - The Write Dir (created if it doesn't exist)
  466. * - The Base Dir (PHYSFS_getBaseDir())
  467. * - All found CD-ROM dirs (optionally)
  468. *
  469. * These directories are then searched for files ending with the extension
  470. * (archiveExt), which, if they are valid and supported archives, will also
  471. * be added to the search path. If you specified "PKG" for (archiveExt), and
  472. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  473. * can either be appended or prepended to the search path in alphabetical
  474. * order, regardless of which directories they were found in.
  475. *
  476. * All of this can be accomplished from the application, but this just does it
  477. * all for you. Feel free to add more to the search path manually, too.
  478. *
  479. * @param organization Name of your company/group/etc to be used as a
  480. * dirname, so keep it small, and no-frills.
  481. *
  482. * @param appName Program-specific name of your program, to separate it
  483. * from other programs using PhysicsFS.
  484. *
  485. * @param archiveExt File extention used by your program to specify an
  486. * archive. For example, Quake 3 uses "pk3", even though
  487. * they are just zipfiles. Specify NULL to not dig out
  488. * archives automatically. Do not specify the '.' char;
  489. * If you want to look for ZIP files, specify "ZIP" and
  490. * not ".ZIP" ... the archive search is case-insensitive.
  491. *
  492. * @param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  493. * (if (archiveExt) != NULL) search them for archives.
  494. * This may cause a significant amount of blocking
  495. * while discs are accessed, and if there are no discs
  496. * in the drive (or even not mounted on Unix systems),
  497. * then they may not be made available anyhow. You may
  498. * want to specify zero and handle the disc setup
  499. * yourself.
  500. *
  501. * @param archivesFirst Non-zero to prepend the archives to the search path.
  502. * Zero to append them. Ignored if !(archiveExt).
  503. *
  504. * @return nonzero on success, zero on error. Specifics of the error can be
  505. * gleaned from PHYSFS_getLastError().
  506. */
  507. __EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
  508. const char *appName,
  509. const char *archiveExt,
  510. int includeCdRoms,
  511. int archivesFirst);
  512. /**
  513. * Create a directory. This is specified in platform-independent notation in
  514. * relation to the write dir. All missing parent directories are also
  515. * created if they don't exist.
  516. *
  517. * So if you've got the write dir set to "C:\mygame\writedir" and call
  518. * PHYSFS_mkdir("downloads/maps") then the directories
  519. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  520. * will be created if possible. If the creation of "maps" fails after we
  521. * have successfully created "downloads", then the function leaves the
  522. * created directory behind and reports failure.
  523. *
  524. * @param dirname New dir to create.
  525. * @return nonzero on success, zero on error. Specifics of the error can be
  526. * gleaned from PHYSFS_getLastError().
  527. */
  528. __EXPORT__ int PHYSFS_mkdir(const char *dirName);
  529. /**
  530. * Delete a file or directory. This is specified in platform-independent
  531. * notation in relation to the write dir.
  532. *
  533. * A directory must be empty before this call can delete it.
  534. *
  535. * Deleting a symlink will remove the link, not what it points to, regardless
  536. * of whether you "permitSymLinks" or not.
  537. *
  538. * So if you've got the write dir set to "C:\mygame\writedir" and call
  539. * PHYSFS_delete("downloads/maps/level1.map") then the file
  540. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  541. * physical filesystem, if it exists and the operating system permits the
  542. * deletion.
  543. *
  544. * Note that on Unix systems, deleting a file may be successful, but the
  545. * actual file won't be removed until all processes that have an open
  546. * filehandle to it (including your program) close their handles.
  547. *
  548. * Chances are, the bits that make up the file still exist, they are just
  549. * made available to be written over at a later point. Don't consider this
  550. * a security method or anything. :)
  551. *
  552. * @param filename Filename to delete.
  553. * @return nonzero on success, zero on error. Specifics of the error can be
  554. * gleaned from PHYSFS_getLastError().
  555. */
  556. __EXPORT__ int PHYSFS_delete(const char *filename);
  557. /**
  558. * Figure out where in the search path a file resides. The file is specified
  559. * in platform-independent notation. The returned filename will be the
  560. * element of the search path where the file was found, which may be a
  561. * directory, or an archive. Even if there are multiple matches in different
  562. * parts of the search path, only the first one found is used, just like
  563. * when opening a file.
  564. *
  565. * So, if you look for "maps/level1.map", and C:\mygame is in your search
  566. * path and C:\mygame\maps\level1.map exists, then "C:\mygame" is returned.
  567. *
  568. * If a any part of a match is a symbolic link, and you've not explicitly
  569. * permitted symlinks, then it will be ignored, and the search for a match
  570. * will continue.
  571. *
  572. * @param filename file to look for.
  573. * @return READ ONLY string of element of search path containing the
  574. * the file in question. NULL if not found.
  575. */
  576. __EXPORT__ const char *PHYSFS_getRealDir(const char *filename);
  577. /**
  578. * Get a file listing of a search path's directory. Matching directories are
  579. * interpolated. That is, if "C:\mydir" is in the search path and contains a
  580. * directory "savegames" that contains "x.sav", "y.sav", and "z.sav", and
  581. * there is also a "C:\userdir" in the search path that has a "savegames"
  582. * subdirectory with "w.sav", then the following code:
  583. *
  584. * ------------------------------------------------
  585. * char **rc = PHYSFS_enumerateFiles("savegames");
  586. * char **i;
  587. *
  588. * for (i = rc; *i != NULL; i++)
  589. * printf("We've got [%s].\n", *i);
  590. *
  591. * PHYSFS_freeList(rc);
  592. * ------------------------------------------------
  593. *
  594. * ...will print:
  595. *
  596. * ------------------------------------------------
  597. * We've got [x.sav].
  598. * We've got [y.sav].
  599. * We've got [z.sav].
  600. * We've got [w.sav].
  601. * ------------------------------------------------
  602. *
  603. * Feel free to sort the list however you like. We only promise there will
  604. * be no duplicates, but not what order the final list will come back in.
  605. *
  606. * Don't forget to call PHYSFS_freeList() with the return value from this
  607. * function when you are done with it.
  608. *
  609. * @param dir directory in platform-independent notation to enumerate.
  610. * @return Null-terminated array of null-terminated strings.
  611. */
  612. __EXPORT__ char **PHYSFS_enumerateFiles(const char *dir);
  613. /**
  614. * Determine if there is an entry anywhere in the search path by the
  615. * name of (fname).
  616. *
  617. * Note that entries that are symlinks are ignored if
  618. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  619. * might end up further down in the search path than expected.
  620. *
  621. * @param fname filename in platform-independent notation.
  622. * @return non-zero if filename exists. zero otherwise.
  623. */
  624. __EXPORT__ int PHYSFS_exists(const char *fname);
  625. /**
  626. * Determine if the first occurence of (fname) in the search path is
  627. * really a directory entry.
  628. *
  629. * Note that entries that are symlinks are ignored if
  630. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  631. * might end up further down in the search path than expected.
  632. *
  633. * @param fname filename in platform-independent notation.
  634. * @return non-zero if filename exists and is a directory. zero otherwise.
  635. */
  636. __EXPORT__ int PHYSFS_isDirectory(const char *fname);
  637. /**
  638. * Determine if the first occurence of (fname) in the search path is
  639. * really a symbolic link.
  640. *
  641. * Note that entries that are symlinks are ignored if
  642. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  643. * this function will always return 0 in that case.
  644. *
  645. * @param fname filename in platform-independent notation.
  646. * @return non-zero if filename exists and is a symlink. zero otherwise.
  647. */
  648. __EXPORT__ int PHYSFS_isSymbolicLink(const char *fname);
  649. /**
  650. * Open a file for writing, in platform-independent notation and in relation
  651. * to the write dir as the root of the writable filesystem. The specified
  652. * file is created if it doesn't exist. If it does exist, it is truncated to
  653. * zero bytes, and the writing offset is set to the start.
  654. *
  655. * Note that entries that are symlinks are ignored if
  656. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  657. * symlink with this function will fail in such a case.
  658. *
  659. * @param filename File to open.
  660. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  661. * of the error can be gleaned from PHYSFS_getLastError().
  662. */
  663. __EXPORT__ PHYSFS_file *PHYSFS_openWrite(const char *filename);
  664. /**
  665. * Open a file for writing, in platform-independent notation and in relation
  666. * to the write dir as the root of the writable filesystem. The specified
  667. * file is created if it doesn't exist. If it does exist, the writing offset
  668. * is set to the end of the file, so the first write will be the byte after
  669. * the end.
  670. *
  671. * Note that entries that are symlinks are ignored if
  672. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  673. * symlink with this function will fail in such a case.
  674. *
  675. * @param filename File to open.
  676. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  677. * of the error can be gleaned from PHYSFS_getLastError().
  678. */
  679. __EXPORT__ PHYSFS_file *PHYSFS_openAppend(const char *filename);
  680. /**
  681. * Open a file for reading, in platform-independent notation. The search path
  682. * is checked one at a time until a matching file is found, in which case an
  683. * abstract filehandle is associated with it, and reading may be done.
  684. * The reading offset is set to the first byte of the file.
  685. *
  686. * Note that entries that are symlinks are ignored if
  687. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  688. * symlink with this function will fail in such a case.
  689. *
  690. * @param filename File to open.
  691. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  692. * of the error can be gleaned from PHYSFS_getLastError().
  693. */
  694. __EXPORT__ PHYSFS_file *PHYSFS_openRead(const char *filename);
  695. /**
  696. * Close a PhysicsFS filehandle. This call is capable of failing if the
  697. * operating system was buffering writes to this file, and (now forced to
  698. * write those changes to physical media) can not store the data for any
  699. * reason. In such a case, the filehandle stays open. A well-written program
  700. * should ALWAYS check the return value from the close call in addition to
  701. * every writing call!
  702. *
  703. * @param handle handle returned from PHYSFS_open*().
  704. * @return nonzero on success, zero on error. Specifics of the error can be
  705. * gleaned from PHYSFS_getLastError().
  706. */
  707. __EXPORT__ int PHYSFS_close(PHYSFS_file *handle);
  708. /**
  709. * Read data from a PhysicsFS filehandle. The file must be opened for reading.
  710. *
  711. * @param handle handle returned from PHYSFS_openRead().
  712. * @param buffer buffer to store read data into.
  713. * @param objSize size in bytes of objects being read from (handle).
  714. * @param objCount number of (objSize) objects to read from (handle).
  715. * @return number of objects read. PHYSFS_getLastError() can shed light on
  716. * the reason this might be < (objCount), as can PHYSFS_eof().
  717. * -1 if complete failure.
  718. */
  719. __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_file *handle,
  720. void *buffer,
  721. PHYSFS_uint32 objSize,
  722. PHYSFS_uint32 objCount);
  723. /**
  724. * Write data to a PhysicsFS filehandle. The file must be opened for writing.
  725. *
  726. * @param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  727. * @param buffer buffer to store read data into.
  728. * @param objSize size in bytes of objects being read from (handle).
  729. * @param objCount number of (objSize) objects to read from (handle).
  730. * @return number of objects written. PHYSFS_getLastError() can shed light on
  731. * the reason this might be < (objCount). -1 if complete failure.
  732. */
  733. __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_file *handle,
  734. const void *buffer,
  735. PHYSFS_uint32 objSize,
  736. PHYSFS_uint32 objCount);
  737. /**
  738. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  739. *
  740. * @param handle handle returned from PHYSFS_openRead().
  741. * @return nonzero if EOF, zero if not.
  742. */
  743. __EXPORT__ int PHYSFS_eof(PHYSFS_file *handle);
  744. /**
  745. * Determine current position within a PhysicsFS filehandle.
  746. *
  747. * @param handle handle returned from PHYSFS_open*().
  748. * @return offset in bytes from start of file. -1 if error occurred.
  749. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  750. */
  751. __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_file *handle);
  752. /**
  753. * Seek to a new position within a PhysicsFS filehandle. The next read or write
  754. * will occur at that place. Seeking past the beginning or end of the file is
  755. * not allowed.
  756. *
  757. * @param handle handle returned from PHYSFS_open*().
  758. * @param pos number of bytes from start of file to seek to.
  759. * @return nonzero on success, zero on error. Specifics of the error can be
  760. * gleaned from PHYSFS_getLastError().
  761. */
  762. __EXPORT__ int PHYSFS_seek(PHYSFS_file *handle, PHYSFS_uint64 pos);
  763. /**
  764. * Get total length of a file in bytes. Note that if the file size can't
  765. * be determined (since the archive is "streamed" or whatnot) than this
  766. * will report (-1). Also note that if another process/thread is writing
  767. * to this file at the same time, then the information this function
  768. * supplies could be incorrect before you get it. Use with caution, or
  769. * better yet, don't use at all.
  770. *
  771. * @param handle handle returned from PHYSFS_open*().
  772. * @return size in bytes of the file. -1 if can't be determined.
  773. */
  774. __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_file *handle);
  775. #if 0 /* !!! FIXME: add this? */
  776. #undef __EXPORT__
  777. #endif
  778. #ifdef __cplusplus
  779. }
  780. #endif
  781. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  782. /* end of physfs.h ... */