physfs.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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 (sort of) NOT thread safe! The error messages returned by
  106. * PHYSFS_getLastError are unique by thread, but that's it. Generally
  107. * speaking, we'd have to request a mutex at the start of each function,
  108. * and release it before returning. Not only is this REALLY slow, it requires
  109. * a thread lock portability layer to be written. All that work is only
  110. * necessary as a safety if the calling application is poorly written.
  111. * Generally speaking, it is safe to call most functions that don't set state
  112. * simultaneously; you can read and write and open and close different files
  113. * at the same time in different threads, but trying to set the write path in
  114. * one thread while opening a file for writing in another will, at best,
  115. * cause a polite error, but depending on the race condition results, you may
  116. * get a segfault and crash, too. Use your head, and implement you own thread
  117. * locks where needed. Also, consider if you REALLY need a multithreaded
  118. * solution in the first place.
  119. *
  120. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  121. * calls, doing so is not recommended, and you can not use system
  122. * filehandles with PhysicsFS filehandles and vice versa.
  123. *
  124. * Note that archives need not be named as such: if you have a ZIP file and
  125. * rename it with a .PKG extension, the file will still be recognized as a
  126. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  127. * type.
  128. *
  129. * Currently supported archive types:
  130. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  131. *
  132. * Please see the file LICENSE in the source's root directory.
  133. *
  134. * This file written by Ryan C. Gordon.
  135. */
  136. #ifndef _INCLUDE_PHYSFS_H_
  137. #define _INCLUDE_PHYSFS_H_
  138. #ifdef __cplusplus
  139. extern "C" {
  140. #endif
  141. typedef struct __PHYSFS_FILE__
  142. {
  143. void *opaque;
  144. } PHYSFS_file;
  145. typedef struct __PHYSFS_ARCHIVEINFO__
  146. {
  147. const char *extension;
  148. const char *description;
  149. } PHYSFS_ArchiveInfo;
  150. /* functions... */
  151. typedef struct __PHYSFS_VERSION__
  152. {
  153. int major;
  154. int minor;
  155. int patch;
  156. } PHYSFS_Version;
  157. #define PHYSFS_VER_MAJOR 0
  158. #define PHYSFS_VER_MINOR 1
  159. #define PHYSFS_VER_PATCH 0
  160. #define PHYSFS_VERSION(x) { \
  161. x->major = PHYSFS_VER_MAJOR; \
  162. x->minor = PHYSFS_VER_MINOR; \
  163. x->patch = PHYSFS_VER_PATCH; \
  164. }
  165. /**
  166. * Get the version of PhysicsFS that is linked against your program. If you
  167. * are using a shared library (DLL) version of PhysFS, then it is possible
  168. * that it will be different than the version you compiled against.
  169. *
  170. * This is a real function; the macro PHYSFS_VERSION tells you what version
  171. * of PhysFS you compiled against:
  172. *
  173. * PHYSFS_Version compiled;
  174. * PHYSFS_Version linked;
  175. *
  176. * PHYSFS_VERSION(&compiled);
  177. * PHYSFS_getLinkedVersion(&linked);
  178. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  179. * compiled.major, compiled.minor, compiled.patch);
  180. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  181. * linked.major, linked.minor, linked.patch);
  182. *
  183. * This function may be called safely at any time, even before PHYSFS_init().
  184. */
  185. void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  186. /**
  187. * Initialize PhysicsFS. This must be called before any other PhysicsFS
  188. * function.
  189. *
  190. * @param argv0 the argv[0] string passed to your program's mainline.
  191. * @return nonzero on success, zero on error. Specifics of the error can be
  192. * gleaned from PHYSFS_getLastError().
  193. */
  194. int PHYSFS_init(const char *argv0);
  195. /**
  196. * Shutdown PhysicsFS. This closes any files opened via PhysicsFS, blanks the
  197. * search/write paths, frees memory, and invalidates all of your handles.
  198. *
  199. * Once deinitialized, PHYSFS_init() can be called again to restart the
  200. * subsystem.
  201. *
  202. * This function can be used with atexit(), if you feel it's prudent to do so.
  203. *
  204. * @return nonzero on success, zero on error. Specifics of the error can be
  205. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  206. * undefined, and probably badly screwed up.
  207. */
  208. void PHYSFS_deinit(void);
  209. /**
  210. * Get a list of archive types supported by this implementation of PhysicFS.
  211. * These are the file formats usable for search path entries. This is for
  212. * informational purposes only. Note that the extension listed is merely
  213. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  214. * with an extension of "XYZ", if you like.
  215. *
  216. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  217. * with a NULL entry to signify the end of the list:
  218. *
  219. * PHYSFS_ArchiveInfo **i;
  220. *
  221. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  222. * {
  223. * printf("Supported archive: [%s], which is [%s].\n",
  224. * i->extension, i->description);
  225. * }
  226. *
  227. * The return values are pointers to static internal memory, and should
  228. * be considered READ ONLY, and never freed.
  229. *
  230. * @return READ ONLY Null-terminated array of READ ONLY structures.
  231. */
  232. const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  233. /**
  234. * Certain PhysicsFS functions return lists of information that are
  235. * dynamically allocated. Use this function to free those resources.
  236. *
  237. * @param list List of information specified as freeable by this function.
  238. */
  239. void PHYSFS_freeList(void *list);
  240. /**
  241. * Get the last PhysicsFS error message as a null-terminated string.
  242. * This will be NULL if there's been no error since the last call to this
  243. * function. The pointer returned by this call points to an internal buffer.
  244. * Each thread has a unique error state associated with it, but each time
  245. * a new error message is set, it will overwrite the previous one associated
  246. * with that thread. It is safe to call this function at anytime, even
  247. * before PHYSFS_init().
  248. *
  249. * @return READ ONLY string of last error message.
  250. */
  251. const char *PHYSFS_getLastError(void);
  252. /**
  253. * Get a platform-dependent dir separator. This is "\\" on win32, "/" on Unix,
  254. * and ":" on MacOS. It may be more than one character, depending on the
  255. * platform, and your code should take that into account. Note that this is
  256. * only useful for setting up the search/write paths, since access into those
  257. * dirs always use '/' (platform-independent notation) to separate
  258. * directories. This is also handy for getting platform-independent access
  259. * when using stdio calls.
  260. *
  261. * @return READ ONLY null-terminated string of platform's dir separator.
  262. */
  263. const char *PHYSFS_getDirSeparator(void);
  264. /**
  265. * Get an array of dirs to available CD-ROM drives.
  266. *
  267. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  268. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  269. * accessible in the drive. So if you've got two drives (D: and E:), and only
  270. * E: has a disc in it, then that's all you get. If the user inserts a disc
  271. * in D: and you call this function again, you get both drives. If, on a
  272. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  273. * call to this function will reflect that change. Fun.
  274. *
  275. * The returned value is an array of strings, with a NULL entry to signify the
  276. * end of the list:
  277. *
  278. * char **cds = PHYSFS_getCdRomDirs();
  279. * char **i;
  280. *
  281. * for (i = cds; *i != NULL; i++)
  282. * printf("cdrom dir [%s] is available.\n", *i);
  283. *
  284. * PHYSFS_freeList(cds);
  285. *
  286. * This call may block while drives spin up. Be forewarned.
  287. *
  288. * When you are done with the returned information, you may dispose of the
  289. * resources by calling PHYSFS_freeList() with the returned pointer.
  290. *
  291. * @return Null-terminated array of null-terminated strings.
  292. */
  293. char **PHYSFS_getCdRomDirs(void);
  294. /**
  295. * Helper function.
  296. *
  297. * Get the "base dir". This is the directory where the application was run
  298. * from, which is probably the installation directory, and may or may not
  299. * be the process's current working directory.
  300. *
  301. * You should probably use the base dir in your search path.
  302. *
  303. * @return READ ONLY string of base dir in platform-dependent notation.
  304. */
  305. const char *PHYSFS_getBaseDir(void);
  306. /**
  307. * Helper function.
  308. *
  309. * Get the "user dir". This is meant to be a suggestion of where a specific
  310. * user of the system can store files. On Unix, this is her home directory.
  311. * On systems with no concept of multiple home directories (MacOS, win95),
  312. * this will default to something like "C:\mybasedir\users\username"
  313. * where "username" will either be the login name, or "default" if the
  314. * platform doesn't support multiple users, either.
  315. *
  316. * You should probably use the user dir as the basis for your write dir, and
  317. * also put it near the beginning of your search path.
  318. *
  319. * @return READ ONLY string of user dir in platform-dependent notation.
  320. */
  321. const char *PHYSFS_getUserDir(void);
  322. /**
  323. * Get the current write dir. The default write dir is NULL.
  324. *
  325. * @return READ ONLY string of write dir in platform-dependent notation,
  326. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  327. */
  328. const char *PHYSFS_getWriteDir(void);
  329. /**
  330. * Set a new write dir. This will override the previous setting. If the
  331. * directory or a parent directory doesn't exist in the physical filesystem,
  332. * PhysicsFS will attempt to create them as needed.
  333. *
  334. * This call will fail (and fail to change the write dir) if the current
  335. * write dir still has files open in it.
  336. *
  337. * @param newDir The new directory to be the root of the write dir,
  338. * specified in platform-dependent notation. Setting to NULL
  339. * disables the write dir, so no files can be opened for
  340. * writing via PhysicsFS.
  341. * @return non-zero on success, zero on failure. All attempts to open a file
  342. * for writing via PhysicsFS will fail until this call succeeds.
  343. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  344. *
  345. */
  346. int PHYSFS_setWriteDir(const char *newDir);
  347. /**
  348. * Add a directory or archive to the search path. If this is a duplicate, the
  349. * entry is not added again, even though the function succeeds.
  350. *
  351. * @param newDir directory or archive to add to the path, in
  352. * platform-dependent notation.
  353. * @param appendToPath nonzero to append to search path, zero to prepend.
  354. * @return nonzero if added to path, zero on failure (bogus archive, dir
  355. * missing, etc). Specifics of the error can be
  356. * gleaned from PHYSFS_getLastError().
  357. */
  358. int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  359. /**
  360. * Remove a directory or archive from the search path.
  361. *
  362. * This must be a (case-sensitive) match to a dir or archive already in the
  363. * search path, specified in platform-dependent notation.
  364. *
  365. * This call will fail (and fail to remove from the path) if the element still
  366. * has files open in it.
  367. *
  368. * @param oldDir dir/archive to remove.
  369. * @return nonzero on success, zero on failure.
  370. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  371. */
  372. int PHYSFS_removeFromSearchPath(const char *oldDir);
  373. /**
  374. * Get the current search path. The default search path is an empty list.
  375. *
  376. * The returned value is an array of strings, with a NULL entry to signify the
  377. * end of the list:
  378. *
  379. * char **i;
  380. *
  381. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  382. * printf("[%s] is in the search path.\n", *i);
  383. *
  384. * When you are done with the returned information, you may dispose of the
  385. * resources by calling PHYSFS_freeList() with the returned pointer.
  386. *
  387. * @return Null-terminated array of null-terminated strings. NULL if there
  388. * was a problem (read: OUT OF MEMORY).
  389. */
  390. char **PHYSFS_getSearchPath(void);
  391. /**
  392. * Helper function.
  393. *
  394. * Set up sane, default paths. The write dir will be set to
  395. * "userdir/.appName", which is created if it doesn't exist.
  396. *
  397. * The above is sufficient to make sure your program's configuration directory
  398. * is separated from other clutter, and platform-independent. The period
  399. * before "mygame" even hides the directory on Unix systems.
  400. *
  401. * The search path will be:
  402. *
  403. * - The Write Dir (created if it doesn't exist)
  404. * - The Write Dir/appName (created if it doesn't exist)
  405. * - The Base Dir (PHYSFS_getBaseDir())
  406. * - The Base Dir/appName (if it exists)
  407. * - All found CD-ROM dirs (optionally)
  408. * - All found CD-ROM dirs/appName (optionally, and if they exist)
  409. *
  410. * These directories are then searched for files ending with the extension
  411. * (archiveExt), which, if they are valid and supported archives, will also
  412. * be added to the search path. If you specified "PKG" for (archiveExt), and
  413. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  414. * can either be appended or prepended to the search path in alphabetical
  415. * order, regardless of which directories they were found in.
  416. *
  417. * All of this can be accomplished from the application, but this just does it
  418. * all for you. Feel free to add more to the search path manually, too.
  419. *
  420. * @param appName Program-specific name of your program, to separate it
  421. * from other programs using PhysicsFS.
  422. *
  423. * @param archiveExt File extention used by your program to specify an
  424. * archive. For example, Quake 3 uses "pk3", even though
  425. * they are just zipfiles. Specify NULL to not dig out
  426. * archives automatically. Do not specify the '.' char;
  427. * If you want to look for ZIP files, specify "ZIP" and
  428. * not ".ZIP" ... the archive search is case-insensitive.
  429. *
  430. * @param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  431. * (if (archiveExt) != NULL) search them for archives.
  432. * This may cause a significant amount of blocking
  433. * while discs are accessed, and if there are no discs
  434. * in the drive (or even not mounted on Unix systems),
  435. * then they may not be made available anyhow. You may
  436. * want to specify zero and handle the disc setup
  437. * yourself.
  438. *
  439. * @param archivesFirst Non-zero to prepend the archives to the search path.
  440. * Zero to append them. Ignored if !(archiveExt).
  441. * @return nonzero on success, zero on error. Specifics of the error can be
  442. * gleaned from PHYSFS_getLastError().
  443. */
  444. int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
  445. int includeCdRoms, int archivesFirst);
  446. /**
  447. * Create a directory. This is specified in platform-independent notation in
  448. * relation to the write dir. All missing parent directories are also
  449. * created if they don't exist.
  450. *
  451. * So if you've got the write dir set to "C:\mygame\writedir" and call
  452. * PHYSFS_mkdir("downloads/maps") then the directories
  453. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  454. * will be created if possible. If the creation of "maps" fails after we
  455. * have successfully created "downloads", then the function leaves the
  456. * created directory behind and reports failure.
  457. *
  458. * @param dirname New dir to create.
  459. * @return nonzero on success, zero on error. Specifics of the error can be
  460. * gleaned from PHYSFS_getLastError().
  461. */
  462. int PHYSFS_mkdir(const char *dirName);
  463. /**
  464. * Delete a file or directory. This is specified in platform-independent
  465. * notation in relation to the write dir.
  466. *
  467. * A directory must be empty before this call can delete it.
  468. *
  469. * So if you've got the write dir set to "C:\mygame\writedir" and call
  470. * PHYSFS_delete("downloads/maps/level1.map") then the file
  471. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  472. * physical filesystem, if it exists and the operating system permits the
  473. * deletion.
  474. *
  475. * Note that on Unix systems, deleting a file may be successful, but the
  476. * actual file won't be removed until all processes that have an open
  477. * filehandle to it (including your program) close their handles.
  478. *
  479. * @param filename Filename to delete.
  480. * @return nonzero on success, zero on error. Specifics of the error can be
  481. * gleaned from PHYSFS_getLastError().
  482. */
  483. int PHYSFS_delete(const char *filename);
  484. /**
  485. * Enable symbolic links. Some physical filesystems and archives contain
  486. * files that are just pointers to other files. On the physical filesystem,
  487. * opening such a link will (transparently) open the file that is pointed to.
  488. *
  489. * By default, PhysicsFS will check if a file is really a symlink during open
  490. * calls and fail if it is. Otherwise, the link could take you outside the
  491. * write and search paths, and compromise security.
  492. *
  493. * If you want to take that risk, call this function with a non-zero parameter.
  494. * Note that this is more for sandboxing a program's scripting language, in
  495. * case untrusted scripts try to compromise the system. Generally speaking,
  496. * a user could very well have a legitimate reason to set up a symlink, so
  497. * unless you feel there's a specific danger in allowing them, you should
  498. * permit them.
  499. *
  500. * Symbolic link permission can be enabled or disabled at any time, and is
  501. * disabled by default.
  502. *
  503. * @param allow nonzero to permit symlinks, zero to deny linking.
  504. */
  505. void PHYSFS_permitSymbolicLinks(int allow);
  506. /**
  507. * Figure out where in the search path a file resides. The file is specified
  508. * in platform-independent notation. The returned filename will be the
  509. * element of the search path where the file was found, which may be a
  510. * directory, or an archive. Even if there are multiple matches in different
  511. * parts of the search path, only the first one found is used, just like
  512. * when opening a file.
  513. *
  514. * So, if you look for "maps/level1.map", and C:\mygame is in your search
  515. * path and C:\mygame\maps\level1.map exists, then "C:\mygame" is returned.
  516. *
  517. * If a match is a symbolic link, and you've not explicitly permitted symlinks,
  518. * then it will be ignored, and the search for a match will continue.
  519. *
  520. * @param filename file to look for.
  521. * @return READ ONLY string of element of search path containing the
  522. * the file in question. NULL if not found.
  523. */
  524. const char *PHYSFS_getRealDir(const char *filename);
  525. /**
  526. * Get a file listing of a search path's directory. Matching directories are
  527. * interpolated. That is, if "C:\mydir" is in the search path and contains a
  528. * directory "savegames" that contains "x.sav", "y.sav", and "z.sav", and
  529. * there is also a "C:\userdir" in the search path that has a "savegames"
  530. * subdirectory with "w.sav", then the following code:
  531. *
  532. * ------------------------------------------------
  533. * char **rc = PHYSFS_enumerateFiles("savegames");
  534. * char **i;
  535. *
  536. * for (i = rc; *i != NULL; i++)
  537. * printf("We've got [%s].\n", *i);
  538. *
  539. * PHYSFS_freeList(rc);
  540. * ------------------------------------------------
  541. *
  542. * ...will print:
  543. *
  544. * ------------------------------------------------
  545. * We've got [x.sav].
  546. * We've got [y.sav].
  547. * We've got [z.sav].
  548. * We've got [w.sav].
  549. * ------------------------------------------------
  550. *
  551. * Feel free to sort the list however you like. We only promise there will
  552. * be no duplicates, but not what order the final list will come back in.
  553. *
  554. * Don't forget to call PHYSFS_freeList() with the return value from this
  555. * function when you are done with it.
  556. *
  557. * @param dir directory in platform-independent notation to enumerate.
  558. * @return Null-terminated array of null-terminated strings.
  559. */
  560. char **PHYSFS_enumerateFiles(const char *dir);
  561. /**
  562. * Open a file for writing, in platform-independent notation and in relation
  563. * to the write dir as the root of the writable filesystem. The specified
  564. * file is created if it doesn't exist. If it does exist, it is truncated to
  565. * zero bytes, and the writing offset is set to the start.
  566. *
  567. * @param filename File to open.
  568. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  569. * of the error can be gleaned from PHYSFS_getLastError().
  570. */
  571. PHYSFS_file *PHYSFS_openWrite(const char *filename);
  572. /**
  573. * Open a file for writing, in platform-independent notation and in relation
  574. * to the write dir as the root of the writable filesystem. The specified
  575. * file is created if it doesn't exist. If it does exist, the writing offset
  576. * is set to the end of the file, so the first write will be the byte after
  577. * the end.
  578. *
  579. * @param filename File to open.
  580. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  581. * of the error can be gleaned from PHYSFS_getLastError().
  582. */
  583. PHYSFS_file *PHYSFS_openAppend(const char *filename);
  584. /**
  585. * Open a file for reading, in platform-independent notation. The search path
  586. * is checked one at a time until a matching file is found, in which case an
  587. * abstract filehandle is associated with it, and reading may be done.
  588. * The reading offset is set to the first byte of the file.
  589. *
  590. * @param filename File to open.
  591. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  592. * of the error can be gleaned from PHYSFS_getLastError().
  593. */
  594. PHYSFS_file *PHYSFS_openRead(const char *filename);
  595. /**
  596. * Close a PhysicsFS filehandle. This call is capable of failing if the
  597. * operating system was buffering writes to this file, and (now forced to
  598. * write those changes to physical media) can not store the data for any
  599. * reason. In such a case, the filehandle stays open. A well-written program
  600. * should ALWAYS check the return value from the close call in addition to
  601. * every writing call!
  602. *
  603. * @param handle handle returned from PHYSFS_open*().
  604. * @return nonzero on success, zero on error. Specifics of the error can be
  605. * gleaned from PHYSFS_getLastError().
  606. */
  607. int PHYSFS_close(PHYSFS_file *handle);
  608. /**
  609. * Read data from a PhysicsFS filehandle. The file must be opened for reading.
  610. *
  611. * @param handle handle returned from PHYSFS_openRead().
  612. * @param buffer buffer to store read data into.
  613. * @param objSize size in bytes of objects being read from (handle).
  614. * @param objCount number of (objSize) objects to read from (handle).
  615. * @return number of objects read. PHYSFS_getLastError() can shed light on
  616. * the reason this might be < (objCount), as can PHYSFS_eof().
  617. * -1 if complete failure.
  618. */
  619. int PHYSFS_read(PHYSFS_file *handle, void *buffer,
  620. unsigned int objSize, unsigned int objCount);
  621. /**
  622. * Write data to a PhysicsFS filehandle. The file must be opened for writing.
  623. *
  624. * @param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  625. * @param buffer buffer to store read data into.
  626. * @param objSize size in bytes of objects being read from (handle).
  627. * @param objCount number of (objSize) objects to read from (handle).
  628. * @return number of objects written. PHYSFS_getLastError() can shed light on
  629. * the reason this might be < (objCount). -1 if complete failure.
  630. */
  631. int PHYSFS_write(PHYSFS_file *handle, void *buffer,
  632. unsigned int objSize, unsigned int objCount);
  633. /**
  634. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  635. *
  636. * @param handle handle returned from PHYSFS_openRead().
  637. * @return nonzero if EOF, zero if not.
  638. */
  639. int PHYSFS_eof(PHYSFS_file *handle);
  640. /**
  641. * Determine current position within a PhysicsFS filehandle.
  642. *
  643. * @param handle handle returned from PHYSFS_open*().
  644. * @return offset in bytes from start of file. -1 if error occurred.
  645. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  646. */
  647. int PHYSFS_tell(PHYSFS_file *handle);
  648. /**
  649. * Seek to a new position within a PhysicsFS filehandle. The next read or write
  650. * will occur at that place. Seeking past the beginning or end of the file is
  651. * not allowed.
  652. *
  653. * @param handle handle returned from PHYSFS_open*().
  654. * @param pos number of bytes from start of file to seek to.
  655. * @return nonzero on success, zero on error. Specifics of the error can be
  656. * gleaned from PHYSFS_getLastError().
  657. */
  658. int PHYSFS_seek(PHYSFS_file *handle, int pos);
  659. #ifdef __cplusplus
  660. }
  661. #endif
  662. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  663. /* end of physfs.h ... */