physfs.h 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002
  1. /** \file physfs.h */
  2. /**
  3. * \mainpage PhysicsFS
  4. *
  5. * The latest version of PhysicsFS can be found at:
  6. * http://icculus.org/physfs/
  7. *
  8. * PhysicsFS; a portable, flexible file i/o abstraction.
  9. *
  10. * This API gives you access to a system file system in ways superior to the
  11. * stdio or system i/o calls. The brief benefits:
  12. *
  13. * - It's portable.
  14. * - It's safe. No file access is permitted outside the specified dirs.
  15. * - It's flexible. Archives (.ZIP files) can be used transparently as
  16. * directory structures.
  17. *
  18. * This system is largely inspired by Quake 3's PK3 files and the related
  19. * fs_* cvars. If you've ever tinkered with these, then this API will be
  20. * familiar to you.
  21. *
  22. * With PhysicsFS, you have a single writing directory and multiple
  23. * directories (the "search path") for reading. You can think of this as a
  24. * filesystem within a filesystem. If (on Windows) you were to set the
  25. * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
  26. * could touch anything above this directory, including the "C:\MyGame" and
  27. * "C:\" directories. This prevents an application's internal scripting
  28. * language from piddling over c:\\config.sys, for example. If you'd rather
  29. * give PHYSFS full access to the system's REAL file system, set the writing
  30. * dir to "C:\", but that's generally A Bad Thing for several reasons.
  31. *
  32. * Drive letters are hidden in PhysicsFS once you set up your initial paths.
  33. * The search path creates a single, hierarchical directory structure.
  34. * Not only does this lend itself well to general abstraction with archives,
  35. * it also gives better support to operating systems like MacOS and Unix.
  36. * Generally speaking, you shouldn't ever hardcode a drive letter; not only
  37. * does this hurt portability to non-Microsoft OSes, but it limits your win32
  38. * users to a single drive, too. Use the PhysicsFS abstraction functions and
  39. * allow user-defined configuration options, too. When opening a file, you
  40. * specify it like it was on a Unix filesystem: if you want to write to
  41. * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to
  42. * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
  43. * abstraction across all platforms. Specifying a file in this way is termed
  44. * "platform-independent notation" in this documentation. Specifying a
  45. * a filename in a form such as "C:\mydir\myfile" or
  46. * "MacOS hard drive:My Directory:My File" is termed "platform-dependent
  47. * notation". The only time you use platform-dependent notation is when
  48. * setting up your write directory and search path; after that, all file
  49. * access into those directories are done with platform-independent notation.
  50. *
  51. * All files opened for writing are opened in relation to the write directory,
  52. * which is the root of the writable filesystem. When opening a file for
  53. * reading, PhysicsFS goes through the search path. This is NOT the
  54. * same thing as the PATH environment variable. An application using
  55. * PhysicsFS specifies directories to be searched which may be actual
  56. * directories, or archive files that contain files and subdirectories of
  57. * their own. See the end of these docs for currently supported archive
  58. * formats.
  59. *
  60. * Once the search path is defined, you may open files for reading. If you've
  61. * got the following search path defined (to use a win32 example again):
  62. *
  63. * - C:\\mygame
  64. * - C:\\mygame\\myuserfiles
  65. * - D:\\mygamescdromdatafiles
  66. * - C:\\mygame\\installeddatafiles.zip
  67. *
  68. * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory
  69. * separator, lack of drive letter, and lack of dir separator at the start of
  70. * the string; this is platform-independent notation) will check for
  71. * C:\\mygame\\textfiles\\myfile.txt, then
  72. * C:\\mygame\\myuserfiles\\textfiles\\myfile.txt, then
  73. * D:\\mygamescdromdatafiles\\textfiles\\myfile.txt, then, finally, for
  74. * textfiles\\myfile.txt inside of C:\\mygame\\installeddatafiles.zip.
  75. * Remember that most archive types and platform filesystems store their
  76. * filenames in a case-sensitive manner, so you should be careful to specify
  77. * it correctly.
  78. *
  79. * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir
  80. * elements. Not only are these meaningless on MacOS Classic and/or Unix,
  81. * they are a security hole. Also, symbolic links (which can be found in
  82. * some archive types and directly in the filesystem on Unix platforms) are
  83. * NOT followed until you call PHYSFS_permitSymbolicLinks(). That's left to
  84. * your own discretion, as following a symlink can allow for access outside
  85. * the write dir and search paths. For portability, there is no mechanism for
  86. * creating new symlinks in PhysicsFS.
  87. *
  88. * The write dir is not included in the search path unless you specifically
  89. * add it. While you CAN change the write dir as many times as you like,
  90. * you should probably set it once and stick to it. Remember that your
  91. * program will not have permission to write in every directory on Unix and
  92. * NT systems.
  93. *
  94. * All files are opened in binary mode; there is no endline conversion for
  95. * textfiles. Other than that, PhysicsFS has some convenience functions for
  96. * platform-independence. There is a function to tell you the current
  97. * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS),
  98. * which is needed only to set up your search/write paths. There is a
  99. * function to tell you what CD-ROM drives contain accessible discs, and a
  100. * function to recommend a good search path, etc.
  101. *
  102. * A recommended order for the search path is the write dir, then the base dir,
  103. * then the cdrom dir, then any archives discovered. Quake 3 does something
  104. * like this, but moves the archives to the start of the search path. Build
  105. * Engine games, like Duke Nukem 3D and Blood, place the archives last, and
  106. * use the base dir for both searching and writing. There is a helper
  107. * function (PHYSFS_setSaneConfig()) that puts together a basic configuration
  108. * for you, based on a few parameters. Also see the comments on
  109. * PHYSFS_getBaseDir(), and PHYSFS_getUserDir() for info on what those
  110. * are and how they can help you determine an optimal search path.
  111. *
  112. * PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points
  113. * in the search path. If a zipfile contains "maps/level.map" and you mount
  114. * that archive at "mods/mymod", then you would have to open
  115. * "mods/mymod/maps/level.map" to access the file, even though "mods/mymod"
  116. * isn't actually specified in the .zip file. Unlike the Unix mentality of
  117. * mounting a filesystem, "mods/mymod" doesn't actually have to exist when
  118. * mounting the zipfile. It's a "virtual" directory. The mounting mechanism
  119. * allows the developer to seperate archives in the tree and avoid trampling
  120. * over files when added new archives, such as including mod support in a
  121. * game...keeping external content on a tight leash in this manner can be of
  122. * utmost importance to some applications.
  123. *
  124. * PhysicsFS is mostly thread safe. The error messages returned by
  125. * PHYSFS_getLastError are unique by thread, and library-state-setting
  126. * functions are mutex'd. For efficiency, individual file accesses are
  127. * not locked, so you can not safely read/write/seek/close/etc the same
  128. * file from two threads at the same time. Other race conditions are bugs
  129. * that should be reported/patched.
  130. *
  131. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  132. * calls, doing so is not recommended, and you can not use system
  133. * filehandles with PhysicsFS and vice versa.
  134. *
  135. * Note that archives need not be named as such: if you have a ZIP file and
  136. * rename it with a .PKG extension, the file will still be recognized as a
  137. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  138. * type where possible.
  139. *
  140. * Currently supported archive types:
  141. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  142. * - .GRP (Build Engine groupfile archives)
  143. * - .PAK (Quake I/II archive format)
  144. * - .HOG (Descent I/II HOG file archives)
  145. * - .MVL (Descent II movielib archives)
  146. * - .WAD (DOOM engine archives)
  147. * - .MIX (Older Westwood games archives)
  148. *
  149. * Please see the file LICENSE in the source's root directory for licensing
  150. * and redistribution rights.
  151. *
  152. * Please see the file CREDITS in the source's root directory for a more or
  153. * less complete list of who's responsible for this.
  154. *
  155. * \author Ryan C. Gordon.
  156. */
  157. #ifndef _INCLUDE_PHYSFS_H_
  158. #define _INCLUDE_PHYSFS_H_
  159. #ifdef __cplusplus
  160. extern "C" {
  161. #endif
  162. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  163. #if (defined _MSC_VER)
  164. #define __EXPORT__ __declspec(dllexport)
  165. #else
  166. #define __EXPORT__
  167. #endif
  168. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  169. /**
  170. * \typedef PHYSFS_uint8
  171. * \brief An unsigned, 8-bit integer type.
  172. */
  173. typedef unsigned char PHYSFS_uint8;
  174. /**
  175. * \typedef PHYSFS_sint8
  176. * \brief A signed, 8-bit integer type.
  177. */
  178. typedef signed char PHYSFS_sint8;
  179. /**
  180. * \typedef PHYSFS_uint16
  181. * \brief An unsigned, 16-bit integer type.
  182. */
  183. typedef unsigned short PHYSFS_uint16;
  184. /**
  185. * \typedef PHYSFS_sint16
  186. * \brief A signed, 16-bit integer type.
  187. */
  188. typedef signed short PHYSFS_sint16;
  189. /**
  190. * \typedef PHYSFS_uint32
  191. * \brief An unsigned, 32-bit integer type.
  192. */
  193. typedef unsigned int PHYSFS_uint32;
  194. /**
  195. * \typedef PHYSFS_sint32
  196. * \brief A signed, 32-bit integer type.
  197. */
  198. typedef signed int PHYSFS_sint32;
  199. /**
  200. * \typedef PHYSFS_uint64
  201. * \brief An unsigned, 64-bit integer type.
  202. * \warning on platforms without any sort of 64-bit datatype, this is
  203. * equivalent to PHYSFS_uint32!
  204. */
  205. /**
  206. * \typedef PHYSFS_sint64
  207. * \brief A signed, 64-bit integer type.
  208. * \warning on platforms without any sort of 64-bit datatype, this is
  209. * equivalent to PHYSFS_sint32!
  210. */
  211. #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */
  212. typedef PHYSFS_uint32 PHYSFS_uint64;
  213. typedef PHYSFS_sint32 PHYSFS_sint64;
  214. #elif (defined _MSC_VER)
  215. typedef signed __int64 PHYSFS_sint64;
  216. typedef unsigned __int64 PHYSFS_uint64;
  217. #else
  218. typedef unsigned long long PHYSFS_uint64;
  219. typedef signed long long PHYSFS_sint64;
  220. #endif
  221. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  222. /* Make sure the types really have the right sizes */
  223. #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \
  224. typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1]
  225. PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1);
  226. PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1);
  227. PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2);
  228. PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2);
  229. PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4);
  230. PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4);
  231. #ifndef PHYSFS_NO_64BIT_SUPPORT
  232. PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8);
  233. PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8);
  234. #endif
  235. #undef PHYSFS_COMPILE_TIME_ASSERT
  236. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  237. /**
  238. * \struct PHYSFS_File
  239. * \brief A PhysicsFS file handle.
  240. *
  241. * You get a pointer to one of these when you open a file for reading,
  242. * writing, or appending via PhysicsFS.
  243. *
  244. * As you can see from the lack of meaningful fields, you should treat this
  245. * as opaque data. Don't try to manipulate the file handle, just pass the
  246. * pointer you got, unmolested, to various PhysicsFS APIs.
  247. *
  248. * \sa PHYSFS_openRead
  249. * \sa PHYSFS_openWrite
  250. * \sa PHYSFS_openAppend
  251. * \sa PHYSFS_close
  252. * \sa PHYSFS_read
  253. * \sa PHYSFS_write
  254. * \sa PHYSFS_seek
  255. * \sa PHYSFS_tell
  256. * \sa PHYSFS_eof
  257. * \sa PHYSFS_setBuffer
  258. * \sa PHYSFS_flush
  259. */
  260. typedef struct
  261. {
  262. void *opaque; /**< That's all you get. Don't touch. */
  263. } PHYSFS_File;
  264. typedef PHYSFS_File PHYSFS_file; /* for backwards compatibility with 1.0 */
  265. /**
  266. * \struct PHYSFS_ArchiveInfo
  267. * \brief Information on various PhysicsFS-supported archives.
  268. *
  269. * This structure gives you details on what sort of archives are supported
  270. * by this implementation of PhysicsFS. Archives tend to be things like
  271. * ZIP files and such.
  272. *
  273. * \warning Not all binaries are created equal! PhysicsFS can be built with
  274. * or without support for various archives. You can check with
  275. * PHYSFS_supportedArchiveTypes() to see if your archive type is
  276. * supported.
  277. *
  278. * \sa PHYSFS_supportedArchiveTypes
  279. */
  280. typedef struct
  281. {
  282. const char *extension; /**< Archive file extension: "ZIP", for example. */
  283. const char *description; /**< Human-readable archive description. */
  284. const char *author; /**< Person who did support for this archive. */
  285. const char *url; /**< URL related to this archive */
  286. } PHYSFS_ArchiveInfo;
  287. /**
  288. * \struct PHYSFS_Version
  289. * \brief Information the version of PhysicsFS in use.
  290. *
  291. * Represents the library's version as three levels: major revision
  292. * (increments with massive changes, additions, and enhancements),
  293. * minor revision (increments with backwards-compatible changes to the
  294. * major revision), and patchlevel (increments with fixes to the minor
  295. * revision).
  296. *
  297. * \sa PHYSFS_VERSION
  298. * \sa PHYFS_getLinkedVersion
  299. */
  300. typedef struct
  301. {
  302. PHYSFS_uint8 major; /**< major revision */
  303. PHYSFS_uint8 minor; /**< minor revision */
  304. PHYSFS_uint8 patch; /**< patchlevel */
  305. } PHYSFS_Version;
  306. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  307. #define PHYSFS_VER_MAJOR 1
  308. #define PHYSFS_VER_MINOR 1
  309. #define PHYSFS_VER_PATCH 0
  310. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  311. /* PhysicsFS state stuff ... */
  312. /**
  313. * \def PHYSFS_VERSION(x)
  314. * \brief Macro to determine PhysicsFS version program was compiled against.
  315. *
  316. * This macro fills in a PHYSFS_Version structure with the version of the
  317. * library you compiled against. This is determined by what header the
  318. * compiler uses. Note that if you dynamically linked the library, you might
  319. * have a slightly newer or older version at runtime. That version can be
  320. * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION,
  321. * is not a macro.
  322. *
  323. * \param x A pointer to a PHYSFS_Version struct to initialize.
  324. *
  325. * \sa PHYSFS_Version
  326. * \sa PHYSFS_getLinkedVersion
  327. */
  328. #define PHYSFS_VERSION(x) \
  329. { \
  330. (x)->major = PHYSFS_VER_MAJOR; \
  331. (x)->minor = PHYSFS_VER_MINOR; \
  332. (x)->patch = PHYSFS_VER_PATCH; \
  333. }
  334. /**
  335. * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  336. * \brief Get the version of PhysicsFS that is linked against your program.
  337. *
  338. * If you are using a shared library (DLL) version of PhysFS, then it is
  339. * possible that it will be different than the version you compiled against.
  340. *
  341. * This is a real function; the macro PHYSFS_VERSION tells you what version
  342. * of PhysFS you compiled against:
  343. *
  344. * \code
  345. * PHYSFS_Version compiled;
  346. * PHYSFS_Version linked;
  347. *
  348. * PHYSFS_VERSION(&compiled);
  349. * PHYSFS_getLinkedVersion(&linked);
  350. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  351. * compiled.major, compiled.minor, compiled.patch);
  352. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  353. * linked.major, linked.minor, linked.patch);
  354. * \endcode
  355. *
  356. * This function may be called safely at any time, even before PHYSFS_init().
  357. *
  358. * \sa PHYSFS_VERSION
  359. */
  360. __EXPORT__ void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  361. /**
  362. * \fn int PHYSFS_init(const char *argv0)
  363. * \brief Initialize the PhysicsFS library.
  364. *
  365. * This must be called before any other PhysicsFS function.
  366. *
  367. * This should be called prior to any attempts to change your process's
  368. * current working directory.
  369. *
  370. * \param argv0 the argv[0] string passed to your program's mainline.
  371. * This may be NULL on most platforms (such as ones without a
  372. * standard main() function), but you should always try to pass
  373. * something in here. Unix-like systems such as Linux _need_ to
  374. * pass argv[0] from main() in here.
  375. * \return nonzero on success, zero on error. Specifics of the error can be
  376. * gleaned from PHYSFS_getLastError().
  377. *
  378. * \sa PHYSFS_deinit
  379. */
  380. __EXPORT__ int PHYSFS_init(const char *argv0);
  381. /**
  382. * \fn int PHYSFS_deinit(void)
  383. * \brief Deinitialize the PhysicsFS library.
  384. *
  385. * This closes any files opened via PhysicsFS, blanks the search/write paths,
  386. * frees memory, and invalidates all of your file handles.
  387. *
  388. * Note that this call can FAIL if there's a file open for writing that
  389. * refuses to close (for example, the underlying operating system was
  390. * buffering writes to network filesystem, and the fileserver has crashed,
  391. * or a hard drive has failed, etc). It is usually best to close all write
  392. * handles yourself before calling this function, so that you can gracefully
  393. * handle a specific failure.
  394. *
  395. * Once successfully deinitialized, PHYSFS_init() can be called again to
  396. * restart the subsystem. All defaults API states are restored at this
  397. * point.
  398. *
  399. * \return nonzero on success, zero on error. Specifics of the error can be
  400. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  401. * undefined, and probably badly screwed up.
  402. *
  403. * \sa PHYSFS_init
  404. */
  405. __EXPORT__ int PHYSFS_deinit(void);
  406. /**
  407. * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
  408. * \brief Get a list of supported archive types.
  409. *
  410. * Get a list of archive types supported by this implementation of PhysicFS.
  411. * These are the file formats usable for search path entries. This is for
  412. * informational purposes only. Note that the extension listed is merely
  413. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  414. * with an extension of "XYZ", if you like.
  415. *
  416. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  417. * with a NULL entry to signify the end of the list:
  418. *
  419. * \code
  420. * PHYSFS_ArchiveInfo **i;
  421. *
  422. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  423. * {
  424. * printf("Supported archive: [%s], which is [%s].\n",
  425. * i->extension, i->description);
  426. * }
  427. * \endcode
  428. *
  429. * The return values are pointers to static internal memory, and should
  430. * be considered READ ONLY, and never freed.
  431. *
  432. * \return READ ONLY Null-terminated array of READ ONLY structures.
  433. */
  434. __EXPORT__ const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  435. /**
  436. * \fn void PHYSFS_freeList(void *listVar)
  437. * \brief Deallocate resources of lists returned by PhysicsFS.
  438. *
  439. * Certain PhysicsFS functions return lists of information that are
  440. * dynamically allocated. Use this function to free those resources.
  441. *
  442. * \param listVar List of information specified as freeable by this function.
  443. *
  444. * \sa PHYSFS_getCdRomDirs
  445. * \sa PHYSFS_enumerateFiles
  446. * \sa PHYSFS_getSearchPath
  447. */
  448. __EXPORT__ void PHYSFS_freeList(void *listVar);
  449. /**
  450. * \fn const char *PHYSFS_getLastError(void)
  451. * \brief Get human-readable error information.
  452. *
  453. * Get the last PhysicsFS error message as a human-readable, null-terminated
  454. * string. This will be NULL if there's been no error since the last call to
  455. * this function. The pointer returned by this call points to an internal
  456. * buffer. Each thread has a unique error state associated with it, but each
  457. * time a new error message is set, it will overwrite the previous one
  458. * associated with that thread. It is safe to call this function at anytime,
  459. * even before PHYSFS_init().
  460. *
  461. * It is not wise to expect a specific string of characters here, since the
  462. * error message may be localized into an unfamiliar language. These strings
  463. * are meant to be passed on directly to the user.
  464. *
  465. * \return READ ONLY string of last error message.
  466. */
  467. __EXPORT__ const char *PHYSFS_getLastError(void);
  468. /**
  469. * \fn const char *PHYSFS_getDirSeparator(void)
  470. * \brief Get platform-dependent dir separator string.
  471. *
  472. * This returns "\\\\" on win32, "/" on Unix, and ":" on MacOS. It may be more
  473. * than one character, depending on the platform, and your code should take
  474. * that into account. Note that this is only useful for setting up the
  475. * search/write paths, since access into those dirs always use '/'
  476. * (platform-independent notation) to separate directories. This is also
  477. * handy for getting platform-independent access when using stdio calls.
  478. *
  479. * \return READ ONLY null-terminated string of platform's dir separator.
  480. */
  481. __EXPORT__ const char *PHYSFS_getDirSeparator(void);
  482. /**
  483. * \fn void PHYSFS_permitSymbolicLinks(int allow)
  484. * \brief Enable or disable following of symbolic links.
  485. *
  486. * Some physical filesystems and archives contain files that are just pointers
  487. * to other files. On the physical filesystem, opening such a link will
  488. * (transparently) open the file that is pointed to.
  489. *
  490. * By default, PhysicsFS will check if a file is really a symlink during open
  491. * calls and fail if it is. Otherwise, the link could take you outside the
  492. * write and search paths, and compromise security.
  493. *
  494. * If you want to take that risk, call this function with a non-zero parameter.
  495. * Note that this is more for sandboxing a program's scripting language, in
  496. * case untrusted scripts try to compromise the system. Generally speaking,
  497. * a user could very well have a legitimate reason to set up a symlink, so
  498. * unless you feel there's a specific danger in allowing them, you should
  499. * permit them.
  500. *
  501. * Symlinks are only explicitly checked when dealing with filenames
  502. * in platform-independent notation. That is, when setting up your
  503. * search and write paths, etc, symlinks are never checked for.
  504. *
  505. * Symbolic link permission can be enabled or disabled at any time after
  506. * you've called PHYSFS_init(), and is disabled by default.
  507. *
  508. * \param allow nonzero to permit symlinks, zero to deny linking.
  509. */
  510. __EXPORT__ void PHYSFS_permitSymbolicLinks(int allow);
  511. /**
  512. * \fn char **PHYSFS_getCdRomDirs(void)
  513. * \brief Get an array of paths to available CD-ROM drives.
  514. *
  515. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  516. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  517. * accessible in the drive. So if you've got two drives (D: and E:), and only
  518. * E: has a disc in it, then that's all you get. If the user inserts a disc
  519. * in D: and you call this function again, you get both drives. If, on a
  520. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  521. * call to this function will reflect that change. Fun.
  522. *
  523. * The returned value is an array of strings, with a NULL entry to signify the
  524. * end of the list:
  525. *
  526. * \code
  527. * char **cds = PHYSFS_getCdRomDirs();
  528. * char **i;
  529. *
  530. * for (i = cds; *i != NULL; i++)
  531. * printf("cdrom dir [%s] is available.\n", *i);
  532. *
  533. * PHYSFS_freeList(cds);
  534. * \endcode
  535. *
  536. * This call may block while drives spin up. Be forewarned.
  537. *
  538. * When you are done with the returned information, you may dispose of the
  539. * resources by calling PHYSFS_freeList() with the returned pointer.
  540. *
  541. * \return Null-terminated array of null-terminated strings.
  542. *
  543. * \sa PHYSFS_getCdRomDirsCallback
  544. */
  545. __EXPORT__ char **PHYSFS_getCdRomDirs(void);
  546. /**
  547. * \fn const char *PHYSFS_getBaseDir(void)
  548. * \brief Get the path where the application resides.
  549. *
  550. * Helper function.
  551. *
  552. * Get the "base dir". This is the directory where the application was run
  553. * from, which is probably the installation directory, and may or may not
  554. * be the process's current working directory.
  555. *
  556. * You should probably use the base dir in your search path.
  557. *
  558. * \return READ ONLY string of base dir in platform-dependent notation.
  559. *
  560. * \sa PHYSFS_getUserDir
  561. */
  562. __EXPORT__ const char *PHYSFS_getBaseDir(void);
  563. /**
  564. * \fn const char *PHYSFS_getUserDir(void)
  565. * \brief Get the path where user's home directory resides.
  566. *
  567. * Helper function.
  568. *
  569. * Get the "user dir". This is meant to be a suggestion of where a specific
  570. * user of the system can store files. On Unix, this is her home directory.
  571. * On systems with no concept of multiple home directories (MacOS, win95),
  572. * this will default to something like "C:\mybasedir\users\username"
  573. * where "username" will either be the login name, or "default" if the
  574. * platform doesn't support multiple users, either.
  575. *
  576. * You should probably use the user dir as the basis for your write dir, and
  577. * also put it near the beginning of your search path.
  578. *
  579. * \return READ ONLY string of user dir in platform-dependent notation.
  580. *
  581. * \sa PHYSFS_getBaseDir
  582. */
  583. __EXPORT__ const char *PHYSFS_getUserDir(void);
  584. /**
  585. * \fn const char *PHYSFS_getWriteDir(void)
  586. * \brief Get path where PhysicsFS will allow file writing.
  587. *
  588. * Get the current write dir. The default write dir is NULL.
  589. *
  590. * \return READ ONLY string of write dir in platform-dependent notation,
  591. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  592. *
  593. * \sa PHYSFS_setWriteDir
  594. */
  595. __EXPORT__ const char *PHYSFS_getWriteDir(void);
  596. /**
  597. * \fn int PHYSFS_setWriteDir(const char *newDir)
  598. * \brief Tell PhysicsFS where it may write files.
  599. *
  600. * Set a new write dir. This will override the previous setting. If the
  601. * directory or a parent directory doesn't exist in the physical filesystem,
  602. * PhysicsFS will attempt to create them as needed.
  603. *
  604. * This call will fail (and fail to change the write dir) if the current
  605. * write dir still has files open in it.
  606. *
  607. * \param newDir The new directory to be the root of the write dir,
  608. * specified in platform-dependent notation. Setting to NULL
  609. * disables the write dir, so no files can be opened for
  610. * writing via PhysicsFS.
  611. * \return non-zero on success, zero on failure. All attempts to open a file
  612. * for writing via PhysicsFS will fail until this call succeeds.
  613. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  614. *
  615. * \sa PHYSFS_getWriteDir
  616. */
  617. __EXPORT__ int PHYSFS_setWriteDir(const char *newDir);
  618. /**
  619. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  620. * \brief Add an archive or directory to the search path.
  621. *
  622. * This is a legacy call in PhysicsFS 2.0, equivalent to:
  623. * PHYSFS_mount(newDir, NULL, appendToPath);
  624. *
  625. * You must use this and not PHYSFS_mount if binary compatibility with
  626. * PhysicsFS 1.0 is important (which it may not be for many people).
  627. *
  628. * \sa PHYSFS_mount
  629. * \sa PHYSFS_removeFromSearchPath
  630. * \sa PHYSFS_getSearchPath
  631. */
  632. __EXPORT__ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  633. /**
  634. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  635. * \brief Remove a directory or archive from the search path.
  636. *
  637. * This must be a (case-sensitive) match to a dir or archive already in the
  638. * search path, specified in platform-dependent notation.
  639. *
  640. * This call will fail (and fail to remove from the path) if the element still
  641. * has files open in it.
  642. *
  643. * \param oldDir dir/archive to remove.
  644. * \return nonzero on success, zero on failure.
  645. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  646. *
  647. * \sa PHYSFS_addToSearchPath
  648. * \sa PHYSFS_getSearchPath
  649. */
  650. __EXPORT__ int PHYSFS_removeFromSearchPath(const char *oldDir);
  651. /**
  652. * \fn char **PHYSFS_getSearchPath(void)
  653. * \brief Get the current search path.
  654. *
  655. * The default search path is an empty list.
  656. *
  657. * The returned value is an array of strings, with a NULL entry to signify the
  658. * end of the list:
  659. *
  660. * \code
  661. * char **i;
  662. *
  663. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  664. * printf("[%s] is in the search path.\n", *i);
  665. * \endcode
  666. *
  667. * When you are done with the returned information, you may dispose of the
  668. * resources by calling PHYSFS_freeList() with the returned pointer.
  669. *
  670. * \return Null-terminated array of null-terminated strings. NULL if there
  671. * was a problem (read: OUT OF MEMORY).
  672. *
  673. * \sa PHYSFS_getSearchPathCallback
  674. * \sa PHYSFS_addToSearchPath
  675. * \sa PHYSFS_removeFromSearchPath
  676. */
  677. __EXPORT__ char **PHYSFS_getSearchPath(void);
  678. /**
  679. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  680. * \brief Set up sane, default paths.
  681. *
  682. * Helper function.
  683. *
  684. * The write dir will be set to "userdir/.organization/appName", which is
  685. * created if it doesn't exist.
  686. *
  687. * The above is sufficient to make sure your program's configuration directory
  688. * is separated from other clutter, and platform-independent. The period
  689. * before "mygame" even hides the directory on Unix systems.
  690. *
  691. * The search path will be:
  692. *
  693. * - The Write Dir (created if it doesn't exist)
  694. * - The Base Dir (PHYSFS_getBaseDir())
  695. * - All found CD-ROM dirs (optionally)
  696. *
  697. * These directories are then searched for files ending with the extension
  698. * (archiveExt), which, if they are valid and supported archives, will also
  699. * be added to the search path. If you specified "PKG" for (archiveExt), and
  700. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  701. * can either be appended or prepended to the search path in alphabetical
  702. * order, regardless of which directories they were found in.
  703. *
  704. * All of this can be accomplished from the application, but this just does it
  705. * all for you. Feel free to add more to the search path manually, too.
  706. *
  707. * \param organization Name of your company/group/etc to be used as a
  708. * dirname, so keep it small, and no-frills.
  709. *
  710. * \param appName Program-specific name of your program, to separate it
  711. * from other programs using PhysicsFS.
  712. *
  713. * \param archiveExt File extension used by your program to specify an
  714. * archive. For example, Quake 3 uses "pk3", even though
  715. * they are just zipfiles. Specify NULL to not dig out
  716. * archives automatically. Do not specify the '.' char;
  717. * If you want to look for ZIP files, specify "ZIP" and
  718. * not ".ZIP" ... the archive search is case-insensitive.
  719. *
  720. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  721. * (if (archiveExt) != NULL) search them for archives.
  722. * This may cause a significant amount of blocking
  723. * while discs are accessed, and if there are no discs
  724. * in the drive (or even not mounted on Unix systems),
  725. * then they may not be made available anyhow. You may
  726. * want to specify zero and handle the disc setup
  727. * yourself.
  728. *
  729. * \param archivesFirst Non-zero to prepend the archives to the search path.
  730. * Zero to append them. Ignored if !(archiveExt).
  731. *
  732. * \return nonzero on success, zero on error. Specifics of the error can be
  733. * gleaned from PHYSFS_getLastError().
  734. */
  735. __EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
  736. const char *appName,
  737. const char *archiveExt,
  738. int includeCdRoms,
  739. int archivesFirst);
  740. /* Directory management stuff ... */
  741. /**
  742. * \fn int PHYSFS_mkdir(const char *dirName)
  743. * \brief Create a directory.
  744. *
  745. * This is specified in platform-independent notation in relation to the
  746. * write dir. All missing parent directories are also created if they
  747. * don't exist.
  748. *
  749. * So if you've got the write dir set to "C:\mygame\writedir" and call
  750. * PHYSFS_mkdir("downloads/maps") then the directories
  751. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  752. * will be created if possible. If the creation of "maps" fails after we
  753. * have successfully created "downloads", then the function leaves the
  754. * created directory behind and reports failure.
  755. *
  756. * \param dirName New dir to create.
  757. * \return nonzero on success, zero on error. Specifics of the error can be
  758. * gleaned from PHYSFS_getLastError().
  759. *
  760. * \sa PHYSFS_delete
  761. */
  762. __EXPORT__ int PHYSFS_mkdir(const char *dirName);
  763. /**
  764. * \fn int PHYSFS_delete(const char *filename)
  765. * \brief Delete a file or directory.
  766. *
  767. * (filename) is specified in platform-independent notation in relation to the
  768. * write dir.
  769. *
  770. * A directory must be empty before this call can delete it.
  771. *
  772. * Deleting a symlink will remove the link, not what it points to, regardless
  773. * of whether you "permitSymLinks" or not.
  774. *
  775. * So if you've got the write dir set to "C:\mygame\writedir" and call
  776. * PHYSFS_delete("downloads/maps/level1.map") then the file
  777. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  778. * physical filesystem, if it exists and the operating system permits the
  779. * deletion.
  780. *
  781. * Note that on Unix systems, deleting a file may be successful, but the
  782. * actual file won't be removed until all processes that have an open
  783. * filehandle to it (including your program) close their handles.
  784. *
  785. * Chances are, the bits that make up the file still exist, they are just
  786. * made available to be written over at a later point. Don't consider this
  787. * a security method or anything. :)
  788. *
  789. * \param filename Filename to delete.
  790. * \return nonzero on success, zero on error. Specifics of the error can be
  791. * gleaned from PHYSFS_getLastError().
  792. */
  793. __EXPORT__ int PHYSFS_delete(const char *filename);
  794. /**
  795. * \fn const char *PHYSFS_getRealDir(const char *filename)
  796. * \brief Figure out where in the search path a file resides.
  797. *
  798. * The file is specified in platform-independent notation. The returned
  799. * filename will be the element of the search path where the file was found,
  800. * which may be a directory, or an archive. Even if there are multiple
  801. * matches in different parts of the search path, only the first one found
  802. * is used, just like when opening a file.
  803. *
  804. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  805. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  806. *
  807. * If a any part of a match is a symbolic link, and you've not explicitly
  808. * permitted symlinks, then it will be ignored, and the search for a match
  809. * will continue.
  810. *
  811. * If you specify a fake directory that only exists as a mount point, it'll
  812. * be associated with the first archive mounted there, even though that
  813. * directory isn't necessarily contained in a real archive.
  814. *
  815. * \param filename file to look for.
  816. * \return READ ONLY string of element of search path containing the
  817. * the file in question. NULL if not found.
  818. */
  819. __EXPORT__ const char *PHYSFS_getRealDir(const char *filename);
  820. /**
  821. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  822. * \brief Get a file listing of a search path's directory.
  823. *
  824. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  825. * search path and contains a directory "savegames" that contains "x.sav",
  826. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  827. * that has a "savegames" subdirectory with "w.sav", then the following code:
  828. *
  829. * \code
  830. * char **rc = PHYSFS_enumerateFiles("savegames");
  831. * char **i;
  832. *
  833. * for (i = rc; *i != NULL; i++)
  834. * printf(" * We've got [%s].\n", *i);
  835. *
  836. * PHYSFS_freeList(rc);
  837. * \endcode
  838. *
  839. * ...will print:
  840. *
  841. * \verbatim
  842. * We've got [x.sav].
  843. * We've got [y.sav].
  844. * We've got [z.sav].
  845. * We've got [w.sav].\endverbatim
  846. *
  847. * Feel free to sort the list however you like. We only promise there will
  848. * be no duplicates, but not what order the final list will come back in.
  849. *
  850. * Don't forget to call PHYSFS_freeList() with the return value from this
  851. * function when you are done with it.
  852. *
  853. * \param dir directory in platform-independent notation to enumerate.
  854. * \return Null-terminated array of null-terminated strings.
  855. *
  856. * \sa PHYSFS_enumerateFilesCallback
  857. */
  858. __EXPORT__ char **PHYSFS_enumerateFiles(const char *dir);
  859. /**
  860. * \fn int PHYSFS_exists(const char *fname)
  861. * \brief Determine if a file exists in the search path.
  862. *
  863. * Reports true if there is an entry anywhere in the search path by the
  864. * name of (fname).
  865. *
  866. * Note that entries that are symlinks are ignored if
  867. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  868. * might end up further down in the search path than expected.
  869. *
  870. * \param fname filename in platform-independent notation.
  871. * \return non-zero if filename exists. zero otherwise.
  872. *
  873. * \sa PHYSFS_isDirectory
  874. * \sa PHYSFS_isSymbolicLink
  875. */
  876. __EXPORT__ int PHYSFS_exists(const char *fname);
  877. /**
  878. * \fn int PHYSFS_isDirectory(const char *fname)
  879. * \brief Determine if a file in the search path is really a directory.
  880. *
  881. * Determine if the first occurence of (fname) in the search path is
  882. * really a directory entry.
  883. *
  884. * Note that entries that are symlinks are ignored if
  885. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  886. * might end up further down in the search path than expected.
  887. *
  888. * \param fname filename in platform-independent notation.
  889. * \return non-zero if filename exists and is a directory. zero otherwise.
  890. *
  891. * \sa PHYSFS_exists
  892. * \sa PHYSFS_isSymbolicLink
  893. */
  894. __EXPORT__ int PHYSFS_isDirectory(const char *fname);
  895. /**
  896. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  897. * \brief Determine if a file in the search path is really a symbolic link.
  898. *
  899. * Determine if the first occurence of (fname) in the search path is
  900. * really a symbolic link.
  901. *
  902. * Note that entries that are symlinks are ignored if
  903. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  904. * this function will always return 0 in that case.
  905. *
  906. * \param fname filename in platform-independent notation.
  907. * \return non-zero if filename exists and is a symlink. zero otherwise.
  908. *
  909. * \sa PHYSFS_exists
  910. * \sa PHYSFS_isDirectory
  911. */
  912. __EXPORT__ int PHYSFS_isSymbolicLink(const char *fname);
  913. /**
  914. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  915. * \brief Get the last modification time of a file.
  916. *
  917. * The modtime is returned as a number of seconds since the epoch
  918. * (Jan 1, 1970). The exact derivation and accuracy of this time depends on
  919. * the particular archiver. If there is no reasonable way to obtain this
  920. * information for a particular archiver, or there was some sort of error,
  921. * this function returns (-1).
  922. *
  923. * \param filename filename to check, in platform-independent notation.
  924. * \return last modified time of the file. -1 if it can't be determined.
  925. */
  926. __EXPORT__ PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename);
  927. /* i/o stuff... */
  928. /**
  929. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  930. * \brief Open a file for writing.
  931. *
  932. * Open a file for writing, in platform-independent notation and in relation
  933. * to the write dir as the root of the writable filesystem. The specified
  934. * file is created if it doesn't exist. If it does exist, it is truncated to
  935. * zero bytes, and the writing offset is set to the start.
  936. *
  937. * Note that entries that are symlinks are ignored if
  938. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  939. * symlink with this function will fail in such a case.
  940. *
  941. * \param filename File to open.
  942. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  943. * of the error can be gleaned from PHYSFS_getLastError().
  944. *
  945. * \sa PHYSFS_openRead
  946. * \sa PHYSFS_openAppend
  947. * \sa PHYSFS_write
  948. * \sa PHYSFS_close
  949. */
  950. __EXPORT__ PHYSFS_File *PHYSFS_openWrite(const char *filename);
  951. /**
  952. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  953. * \brief Open a file for appending.
  954. *
  955. * Open a file for writing, in platform-independent notation and in relation
  956. * to the write dir as the root of the writable filesystem. The specified
  957. * file is created if it doesn't exist. If it does exist, the writing offset
  958. * is set to the end of the file, so the first write will be the byte after
  959. * the end.
  960. *
  961. * Note that entries that are symlinks are ignored if
  962. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  963. * symlink with this function will fail in such a case.
  964. *
  965. * \param filename File to open.
  966. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  967. * of the error can be gleaned from PHYSFS_getLastError().
  968. *
  969. * \sa PHYSFS_openRead
  970. * \sa PHYSFS_openWrite
  971. * \sa PHYSFS_write
  972. * \sa PHYSFS_close
  973. */
  974. __EXPORT__ PHYSFS_File *PHYSFS_openAppend(const char *filename);
  975. /**
  976. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  977. * \brief Open a file for reading.
  978. *
  979. * Open a file for reading, in platform-independent notation. The search path
  980. * is checked one at a time until a matching file is found, in which case an
  981. * abstract filehandle is associated with it, and reading may be done.
  982. * The reading offset is set to the first byte of the file.
  983. *
  984. * Note that entries that are symlinks are ignored if
  985. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  986. * symlink with this function will fail in such a case.
  987. *
  988. * \param filename File to open.
  989. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  990. * of the error can be gleaned from PHYSFS_getLastError().
  991. *
  992. * \sa PHYSFS_openWrite
  993. * \sa PHYSFS_openAppend
  994. * \sa PHYSFS_read
  995. * \sa PHYSFS_close
  996. */
  997. __EXPORT__ PHYSFS_File *PHYSFS_openRead(const char *filename);
  998. /**
  999. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1000. * \brief Close a PhysicsFS filehandle.
  1001. *
  1002. * This call is capable of failing if the operating system was buffering
  1003. * writes to the physical media, and, now forced to write those changes to
  1004. * physical media, can not store the data for some reason. In such a case,
  1005. * the filehandle stays open. A well-written program should ALWAYS check the
  1006. * return value from the close call in addition to every writing call!
  1007. *
  1008. * \param handle handle returned from PHYSFS_open*().
  1009. * \return nonzero on success, zero on error. Specifics of the error can be
  1010. * gleaned from PHYSFS_getLastError().
  1011. *
  1012. * \sa PHYSFS_openRead
  1013. * \sa PHYSFS_openWrite
  1014. * \sa PHYSFS_openAppend
  1015. */
  1016. __EXPORT__ int PHYSFS_close(PHYSFS_File *handle);
  1017. /**
  1018. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1019. * \brief Read data from a PhysicsFS filehandle
  1020. *
  1021. * The file must be opened for reading.
  1022. *
  1023. * \param handle handle returned from PHYSFS_openRead().
  1024. * \param buffer buffer to store read data into.
  1025. * \param objSize size in bytes of objects being read from (handle).
  1026. * \param objCount number of (objSize) objects to read from (handle).
  1027. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1028. * the reason this might be < (objCount), as can PHYSFS_eof().
  1029. * -1 if complete failure.
  1030. *
  1031. * \sa PHYSFS_eof
  1032. */
  1033. __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1034. void *buffer,
  1035. PHYSFS_uint32 objSize,
  1036. PHYSFS_uint32 objCount);
  1037. /**
  1038. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1039. * \brief Write data to a PhysicsFS filehandle
  1040. *
  1041. * The file must be opened for writing.
  1042. *
  1043. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1044. * \param buffer buffer to store read data into.
  1045. * \param objSize size in bytes of objects being read from (handle).
  1046. * \param objCount number of (objSize) objects to read from (handle).
  1047. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1048. * the reason this might be < (objCount). -1 if complete failure.
  1049. */
  1050. __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1051. const void *buffer,
  1052. PHYSFS_uint32 objSize,
  1053. PHYSFS_uint32 objCount);
  1054. /* File position stuff... */
  1055. /**
  1056. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1057. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1058. *
  1059. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1060. *
  1061. * \param handle handle returned from PHYSFS_openRead().
  1062. * \return nonzero if EOF, zero if not.
  1063. *
  1064. * \sa PHYSFS_read
  1065. * \sa PHYSFS_tell
  1066. */
  1067. __EXPORT__ int PHYSFS_eof(PHYSFS_File *handle);
  1068. /**
  1069. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1070. * \brief Determine current position within a PhysicsFS filehandle.
  1071. *
  1072. * \param handle handle returned from PHYSFS_open*().
  1073. * \return offset in bytes from start of file. -1 if error occurred.
  1074. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1075. *
  1076. * \sa PHYSFS_seek
  1077. */
  1078. __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1079. /**
  1080. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1081. * \brief Seek to a new position within a PhysicsFS filehandle.
  1082. *
  1083. * The next read or write will occur at that place. Seeking past the
  1084. * beginning or end of the file is not allowed, and causes an error.
  1085. *
  1086. * \param handle handle returned from PHYSFS_open*().
  1087. * \param pos number of bytes from start of file to seek to.
  1088. * \return nonzero on success, zero on error. Specifics of the error can be
  1089. * gleaned from PHYSFS_getLastError().
  1090. *
  1091. * \sa PHYSFS_tell
  1092. */
  1093. __EXPORT__ int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1094. /**
  1095. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1096. * \brief Get total length of a file in bytes.
  1097. *
  1098. * Note that if the file size can't be determined (since the archive is
  1099. * "streamed" or whatnot) than this will report (-1). Also note that if
  1100. * another process/thread is writing to this file at the same time, then
  1101. * the information this function supplies could be incorrect before you
  1102. * get it. Use with caution, or better yet, don't use at all.
  1103. *
  1104. * \param handle handle returned from PHYSFS_open*().
  1105. * \return size in bytes of the file. -1 if can't be determined.
  1106. *
  1107. * \sa PHYSFS_tell
  1108. * \sa PHYSFS_seek
  1109. */
  1110. __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1111. /* Buffering stuff... */
  1112. /**
  1113. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1114. * \brief Set up buffering for a PhysicsFS file handle.
  1115. *
  1116. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1117. * will be allocated and associated with (handle).
  1118. *
  1119. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1120. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1121. * from this buffer until it is empty, and then refill it for more reading.
  1122. * Note that compressed files, like ZIP archives, will decompress while
  1123. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1124. * The buffer isn't filled until you do your next read.
  1125. *
  1126. * For files opened for writing, data will be buffered to memory until the
  1127. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1128. * causes a flush...check your return values!
  1129. *
  1130. * Seeking, etc transparently accounts for buffering.
  1131. *
  1132. * You can resize an existing buffer by calling this function more than once
  1133. * on the same file. Setting the buffer size to zero will free an existing
  1134. * buffer.
  1135. *
  1136. * PhysicsFS file handles are unbuffered by default.
  1137. *
  1138. * Please check the return value of this function! Failures can include
  1139. * not being able to seek backwards in a read-only file when removing the
  1140. * buffer, not being able to allocate the buffer, and not being able to
  1141. * flush the buffer to disk, among other unexpected problems.
  1142. *
  1143. * \param handle handle returned from PHYSFS_open*().
  1144. * \param bufsize size, in bytes, of buffer to allocate.
  1145. * \return nonzero if successful, zero on error.
  1146. *
  1147. * \sa PHYSFS_flush
  1148. * \sa PHYSFS_read
  1149. * \sa PHYSFS_write
  1150. * \sa PHYSFS_close
  1151. */
  1152. __EXPORT__ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1153. /**
  1154. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1155. * \brief Flush a buffered PhysicsFS file handle.
  1156. *
  1157. * For buffered files opened for writing, this will put the current contents
  1158. * of the buffer to disk and flag the buffer as empty if possible.
  1159. *
  1160. * For buffered files opened for reading or unbuffered files, this is a safe
  1161. * no-op, and will report success.
  1162. *
  1163. * \param handle handle returned from PHYSFS_open*().
  1164. * \return nonzero if successful, zero on error.
  1165. *
  1166. * \sa PHYSFS_setBuffer
  1167. * \sa PHYSFS_close
  1168. */
  1169. __EXPORT__ int PHYSFS_flush(PHYSFS_File *handle);
  1170. /* Byteorder stuff... */
  1171. /**
  1172. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1173. * \brief Swap littleendian signed 16 to platform's native byte order.
  1174. *
  1175. * Take a 16-bit signed value in littleendian format and convert it to
  1176. * the platform's native byte order.
  1177. *
  1178. * \param val value to convert
  1179. * \return converted value.
  1180. */
  1181. __EXPORT__ PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1182. /**
  1183. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1184. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1185. *
  1186. * Take a 16-bit unsigned value in littleendian format and convert it to
  1187. * the platform's native byte order.
  1188. *
  1189. * \param val value to convert
  1190. * \return converted value.
  1191. */
  1192. __EXPORT__ PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1193. /**
  1194. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1195. * \brief Swap littleendian signed 32 to platform's native byte order.
  1196. *
  1197. * Take a 32-bit signed value in littleendian format and convert it to
  1198. * the platform's native byte order.
  1199. *
  1200. * \param val value to convert
  1201. * \return converted value.
  1202. */
  1203. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1204. /**
  1205. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1206. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1207. *
  1208. * Take a 32-bit unsigned value in littleendian format and convert it to
  1209. * the platform's native byte order.
  1210. *
  1211. * \param val value to convert
  1212. * \return converted value.
  1213. */
  1214. __EXPORT__ PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1215. /**
  1216. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1217. * \brief Swap littleendian signed 64 to platform's native byte order.
  1218. *
  1219. * Take a 64-bit signed value in littleendian format and convert it to
  1220. * the platform's native byte order.
  1221. *
  1222. * \param val value to convert
  1223. * \return converted value.
  1224. *
  1225. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1226. * any sort of 64-bit support.
  1227. */
  1228. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1229. /**
  1230. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1231. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1232. *
  1233. * Take a 64-bit unsigned value in littleendian format and convert it to
  1234. * the platform's native byte order.
  1235. *
  1236. * \param val value to convert
  1237. * \return converted value.
  1238. *
  1239. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1240. * any sort of 64-bit support.
  1241. */
  1242. __EXPORT__ PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1243. /**
  1244. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1245. * \brief Swap bigendian signed 16 to platform's native byte order.
  1246. *
  1247. * Take a 16-bit signed value in bigendian format and convert it to
  1248. * the platform's native byte order.
  1249. *
  1250. * \param val value to convert
  1251. * \return converted value.
  1252. */
  1253. __EXPORT__ PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1254. /**
  1255. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1256. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1257. *
  1258. * Take a 16-bit unsigned value in bigendian format and convert it to
  1259. * the platform's native byte order.
  1260. *
  1261. * \param val value to convert
  1262. * \return converted value.
  1263. */
  1264. __EXPORT__ PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1265. /**
  1266. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1267. * \brief Swap bigendian signed 32 to platform's native byte order.
  1268. *
  1269. * Take a 32-bit signed value in bigendian format and convert it to
  1270. * the platform's native byte order.
  1271. *
  1272. * \param val value to convert
  1273. * \return converted value.
  1274. */
  1275. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1276. /**
  1277. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1278. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1279. *
  1280. * Take a 32-bit unsigned value in bigendian format and convert it to
  1281. * the platform's native byte order.
  1282. *
  1283. * \param val value to convert
  1284. * \return converted value.
  1285. */
  1286. __EXPORT__ PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1287. /**
  1288. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1289. * \brief Swap bigendian signed 64 to platform's native byte order.
  1290. *
  1291. * Take a 64-bit signed value in bigendian format and convert it to
  1292. * the platform's native byte order.
  1293. *
  1294. * \param val value to convert
  1295. * \return converted value.
  1296. *
  1297. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1298. * any sort of 64-bit support.
  1299. */
  1300. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1301. /**
  1302. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1303. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1304. *
  1305. * Take a 64-bit unsigned value in bigendian format and convert it to
  1306. * the platform's native byte order.
  1307. *
  1308. * \param val value to convert
  1309. * \return converted value.
  1310. *
  1311. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1312. * any sort of 64-bit support.
  1313. */
  1314. __EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1315. /**
  1316. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1317. * \brief Read and convert a signed 16-bit littleendian value.
  1318. *
  1319. * Convenience function. Read a signed 16-bit littleendian value from a
  1320. * file and convert it to the platform's native byte order.
  1321. *
  1322. * \param file PhysicsFS file handle from which to read.
  1323. * \param val pointer to where value should be stored.
  1324. * \return zero on failure, non-zero on success. If successful, (*val) will
  1325. * store the result. On failure, you can find out what went wrong
  1326. * from PHYSFS_getLastError().
  1327. */
  1328. __EXPORT__ int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1329. /**
  1330. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1331. * \brief Read and convert an unsigned 16-bit littleendian value.
  1332. *
  1333. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1334. * file and convert it to the platform's native byte order.
  1335. *
  1336. * \param file PhysicsFS file handle from which to read.
  1337. * \param val pointer to where value should be stored.
  1338. * \return zero on failure, non-zero on success. If successful, (*val) will
  1339. * store the result. On failure, you can find out what went wrong
  1340. * from PHYSFS_getLastError().
  1341. *
  1342. */
  1343. __EXPORT__ int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1344. /**
  1345. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1346. * \brief Read and convert a signed 16-bit bigendian value.
  1347. *
  1348. * Convenience function. Read a signed 16-bit bigendian value from a
  1349. * file and convert it to the platform's native byte order.
  1350. *
  1351. * \param file PhysicsFS file handle from which to read.
  1352. * \param val pointer to where value should be stored.
  1353. * \return zero on failure, non-zero on success. If successful, (*val) will
  1354. * store the result. On failure, you can find out what went wrong
  1355. * from PHYSFS_getLastError().
  1356. */
  1357. __EXPORT__ int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1358. /**
  1359. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1360. * \brief Read and convert an unsigned 16-bit bigendian value.
  1361. *
  1362. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1363. * file and convert it to the platform's native byte order.
  1364. *
  1365. * \param file PhysicsFS file handle from which to read.
  1366. * \param val pointer to where value should be stored.
  1367. * \return zero on failure, non-zero on success. If successful, (*val) will
  1368. * store the result. On failure, you can find out what went wrong
  1369. * from PHYSFS_getLastError().
  1370. *
  1371. */
  1372. __EXPORT__ int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1373. /**
  1374. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1375. * \brief Read and convert a signed 32-bit littleendian value.
  1376. *
  1377. * Convenience function. Read a signed 32-bit littleendian value from a
  1378. * file and convert it to the platform's native byte order.
  1379. *
  1380. * \param file PhysicsFS file handle from which to read.
  1381. * \param val pointer to where value should be stored.
  1382. * \return zero on failure, non-zero on success. If successful, (*val) will
  1383. * store the result. On failure, you can find out what went wrong
  1384. * from PHYSFS_getLastError().
  1385. */
  1386. __EXPORT__ int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1387. /**
  1388. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1389. * \brief Read and convert an unsigned 32-bit littleendian value.
  1390. *
  1391. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1392. * file and convert it to the platform's native byte order.
  1393. *
  1394. * \param file PhysicsFS file handle from which to read.
  1395. * \param val pointer to where value should be stored.
  1396. * \return zero on failure, non-zero on success. If successful, (*val) will
  1397. * store the result. On failure, you can find out what went wrong
  1398. * from PHYSFS_getLastError().
  1399. *
  1400. */
  1401. __EXPORT__ int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1402. /**
  1403. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1404. * \brief Read and convert a signed 32-bit bigendian value.
  1405. *
  1406. * Convenience function. Read a signed 32-bit bigendian value from a
  1407. * file and convert it to the platform's native byte order.
  1408. *
  1409. * \param file PhysicsFS file handle from which to read.
  1410. * \param val pointer to where value should be stored.
  1411. * \return zero on failure, non-zero on success. If successful, (*val) will
  1412. * store the result. On failure, you can find out what went wrong
  1413. * from PHYSFS_getLastError().
  1414. */
  1415. __EXPORT__ int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1416. /**
  1417. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1418. * \brief Read and convert an unsigned 32-bit bigendian value.
  1419. *
  1420. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1421. * file and convert it to the platform's native byte order.
  1422. *
  1423. * \param file PhysicsFS file handle from which to read.
  1424. * \param val pointer to where value should be stored.
  1425. * \return zero on failure, non-zero on success. If successful, (*val) will
  1426. * store the result. On failure, you can find out what went wrong
  1427. * from PHYSFS_getLastError().
  1428. *
  1429. */
  1430. __EXPORT__ int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1431. /**
  1432. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1433. * \brief Read and convert a signed 64-bit littleendian value.
  1434. *
  1435. * Convenience function. Read a signed 64-bit littleendian value from a
  1436. * file and convert it to the platform's native byte order.
  1437. *
  1438. * \param file PhysicsFS file handle from which to read.
  1439. * \param val pointer to where value should be stored.
  1440. * \return zero on failure, non-zero on success. If successful, (*val) will
  1441. * store the result. On failure, you can find out what went wrong
  1442. * from PHYSFS_getLastError().
  1443. *
  1444. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1445. * any sort of 64-bit support.
  1446. */
  1447. __EXPORT__ int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1448. /**
  1449. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1450. * \brief Read and convert an unsigned 64-bit littleendian value.
  1451. *
  1452. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1453. * file and convert it to the platform's native byte order.
  1454. *
  1455. * \param file PhysicsFS file handle from which to read.
  1456. * \param val pointer to where value should be stored.
  1457. * \return zero on failure, non-zero on success. If successful, (*val) will
  1458. * store the result. On failure, you can find out what went wrong
  1459. * from PHYSFS_getLastError().
  1460. *
  1461. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1462. * any sort of 64-bit support.
  1463. */
  1464. __EXPORT__ int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1465. /**
  1466. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1467. * \brief Read and convert a signed 64-bit bigendian value.
  1468. *
  1469. * Convenience function. Read a signed 64-bit bigendian value from a
  1470. * file and convert it to the platform's native byte order.
  1471. *
  1472. * \param file PhysicsFS file handle from which to read.
  1473. * \param val pointer to where value should be stored.
  1474. * \return zero on failure, non-zero on success. If successful, (*val) will
  1475. * store the result. On failure, you can find out what went wrong
  1476. * from PHYSFS_getLastError().
  1477. *
  1478. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1479. * any sort of 64-bit support.
  1480. */
  1481. __EXPORT__ int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1482. /**
  1483. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1484. * \brief Read and convert an unsigned 64-bit bigendian value.
  1485. *
  1486. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1487. * file and convert it to the platform's native byte order.
  1488. *
  1489. * \param file PhysicsFS file handle from which to read.
  1490. * \param val pointer to where value should be stored.
  1491. * \return zero on failure, non-zero on success. If successful, (*val) will
  1492. * store the result. On failure, you can find out what went wrong
  1493. * from PHYSFS_getLastError().
  1494. *
  1495. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1496. * any sort of 64-bit support.
  1497. */
  1498. __EXPORT__ int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1499. /**
  1500. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1501. * \brief Convert and write a signed 16-bit littleendian value.
  1502. *
  1503. * Convenience function. Convert a signed 16-bit value from the platform's
  1504. * native byte order to littleendian and write it to a file.
  1505. *
  1506. * \param file PhysicsFS file handle to which to write.
  1507. * \param val Value to convert and write.
  1508. * \return zero on failure, non-zero on success. On failure, you can
  1509. * find out what went wrong from PHYSFS_getLastError().
  1510. */
  1511. __EXPORT__ int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1512. /**
  1513. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1514. * \brief Convert and write an unsigned 16-bit littleendian value.
  1515. *
  1516. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1517. * native byte order to littleendian and write it to a file.
  1518. *
  1519. * \param file PhysicsFS file handle to which to write.
  1520. * \param val Value to convert and write.
  1521. * \return zero on failure, non-zero on success. On failure, you can
  1522. * find out what went wrong from PHYSFS_getLastError().
  1523. */
  1524. __EXPORT__ int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1525. /**
  1526. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1527. * \brief Convert and write a signed 16-bit bigendian value.
  1528. *
  1529. * Convenience function. Convert a signed 16-bit value from the platform's
  1530. * native byte order to bigendian and write it to a file.
  1531. *
  1532. * \param file PhysicsFS file handle to which to write.
  1533. * \param val Value to convert and write.
  1534. * \return zero on failure, non-zero on success. On failure, you can
  1535. * find out what went wrong from PHYSFS_getLastError().
  1536. */
  1537. __EXPORT__ int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1538. /**
  1539. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1540. * \brief Convert and write an unsigned 16-bit bigendian value.
  1541. *
  1542. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1543. * native byte order to bigendian and write it to a file.
  1544. *
  1545. * \param file PhysicsFS file handle to which to write.
  1546. * \param val Value to convert and write.
  1547. * \return zero on failure, non-zero on success. On failure, you can
  1548. * find out what went wrong from PHYSFS_getLastError().
  1549. */
  1550. __EXPORT__ int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1551. /**
  1552. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1553. * \brief Convert and write a signed 32-bit littleendian value.
  1554. *
  1555. * Convenience function. Convert a signed 32-bit value from the platform's
  1556. * native byte order to littleendian and write it to a file.
  1557. *
  1558. * \param file PhysicsFS file handle to which to write.
  1559. * \param val Value to convert and write.
  1560. * \return zero on failure, non-zero on success. On failure, you can
  1561. * find out what went wrong from PHYSFS_getLastError().
  1562. */
  1563. __EXPORT__ int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1564. /**
  1565. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1566. * \brief Convert and write an unsigned 32-bit littleendian value.
  1567. *
  1568. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1569. * native byte order to littleendian and write it to a file.
  1570. *
  1571. * \param file PhysicsFS file handle to which to write.
  1572. * \param val Value to convert and write.
  1573. * \return zero on failure, non-zero on success. On failure, you can
  1574. * find out what went wrong from PHYSFS_getLastError().
  1575. */
  1576. __EXPORT__ int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1577. /**
  1578. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1579. * \brief Convert and write a signed 32-bit bigendian value.
  1580. *
  1581. * Convenience function. Convert a signed 32-bit value from the platform's
  1582. * native byte order to bigendian and write it to a file.
  1583. *
  1584. * \param file PhysicsFS file handle to which to write.
  1585. * \param val Value to convert and write.
  1586. * \return zero on failure, non-zero on success. On failure, you can
  1587. * find out what went wrong from PHYSFS_getLastError().
  1588. */
  1589. __EXPORT__ int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1590. /**
  1591. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1592. * \brief Convert and write an unsigned 32-bit bigendian value.
  1593. *
  1594. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1595. * native byte order to bigendian and write it to a file.
  1596. *
  1597. * \param file PhysicsFS file handle to which to write.
  1598. * \param val Value to convert and write.
  1599. * \return zero on failure, non-zero on success. On failure, you can
  1600. * find out what went wrong from PHYSFS_getLastError().
  1601. */
  1602. __EXPORT__ int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1603. /**
  1604. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1605. * \brief Convert and write a signed 64-bit littleendian value.
  1606. *
  1607. * Convenience function. Convert a signed 64-bit value from the platform's
  1608. * native byte order to littleendian and write it to a file.
  1609. *
  1610. * \param file PhysicsFS file handle to which to write.
  1611. * \param val Value to convert and write.
  1612. * \return zero on failure, non-zero on success. On failure, you can
  1613. * find out what went wrong from PHYSFS_getLastError().
  1614. *
  1615. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1616. * any sort of 64-bit support.
  1617. */
  1618. __EXPORT__ int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1619. /**
  1620. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1621. * \brief Convert and write an unsigned 64-bit littleendian value.
  1622. *
  1623. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1624. * native byte order to littleendian and write it to a file.
  1625. *
  1626. * \param file PhysicsFS file handle to which to write.
  1627. * \param val Value to convert and write.
  1628. * \return zero on failure, non-zero on success. On failure, you can
  1629. * find out what went wrong from PHYSFS_getLastError().
  1630. *
  1631. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1632. * any sort of 64-bit support.
  1633. */
  1634. __EXPORT__ int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1635. /**
  1636. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1637. * \brief Convert and write a signed 64-bit bigending value.
  1638. *
  1639. * Convenience function. Convert a signed 64-bit value from the platform's
  1640. * native byte order to bigendian and write it to a file.
  1641. *
  1642. * \param file PhysicsFS file handle to which to write.
  1643. * \param val Value to convert and write.
  1644. * \return zero on failure, non-zero on success. On failure, you can
  1645. * find out what went wrong from PHYSFS_getLastError().
  1646. *
  1647. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1648. * any sort of 64-bit support.
  1649. */
  1650. __EXPORT__ int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1651. /**
  1652. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1653. * \brief Convert and write an unsigned 64-bit bigendian value.
  1654. *
  1655. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1656. * native byte order to bigendian and write it to a file.
  1657. *
  1658. * \param file PhysicsFS file handle to which to write.
  1659. * \param val Value to convert and write.
  1660. * \return zero on failure, non-zero on success. On failure, you can
  1661. * find out what went wrong from PHYSFS_getLastError().
  1662. *
  1663. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1664. * any sort of 64-bit support.
  1665. */
  1666. __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1667. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1668. /**
  1669. * \struct PHYSFS_Allocator
  1670. * \brief PhysicsFS allocation function pointers.
  1671. *
  1672. * (This is for limited, hardcore use. If you don't immediately see a need
  1673. * for it, you can probably ignore this forever.)
  1674. *
  1675. * You create one of these structures for use with PHYSFS_setAllocator.
  1676. * Allocators are assumed to be reentrant by the caller; please mutex
  1677. * accordingly.
  1678. *
  1679. * Allocations are always discussed in 64-bits, for future expansion...we're
  1680. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1681. * gigabytes like it's nothing sooner or later, and I don't want to change
  1682. * this again at that point. If you're on a 32-bit platform and have to
  1683. * downcast, it's okay to return NULL if the allocation is greater than
  1684. * 4 gigabytes, since you'd have to do so anyhow.
  1685. *
  1686. * \sa PHYSFS_setAllocator
  1687. */
  1688. typedef struct
  1689. {
  1690. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1691. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1692. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1693. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1694. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1695. } PHYSFS_Allocator;
  1696. /**
  1697. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1698. * \brief Hook your own allocation routines into PhysicsFS.
  1699. *
  1700. * (This is for limited, hardcore use. If you don't immediately see a need
  1701. * for it, you can probably ignore this forever.)
  1702. *
  1703. * !!! FIXME: don't promise C runtime malloc.
  1704. *
  1705. * By default, PhysicsFS will use ANSI C malloc/realloc/calloc/free calls
  1706. * to manage dynamic memory, but in some uncommon cases, the app might want
  1707. * more control over the library's memory management. This lets you redirect
  1708. * physfs to use your own allocation routines instead. You can only call this
  1709. * function before PHYSFS_init(); if the library is initialized, it'll
  1710. * reject your efforts to change the allocator mid-stream. You may call this
  1711. * function after PHYSFS_deinit() if you are willing to shutdown the library
  1712. * and restart it with a new allocator; this is a safe and supported
  1713. * operation. The allocator remains intact between deinit/init calls.
  1714. * If you want to return to the default allocator, pass a NULL in here.
  1715. *
  1716. * If you aren't immediately sure what to do with this function, you can
  1717. * safely ignore it altogether.
  1718. *
  1719. * \param allocator Structure containing your allocator's entry points.
  1720. * \return zero on failure, non-zero on success. This call only fails
  1721. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1722. */
  1723. __EXPORT__ int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1724. /**
  1725. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  1726. * \brief Add an archive or directory to the search path.
  1727. *
  1728. * If this is a duplicate, the entry is not added again, even though the
  1729. * function succeeds. You may not add the same archive to two different
  1730. * mountpoints: duplicate checking is done against the archive and not the
  1731. * mountpoint.
  1732. *
  1733. * When you mount an archive, it is added to a virtual file system...all files
  1734. * in all of the archives are interpolated into a single hierachical file
  1735. * tree. Two archives mounted at the same place (or an archive with files
  1736. * overlapping another mountpoint) may have overlapping files: in such a case,
  1737. * the file earliest in the search path is selected, and the other files are
  1738. * inaccessible to the application. This allows archives to be used to
  1739. * override previous revisions; you can use the mounting mechanism to place
  1740. * archives at a specific point in the file tree and prevent overlap; this
  1741. * is useful for downloadable mods that might trample over application data
  1742. * or each other, for example.
  1743. *
  1744. * The mountpoint does not need to exist prior to mounting, which is different
  1745. * than those familiar with the Unix concept of "mounting" may not expect.
  1746. * As well, more than one archive can be mounted to the same mountpoint, or
  1747. * mountpoints and archive contents can overlap...the interpolation mechanism
  1748. * still functions as usual.
  1749. *
  1750. * \param newDir directory or archive to add to the path, in
  1751. * platform-dependent notation.
  1752. * \param mountPoint Location in the interpolated tree that this archive
  1753. * will be "mounted", in platform-independent notation.
  1754. * NULL or "" is equivalent to "/".
  1755. * \param appendToPath nonzero to append to search path, zero to prepend.
  1756. * \return nonzero if added to path, zero on failure (bogus archive, dir
  1757. * missing, etc). Specifics of the error can be
  1758. * gleaned from PHYSFS_getLastError().
  1759. *
  1760. * \sa PHYSFS_removeFromSearchPath
  1761. * \sa PHYSFS_getSearchPath
  1762. * \sa PHYSFS_getMountPoint
  1763. */
  1764. __EXPORT__ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  1765. /**
  1766. * \fn int PHYSFS_getMountPoint(const char *dir);
  1767. * \brief Determine a mounted archive's mountpoint.
  1768. *
  1769. * You give this function the name of an archive or dir you successfully
  1770. * added to the search path, and it reports the location in the interpolated
  1771. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  1772. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  1773. * and valid until the archive is removed from the search path.
  1774. *
  1775. * \param dir directory or archive previously added to the path, in
  1776. * platform-dependent notation. This must match the string
  1777. * used when adding, even if your string would also reference
  1778. * the same file with a different string of characters.
  1779. * \return READ-ONLY string of mount point if added to path, NULL on failure
  1780. * (bogus archive, etc) Specifics of the error can be gleaned from
  1781. * PHYSFS_getLastError().
  1782. *
  1783. * \sa PHYSFS_removeFromSearchPath
  1784. * \sa PHYSFS_getSearchPath
  1785. * \sa PHYSFS_getMountPoint
  1786. */
  1787. __EXPORT__ const char *PHYSFS_getMountPoint(const char *dir);
  1788. /*
  1789. * it is not safe to call physfs functions in these callbacks, as they may
  1790. * be holding non recursive mutexes.
  1791. */
  1792. /* !!! FIXME: comment! */
  1793. typedef void (*PHYSFS_StringCallback)(void *data, const char *);
  1794. __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  1795. __EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  1796. __EXPORT__ void PHYSFS_enumerateFilesCallback(const char *dir,
  1797. PHYSFS_StringCallback c,
  1798. void *d);
  1799. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  1800. #ifdef __cplusplus
  1801. }
  1802. #endif
  1803. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  1804. /* end of physfs.h ... */