physfs.h 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  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 0
  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 null-terminated string.
  454. * This will be NULL if there's been no error since the last call to this
  455. * function. The pointer returned by this call points to an internal buffer.
  456. * Each thread has a unique error state associated with it, but each time
  457. * a new error message is set, it will overwrite the previous one associated
  458. * with that thread. It is safe to call this function at anytime, even
  459. * before PHYSFS_init().
  460. *
  461. * \return READ ONLY string of last error message.
  462. */
  463. __EXPORT__ const char *PHYSFS_getLastError(void);
  464. /**
  465. * \fn const char *PHYSFS_getDirSeparator(void)
  466. * \brief Get platform-dependent dir separator string.
  467. *
  468. * This returns "\\\\" on win32, "/" on Unix, and ":" on MacOS. It may be more
  469. * than one character, depending on the platform, and your code should take
  470. * that into account. Note that this is only useful for setting up the
  471. * search/write paths, since access into those dirs always use '/'
  472. * (platform-independent notation) to separate directories. This is also
  473. * handy for getting platform-independent access when using stdio calls.
  474. *
  475. * \return READ ONLY null-terminated string of platform's dir separator.
  476. */
  477. __EXPORT__ const char *PHYSFS_getDirSeparator(void);
  478. /**
  479. * \fn void PHYSFS_permitSymbolicLinks(int allow)
  480. * \brief Enable or disable following of symbolic links.
  481. *
  482. * Some physical filesystems and archives contain files that are just pointers
  483. * to other files. On the physical filesystem, opening such a link will
  484. * (transparently) open the file that is pointed to.
  485. *
  486. * By default, PhysicsFS will check if a file is really a symlink during open
  487. * calls and fail if it is. Otherwise, the link could take you outside the
  488. * write and search paths, and compromise security.
  489. *
  490. * If you want to take that risk, call this function with a non-zero parameter.
  491. * Note that this is more for sandboxing a program's scripting language, in
  492. * case untrusted scripts try to compromise the system. Generally speaking,
  493. * a user could very well have a legitimate reason to set up a symlink, so
  494. * unless you feel there's a specific danger in allowing them, you should
  495. * permit them.
  496. *
  497. * Symlinks are only explicitly checked when dealing with filenames
  498. * in platform-independent notation. That is, when setting up your
  499. * search and write paths, etc, symlinks are never checked for.
  500. *
  501. * Symbolic link permission can be enabled or disabled at any time after
  502. * you've called PHYSFS_init(), and is disabled by default.
  503. *
  504. * \param allow nonzero to permit symlinks, zero to deny linking.
  505. */
  506. __EXPORT__ void PHYSFS_permitSymbolicLinks(int allow);
  507. /**
  508. * \fn char **PHYSFS_getCdRomDirs(void)
  509. * \brief Get an array of paths to available CD-ROM drives.
  510. *
  511. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  512. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  513. * accessible in the drive. So if you've got two drives (D: and E:), and only
  514. * E: has a disc in it, then that's all you get. If the user inserts a disc
  515. * in D: and you call this function again, you get both drives. If, on a
  516. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  517. * call to this function will reflect that change. Fun.
  518. *
  519. * The returned value is an array of strings, with a NULL entry to signify the
  520. * end of the list:
  521. *
  522. * \code
  523. * char **cds = PHYSFS_getCdRomDirs();
  524. * char **i;
  525. *
  526. * for (i = cds; *i != NULL; i++)
  527. * printf("cdrom dir [%s] is available.\n", *i);
  528. *
  529. * PHYSFS_freeList(cds);
  530. * \endcode
  531. *
  532. * This call may block while drives spin up. Be forewarned.
  533. *
  534. * When you are done with the returned information, you may dispose of the
  535. * resources by calling PHYSFS_freeList() with the returned pointer.
  536. *
  537. * \return Null-terminated array of null-terminated strings.
  538. */
  539. __EXPORT__ char **PHYSFS_getCdRomDirs(void);
  540. /**
  541. * \fn const char *PHYSFS_getBaseDir(void)
  542. * \brief Get the path where the application resides.
  543. *
  544. * Helper function.
  545. *
  546. * Get the "base dir". This is the directory where the application was run
  547. * from, which is probably the installation directory, and may or may not
  548. * be the process's current working directory.
  549. *
  550. * You should probably use the base dir in your search path.
  551. *
  552. * \return READ ONLY string of base dir in platform-dependent notation.
  553. *
  554. * \sa PHYSFS_getUserDir
  555. */
  556. __EXPORT__ const char *PHYSFS_getBaseDir(void);
  557. /**
  558. * \fn const char *PHYSFS_getUserDir(void)
  559. * \brief Get the path where user's home directory resides.
  560. *
  561. * Helper function.
  562. *
  563. * Get the "user dir". This is meant to be a suggestion of where a specific
  564. * user of the system can store files. On Unix, this is her home directory.
  565. * On systems with no concept of multiple home directories (MacOS, win95),
  566. * this will default to something like "C:\mybasedir\users\username"
  567. * where "username" will either be the login name, or "default" if the
  568. * platform doesn't support multiple users, either.
  569. *
  570. * You should probably use the user dir as the basis for your write dir, and
  571. * also put it near the beginning of your search path.
  572. *
  573. * \return READ ONLY string of user dir in platform-dependent notation.
  574. *
  575. * \sa PHYSFS_getBaseDir
  576. */
  577. __EXPORT__ const char *PHYSFS_getUserDir(void);
  578. /**
  579. * \fn const char *PHYSFS_getWriteDir(void)
  580. * \brief Get path where PhysicsFS will allow file writing.
  581. *
  582. * Get the current write dir. The default write dir is NULL.
  583. *
  584. * \return READ ONLY string of write dir in platform-dependent notation,
  585. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  586. *
  587. * \sa PHYSFS_setWriteDir
  588. */
  589. __EXPORT__ const char *PHYSFS_getWriteDir(void);
  590. /**
  591. * \fn int PHYSFS_setWriteDir(const char *newDir)
  592. * \brief Tell PhysicsFS where it may write files.
  593. *
  594. * Set a new write dir. This will override the previous setting. If the
  595. * directory or a parent directory doesn't exist in the physical filesystem,
  596. * PhysicsFS will attempt to create them as needed.
  597. *
  598. * This call will fail (and fail to change the write dir) if the current
  599. * write dir still has files open in it.
  600. *
  601. * \param newDir The new directory to be the root of the write dir,
  602. * specified in platform-dependent notation. Setting to NULL
  603. * disables the write dir, so no files can be opened for
  604. * writing via PhysicsFS.
  605. * \return non-zero on success, zero on failure. All attempts to open a file
  606. * for writing via PhysicsFS will fail until this call succeeds.
  607. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  608. *
  609. * \sa PHYSFS_getWriteDir
  610. */
  611. __EXPORT__ int PHYSFS_setWriteDir(const char *newDir);
  612. /**
  613. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  614. * \brief Add an archive or directory to the search path.
  615. *
  616. * If this is a duplicate, the entry is not added again, even though the
  617. * function succeeds. You may not add the same archive to two different
  618. * mountpoints: duplicate checking is done against the archive and not the
  619. * mountpoint.
  620. *
  621. * When you mount an archive, it is added to a virtual file system...all files
  622. * in all of the archives are interpolated into a single hierachical file
  623. * tree. Two archives mounted at the same place (or an archive with files
  624. * overlapping another mountpoint) may have overlapping files: in such a case,
  625. * the file earliest in the search path is selected, and the other files are
  626. * inaccessible to the application. This allows archives to be used to
  627. * override previous revisions; you can use the mounting mechanism to place
  628. * archives at a specific point in the file tree and prevent overlap; this
  629. * is useful for downloadable mods that might trample over application data
  630. * or each other, for example.
  631. *
  632. * The mountpoint does not need to exist prior to mounting, which is different
  633. * than those familiar with the Unix concept of "mounting" may not expect.
  634. * As well, more than one archive can be mounted to the same mountpoint, or
  635. * mountpoints and archive contents can overlap...the interpolation mechanism
  636. * still functions as usual.
  637. *
  638. * \param newDir directory or archive to add to the path, in
  639. * platform-dependent notation.
  640. * \param mountPoint Location in the interpolated tree that this archive
  641. * will be "mounted", in platform-independent notation.
  642. * NULL or "" is equivalent to "/".
  643. * \param appendToPath nonzero to append to search path, zero to prepend.
  644. * \return nonzero if added to path, zero on failure (bogus archive, dir
  645. * missing, etc). Specifics of the error can be
  646. * gleaned from PHYSFS_getLastError().
  647. */
  648. __EXPORT__ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  649. /**
  650. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  651. * \brief Add an archive or directory to the search path.
  652. *
  653. * This is a legacy call, equivalent to:
  654. * PHYSFS_mount(newDir, NULL, appendToPath);
  655. *
  656. * \sa PHYSFS_mount
  657. * \sa PHYSFS_unmount
  658. * \sa PHYSFS_removeFromSearchPath
  659. * \sa PHYSFS_getSearchPath
  660. */
  661. __EXPORT__ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  662. /**
  663. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  664. * \brief Remove a directory or archive from the search path.
  665. *
  666. * This must be a (case-sensitive) match to a dir or archive already in the
  667. * search path, specified in platform-dependent notation.
  668. *
  669. * This call will fail (and fail to remove from the path) if the element still
  670. * has files open in it.
  671. *
  672. * \param oldDir dir/archive to remove.
  673. * \return nonzero on success, zero on failure.
  674. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  675. *
  676. * \sa PHYSFS_addToSearchPath
  677. * \sa PHYSFS_getSearchPath
  678. */
  679. __EXPORT__ int PHYSFS_removeFromSearchPath(const char *oldDir);
  680. /**
  681. * \fn char **PHYSFS_getSearchPath(void)
  682. * \brief Get the current search path.
  683. *
  684. * The default search path is an empty list.
  685. *
  686. * The returned value is an array of strings, with a NULL entry to signify the
  687. * end of the list:
  688. *
  689. * \code
  690. * char **i;
  691. *
  692. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  693. * printf("[%s] is in the search path.\n", *i);
  694. * \endcode
  695. *
  696. * When you are done with the returned information, you may dispose of the
  697. * resources by calling PHYSFS_freeList() with the returned pointer.
  698. *
  699. * \return Null-terminated array of null-terminated strings. NULL if there
  700. * was a problem (read: OUT OF MEMORY).
  701. *
  702. * \sa PHYSFS_addToSearchPath
  703. * \sa PHYSFS_removeFromSearchPath
  704. */
  705. __EXPORT__ char **PHYSFS_getSearchPath(void);
  706. /**
  707. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  708. * \brief Set up sane, default paths.
  709. *
  710. * Helper function.
  711. *
  712. * The write dir will be set to "userdir/.organization/appName", which is
  713. * created if it doesn't exist.
  714. *
  715. * The above is sufficient to make sure your program's configuration directory
  716. * is separated from other clutter, and platform-independent. The period
  717. * before "mygame" even hides the directory on Unix systems.
  718. *
  719. * The search path will be:
  720. *
  721. * - The Write Dir (created if it doesn't exist)
  722. * - The Base Dir (PHYSFS_getBaseDir())
  723. * - All found CD-ROM dirs (optionally)
  724. *
  725. * These directories are then searched for files ending with the extension
  726. * (archiveExt), which, if they are valid and supported archives, will also
  727. * be added to the search path. If you specified "PKG" for (archiveExt), and
  728. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  729. * can either be appended or prepended to the search path in alphabetical
  730. * order, regardless of which directories they were found in.
  731. *
  732. * All of this can be accomplished from the application, but this just does it
  733. * all for you. Feel free to add more to the search path manually, too.
  734. *
  735. * \param organization Name of your company/group/etc to be used as a
  736. * dirname, so keep it small, and no-frills.
  737. *
  738. * \param appName Program-specific name of your program, to separate it
  739. * from other programs using PhysicsFS.
  740. *
  741. * \param archiveExt File extension used by your program to specify an
  742. * archive. For example, Quake 3 uses "pk3", even though
  743. * they are just zipfiles. Specify NULL to not dig out
  744. * archives automatically. Do not specify the '.' char;
  745. * If you want to look for ZIP files, specify "ZIP" and
  746. * not ".ZIP" ... the archive search is case-insensitive.
  747. *
  748. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  749. * (if (archiveExt) != NULL) search them for archives.
  750. * This may cause a significant amount of blocking
  751. * while discs are accessed, and if there are no discs
  752. * in the drive (or even not mounted on Unix systems),
  753. * then they may not be made available anyhow. You may
  754. * want to specify zero and handle the disc setup
  755. * yourself.
  756. *
  757. * \param archivesFirst Non-zero to prepend the archives to the search path.
  758. * Zero to append them. Ignored if !(archiveExt).
  759. *
  760. * \return nonzero on success, zero on error. Specifics of the error can be
  761. * gleaned from PHYSFS_getLastError().
  762. */
  763. __EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
  764. const char *appName,
  765. const char *archiveExt,
  766. int includeCdRoms,
  767. int archivesFirst);
  768. /* Directory management stuff ... */
  769. /**
  770. * \fn int PHYSFS_mkdir(const char *dirName)
  771. * \brief Create a directory.
  772. *
  773. * This is specified in platform-independent notation in relation to the
  774. * write dir. All missing parent directories are also created if they
  775. * don't exist.
  776. *
  777. * So if you've got the write dir set to "C:\mygame\writedir" and call
  778. * PHYSFS_mkdir("downloads/maps") then the directories
  779. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  780. * will be created if possible. If the creation of "maps" fails after we
  781. * have successfully created "downloads", then the function leaves the
  782. * created directory behind and reports failure.
  783. *
  784. * \param dirName New dir to create.
  785. * \return nonzero on success, zero on error. Specifics of the error can be
  786. * gleaned from PHYSFS_getLastError().
  787. *
  788. * \sa PHYSFS_delete
  789. */
  790. __EXPORT__ int PHYSFS_mkdir(const char *dirName);
  791. /**
  792. * \fn int PHYSFS_delete(const char *filename)
  793. * \brief Delete a file or directory.
  794. *
  795. * (filename) is specified in platform-independent notation in relation to the
  796. * write dir.
  797. *
  798. * A directory must be empty before this call can delete it.
  799. *
  800. * Deleting a symlink will remove the link, not what it points to, regardless
  801. * of whether you "permitSymLinks" or not.
  802. *
  803. * So if you've got the write dir set to "C:\mygame\writedir" and call
  804. * PHYSFS_delete("downloads/maps/level1.map") then the file
  805. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  806. * physical filesystem, if it exists and the operating system permits the
  807. * deletion.
  808. *
  809. * Note that on Unix systems, deleting a file may be successful, but the
  810. * actual file won't be removed until all processes that have an open
  811. * filehandle to it (including your program) close their handles.
  812. *
  813. * Chances are, the bits that make up the file still exist, they are just
  814. * made available to be written over at a later point. Don't consider this
  815. * a security method or anything. :)
  816. *
  817. * \param filename Filename to delete.
  818. * \return nonzero on success, zero on error. Specifics of the error can be
  819. * gleaned from PHYSFS_getLastError().
  820. */
  821. __EXPORT__ int PHYSFS_delete(const char *filename);
  822. /**
  823. * \fn const char *PHYSFS_getRealDir(const char *filename)
  824. * \brief Figure out where in the search path a file resides.
  825. *
  826. * The file is specified in platform-independent notation. The returned
  827. * filename will be the element of the search path where the file was found,
  828. * which may be a directory, or an archive. Even if there are multiple
  829. * matches in different parts of the search path, only the first one found
  830. * is used, just like when opening a file.
  831. *
  832. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  833. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  834. *
  835. * If a any part of a match is a symbolic link, and you've not explicitly
  836. * permitted symlinks, then it will be ignored, and the search for a match
  837. * will continue.
  838. *
  839. * \param filename file to look for.
  840. * \return READ ONLY string of element of search path containing the
  841. * the file in question. NULL if not found.
  842. */
  843. __EXPORT__ const char *PHYSFS_getRealDir(const char *filename);
  844. /**
  845. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  846. * \brief Get a file listing of a search path's directory.
  847. *
  848. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  849. * search path and contains a directory "savegames" that contains "x.sav",
  850. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  851. * that has a "savegames" subdirectory with "w.sav", then the following code:
  852. *
  853. * \code
  854. * char **rc = PHYSFS_enumerateFiles("savegames");
  855. * char **i;
  856. *
  857. * for (i = rc; *i != NULL; i++)
  858. * printf(" * We've got [%s].\n", *i);
  859. *
  860. * PHYSFS_freeList(rc);
  861. * \endcode
  862. *
  863. * ...will print:
  864. *
  865. * \verbatim
  866. * We've got [x.sav].
  867. * We've got [y.sav].
  868. * We've got [z.sav].
  869. * We've got [w.sav].\endverbatim
  870. *
  871. * Feel free to sort the list however you like. We only promise there will
  872. * be no duplicates, but not what order the final list will come back in.
  873. *
  874. * Don't forget to call PHYSFS_freeList() with the return value from this
  875. * function when you are done with it.
  876. *
  877. * \param dir directory in platform-independent notation to enumerate.
  878. * \return Null-terminated array of null-terminated strings.
  879. */
  880. __EXPORT__ char **PHYSFS_enumerateFiles(const char *dir);
  881. /**
  882. * \fn int PHYSFS_exists(const char *fname)
  883. * \brief Determine if a file exists in the search path.
  884. *
  885. * Reports true if there is an entry anywhere in the search path by the
  886. * name of (fname).
  887. *
  888. * Note that entries that are symlinks are ignored if
  889. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  890. * might end up further down in the search path than expected.
  891. *
  892. * \param fname filename in platform-independent notation.
  893. * \return non-zero if filename exists. zero otherwise.
  894. *
  895. * \sa PHYSFS_isDirectory
  896. * \sa PHYSFS_isSymbolicLink
  897. */
  898. __EXPORT__ int PHYSFS_exists(const char *fname);
  899. /**
  900. * \fn int PHYSFS_isDirectory(const char *fname)
  901. * \brief Determine if a file in the search path is really a directory.
  902. *
  903. * Determine if the first occurence of (fname) in the search path is
  904. * really a directory entry.
  905. *
  906. * Note that entries that are symlinks are ignored if
  907. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  908. * might end up further down in the search path than expected.
  909. *
  910. * \param fname filename in platform-independent notation.
  911. * \return non-zero if filename exists and is a directory. zero otherwise.
  912. *
  913. * \sa PHYSFS_exists
  914. * \sa PHYSFS_isSymbolicLink
  915. */
  916. __EXPORT__ int PHYSFS_isDirectory(const char *fname);
  917. /**
  918. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  919. * \brief Determine if a file in the search path is really a symbolic link.
  920. *
  921. * Determine if the first occurence of (fname) in the search path is
  922. * really a symbolic link.
  923. *
  924. * Note that entries that are symlinks are ignored if
  925. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  926. * this function will always return 0 in that case.
  927. *
  928. * \param fname filename in platform-independent notation.
  929. * \return non-zero if filename exists and is a symlink. zero otherwise.
  930. *
  931. * \sa PHYSFS_exists
  932. * \sa PHYSFS_isDirectory
  933. */
  934. __EXPORT__ int PHYSFS_isSymbolicLink(const char *fname);
  935. /**
  936. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  937. * \brief Get the last modification time of a file.
  938. *
  939. * The modtime is returned as a number of seconds since the epoch
  940. * (Jan 1, 1970). The exact derivation and accuracy of this time depends on
  941. * the particular archiver. If there is no reasonable way to obtain this
  942. * information for a particular archiver, or there was some sort of error,
  943. * this function returns (-1).
  944. *
  945. * \param filename filename to check, in platform-independent notation.
  946. * \return last modified time of the file. -1 if it can't be determined.
  947. */
  948. __EXPORT__ PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename);
  949. /* i/o stuff... */
  950. /**
  951. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  952. * \brief Open a file for writing.
  953. *
  954. * Open a file for writing, in platform-independent notation and in relation
  955. * to the write dir as the root of the writable filesystem. The specified
  956. * file is created if it doesn't exist. If it does exist, it is truncated to
  957. * zero bytes, and the writing offset is set to the start.
  958. *
  959. * Note that entries that are symlinks are ignored if
  960. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  961. * symlink with this function will fail in such a case.
  962. *
  963. * \param filename File to open.
  964. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  965. * of the error can be gleaned from PHYSFS_getLastError().
  966. *
  967. * \sa PHYSFS_openRead
  968. * \sa PHYSFS_openAppend
  969. * \sa PHYSFS_write
  970. * \sa PHYSFS_close
  971. */
  972. __EXPORT__ PHYSFS_File *PHYSFS_openWrite(const char *filename);
  973. /**
  974. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  975. * \brief Open a file for appending.
  976. *
  977. * Open a file for writing, in platform-independent notation and in relation
  978. * to the write dir as the root of the writable filesystem. The specified
  979. * file is created if it doesn't exist. If it does exist, the writing offset
  980. * is set to the end of the file, so the first write will be the byte after
  981. * the end.
  982. *
  983. * Note that entries that are symlinks are ignored if
  984. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  985. * symlink with this function will fail in such a case.
  986. *
  987. * \param filename File to open.
  988. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  989. * of the error can be gleaned from PHYSFS_getLastError().
  990. *
  991. * \sa PHYSFS_openRead
  992. * \sa PHYSFS_openWrite
  993. * \sa PHYSFS_write
  994. * \sa PHYSFS_close
  995. */
  996. __EXPORT__ PHYSFS_File *PHYSFS_openAppend(const char *filename);
  997. /**
  998. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  999. * \brief Open a file for reading.
  1000. *
  1001. * Open a file for reading, in platform-independent notation. The search path
  1002. * is checked one at a time until a matching file is found, in which case an
  1003. * abstract filehandle is associated with it, and reading may be done.
  1004. * The reading offset is set to the first byte of the file.
  1005. *
  1006. * Note that entries that are symlinks are ignored if
  1007. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1008. * symlink with this function will fail in such a case.
  1009. *
  1010. * \param filename File to open.
  1011. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1012. * of the error can be gleaned from PHYSFS_getLastError().
  1013. *
  1014. * \sa PHYSFS_openWrite
  1015. * \sa PHYSFS_openAppend
  1016. * \sa PHYSFS_read
  1017. * \sa PHYSFS_close
  1018. */
  1019. __EXPORT__ PHYSFS_File *PHYSFS_openRead(const char *filename);
  1020. /**
  1021. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1022. * \brief Close a PhysicsFS filehandle.
  1023. *
  1024. * This call is capable of failing if the operating system was buffering
  1025. * writes to the physical media, and, now forced to write those changes to
  1026. * physical media, can not store the data for some reason. In such a case,
  1027. * the filehandle stays open. A well-written program should ALWAYS check the
  1028. * return value from the close call in addition to every writing call!
  1029. *
  1030. * \param handle handle returned from PHYSFS_open*().
  1031. * \return nonzero on success, zero on error. Specifics of the error can be
  1032. * gleaned from PHYSFS_getLastError().
  1033. *
  1034. * \sa PHYSFS_openRead
  1035. * \sa PHYSFS_openWrite
  1036. * \sa PHYSFS_openAppend
  1037. */
  1038. __EXPORT__ int PHYSFS_close(PHYSFS_File *handle);
  1039. /**
  1040. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1041. * \brief Read data from a PhysicsFS filehandle
  1042. *
  1043. * The file must be opened for reading.
  1044. *
  1045. * \param handle handle returned from PHYSFS_openRead().
  1046. * \param buffer buffer to store read data into.
  1047. * \param objSize size in bytes of objects being read from (handle).
  1048. * \param objCount number of (objSize) objects to read from (handle).
  1049. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1050. * the reason this might be < (objCount), as can PHYSFS_eof().
  1051. * -1 if complete failure.
  1052. *
  1053. * \sa PHYSFS_eof
  1054. */
  1055. __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1056. void *buffer,
  1057. PHYSFS_uint32 objSize,
  1058. PHYSFS_uint32 objCount);
  1059. /**
  1060. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1061. * \brief Write data to a PhysicsFS filehandle
  1062. *
  1063. * The file must be opened for writing.
  1064. *
  1065. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1066. * \param buffer buffer to store read data into.
  1067. * \param objSize size in bytes of objects being read from (handle).
  1068. * \param objCount number of (objSize) objects to read from (handle).
  1069. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1070. * the reason this might be < (objCount). -1 if complete failure.
  1071. */
  1072. __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1073. const void *buffer,
  1074. PHYSFS_uint32 objSize,
  1075. PHYSFS_uint32 objCount);
  1076. /* File position stuff... */
  1077. /**
  1078. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1079. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1080. *
  1081. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1082. *
  1083. * \param handle handle returned from PHYSFS_openRead().
  1084. * \return nonzero if EOF, zero if not.
  1085. *
  1086. * \sa PHYSFS_read
  1087. * \sa PHYSFS_tell
  1088. */
  1089. __EXPORT__ int PHYSFS_eof(PHYSFS_File *handle);
  1090. /**
  1091. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1092. * \brief Determine current position within a PhysicsFS filehandle.
  1093. *
  1094. * \param handle handle returned from PHYSFS_open*().
  1095. * \return offset in bytes from start of file. -1 if error occurred.
  1096. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1097. *
  1098. * \sa PHYSFS_seek
  1099. */
  1100. __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1101. /**
  1102. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1103. * \brief Seek to a new position within a PhysicsFS filehandle.
  1104. *
  1105. * The next read or write will occur at that place. Seeking past the
  1106. * beginning or end of the file is not allowed, and causes an error.
  1107. *
  1108. * \param handle handle returned from PHYSFS_open*().
  1109. * \param pos number of bytes from start of file to seek to.
  1110. * \return nonzero on success, zero on error. Specifics of the error can be
  1111. * gleaned from PHYSFS_getLastError().
  1112. *
  1113. * \sa PHYSFS_tell
  1114. */
  1115. __EXPORT__ int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1116. /**
  1117. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1118. * \brief Get total length of a file in bytes.
  1119. *
  1120. * Note that if the file size can't be determined (since the archive is
  1121. * "streamed" or whatnot) than this will report (-1). Also note that if
  1122. * another process/thread is writing to this file at the same time, then
  1123. * the information this function supplies could be incorrect before you
  1124. * get it. Use with caution, or better yet, don't use at all.
  1125. *
  1126. * \param handle handle returned from PHYSFS_open*().
  1127. * \return size in bytes of the file. -1 if can't be determined.
  1128. *
  1129. * \sa PHYSFS_tell
  1130. * \sa PHYSFS_seek
  1131. */
  1132. __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1133. /* Buffering stuff... */
  1134. /**
  1135. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1136. * \brief Set up buffering for a PhysicsFS file handle.
  1137. *
  1138. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1139. * will be allocated and associated with (handle).
  1140. *
  1141. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1142. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1143. * from this buffer until it is empty, and then refill it for more reading.
  1144. * Note that compressed files, like ZIP archives, will decompress while
  1145. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1146. * The buffer isn't filled until you do your next read.
  1147. *
  1148. * For files opened for writing, data will be buffered to memory until the
  1149. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1150. * causes a flush...check your return values!
  1151. *
  1152. * Seeking, etc transparently accounts for buffering.
  1153. *
  1154. * You can resize an existing buffer by calling this function more than once
  1155. * on the same file. Setting the buffer size to zero will free an existing
  1156. * buffer.
  1157. *
  1158. * PhysicsFS file handles are unbuffered by default.
  1159. *
  1160. * Please check the return value of this function! Failures can include
  1161. * not being able to seek backwards in a read-only file when removing the
  1162. * buffer, not being able to allocate the buffer, and not being able to
  1163. * flush the buffer to disk, among other unexpected problems.
  1164. *
  1165. * \param handle handle returned from PHYSFS_open*().
  1166. * \param bufsize size, in bytes, of buffer to allocate.
  1167. * \return nonzero if successful, zero on error.
  1168. *
  1169. * \sa PHYSFS_flush
  1170. * \sa PHYSFS_read
  1171. * \sa PHYSFS_write
  1172. * \sa PHYSFS_close
  1173. */
  1174. __EXPORT__ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1175. /**
  1176. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1177. * \brief Flush a buffered PhysicsFS file handle.
  1178. *
  1179. * For buffered files opened for writing, this will put the current contents
  1180. * of the buffer to disk and flag the buffer as empty if possible.
  1181. *
  1182. * For buffered files opened for reading or unbuffered files, this is a safe
  1183. * no-op, and will report success.
  1184. *
  1185. * \param handle handle returned from PHYSFS_open*().
  1186. * \return nonzero if successful, zero on error.
  1187. *
  1188. * \sa PHYSFS_setBuffer
  1189. * \sa PHYSFS_close
  1190. */
  1191. __EXPORT__ int PHYSFS_flush(PHYSFS_File *handle);
  1192. /* Byteorder stuff... */
  1193. /**
  1194. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1195. * \brief Swap littleendian signed 16 to platform's native byte order.
  1196. *
  1197. * Take a 16-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_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1204. /**
  1205. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1206. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1207. *
  1208. * Take a 16-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_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1215. /**
  1216. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1217. * \brief Swap littleendian signed 32 to platform's native byte order.
  1218. *
  1219. * Take a 32-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. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1226. /**
  1227. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1228. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1229. *
  1230. * Take a 32-bit unsigned value in littleendian format and convert it to
  1231. * the platform's native byte order.
  1232. *
  1233. * \param val value to convert
  1234. * \return converted value.
  1235. */
  1236. __EXPORT__ PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1237. /**
  1238. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1239. * \brief Swap littleendian signed 64 to platform's native byte order.
  1240. *
  1241. * Take a 64-bit signed value in littleendian format and convert it to
  1242. * the platform's native byte order.
  1243. *
  1244. * \param val value to convert
  1245. * \return converted value.
  1246. *
  1247. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1248. * any sort of 64-bit support.
  1249. */
  1250. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1251. /**
  1252. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1253. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1254. *
  1255. * Take a 64-bit unsigned value in littleendian format and convert it to
  1256. * the platform's native byte order.
  1257. *
  1258. * \param val value to convert
  1259. * \return converted value.
  1260. *
  1261. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1262. * any sort of 64-bit support.
  1263. */
  1264. __EXPORT__ PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1265. /**
  1266. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1267. * \brief Swap bigendian signed 16 to platform's native byte order.
  1268. *
  1269. * Take a 16-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_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1276. /**
  1277. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1278. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1279. *
  1280. * Take a 16-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_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1287. /**
  1288. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1289. * \brief Swap bigendian signed 32 to platform's native byte order.
  1290. *
  1291. * Take a 32-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. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1298. /**
  1299. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1300. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1301. *
  1302. * Take a 32-bit unsigned value in bigendian format and convert it to
  1303. * the platform's native byte order.
  1304. *
  1305. * \param val value to convert
  1306. * \return converted value.
  1307. */
  1308. __EXPORT__ PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1309. /**
  1310. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1311. * \brief Swap bigendian signed 64 to platform's native byte order.
  1312. *
  1313. * Take a 64-bit signed value in bigendian format and convert it to
  1314. * the platform's native byte order.
  1315. *
  1316. * \param val value to convert
  1317. * \return converted value.
  1318. *
  1319. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1320. * any sort of 64-bit support.
  1321. */
  1322. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1323. /**
  1324. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1325. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1326. *
  1327. * Take a 64-bit unsigned value in bigendian format and convert it to
  1328. * the platform's native byte order.
  1329. *
  1330. * \param val value to convert
  1331. * \return converted value.
  1332. *
  1333. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1334. * any sort of 64-bit support.
  1335. */
  1336. __EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1337. /**
  1338. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1339. * \brief Read and convert a signed 16-bit littleendian value.
  1340. *
  1341. * Convenience function. Read a signed 16-bit littleendian value from a
  1342. * file and convert it to the platform's native byte order.
  1343. *
  1344. * \param file PhysicsFS file handle from which to read.
  1345. * \param val pointer to where value should be stored.
  1346. * \return zero on failure, non-zero on success. If successful, (*val) will
  1347. * store the result. On failure, you can find out what went wrong
  1348. * from PHYSFS_getLastError().
  1349. */
  1350. __EXPORT__ int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1351. /**
  1352. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1353. * \brief Read and convert an unsigned 16-bit littleendian value.
  1354. *
  1355. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1356. * file and convert it to the platform's native byte order.
  1357. *
  1358. * \param file PhysicsFS file handle from which to read.
  1359. * \param val pointer to where value should be stored.
  1360. * \return zero on failure, non-zero on success. If successful, (*val) will
  1361. * store the result. On failure, you can find out what went wrong
  1362. * from PHYSFS_getLastError().
  1363. *
  1364. */
  1365. __EXPORT__ int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1366. /**
  1367. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1368. * \brief Read and convert a signed 16-bit bigendian value.
  1369. *
  1370. * Convenience function. Read a signed 16-bit bigendian value from a
  1371. * file and convert it to the platform's native byte order.
  1372. *
  1373. * \param file PhysicsFS file handle from which to read.
  1374. * \param val pointer to where value should be stored.
  1375. * \return zero on failure, non-zero on success. If successful, (*val) will
  1376. * store the result. On failure, you can find out what went wrong
  1377. * from PHYSFS_getLastError().
  1378. */
  1379. __EXPORT__ int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1380. /**
  1381. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1382. * \brief Read and convert an unsigned 16-bit bigendian value.
  1383. *
  1384. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1385. * file and convert it to the platform's native byte order.
  1386. *
  1387. * \param file PhysicsFS file handle from which to read.
  1388. * \param val pointer to where value should be stored.
  1389. * \return zero on failure, non-zero on success. If successful, (*val) will
  1390. * store the result. On failure, you can find out what went wrong
  1391. * from PHYSFS_getLastError().
  1392. *
  1393. */
  1394. __EXPORT__ int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1395. /**
  1396. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1397. * \brief Read and convert a signed 32-bit littleendian value.
  1398. *
  1399. * Convenience function. Read a signed 32-bit littleendian value from a
  1400. * file and convert it to the platform's native byte order.
  1401. *
  1402. * \param file PhysicsFS file handle from which to read.
  1403. * \param val pointer to where value should be stored.
  1404. * \return zero on failure, non-zero on success. If successful, (*val) will
  1405. * store the result. On failure, you can find out what went wrong
  1406. * from PHYSFS_getLastError().
  1407. */
  1408. __EXPORT__ int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1409. /**
  1410. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1411. * \brief Read and convert an unsigned 32-bit littleendian value.
  1412. *
  1413. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1414. * file and convert it to the platform's native byte order.
  1415. *
  1416. * \param file PhysicsFS file handle from which to read.
  1417. * \param val pointer to where value should be stored.
  1418. * \return zero on failure, non-zero on success. If successful, (*val) will
  1419. * store the result. On failure, you can find out what went wrong
  1420. * from PHYSFS_getLastError().
  1421. *
  1422. */
  1423. __EXPORT__ int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1424. /**
  1425. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1426. * \brief Read and convert a signed 32-bit bigendian value.
  1427. *
  1428. * Convenience function. Read a signed 32-bit bigendian value from a
  1429. * file and convert it to the platform's native byte order.
  1430. *
  1431. * \param file PhysicsFS file handle from which to read.
  1432. * \param val pointer to where value should be stored.
  1433. * \return zero on failure, non-zero on success. If successful, (*val) will
  1434. * store the result. On failure, you can find out what went wrong
  1435. * from PHYSFS_getLastError().
  1436. */
  1437. __EXPORT__ int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1438. /**
  1439. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1440. * \brief Read and convert an unsigned 32-bit bigendian value.
  1441. *
  1442. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1443. * file and convert it to the platform's native byte order.
  1444. *
  1445. * \param file PhysicsFS file handle from which to read.
  1446. * \param val pointer to where value should be stored.
  1447. * \return zero on failure, non-zero on success. If successful, (*val) will
  1448. * store the result. On failure, you can find out what went wrong
  1449. * from PHYSFS_getLastError().
  1450. *
  1451. */
  1452. __EXPORT__ int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1453. /**
  1454. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1455. * \brief Read and convert a signed 64-bit littleendian value.
  1456. *
  1457. * Convenience function. Read a signed 64-bit littleendian value from a
  1458. * file and convert it to the platform's native byte order.
  1459. *
  1460. * \param file PhysicsFS file handle from which to read.
  1461. * \param val pointer to where value should be stored.
  1462. * \return zero on failure, non-zero on success. If successful, (*val) will
  1463. * store the result. On failure, you can find out what went wrong
  1464. * from PHYSFS_getLastError().
  1465. *
  1466. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1467. * any sort of 64-bit support.
  1468. */
  1469. __EXPORT__ int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1470. /**
  1471. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1472. * \brief Read and convert an unsigned 64-bit littleendian value.
  1473. *
  1474. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1475. * file and convert it to the platform's native byte order.
  1476. *
  1477. * \param file PhysicsFS file handle from which to read.
  1478. * \param val pointer to where value should be stored.
  1479. * \return zero on failure, non-zero on success. If successful, (*val) will
  1480. * store the result. On failure, you can find out what went wrong
  1481. * from PHYSFS_getLastError().
  1482. *
  1483. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1484. * any sort of 64-bit support.
  1485. */
  1486. __EXPORT__ int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1487. /**
  1488. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1489. * \brief Read and convert a signed 64-bit bigendian value.
  1490. *
  1491. * Convenience function. Read a signed 64-bit bigendian value from a
  1492. * file and convert it to the platform's native byte order.
  1493. *
  1494. * \param file PhysicsFS file handle from which to read.
  1495. * \param val pointer to where value should be stored.
  1496. * \return zero on failure, non-zero on success. If successful, (*val) will
  1497. * store the result. On failure, you can find out what went wrong
  1498. * from PHYSFS_getLastError().
  1499. *
  1500. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1501. * any sort of 64-bit support.
  1502. */
  1503. __EXPORT__ int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1504. /**
  1505. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1506. * \brief Read and convert an unsigned 64-bit bigendian value.
  1507. *
  1508. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1509. * file and convert it to the platform's native byte order.
  1510. *
  1511. * \param file PhysicsFS file handle from which to read.
  1512. * \param val pointer to where value should be stored.
  1513. * \return zero on failure, non-zero on success. If successful, (*val) will
  1514. * store the result. On failure, you can find out what went wrong
  1515. * from PHYSFS_getLastError().
  1516. *
  1517. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1518. * any sort of 64-bit support.
  1519. */
  1520. __EXPORT__ int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1521. /**
  1522. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1523. * \brief Convert and write a signed 16-bit littleendian value.
  1524. *
  1525. * Convenience function. Convert a signed 16-bit value from the platform's
  1526. * native byte order to littleendian and write it to a file.
  1527. *
  1528. * \param file PhysicsFS file handle to which to write.
  1529. * \param val Value to convert and write.
  1530. * \return zero on failure, non-zero on success. On failure, you can
  1531. * find out what went wrong from PHYSFS_getLastError().
  1532. */
  1533. __EXPORT__ int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1534. /**
  1535. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1536. * \brief Convert and write an unsigned 16-bit littleendian value.
  1537. *
  1538. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1539. * native byte order to littleendian and write it to a file.
  1540. *
  1541. * \param file PhysicsFS file handle to which to write.
  1542. * \param val Value to convert and write.
  1543. * \return zero on failure, non-zero on success. On failure, you can
  1544. * find out what went wrong from PHYSFS_getLastError().
  1545. */
  1546. __EXPORT__ int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1547. /**
  1548. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1549. * \brief Convert and write a signed 16-bit bigendian value.
  1550. *
  1551. * Convenience function. Convert a signed 16-bit value from the platform's
  1552. * native byte order to bigendian and write it to a file.
  1553. *
  1554. * \param file PhysicsFS file handle to which to write.
  1555. * \param val Value to convert and write.
  1556. * \return zero on failure, non-zero on success. On failure, you can
  1557. * find out what went wrong from PHYSFS_getLastError().
  1558. */
  1559. __EXPORT__ int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1560. /**
  1561. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1562. * \brief Convert and write an unsigned 16-bit bigendian value.
  1563. *
  1564. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1565. * native byte order to bigendian and write it to a file.
  1566. *
  1567. * \param file PhysicsFS file handle to which to write.
  1568. * \param val Value to convert and write.
  1569. * \return zero on failure, non-zero on success. On failure, you can
  1570. * find out what went wrong from PHYSFS_getLastError().
  1571. */
  1572. __EXPORT__ int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1573. /**
  1574. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1575. * \brief Convert and write a signed 32-bit littleendian value.
  1576. *
  1577. * Convenience function. Convert a signed 32-bit value from the platform's
  1578. * native byte order to littleendian and write it to a file.
  1579. *
  1580. * \param file PhysicsFS file handle to which to write.
  1581. * \param val Value to convert and write.
  1582. * \return zero on failure, non-zero on success. On failure, you can
  1583. * find out what went wrong from PHYSFS_getLastError().
  1584. */
  1585. __EXPORT__ int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1586. /**
  1587. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1588. * \brief Convert and write an unsigned 32-bit littleendian value.
  1589. *
  1590. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1591. * native byte order to littleendian and write it to a file.
  1592. *
  1593. * \param file PhysicsFS file handle to which to write.
  1594. * \param val Value to convert and write.
  1595. * \return zero on failure, non-zero on success. On failure, you can
  1596. * find out what went wrong from PHYSFS_getLastError().
  1597. */
  1598. __EXPORT__ int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1599. /**
  1600. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1601. * \brief Convert and write a signed 32-bit bigendian value.
  1602. *
  1603. * Convenience function. Convert a signed 32-bit value from the platform's
  1604. * native byte order to bigendian and write it to a file.
  1605. *
  1606. * \param file PhysicsFS file handle to which to write.
  1607. * \param val Value to convert and write.
  1608. * \return zero on failure, non-zero on success. On failure, you can
  1609. * find out what went wrong from PHYSFS_getLastError().
  1610. */
  1611. __EXPORT__ int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1612. /**
  1613. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1614. * \brief Convert and write an unsigned 32-bit bigendian value.
  1615. *
  1616. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1617. * native byte order to bigendian and write it to a file.
  1618. *
  1619. * \param file PhysicsFS file handle to which to write.
  1620. * \param val Value to convert and write.
  1621. * \return zero on failure, non-zero on success. On failure, you can
  1622. * find out what went wrong from PHYSFS_getLastError().
  1623. */
  1624. __EXPORT__ int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1625. /**
  1626. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1627. * \brief Convert and write a signed 64-bit littleendian value.
  1628. *
  1629. * Convenience function. Convert a signed 64-bit value from the platform's
  1630. * native byte order to littleendian and write it to a file.
  1631. *
  1632. * \param file PhysicsFS file handle to which to write.
  1633. * \param val Value to convert and write.
  1634. * \return zero on failure, non-zero on success. On failure, you can
  1635. * find out what went wrong from PHYSFS_getLastError().
  1636. *
  1637. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1638. * any sort of 64-bit support.
  1639. */
  1640. __EXPORT__ int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1641. /**
  1642. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1643. * \brief Convert and write an unsigned 64-bit littleendian value.
  1644. *
  1645. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1646. * native byte order to littleendian and write it to a file.
  1647. *
  1648. * \param file PhysicsFS file handle to which to write.
  1649. * \param val Value to convert and write.
  1650. * \return zero on failure, non-zero on success. On failure, you can
  1651. * find out what went wrong from PHYSFS_getLastError().
  1652. *
  1653. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1654. * any sort of 64-bit support.
  1655. */
  1656. __EXPORT__ int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1657. /**
  1658. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1659. * \brief Convert and write a signed 64-bit bigending value.
  1660. *
  1661. * Convenience function. Convert a signed 64-bit value from the platform's
  1662. * native byte order to bigendian and write it to a file.
  1663. *
  1664. * \param file PhysicsFS file handle to which to write.
  1665. * \param val Value to convert and write.
  1666. * \return zero on failure, non-zero on success. On failure, you can
  1667. * find out what went wrong from PHYSFS_getLastError().
  1668. *
  1669. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1670. * any sort of 64-bit support.
  1671. */
  1672. __EXPORT__ int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1673. /**
  1674. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1675. * \brief Convert and write an unsigned 64-bit bigendian value.
  1676. *
  1677. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1678. * native byte order to bigendian and write it to a file.
  1679. *
  1680. * \param file PhysicsFS file handle to which to write.
  1681. * \param val Value to convert and write.
  1682. * \return zero on failure, non-zero on success. On failure, you can
  1683. * find out what went wrong from PHYSFS_getLastError().
  1684. *
  1685. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1686. * any sort of 64-bit support.
  1687. */
  1688. __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1689. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1690. /**
  1691. * \struct PHYSFS_allocator
  1692. * \brief PhysicsFS allocation function pointers.
  1693. *
  1694. * (This is for limited, hardcore use. If you don't immediately see a need
  1695. * for it, you can probably ignore this forever.)
  1696. *
  1697. * You create one of these structures for use with PHYSFS_setAllocator.
  1698. * Allocators are assumed to be reentrant by the caller; please mutex
  1699. * accordingly.
  1700. *
  1701. * \sa PHYSFS_setAllocator
  1702. */
  1703. typedef struct
  1704. {
  1705. int (*init)(void);
  1706. void (*deinit)(void);
  1707. void *(*malloc)(size_t);
  1708. void *(*realloc)(void *, size_t);
  1709. void (*free)(void *);
  1710. } PHYSFS_Allocator;
  1711. /**
  1712. * \fn int PHYSFS_setAllocator(PHYSFS_Allocator *allocator)
  1713. * \brief Hook your own allocation routines into PhysicsFS.
  1714. *
  1715. * (This is for limited, hardcore use. If you don't immediately see a need
  1716. * for it, you can probably ignore this forever.)
  1717. *
  1718. * By default, PhysicsFS will use ANSI C malloc/realloc/calloc/free calls
  1719. * to manage dynamic memory, but in some uncommon cases, the app might want
  1720. * more control over the library's memory management. This lets you redirect
  1721. * physfs to use your own allocation routines instead. You can only call this
  1722. * function before PHYSFS_init(); if the library is initialized, it'll
  1723. * reject your efforts to change the allocator mid-stream. You may call this
  1724. * function after PHYSFS_deinit() if you are willing to shutdown the library
  1725. * and restart it with a new allocator; this is a safe and supported
  1726. * operation. The allocator remains intact between deinit/init calls.
  1727. * If you want to return to the default allocator, pass a NULL in here.
  1728. *
  1729. * If you aren't immediately sure what to do with this function, you can
  1730. * safely ignore it altogether.
  1731. *
  1732. * \param allocator Structure containing your allocator's entry points.
  1733. * \return zero on failure, non-zero on success. This call only fails
  1734. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1735. */
  1736. __EXPORT__ int PHYSFS_setAllocator(PHYSFS_Allocator *allocator);
  1737. /*
  1738. * it is not safe to call physfs functions in these callbacks, as they may
  1739. * be holding non recursive mutexes.
  1740. */
  1741. /* !!! FIXME: comment! */
  1742. typedef void (*PHYSFS_StringCallback)(void *data, const char *);
  1743. __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  1744. __EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  1745. __EXPORT__ void PHYSFS_enumerateFilesCallback(const char *dir,
  1746. PHYSFS_StringCallback c,
  1747. void *d);
  1748. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  1749. #ifdef __cplusplus
  1750. }
  1751. #endif
  1752. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  1753. /* end of physfs.h ... */