physfs.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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 path and multiple "search paths"
  17. * for reading. You can think of this as a filesystem within a
  18. * filesystem. If (on Windows) you were to set the writing directory to
  19. * "C:\MyGame\MyWritingDirectory", then no PHYSFS calls could touch anything
  20. * above this directory, including the "C:\MyGame" and "C:\" directories.
  21. * This prevents an application's internal scripting language from piddling
  22. * over c:\config.sys, for example. If you'd rather give PHYSFS full access
  23. * to the system's REAL file system, set the writing path to "C:\", but
  24. * 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 paths create 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 path 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 path
  39. * as "C:\mydir\myfile" or "MacOS hard drive:My Directory:My File" is termed
  40. * "platform-dependent notation". The only time you use platform-dependent
  41. * notation is when setting up your write and search paths; after that, all
  42. * file access into those paths are done with platform-independent notation.
  43. *
  44. * All files opened for writing are opened in relation to the write path,
  45. * which is the root of the writable filesystem. When opening a file for
  46. * reading, PhysicsFS goes through it's internal search path. This is NOT the
  47. * same thing as the PATH environment variable. An application using
  48. * PhysicsFS specifies directories to be searched which may be actual
  49. * directories, or archive files that contain files and subdirectories of
  50. * their own. See the end of these docs for currently supported archive
  51. * formats.
  52. *
  53. * Once a search path is defined, you may open files for reading. If you've
  54. * got the following search path defined (to use a win32 example again):
  55. *
  56. * C:\mygame
  57. * C:\mygame\myuserfiles
  58. * D:\mygamescdromdatafiles
  59. * C:\mygame\installeddatafiles.zip
  60. *
  61. * Then a call to PHYSFS_openread("textfiles/myfile.txt") (note the directory
  62. * separator, lack of drive letter, and lack of dir separator at the start of
  63. * the string; this is platform-independent notation) will check for
  64. * C:\mygame\textfiles\myfile.txt, then
  65. * C:\mygame\myuserfiles\textfiles\myfile.txt, then
  66. * D:\mygamescdromdatafiles\textfiles\myfile.txt, then, finally, for
  67. * textfiles\myfile.txt inside of C:\mygame\installeddatafiles.zip. Remember
  68. * that most archive types and platform filesystems store their filenames in
  69. * a case-sensitive manner, so you should be careful to specify it correctly.
  70. *
  71. * Files opened through PhysicsFS may NOT contain "." or ".." as path
  72. * elements. Not only are these meaningless on MacOS, they are a security
  73. * hole. Also, symbolic links (which can be found in some archive types and
  74. * directly in the filesystem on Unix platforms) are NOT followed until you
  75. * call PHYSFS_permitSymbolicLinks(). That's left to your own discretion, as
  76. * following a symlink can allow for access outside the write and search
  77. * paths. There is no mechanism for creating new symlinks in PhysicsFS.
  78. *
  79. * The write path is not included in the search path unless you specifically
  80. * add it. While you CAN change the write path as many times as you like,
  81. * you should probably set it once and stick to that path. Remember that
  82. * your program will not have permission to write in every directory on
  83. * Unix and NT systems.
  84. *
  85. * All files are opened in binary mode; there is no endline conversion for
  86. * textfiles. Other than that, PhysicsFS has some convenience functions for
  87. * platform-independence. There is a function to tell you the current
  88. * platform's path separator ("\\" on windows, "/" on Unix, ":" on MacOS),
  89. * which is needed only to set up your search/write paths. There is a
  90. * function to tell you what CD-ROM drives contain accessible discs, and a
  91. * function to recommend a good search path, etc.
  92. *
  93. * A recommended order for a search path is the write path, then the base path,
  94. * then the cdrom path, then any archives discovered. Quake 3 does something
  95. * like this, but moves the archives to the start of the search path. Build
  96. * Engine games, like Duke Nukem 3D and Blood, place the archives last, and
  97. * use the base path for both searching and writing. There is a helper
  98. * function (PHYSFS_setSanePaths()) that puts together a basic configuration
  99. * for you, based on a few parameters. Also see the comments on
  100. * PHYSFS_getBasePath(), and PHYSFS_getUserPath() for info on what those
  101. * are and how they can help you determine an optimal searchpath.
  102. *
  103. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  104. * calls, doing so is not recommended, and you can not use system
  105. * filehandles with PhysicsFS filehandles and vice versa.
  106. *
  107. * Note that archives need not be named as such: if you have a ZIP file and
  108. * rename it with a .PKG extension, the file will still be recognized as a
  109. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  110. * type.
  111. *
  112. * Currently supported archive types:
  113. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  114. *
  115. * Please see the file LICENSE in the source's root directory.
  116. *
  117. * This file written by Ryan C. Gordon.
  118. */
  119. #ifndef _INCLUDE_PHYSFS_H_
  120. #define _INCLUDE_PHYSFS_H_
  121. #ifdef __cplusplus
  122. extern "C" {
  123. #endif
  124. typedef struct __PHYSFS_FILE__
  125. {
  126. unsigned int opaque;
  127. } PHYSFS_file;
  128. typedef struct __PHYSFS_ARCHIVEINFO__
  129. {
  130. const char *extension;
  131. const char *description;
  132. } PHYSFS_ArchiveInfo;
  133. /* functions... */
  134. /**
  135. * Initialize PhysicsFS. This must be called before any other PhysicsFS
  136. * function.
  137. *
  138. * @param argv0 the argv[0] string passed to your program's mainline.
  139. * @return nonzero on success, zero on error. Specifics of the error can be
  140. * gleaned from PHYSFS_getLastError().
  141. */
  142. int PHYSFS_init(const char *argv0);
  143. /**
  144. * Shutdown PhysicsFS. This closes any files opened via PhysicsFS, blanks the
  145. * search/write paths, frees memory, and invalidates all of your handles.
  146. *
  147. * Once deinitialized, PHYSFS_init() can be called again to restart the
  148. * subsystem.
  149. *
  150. * @return nonzero on success, zero on error. Specifics of the error can be
  151. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  152. * undefined, and probably badly screwed up.
  153. */
  154. void PHYSFS_deinit(void);
  155. /**
  156. * Get a list of archive types supported by this implementation of PhysicFS.
  157. * These are the file formats usable for search path entries. This is for
  158. * informational purposes only. Note that the extension listed is merely
  159. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  160. * with an extension of "XYZ", if you like.
  161. *
  162. * The returned value is an array of strings, with a NULL entry to signify the
  163. * end of the list:
  164. *
  165. * PHYSFS_ArchiveInfo **i;
  166. *
  167. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  168. * {
  169. * printf("Supported archive: [%s], which is [%s].\n",
  170. * i->extension, i->description);
  171. * }
  172. *
  173. * The return values are pointers to static internal memory, and should
  174. * be considered READ ONLY, and never freed.
  175. *
  176. * @return READ ONLY Null-terminated array of READ ONLY structures.
  177. */
  178. const PHYSFS_ArchiveInfo *PHYSFS_supportedArchiveTypes(void);
  179. /**
  180. * Certain PhysicsFS functions return lists of information that are
  181. * dynamically allocated. Use this function to free those resources.
  182. *
  183. * @param list List of information specified as freeable by this function.
  184. */
  185. void PHYSFS_freeList(void *list);
  186. /**
  187. * Get the last PhysicsFS error message as a null-terminated string.
  188. * This will be NULL if there's been no error since the last call to this
  189. * function. The pointer returned by this call points to an
  190. * internal buffer. Each thread has a unique error state associated with it.
  191. *
  192. * @return READ ONLY string of last error message.
  193. */
  194. const char *PHYSFS_getLastError(void);
  195. /**
  196. * Get a platform-dependent path separator. This is "\\" on win32, "/" on Unix,
  197. * and ":" on MacOS. It may be more than one character, depending on the
  198. * platform, and your code should take that into account. Note that this is
  199. * only useful for setting up the search/write paths, since access into those
  200. * paths always use '/' (platform-independent notation) to separate
  201. * directories. This is also handy for getting platform-independent access
  202. * when using stdio calls.
  203. *
  204. * @return READ ONLY null-terminated string of platform's path separator.
  205. */
  206. const char *PHYSFS_getPathSeparator(void);
  207. /**
  208. * Get an array of paths to available CD-ROM drives.
  209. *
  210. * The paths returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  211. * whatnot on Unix). Paths are only returned if there is a disc ready and
  212. * accessible in the drive. So if you've got two drives (D: and E:), and only
  213. * E: has a disc in it, then that's all you get. If the user inserts a disc
  214. * in D: and you call this function again, you get both drives. If, on a
  215. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  216. * call to this function will reflect that change. Fun.
  217. *
  218. * The returned value is an array of strings, with a NULL entry to signify the
  219. * end of the list:
  220. *
  221. * char **i;
  222. *
  223. * for (i = PHYSFS_getCdRomPaths(); *i != NULL; i++)
  224. * printf("cdrom path [%s] is available.\n", *i);
  225. *
  226. * This call may block while drives spin up. Be forewarned.
  227. *
  228. * When you are done with the returned information, you may dispose of the
  229. * resources by calling PHYSFS_freeList() with the returned pointer.
  230. *
  231. * @return Null-terminated array of null-terminated strings.
  232. */
  233. char **PHYSFS_getCdRomPaths(void);
  234. /**
  235. * Helper function.
  236. *
  237. * Get the "base path". This is the directory where the application was run
  238. * from, which is probably the installation directory, and may or may not
  239. * be the process's current working directory.
  240. *
  241. * You should probably use the base path in your search path.
  242. *
  243. * @return READ ONLY string of base path in platform-dependent notation.
  244. */
  245. const char *PHYSFS_getBasePath(void);
  246. /**
  247. * Helper function.
  248. *
  249. * Get the "user path". This is meant to be a suggestion of where a specific
  250. * user of the system can store files. On Unix, this is her home directory.
  251. * On systems with no concept of multiple home directories (MacOS, win95),
  252. * this will default to something like "C:\mybasepath\users\username"
  253. * where "username" will either be the login name, or "default" if the
  254. * platform doesn't support multiple users, either.
  255. *
  256. * You should probably use the user path as the basis for your write path, and
  257. * also put it near the beginning of your search path.
  258. *
  259. * @return READ ONLY string of user path in platform-dependent notation.
  260. */
  261. const char *PHYSFS_getUserPath(void);
  262. /**
  263. * Get the current write path. The default write path is NULL.
  264. *
  265. * @return READ ONLY string of write path in platform-dependent notation,
  266. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  267. */
  268. const char *PHYSFS_getWritePath(char *buffer, int bufferSize);
  269. /**
  270. * Set a new write path. This will override the previous setting. If the
  271. * directory or a parent directory doesn't exist in the physical filesystem,
  272. * PhysicsFS will attempt to create them as needed.
  273. *
  274. * This call will fail (and fail to change the write path) if the current path
  275. * still has files open in it.
  276. *
  277. * @param newPath The new directory to be the root of the write path,
  278. * specified in platform-dependent notation. Setting to NULL
  279. * disables the write path, so no files can be opened for
  280. * writing via PhysicsFS.
  281. * @return non-zero on success, zero on failure. All attempts to open a file
  282. * for writing via PhysicsFS will fail until this call succeeds.
  283. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  284. *
  285. */
  286. int PHYSFS_setWritePath(const char *newPath);
  287. /**
  288. * Add a directory or archive to the search path. If this is a duplicate, the
  289. * entry is not added again, even though the function succeeds.
  290. *
  291. * @param newPath directory or archive to add to the path, in
  292. * platform-dependent notation.
  293. * @param appendToPath nonzero to append to search path, zero to prepend.
  294. * @return nonzero if added to path, zero on failure (bogus archive, path
  295. * missing, etc). Specifics of the error can be
  296. * gleaned from PHYSFS_getLastError().
  297. */
  298. int PHYSFS_addToSearchPath(const char *newPath, int appendToPath);
  299. /**
  300. * Remove a directory or archive from the search path.
  301. *
  302. * This must be a (case-sensitive) match to a dir or archive already in the
  303. * search path, specified in platform-dependent notation.
  304. *
  305. * This call will fail (and fail to remove from the path) if the element still
  306. * has files open in it.
  307. *
  308. * @param oldPath dir/archive to remove.
  309. * @return nonzero on success, zero on failure.
  310. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  311. */
  312. int PHYSFS_removeFromSearchPath(const char *oldPath);
  313. /**
  314. * Get the current search path. The default search path is an empty list.
  315. *
  316. * The returned value is an array of strings, with a NULL entry to signify the
  317. * end of the list:
  318. *
  319. * char **i;
  320. *
  321. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  322. * printf("[%s] is in the search path.\n", *i);
  323. *
  324. * When you are done with the returned information, you may dispose of the
  325. * resources by calling PHYSFS_freeList() with the returned pointer.
  326. *
  327. * @return Null-terminated array of null-terminated strings.
  328. */
  329. char **PHYSFS_getSearchPath(void);
  330. /**
  331. * Helper function.
  332. *
  333. * Set up sane, default paths. The write path will be set to
  334. * "userpath/.appName", which is created if it doesn't exist.
  335. *
  336. * The above is sufficient to make sure your program's configuration directory
  337. * is separated from other clutter, and platform-independent. The period
  338. * before "mygame" even hides the directory on Unix systems.
  339. *
  340. * The search path will be:
  341. *
  342. * - The Write Path (created if it doesn't exist)
  343. * - The Write Path/appName (created if it doesn't exist)
  344. * - The Base Path (PHYSFS_getBasePath())
  345. * - The Base Path/appName (if it exists)
  346. * - All found CD-ROM paths (optionally)
  347. * - All found CD-ROM paths/appName (optionally, and if they exist)
  348. *
  349. * These directories are then searched for files ending with the extension
  350. * (archiveExt), which, if they are valid and supported archives, will also
  351. * be added to the search path. If you specified "PKG" for (archiveExt), and
  352. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  353. * can either be appended or prepended to the search path in alphabetical
  354. * order, regardless of which directories they were found in.
  355. *
  356. * All of this can be accomplished from the application, but this just does it
  357. * all for you. Feel free to add more to the search path manually, too.
  358. *
  359. * @param appName Program-specific name of your program, to separate it
  360. * from other programs using PhysicsFS.
  361. *
  362. * @param archiveExt File extention used by your program to specify an
  363. * archive. For example, Quake 3 uses "pk3", even though
  364. * they are just zipfiles. Specify NULL to not dig out
  365. * archives automatically.
  366. *
  367. * @param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  368. * (if (archiveExt) != NULL) search them for archives.
  369. * This may cause a significant amount of blocking
  370. * while discs are accessed, and if there are no discs
  371. * in the drive (or even not mounted on Unix systems),
  372. * then they may not be made available anyhow. You may
  373. * want to specify zero and handle the disc setup
  374. * yourself.
  375. *
  376. * @param archivesFirst Non-zero to prepend the archives to the search path.
  377. * Zero to append them. Ignored if !(archiveExt).
  378. */
  379. void PHYSFS_setSanePaths(const char *appName, const char *archiveExt,
  380. int includeCdRoms, int archivesFirst);
  381. /**
  382. * Create a directory. This is specified in platform-independent notation in
  383. * relation to the write path. All missing parent directories are also
  384. * created if they don't exist.
  385. *
  386. * So if you've got the write path set to "C:\mygame\writepath" and call
  387. * PHYSFS_mkdir("downloads/maps") then the directories
  388. * "C:\mygame\writepath\downloads" and "C:\mygame\writepath\downloads\maps"
  389. * will be created if possible. If the creation of "maps" fails after we
  390. * have successfully created "downloads", then the function leaves the
  391. * created directory behind and reports failure.
  392. *
  393. * @param dirname New path to create.
  394. * @return nonzero on success, zero on error. Specifics of the error can be
  395. * gleaned from PHYSFS_getLastError().
  396. */
  397. int PHYSFS_mkdir(const char *dirName);
  398. /**
  399. * Delete a file or directory. This is specified in platform-independent
  400. * notation in relation to the write path.
  401. *
  402. * A directory must be empty before this call can delete it.
  403. *
  404. * So if you've got the write path set to "C:\mygame\writepath" and call
  405. * PHYSFS_delete("downloads/maps/level1.map") then the file
  406. * "C:\mygame\writepath\downloads\maps\level1.map" is removed from the
  407. * physical filesystem, if it exists and the operating system permits the
  408. * deletion.
  409. *
  410. * Note that on Unix systems, deleting a file may be successful, but the
  411. * actual file won't be removed until all processes that have an open
  412. * filehandle to it (including your program) close their handles.
  413. *
  414. * @param filename Filename to delete.
  415. * @return nonzero on success, zero on error. Specifics of the error can be
  416. * gleaned from PHYSFS_getLastError().
  417. */
  418. int PHYSFS_delete(const char *filename);
  419. /**
  420. * Enable symbolic links. Some physical filesystems and archives contain
  421. * files that are just pointers to other files. On the physical filesystem,
  422. * opening such a link will (transparently) open the file that is pointed to.
  423. *
  424. * By default, PhysicsFS will check if a file is really a symlink during open
  425. * calls and fail if it is. Otherwise, the link could take you outside the
  426. * write and search paths, and compromise security.
  427. *
  428. * If you want to take that risk, call this function with a non-zero parameter.
  429. * Note that this is more for sandboxing a program's scripting language, in
  430. * case untrusted scripts try to compromise the system. Generally speaking,
  431. * a user could very well have a legitimate reason to set up a symlink, so
  432. * unless you feel there's a specific danger in allowing them, you should
  433. * permit them.
  434. *
  435. * Symbolic link permission can be enabled or disabled at any time, and is
  436. * disabled by default.
  437. *
  438. * @param allow nonzero to permit symlinks, zero to deny linking.
  439. */
  440. void PHYSFS_permitSymbolicLinks(int allow);
  441. /**
  442. * Figure out where in the search path a file resides. The file is specified
  443. * in platform-independent notation. The returned filename will be the
  444. * element of the search path where the file was found, which may be a
  445. * directory, or an archive. Even if there are multiple matches in different
  446. * parts of the search path, only the first one found is used, just like
  447. * when opening a file.
  448. *
  449. * So, if you look for "maps/level1.map", and C:\mygame is in your search
  450. * path and C:\mygame\maps\level1.map exists, then "C:\mygame" is returned.
  451. *
  452. * If a match is a symbolic link, and you've not explicitly permitted symlinks,
  453. * then it will be ignored, and the search for a match will continue.
  454. *
  455. * @param filename file to look for.
  456. * @return READ ONLY string of element of search path containing the
  457. * the file in question. NULL if not found.
  458. */
  459. const char *PHYSFS_getRealPath(const char *filename);
  460. /**
  461. * Get a file listing of a search path's directory. Matching directories are
  462. * interpolated. That is, if "C:\mypath" is in the search path and contains a
  463. * directory "savegames" that contains "x.sav", "y.sav", and "z.sav", and
  464. * there is also a "C:\userpath" in the search path that has a "savegames"
  465. * subdirectory with "w.sav", then the following code:
  466. *
  467. * ------------------------------------------------
  468. * char **rc = PHYSFS_enumerateFiles("savegames");
  469. * char **i;
  470. *
  471. * for (i = rc; *i != NULL; i++)
  472. * printf("We've got [%s].\n", *i);
  473. *
  474. * PHYSFS_freeList(rc);
  475. * ------------------------------------------------
  476. *
  477. * ...will print:
  478. *
  479. * ------------------------------------------------
  480. * We've got [x.sav].
  481. * We've got [y.sav].
  482. * We've got [z.sav].
  483. * We've got [w.sav].
  484. * ------------------------------------------------
  485. *
  486. * Don't forget to call PHYSFS_freeList() with the return value from this
  487. * function when you are done with it.
  488. *
  489. * @param path directory in platform-independent notation to enumerate.
  490. * @return Null-terminated array of null-terminated strings.
  491. */
  492. char **PHYSFS_enumerateFiles(const char *path);
  493. /**
  494. * Open a file for writing, in platform-independent notation and in relation
  495. * to the write path as the root of the writable filesystem. The specified
  496. * file is created if it doesn't exist. If it does exist, it is truncated to
  497. * zero bytes, and the writing offset is set to the start.
  498. *
  499. * @param filename File to open.
  500. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  501. * of the error can be gleaned from PHYSFS_getLastError().
  502. */
  503. PHYSFS_file *PHYSFS_openWrite(const char *filename);
  504. /**
  505. * Open a file for writing, in platform-independent notation and in relation
  506. * to the write path as the root of the writable filesystem. The specified
  507. * file is created if it doesn't exist. If it does exist, the writing offset
  508. * is set to the end of the file, so the first write will be the byte after
  509. * the end.
  510. *
  511. * @param filename File to open.
  512. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  513. * of the error can be gleaned from PHYSFS_getLastError().
  514. */
  515. PHYSFS_file *PHYSFS_openAppend(const char *filename);
  516. /**
  517. * Open a file for reading, in platform-independent notation. The search path
  518. * is checked one at a time until a matching file is found, in which case an
  519. * abstract filehandle is associated with it, and reading may be done.
  520. * The reading offset is set to the first byte of the file.
  521. *
  522. * @param filename File to open.
  523. * @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  524. * of the error can be gleaned from PHYSFS_getLastError().
  525. */
  526. PHYSFS_file *PHYSFS_openRead(const char *filename);
  527. /**
  528. * Close a PhysicsFS filehandle. This call is capable of failing if the
  529. * operating system was buffering writes to this file, and (now forced to
  530. * write those changes to physical media) can not store the data for any
  531. * reason. In such a case, the filehandle stays open. A well-written program
  532. * should ALWAYS check the return value from the close call in addition to
  533. * every writing call!
  534. *
  535. * @param handle handle returned from PHYSFS_open*().
  536. * @return nonzero on success, zero on error. Specifics of the error can be
  537. * gleaned from PHYSFS_getLastError().
  538. */
  539. int PHYSFS_close(PHYSFS_file *handle);
  540. /**
  541. * Read data from a PhysicsFS filehandle. The file must be opened for reading.
  542. *
  543. * @param handle handle returned from PHYSFS_openRead().
  544. * @param buffer buffer to store read data into.
  545. * @param objSize size in bytes of objects being read from (handle).
  546. * @param objCount number of (objSize) objects to read from (handle).
  547. * @return number of objects read. PHYSFS_getLastError() can shed light on
  548. * the reason this might be < (objCount), as can PHYSFS_eof().
  549. */
  550. int PHYSFS_read(PHYSFS_file *handle, void *buffer,
  551. unsigned int objSize, unsigned int objCount);
  552. /**
  553. * Write data to a PhysicsFS filehandle. The file must be opened for writing.
  554. *
  555. * @param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  556. * @param buffer buffer to store read data into.
  557. * @param objSize size in bytes of objects being read from (handle).
  558. * @param objCount number of (objSize) objects to read from (handle).
  559. * @return number of objects read. PHYSFS_getLastError() can shed light on
  560. * the reason this might be < (objCount).
  561. */
  562. int PHYSFS_write(PHYSFS_file *handle, void *buffer,
  563. unsigned int objSize, unsigned int objCount);
  564. /**
  565. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  566. *
  567. * @param handle handle returned from PHYSFS_openRead().
  568. * @return nonzero if EOF, zero if not.
  569. */
  570. int PHYSFS_eof(PHYSFS_file *handle);
  571. /**
  572. * Determine current position within a PhysicsFS filehandle.
  573. *
  574. * @param handle handle returned from PHYSFS_open*().
  575. * @return offset in bytes from start of file. -1 if error occurred.
  576. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  577. */
  578. int PHYSFS_tell(PHYSFS_file *handle);
  579. /**
  580. * Seek to a new position within a PhysicsFS filehandle. The next read or write
  581. * will occur at that place. Seeking past the beginning or end of the file is
  582. * not allowed.
  583. *
  584. * @param handle handle returned from PHYSFS_open*().
  585. * @param pos number of bytes from start of file to seek to.
  586. * @return nonzero on success, zero on error. Specifics of the error can be
  587. * gleaned from PHYSFS_getLastError().
  588. */
  589. int PHYSFS_seek(PHYSFS_file *handle, int pos);
  590. #ifdef __cplusplus
  591. }
  592. #endif
  593. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  594. /* end of physfs.h ... */