1
0

physfs.h 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535
  1. /**
  2. * \file physfs.h
  3. *
  4. * Main header file for PhysicsFS.
  5. */
  6. /**
  7. * \mainpage PhysicsFS
  8. *
  9. * The latest version of PhysicsFS can be found at:
  10. * http://icculus.org/physfs/
  11. *
  12. * PhysicsFS; a portable, flexible file i/o abstraction.
  13. *
  14. * This API gives you access to a system file system in ways superior to the
  15. * stdio or system i/o calls. The brief benefits:
  16. *
  17. * - It's portable.
  18. * - It's safe. No file access is permitted outside the specified dirs.
  19. * - It's flexible. Archives (.ZIP files) can be used transparently as
  20. * directory structures.
  21. *
  22. * This system is largely inspired by Quake 3's PK3 files and the related
  23. * fs_* cvars. If you've ever tinkered with these, then this API will be
  24. * familiar to you.
  25. *
  26. * With PhysicsFS, you have a single writing directory and multiple
  27. * directories (the "search path") for reading. You can think of this as a
  28. * filesystem within a filesystem. If (on Windows) you were to set the
  29. * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
  30. * could touch anything above this directory, including the "C:\MyGame" and
  31. * "C:\" directories. This prevents an application's internal scripting
  32. * language from piddling over c:\\config.sys, for example. If you'd rather
  33. * give PHYSFS full access to the system's REAL file system, set the writing
  34. * dir to "C:\", but that's generally A Bad Thing for several reasons.
  35. *
  36. * Drive letters are hidden in PhysicsFS once you set up your initial paths.
  37. * The search path creates a single, hierarchical directory structure.
  38. * Not only does this lend itself well to general abstraction with archives,
  39. * it also gives better support to operating systems like MacOS and Unix.
  40. * Generally speaking, you shouldn't ever hardcode a drive letter; not only
  41. * does this hurt portability to non-Microsoft OSes, but it limits your win32
  42. * users to a single drive, too. Use the PhysicsFS abstraction functions and
  43. * allow user-defined configuration options, too. When opening a file, you
  44. * specify it like it was on a Unix filesystem: if you want to write to
  45. * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to
  46. * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
  47. * abstraction across all platforms. Specifying a file in this way is termed
  48. * "platform-independent notation" in this documentation. Specifying a
  49. * a filename in a form such as "C:\mydir\myfile" or
  50. * "MacOS hard drive:My Directory:My File" is termed "platform-dependent
  51. * notation". The only time you use platform-dependent notation is when
  52. * setting up your write directory and search path; after that, all file
  53. * access into those directories are done with platform-independent notation.
  54. *
  55. * All files opened for writing are opened in relation to the write directory,
  56. * which is the root of the writable filesystem. When opening a file for
  57. * reading, PhysicsFS goes through the search path. This is NOT the
  58. * same thing as the PATH environment variable. An application using
  59. * PhysicsFS specifies directories to be searched which may be actual
  60. * directories, or archive files that contain files and subdirectories of
  61. * their own. See the end of these docs for currently supported archive
  62. * formats.
  63. *
  64. * Once the search path is defined, you may open files for reading. If you've
  65. * got the following search path defined (to use a win32 example again):
  66. *
  67. * - C:\\mygame
  68. * - C:\\mygame\\myuserfiles
  69. * - D:\\mygamescdromdatafiles
  70. * - C:\\mygame\\installeddatafiles.zip
  71. *
  72. * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory
  73. * separator, lack of drive letter, and lack of dir separator at the start of
  74. * the string; this is platform-independent notation) will check for
  75. * C:\\mygame\\textfiles\\myfile.txt, then
  76. * C:\\mygame\\myuserfiles\\textfiles\\myfile.txt, then
  77. * D:\\mygamescdromdatafiles\\textfiles\\myfile.txt, then, finally, for
  78. * textfiles\\myfile.txt inside of C:\\mygame\\installeddatafiles.zip.
  79. * Remember that most archive types and platform filesystems store their
  80. * filenames in a case-sensitive manner, so you should be careful to specify
  81. * it correctly.
  82. *
  83. * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir
  84. * elements. Not only are these meaningless on MacOS Classic and/or Unix,
  85. * they are a security hole. Also, symbolic links (which can be found in
  86. * some archive types and directly in the filesystem on Unix platforms) are
  87. * NOT followed until you call PHYSFS_permitSymbolicLinks(). That's left to
  88. * your own discretion, as following a symlink can allow for access outside
  89. * the write dir and search paths. For portability, there is no mechanism for
  90. * creating new symlinks in PhysicsFS.
  91. *
  92. * The write dir is not included in the search path unless you specifically
  93. * add it. While you CAN change the write dir as many times as you like,
  94. * you should probably set it once and stick to it. Remember that your
  95. * program will not have permission to write in every directory on Unix and
  96. * NT systems.
  97. *
  98. * All files are opened in binary mode; there is no endline conversion for
  99. * textfiles. Other than that, PhysicsFS has some convenience functions for
  100. * platform-independence. There is a function to tell you the current
  101. * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS),
  102. * which is needed only to set up your search/write paths. There is a
  103. * function to tell you what CD-ROM drives contain accessible discs, and a
  104. * function to recommend a good search path, etc.
  105. *
  106. * A recommended order for the search path is the write dir, then the base dir,
  107. * then the cdrom dir, then any archives discovered. Quake 3 does something
  108. * like this, but moves the archives to the start of the search path. Build
  109. * Engine games, like Duke Nukem 3D and Blood, place the archives last, and
  110. * use the base dir for both searching and writing. There is a helper
  111. * function (PHYSFS_setSaneConfig()) that puts together a basic configuration
  112. * for you, based on a few parameters. Also see the comments on
  113. * PHYSFS_getBaseDir(), and PHYSFS_getUserDir() for info on what those
  114. * are and how they can help you determine an optimal search path.
  115. *
  116. * PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points
  117. * in the search path. If a zipfile contains "maps/level.map" and you mount
  118. * that archive at "mods/mymod", then you would have to open
  119. * "mods/mymod/maps/level.map" to access the file, even though "mods/mymod"
  120. * isn't actually specified in the .zip file. Unlike the Unix mentality of
  121. * mounting a filesystem, "mods/mymod" doesn't actually have to exist when
  122. * mounting the zipfile. It's a "virtual" directory. The mounting mechanism
  123. * allows the developer to seperate archives in the tree and avoid trampling
  124. * over files when added new archives, such as including mod support in a
  125. * game...keeping external content on a tight leash in this manner can be of
  126. * utmost importance to some applications.
  127. *
  128. * PhysicsFS is mostly thread safe. The error messages returned by
  129. * PHYSFS_getLastError are unique by thread, and library-state-setting
  130. * functions are mutex'd. For efficiency, individual file accesses are
  131. * not locked, so you can not safely read/write/seek/close/etc the same
  132. * file from two threads at the same time. Other race conditions are bugs
  133. * that should be reported/patched.
  134. *
  135. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  136. * calls, doing so is not recommended, and you can not use system
  137. * filehandles with PhysicsFS and vice versa.
  138. *
  139. * Note that archives need not be named as such: if you have a ZIP file and
  140. * rename it with a .PKG extension, the file will still be recognized as a
  141. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  142. * type where possible.
  143. *
  144. * Currently supported archive types:
  145. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  146. * - .7Z (7zip archives)
  147. * - .ISO (ISO9660 files, CD-ROM images)
  148. * - .GRP (Build Engine groupfile archives)
  149. * - .PAK (Quake I/II archive format)
  150. * - .HOG (Descent I/II HOG file archives)
  151. * - .MVL (Descent II movielib archives)
  152. * - .WAD (DOOM engine archives)
  153. *
  154. *
  155. * String policy for PhysicsFS 2.0 and later:
  156. *
  157. * PhysicsFS 1.0 could only deal with null-terminated ASCII strings. All high
  158. * ASCII chars resulted in undefined behaviour, and there was no Unicode
  159. * support at all. PhysicsFS 2.0 supports Unicode without breaking binary
  160. * compatibility with the 1.0 API by using UTF-8 encoding of all strings
  161. * passed in and out of the library.
  162. *
  163. * All strings passed through PhysicsFS are in null-terminated UTF-8 format.
  164. * This means that if all you care about is English (ASCII characters <= 127)
  165. * then you just use regular C strings. If you care about Unicode (and you
  166. * should!) then you need to figure out what your platform wants, needs, and
  167. * offers. If you are on Windows and build with Unicode support, your TCHAR
  168. * strings are two bytes per character (this is called "UCS-2 encoding"). You
  169. * should convert them to UTF-8 before handing them to PhysicsFS with
  170. * PHYSFS_utf8FromUcs2(). If you're using Unix or Mac OS X, your wchar_t
  171. * strings are four bytes per character ("UCS-4 encoding"). Use
  172. * PHYSFS_utf8FromUcs4(). Mac OS X can give you UTF-8 directly from a
  173. * CFString, and many Unixes generally give you C strings in UTF-8 format
  174. * everywhere. If you have a single-byte high ASCII charset, like so-many
  175. * European "codepages" you may be out of luck. We'll convert from "Latin1"
  176. * to UTF-8 only, and never back to Latin1. If you're above ASCII 127, all
  177. * bets are off: move to Unicode or use your platform's facilities. Passing a
  178. * C string with high-ASCII data that isn't UTF-8 encoded will NOT do what
  179. * you expect!
  180. *
  181. * Naturally, there's also PHYSFS_utf8ToUcs2() and PHYSFS_utf8ToUcs4() to get
  182. * data back into a format you like. Behind the scenes, PhysicsFS will use
  183. * Unicode where possible: the UTF-8 strings on Windows will be converted
  184. * and used with the multibyte Windows APIs, for example.
  185. *
  186. * PhysicsFS offers basic encoding conversion support, but not a whole string
  187. * library. Get your stuff into whatever format you can work with.
  188. *
  189. * Some platforms and archivers don't offer full Unicode support behind the
  190. * scenes. For example, OS/2 only offers "codepages" and the filesystem
  191. * itself doesn't support multibyte encodings. We make an earnest effort to
  192. * convert to/from the current locale here, but all bets are off if
  193. * you want to hand an arbitrary Japanese character through to these systems.
  194. * Modern OSes (Mac OS X, Linux, Windows, PocketPC, etc) should all be fine.
  195. * Many game-specific archivers are seriously unprepared for Unicode (the
  196. * Descent HOG/MVL and Build Engine GRP archivers, for example, only offer a
  197. * DOS 8.3 filename, for example). Nothing can be done for these, but they
  198. * tend to be legacy formats for existing content that was all ASCII (and
  199. * thus, valid UTF-8) anyhow. Other formats, like .ZIP, don't explicitly
  200. * offer Unicode support, but unofficially expect filenames to be UTF-8
  201. * encoded, and thus Just Work. Most everything does the right thing without
  202. * bothering you, but it's good to be aware of these nuances in case they
  203. * don't.
  204. *
  205. *
  206. * Other stuff:
  207. *
  208. * Please see the file LICENSE.txt in the source's root directory for licensing
  209. * and redistribution rights.
  210. *
  211. * Please see the file CREDITS.txt in the source's root directory for a more or
  212. * less complete list of who's responsible for this.
  213. *
  214. * \author Ryan C. Gordon.
  215. */
  216. #ifndef _INCLUDE_PHYSFS_H_
  217. #define _INCLUDE_PHYSFS_H_
  218. #ifdef __cplusplus
  219. extern "C" {
  220. #endif
  221. #if defined(PHYSFS_DECL)
  222. /* do nothing. */
  223. #elif (defined SWIG)
  224. #define PHYSFS_DECL extern
  225. #elif (defined _MSC_VER)
  226. #define PHYSFS_DECL __declspec(dllexport)
  227. #elif (defined __SUNPRO_C)
  228. #define PHYSFS_DECL __global
  229. #elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun))
  230. #define PHYSFS_DECL __attribute__((visibility("default")))
  231. #else
  232. #define PHYSFS_DECL
  233. #endif
  234. #if 0 /* !!! FIXME: look into this later. */
  235. #if defined(PHYSFS_CALL)
  236. /* do nothing. */
  237. #elif defined(__WIN32__) && !defined(__GNUC__)
  238. #define PHYSFS_CALL __cdecl
  239. #elif defined(__OS2__) /* use _System, so it works across all compilers. */
  240. #define PHYSFS_CALL _System
  241. #else
  242. #define PHYSFS_CALL
  243. #endif
  244. #endif
  245. /**
  246. * \typedef PHYSFS_uint8
  247. * \brief An unsigned, 8-bit integer type.
  248. */
  249. typedef unsigned char PHYSFS_uint8;
  250. /**
  251. * \typedef PHYSFS_sint8
  252. * \brief A signed, 8-bit integer type.
  253. */
  254. typedef signed char PHYSFS_sint8;
  255. /**
  256. * \typedef PHYSFS_uint16
  257. * \brief An unsigned, 16-bit integer type.
  258. */
  259. typedef unsigned short PHYSFS_uint16;
  260. /**
  261. * \typedef PHYSFS_sint16
  262. * \brief A signed, 16-bit integer type.
  263. */
  264. typedef signed short PHYSFS_sint16;
  265. /**
  266. * \typedef PHYSFS_uint32
  267. * \brief An unsigned, 32-bit integer type.
  268. */
  269. typedef unsigned int PHYSFS_uint32;
  270. /**
  271. * \typedef PHYSFS_sint32
  272. * \brief A signed, 32-bit integer type.
  273. */
  274. typedef signed int PHYSFS_sint32;
  275. /**
  276. * \typedef PHYSFS_uint64
  277. * \brief An unsigned, 64-bit integer type.
  278. * \warning on platforms without any sort of 64-bit datatype, this is
  279. * equivalent to PHYSFS_uint32!
  280. */
  281. /**
  282. * \typedef PHYSFS_sint64
  283. * \brief A signed, 64-bit integer type.
  284. * \warning on platforms without any sort of 64-bit datatype, this is
  285. * equivalent to PHYSFS_sint32!
  286. */
  287. #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */
  288. typedef PHYSFS_uint32 PHYSFS_uint64;
  289. typedef PHYSFS_sint32 PHYSFS_sint64;
  290. #elif (defined _MSC_VER)
  291. typedef signed __int64 PHYSFS_sint64;
  292. typedef unsigned __int64 PHYSFS_uint64;
  293. #else
  294. typedef unsigned long long PHYSFS_uint64;
  295. typedef signed long long PHYSFS_sint64;
  296. #endif
  297. #ifndef SWIG
  298. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  299. /* Make sure the types really have the right sizes */
  300. #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \
  301. typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1]
  302. PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1);
  303. PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1);
  304. PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2);
  305. PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2);
  306. PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4);
  307. PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4);
  308. #ifndef PHYSFS_NO_64BIT_SUPPORT
  309. PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8);
  310. PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8);
  311. #endif
  312. #undef PHYSFS_COMPILE_TIME_ASSERT
  313. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  314. #endif /* SWIG */
  315. /**
  316. * \struct PHYSFS_File
  317. * \brief A PhysicsFS file handle.
  318. *
  319. * You get a pointer to one of these when you open a file for reading,
  320. * writing, or appending via PhysicsFS.
  321. *
  322. * As you can see from the lack of meaningful fields, you should treat this
  323. * as opaque data. Don't try to manipulate the file handle, just pass the
  324. * pointer you got, unmolested, to various PhysicsFS APIs.
  325. *
  326. * \sa PHYSFS_openRead
  327. * \sa PHYSFS_openWrite
  328. * \sa PHYSFS_openAppend
  329. * \sa PHYSFS_close
  330. * \sa PHYSFS_read
  331. * \sa PHYSFS_write
  332. * \sa PHYSFS_seek
  333. * \sa PHYSFS_tell
  334. * \sa PHYSFS_eof
  335. * \sa PHYSFS_setBuffer
  336. * \sa PHYSFS_flush
  337. */
  338. typedef struct PHYSFS_File
  339. {
  340. void *opaque; /**< That's all you get. Don't touch. */
  341. } PHYSFS_File;
  342. /**
  343. * \def PHYSFS_file
  344. * \brief 1.0 API compatibility define.
  345. *
  346. * PHYSFS_file is identical to PHYSFS_File. This #define is here for backwards
  347. * compatibility with the 1.0 API, which had an inconsistent capitalization
  348. * convention in this case. New code should use PHYSFS_File, as this #define
  349. * may go away someday.
  350. *
  351. * \sa PHYSFS_File
  352. */
  353. #define PHYSFS_file PHYSFS_File
  354. /**
  355. * \struct PHYSFS_ArchiveInfo
  356. * \brief Information on various PhysicsFS-supported archives.
  357. *
  358. * This structure gives you details on what sort of archives are supported
  359. * by this implementation of PhysicsFS. Archives tend to be things like
  360. * ZIP files and such.
  361. *
  362. * \warning Not all binaries are created equal! PhysicsFS can be built with
  363. * or without support for various archives. You can check with
  364. * PHYSFS_supportedArchiveTypes() to see if your archive type is
  365. * supported.
  366. *
  367. * \sa PHYSFS_supportedArchiveTypes
  368. */
  369. typedef struct PHYSFS_ArchiveInfo
  370. {
  371. const char *extension; /**< Archive file extension: "ZIP", for example. */
  372. const char *description; /**< Human-readable archive description. */
  373. const char *author; /**< Person who did support for this archive. */
  374. const char *url; /**< URL related to this archive */
  375. } PHYSFS_ArchiveInfo;
  376. /**
  377. * \struct PHYSFS_Version
  378. * \brief Information the version of PhysicsFS in use.
  379. *
  380. * Represents the library's version as three levels: major revision
  381. * (increments with massive changes, additions, and enhancements),
  382. * minor revision (increments with backwards-compatible changes to the
  383. * major revision), and patchlevel (increments with fixes to the minor
  384. * revision).
  385. *
  386. * \sa PHYSFS_VERSION
  387. * \sa PHYSFS_getLinkedVersion
  388. */
  389. typedef struct PHYSFS_Version
  390. {
  391. PHYSFS_uint8 major; /**< major revision */
  392. PHYSFS_uint8 minor; /**< minor revision */
  393. PHYSFS_uint8 patch; /**< patchlevel */
  394. } PHYSFS_Version;
  395. #ifndef SWIG /* not available from scripting languages. */
  396. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  397. #define PHYSFS_VER_MAJOR 2
  398. #define PHYSFS_VER_MINOR 1
  399. #define PHYSFS_VER_PATCH 0
  400. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  401. /* PhysicsFS state stuff ... */
  402. /**
  403. * \def PHYSFS_VERSION(x)
  404. * \brief Macro to determine PhysicsFS version program was compiled against.
  405. *
  406. * This macro fills in a PHYSFS_Version structure with the version of the
  407. * library you compiled against. This is determined by what header the
  408. * compiler uses. Note that if you dynamically linked the library, you might
  409. * have a slightly newer or older version at runtime. That version can be
  410. * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION,
  411. * is not a macro.
  412. *
  413. * \param x A pointer to a PHYSFS_Version struct to initialize.
  414. *
  415. * \sa PHYSFS_Version
  416. * \sa PHYSFS_getLinkedVersion
  417. */
  418. #define PHYSFS_VERSION(x) \
  419. { \
  420. (x)->major = PHYSFS_VER_MAJOR; \
  421. (x)->minor = PHYSFS_VER_MINOR; \
  422. (x)->patch = PHYSFS_VER_PATCH; \
  423. }
  424. #endif /* SWIG */
  425. /**
  426. * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  427. * \brief Get the version of PhysicsFS that is linked against your program.
  428. *
  429. * If you are using a shared library (DLL) version of PhysFS, then it is
  430. * possible that it will be different than the version you compiled against.
  431. *
  432. * This is a real function; the macro PHYSFS_VERSION tells you what version
  433. * of PhysFS you compiled against:
  434. *
  435. * \code
  436. * PHYSFS_Version compiled;
  437. * PHYSFS_Version linked;
  438. *
  439. * PHYSFS_VERSION(&compiled);
  440. * PHYSFS_getLinkedVersion(&linked);
  441. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  442. * compiled.major, compiled.minor, compiled.patch);
  443. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  444. * linked.major, linked.minor, linked.patch);
  445. * \endcode
  446. *
  447. * This function may be called safely at any time, even before PHYSFS_init().
  448. *
  449. * \sa PHYSFS_VERSION
  450. */
  451. PHYSFS_DECL void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  452. /**
  453. * \fn int PHYSFS_init(const char *argv0)
  454. * \brief Initialize the PhysicsFS library.
  455. *
  456. * This must be called before any other PhysicsFS function.
  457. *
  458. * This should be called prior to any attempts to change your process's
  459. * current working directory.
  460. *
  461. * \param argv0 the argv[0] string passed to your program's mainline.
  462. * This may be NULL on most platforms (such as ones without a
  463. * standard main() function), but you should always try to pass
  464. * something in here. Unix-like systems such as Linux _need_ to
  465. * pass argv[0] from main() in here.
  466. * \return nonzero on success, zero on error. Specifics of the error can be
  467. * gleaned from PHYSFS_getLastError().
  468. *
  469. * \sa PHYSFS_deinit
  470. * \sa PHYSFS_isInit
  471. */
  472. PHYSFS_DECL int PHYSFS_init(const char *argv0);
  473. /**
  474. * \fn int PHYSFS_deinit(void)
  475. * \brief Deinitialize the PhysicsFS library.
  476. *
  477. * This closes any files opened via PhysicsFS, blanks the search/write paths,
  478. * frees memory, and invalidates all of your file handles.
  479. *
  480. * Note that this call can FAIL if there's a file open for writing that
  481. * refuses to close (for example, the underlying operating system was
  482. * buffering writes to network filesystem, and the fileserver has crashed,
  483. * or a hard drive has failed, etc). It is usually best to close all write
  484. * handles yourself before calling this function, so that you can gracefully
  485. * handle a specific failure.
  486. *
  487. * Once successfully deinitialized, PHYSFS_init() can be called again to
  488. * restart the subsystem. All default API states are restored at this
  489. * point, with the exception of any custom allocator you might have
  490. * specified, which survives between initializations.
  491. *
  492. * \return nonzero on success, zero on error. Specifics of the error can be
  493. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  494. * undefined, and probably badly screwed up.
  495. *
  496. * \sa PHYSFS_init
  497. * \sa PHYSFS_isInit
  498. */
  499. PHYSFS_DECL int PHYSFS_deinit(void);
  500. /**
  501. * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
  502. * \brief Get a list of supported archive types.
  503. *
  504. * Get a list of archive types supported by this implementation of PhysicFS.
  505. * These are the file formats usable for search path entries. This is for
  506. * informational purposes only. Note that the extension listed is merely
  507. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  508. * with an extension of "XYZ", if you like.
  509. *
  510. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  511. * with a NULL entry to signify the end of the list:
  512. *
  513. * \code
  514. * PHYSFS_ArchiveInfo **i;
  515. *
  516. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  517. * {
  518. * printf("Supported archive: [%s], which is [%s].\n",
  519. * (*i)->extension, (*i)->description);
  520. * }
  521. * \endcode
  522. *
  523. * The return values are pointers to static internal memory, and should
  524. * be considered READ ONLY, and never freed.
  525. *
  526. * \return READ ONLY Null-terminated array of READ ONLY structures.
  527. */
  528. PHYSFS_DECL const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  529. /**
  530. * \fn void PHYSFS_freeList(void *listVar)
  531. * \brief Deallocate resources of lists returned by PhysicsFS.
  532. *
  533. * Certain PhysicsFS functions return lists of information that are
  534. * dynamically allocated. Use this function to free those resources.
  535. *
  536. * It is safe to pass a NULL here, but doing so will cause a crash in versions
  537. * before PhysicsFS 2.1.0.
  538. *
  539. * \param listVar List of information specified as freeable by this function.
  540. * Passing NULL is safe; it is a valid no-op.
  541. *
  542. * \sa PHYSFS_getCdRomDirs
  543. * \sa PHYSFS_enumerateFiles
  544. * \sa PHYSFS_getSearchPath
  545. */
  546. PHYSFS_DECL void PHYSFS_freeList(void *listVar);
  547. /**
  548. * \fn const char *PHYSFS_getLastError(void)
  549. * \brief Get human-readable error information.
  550. *
  551. * Get the last PhysicsFS error message as a human-readable, null-terminated
  552. * string. This will be NULL if there's been no error since the last call to
  553. * this function. The pointer returned by this call points to an internal
  554. * buffer. Each thread has a unique error state associated with it, but each
  555. * time a new error message is set, it will overwrite the previous one
  556. * associated with that thread. It is safe to call this function at anytime,
  557. * even before PHYSFS_init().
  558. *
  559. * It is not wise to expect a specific string of characters here, since the
  560. * error message may be localized into an unfamiliar language. These strings
  561. * are meant to be passed on directly to the user.
  562. *
  563. * \return READ ONLY string of last error message.
  564. */
  565. PHYSFS_DECL const char *PHYSFS_getLastError(void);
  566. /**
  567. * \fn const char *PHYSFS_getDirSeparator(void)
  568. * \brief Get platform-dependent dir separator string.
  569. *
  570. * This returns "\\" on win32, "/" on Unix, and ":" on MacOS. It may be more
  571. * than one character, depending on the platform, and your code should take
  572. * that into account. Note that this is only useful for setting up the
  573. * search/write paths, since access into those dirs always use '/'
  574. * (platform-independent notation) to separate directories. This is also
  575. * handy for getting platform-independent access when using stdio calls.
  576. *
  577. * \return READ ONLY null-terminated string of platform's dir separator.
  578. */
  579. PHYSFS_DECL const char *PHYSFS_getDirSeparator(void);
  580. /**
  581. * \fn void PHYSFS_permitSymbolicLinks(int allow)
  582. * \brief Enable or disable following of symbolic links.
  583. *
  584. * Some physical filesystems and archives contain files that are just pointers
  585. * to other files. On the physical filesystem, opening such a link will
  586. * (transparently) open the file that is pointed to.
  587. *
  588. * By default, PhysicsFS will check if a file is really a symlink during open
  589. * calls and fail if it is. Otherwise, the link could take you outside the
  590. * write and search paths, and compromise security.
  591. *
  592. * If you want to take that risk, call this function with a non-zero parameter.
  593. * Note that this is more for sandboxing a program's scripting language, in
  594. * case untrusted scripts try to compromise the system. Generally speaking,
  595. * a user could very well have a legitimate reason to set up a symlink, so
  596. * unless you feel there's a specific danger in allowing them, you should
  597. * permit them.
  598. *
  599. * Symlinks are only explicitly checked when dealing with filenames
  600. * in platform-independent notation. That is, when setting up your
  601. * search and write paths, etc, symlinks are never checked for.
  602. *
  603. * Symbolic link permission can be enabled or disabled at any time after
  604. * you've called PHYSFS_init(), and is disabled by default.
  605. *
  606. * \param allow nonzero to permit symlinks, zero to deny linking.
  607. *
  608. * \sa PHYSFS_symbolicLinksPermitted
  609. */
  610. PHYSFS_DECL void PHYSFS_permitSymbolicLinks(int allow);
  611. /* !!! FIXME: const this? */
  612. /**
  613. * \fn char **PHYSFS_getCdRomDirs(void)
  614. * \brief Get an array of paths to available CD-ROM drives.
  615. *
  616. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  617. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  618. * accessible in the drive. So if you've got two drives (D: and E:), and only
  619. * E: has a disc in it, then that's all you get. If the user inserts a disc
  620. * in D: and you call this function again, you get both drives. If, on a
  621. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  622. * call to this function will reflect that change.
  623. *
  624. * This function refers to "CD-ROM" media, but it really means "inserted disc
  625. * media," such as DVD-ROM, HD-DVD, CDRW, and Blu-Ray discs. It looks for
  626. * filesystems, and as such won't report an audio CD, unless there's a
  627. * mounted filesystem track on it.
  628. *
  629. * The returned value is an array of strings, with a NULL entry to signify the
  630. * end of the list:
  631. *
  632. * \code
  633. * char **cds = PHYSFS_getCdRomDirs();
  634. * char **i;
  635. *
  636. * for (i = cds; *i != NULL; i++)
  637. * printf("cdrom dir [%s] is available.\n", *i);
  638. *
  639. * PHYSFS_freeList(cds);
  640. * \endcode
  641. *
  642. * This call may block while drives spin up. Be forewarned.
  643. *
  644. * When you are done with the returned information, you may dispose of the
  645. * resources by calling PHYSFS_freeList() with the returned pointer.
  646. *
  647. * \return Null-terminated array of null-terminated strings.
  648. *
  649. * \sa PHYSFS_getCdRomDirsCallback
  650. */
  651. PHYSFS_DECL char **PHYSFS_getCdRomDirs(void);
  652. /**
  653. * \fn const char *PHYSFS_getBaseDir(void)
  654. * \brief Get the path where the application resides.
  655. *
  656. * Helper function.
  657. *
  658. * Get the "base dir". This is the directory where the application was run
  659. * from, which is probably the installation directory, and may or may not
  660. * be the process's current working directory.
  661. *
  662. * You should probably use the base dir in your search path.
  663. *
  664. * \return READ ONLY string of base dir in platform-dependent notation.
  665. *
  666. * \sa PHYSFS_getUserDir
  667. */
  668. PHYSFS_DECL const char *PHYSFS_getBaseDir(void);
  669. /**
  670. * \fn const char *PHYSFS_getUserDir(void)
  671. * \brief Get the path where user's home directory resides.
  672. *
  673. * Helper function.
  674. *
  675. * Get the "user dir". This is meant to be a suggestion of where a specific
  676. * user of the system can store files. On Unix, this is her home directory.
  677. * On systems with no concept of multiple home directories (MacOS, win95),
  678. * this will default to something like "C:\mybasedir\users\username"
  679. * where "username" will either be the login name, or "default" if the
  680. * platform doesn't support multiple users, either.
  681. *
  682. * You should probably use the user dir as the basis for your write dir, and
  683. * also put it near the beginning of your search path.
  684. *
  685. * \return READ ONLY string of user dir in platform-dependent notation.
  686. *
  687. * \sa PHYSFS_getBaseDir
  688. */
  689. PHYSFS_DECL const char *PHYSFS_getUserDir(void);
  690. /**
  691. * \fn const char *PHYSFS_getWriteDir(void)
  692. * \brief Get path where PhysicsFS will allow file writing.
  693. *
  694. * Get the current write dir. The default write dir is NULL.
  695. *
  696. * \return READ ONLY string of write dir in platform-dependent notation,
  697. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  698. *
  699. * \sa PHYSFS_setWriteDir
  700. */
  701. PHYSFS_DECL const char *PHYSFS_getWriteDir(void);
  702. /**
  703. * \fn int PHYSFS_setWriteDir(const char *newDir)
  704. * \brief Tell PhysicsFS where it may write files.
  705. *
  706. * Set a new write dir. This will override the previous setting.
  707. *
  708. * This call will fail (and fail to change the write dir) if the current
  709. * write dir still has files open in it.
  710. *
  711. * \param newDir The new directory to be the root of the write dir,
  712. * specified in platform-dependent notation. Setting to NULL
  713. * disables the write dir, so no files can be opened for
  714. * writing via PhysicsFS.
  715. * \return non-zero on success, zero on failure. All attempts to open a file
  716. * for writing via PhysicsFS will fail until this call succeeds.
  717. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  718. *
  719. * \sa PHYSFS_getWriteDir
  720. */
  721. PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
  722. /**
  723. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  724. * \brief Add an archive or directory to the search path.
  725. *
  726. * This is a legacy call in PhysicsFS 2.0, equivalent to:
  727. * PHYSFS_mount(newDir, NULL, appendToPath);
  728. *
  729. * You must use this and not PHYSFS_mount if binary compatibility with
  730. * PhysicsFS 1.0 is important (which it may not be for many people).
  731. *
  732. * \sa PHYSFS_mount
  733. * \sa PHYSFS_removeFromSearchPath
  734. * \sa PHYSFS_getSearchPath
  735. */
  736. PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  737. /**
  738. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  739. * \brief Remove a directory or archive from the search path.
  740. *
  741. * This must be a (case-sensitive) match to a dir or archive already in the
  742. * search path, specified in platform-dependent notation.
  743. *
  744. * This call will fail (and fail to remove from the path) if the element still
  745. * has files open in it.
  746. *
  747. * \param oldDir dir/archive to remove.
  748. * \return nonzero on success, zero on failure.
  749. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  750. *
  751. * \sa PHYSFS_addToSearchPath
  752. * \sa PHYSFS_getSearchPath
  753. */
  754. PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir);
  755. /**
  756. * \fn char **PHYSFS_getSearchPath(void)
  757. * \brief Get the current search path.
  758. *
  759. * The default search path is an empty list.
  760. *
  761. * The returned value is an array of strings, with a NULL entry to signify the
  762. * end of the list:
  763. *
  764. * \code
  765. * char **i;
  766. *
  767. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  768. * printf("[%s] is in the search path.\n", *i);
  769. * \endcode
  770. *
  771. * When you are done with the returned information, you may dispose of the
  772. * resources by calling PHYSFS_freeList() with the returned pointer.
  773. *
  774. * \return Null-terminated array of null-terminated strings. NULL if there
  775. * was a problem (read: OUT OF MEMORY).
  776. *
  777. * \sa PHYSFS_getSearchPathCallback
  778. * \sa PHYSFS_addToSearchPath
  779. * \sa PHYSFS_removeFromSearchPath
  780. */
  781. PHYSFS_DECL char **PHYSFS_getSearchPath(void);
  782. /**
  783. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  784. * \brief Set up sane, default paths.
  785. *
  786. * Helper function.
  787. *
  788. * The write dir will be set to "userdir/.organization/appName", which is
  789. * created if it doesn't exist.
  790. *
  791. * The above is sufficient to make sure your program's configuration directory
  792. * is separated from other clutter, and platform-independent. The period
  793. * before "mygame" even hides the directory on Unix systems.
  794. *
  795. * The search path will be:
  796. *
  797. * - The Write Dir (created if it doesn't exist)
  798. * - The Base Dir (PHYSFS_getBaseDir())
  799. * - All found CD-ROM dirs (optionally)
  800. *
  801. * These directories are then searched for files ending with the extension
  802. * (archiveExt), which, if they are valid and supported archives, will also
  803. * be added to the search path. If you specified "PKG" for (archiveExt), and
  804. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  805. * can either be appended or prepended to the search path in alphabetical
  806. * order, regardless of which directories they were found in.
  807. *
  808. * All of this can be accomplished from the application, but this just does it
  809. * all for you. Feel free to add more to the search path manually, too.
  810. *
  811. * \param organization Name of your company/group/etc to be used as a
  812. * dirname, so keep it small, and no-frills.
  813. *
  814. * \param appName Program-specific name of your program, to separate it
  815. * from other programs using PhysicsFS.
  816. *
  817. * \param archiveExt File extension used by your program to specify an
  818. * archive. For example, Quake 3 uses "pk3", even though
  819. * they are just zipfiles. Specify NULL to not dig out
  820. * archives automatically. Do not specify the '.' char;
  821. * If you want to look for ZIP files, specify "ZIP" and
  822. * not ".ZIP" ... the archive search is case-insensitive.
  823. *
  824. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  825. * (if (archiveExt) != NULL) search them for archives.
  826. * This may cause a significant amount of blocking
  827. * while discs are accessed, and if there are no discs
  828. * in the drive (or even not mounted on Unix systems),
  829. * then they may not be made available anyhow. You may
  830. * want to specify zero and handle the disc setup
  831. * yourself.
  832. *
  833. * \param archivesFirst Non-zero to prepend the archives to the search path.
  834. * Zero to append them. Ignored if !(archiveExt).
  835. *
  836. * \return nonzero on success, zero on error. Specifics of the error can be
  837. * gleaned from PHYSFS_getLastError().
  838. */
  839. PHYSFS_DECL int PHYSFS_setSaneConfig(const char *organization,
  840. const char *appName,
  841. const char *archiveExt,
  842. int includeCdRoms,
  843. int archivesFirst);
  844. /* Directory management stuff ... */
  845. /**
  846. * \fn int PHYSFS_mkdir(const char *dirName)
  847. * \brief Create a directory.
  848. *
  849. * This is specified in platform-independent notation in relation to the
  850. * write dir. All missing parent directories are also created if they
  851. * don't exist.
  852. *
  853. * So if you've got the write dir set to "C:\mygame\writedir" and call
  854. * PHYSFS_mkdir("downloads/maps") then the directories
  855. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  856. * will be created if possible. If the creation of "maps" fails after we
  857. * have successfully created "downloads", then the function leaves the
  858. * created directory behind and reports failure.
  859. *
  860. * \param dirName New dir to create.
  861. * \return nonzero on success, zero on error. Specifics of the error can be
  862. * gleaned from PHYSFS_getLastError().
  863. *
  864. * \sa PHYSFS_delete
  865. */
  866. PHYSFS_DECL int PHYSFS_mkdir(const char *dirName);
  867. /**
  868. * \fn int PHYSFS_delete(const char *filename)
  869. * \brief Delete a file or directory.
  870. *
  871. * (filename) is specified in platform-independent notation in relation to the
  872. * write dir.
  873. *
  874. * A directory must be empty before this call can delete it.
  875. *
  876. * Deleting a symlink will remove the link, not what it points to, regardless
  877. * of whether you "permitSymLinks" or not.
  878. *
  879. * So if you've got the write dir set to "C:\mygame\writedir" and call
  880. * PHYSFS_delete("downloads/maps/level1.map") then the file
  881. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  882. * physical filesystem, if it exists and the operating system permits the
  883. * deletion.
  884. *
  885. * Note that on Unix systems, deleting a file may be successful, but the
  886. * actual file won't be removed until all processes that have an open
  887. * filehandle to it (including your program) close their handles.
  888. *
  889. * Chances are, the bits that make up the file still exist, they are just
  890. * made available to be written over at a later point. Don't consider this
  891. * a security method or anything. :)
  892. *
  893. * \param filename Filename to delete.
  894. * \return nonzero on success, zero on error. Specifics of the error can be
  895. * gleaned from PHYSFS_getLastError().
  896. */
  897. PHYSFS_DECL int PHYSFS_delete(const char *filename);
  898. /**
  899. * \fn const char *PHYSFS_getRealDir(const char *filename)
  900. * \brief Figure out where in the search path a file resides.
  901. *
  902. * The file is specified in platform-independent notation. The returned
  903. * filename will be the element of the search path where the file was found,
  904. * which may be a directory, or an archive. Even if there are multiple
  905. * matches in different parts of the search path, only the first one found
  906. * is used, just like when opening a file.
  907. *
  908. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  909. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  910. *
  911. * If a any part of a match is a symbolic link, and you've not explicitly
  912. * permitted symlinks, then it will be ignored, and the search for a match
  913. * will continue.
  914. *
  915. * If you specify a fake directory that only exists as a mount point, it'll
  916. * be associated with the first archive mounted there, even though that
  917. * directory isn't necessarily contained in a real archive.
  918. *
  919. * \param filename file to look for.
  920. * \return READ ONLY string of element of search path containing the
  921. * the file in question. NULL if not found.
  922. */
  923. PHYSFS_DECL const char *PHYSFS_getRealDir(const char *filename);
  924. /**
  925. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  926. * \brief Get a file listing of a search path's directory.
  927. *
  928. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  929. * search path and contains a directory "savegames" that contains "x.sav",
  930. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  931. * that has a "savegames" subdirectory with "w.sav", then the following code:
  932. *
  933. * \code
  934. * char **rc = PHYSFS_enumerateFiles("savegames");
  935. * char **i;
  936. *
  937. * for (i = rc; *i != NULL; i++)
  938. * printf(" * We've got [%s].\n", *i);
  939. *
  940. * PHYSFS_freeList(rc);
  941. * \endcode
  942. *
  943. * \...will print:
  944. *
  945. * \verbatim
  946. * We've got [x.sav].
  947. * We've got [y.sav].
  948. * We've got [z.sav].
  949. * We've got [w.sav].\endverbatim
  950. *
  951. * Feel free to sort the list however you like. We only promise there will
  952. * be no duplicates, but not what order the final list will come back in.
  953. *
  954. * Don't forget to call PHYSFS_freeList() with the return value from this
  955. * function when you are done with it.
  956. *
  957. * \param dir directory in platform-independent notation to enumerate.
  958. * \return Null-terminated array of null-terminated strings.
  959. *
  960. * \sa PHYSFS_enumerateFilesCallback
  961. */
  962. PHYSFS_DECL char **PHYSFS_enumerateFiles(const char *dir);
  963. /**
  964. * \fn int PHYSFS_exists(const char *fname)
  965. * \brief Determine if a file exists in the search path.
  966. *
  967. * Reports true if there is an entry anywhere in the search path by the
  968. * name of (fname).
  969. *
  970. * Note that entries that are symlinks are ignored if
  971. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  972. * might end up further down in the search path than expected.
  973. *
  974. * \param fname filename in platform-independent notation.
  975. * \return non-zero if filename exists. zero otherwise.
  976. *
  977. * \sa PHYSFS_isDirectory
  978. * \sa PHYSFS_isSymbolicLink
  979. */
  980. PHYSFS_DECL int PHYSFS_exists(const char *fname);
  981. /**
  982. * \fn int PHYSFS_isDirectory(const char *fname)
  983. * \brief Determine if a file in the search path is really a directory.
  984. *
  985. * Determine if the first occurence of (fname) in the search path is
  986. * really a directory entry.
  987. *
  988. * Note that entries that are symlinks are ignored if
  989. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  990. * might end up further down in the search path than expected.
  991. *
  992. * \param fname filename in platform-independent notation.
  993. * \return non-zero if filename exists and is a directory. zero otherwise.
  994. *
  995. * \sa PHYSFS_exists
  996. * \sa PHYSFS_isSymbolicLink
  997. */
  998. PHYSFS_DECL int PHYSFS_isDirectory(const char *fname);
  999. /**
  1000. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  1001. * \brief Determine if a file in the search path is really a symbolic link.
  1002. *
  1003. * Determine if the first occurence of (fname) in the search path is
  1004. * really a symbolic link.
  1005. *
  1006. * Note that entries that are symlinks are ignored if
  1007. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  1008. * this function will always return 0 in that case.
  1009. *
  1010. * \param fname filename in platform-independent notation.
  1011. * \return non-zero if filename exists and is a symlink. zero otherwise.
  1012. *
  1013. * \sa PHYSFS_exists
  1014. * \sa PHYSFS_isDirectory
  1015. */
  1016. PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname);
  1017. /**
  1018. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1019. * \brief Get the last modification time of a file.
  1020. *
  1021. * The modtime is returned as a number of seconds since the epoch
  1022. * (Jan 1, 1970). The exact derivation and accuracy of this time depends on
  1023. * the particular archiver. If there is no reasonable way to obtain this
  1024. * information for a particular archiver, or there was some sort of error,
  1025. * this function returns (\-1).
  1026. *
  1027. * \param filename filename to check, in platform-independent notation.
  1028. * \return last modified time of the file. \-1 if it can't be determined.
  1029. */
  1030. PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename);
  1031. /* i/o stuff... */
  1032. /**
  1033. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  1034. * \brief Open a file for writing.
  1035. *
  1036. * Open a file for writing, in platform-independent notation and in relation
  1037. * to the write dir as the root of the writable filesystem. The specified
  1038. * file is created if it doesn't exist. If it does exist, it is truncated to
  1039. * zero bytes, and the writing offset is set to the start.
  1040. *
  1041. * Note that entries that are symlinks are ignored if
  1042. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1043. * symlink with this function will fail in such a case.
  1044. *
  1045. * \param filename File to open.
  1046. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1047. * of the error can be gleaned from PHYSFS_getLastError().
  1048. *
  1049. * \sa PHYSFS_openRead
  1050. * \sa PHYSFS_openAppend
  1051. * \sa PHYSFS_write
  1052. * \sa PHYSFS_close
  1053. */
  1054. PHYSFS_DECL PHYSFS_File *PHYSFS_openWrite(const char *filename);
  1055. /**
  1056. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  1057. * \brief Open a file for appending.
  1058. *
  1059. * Open a file for writing, in platform-independent notation and in relation
  1060. * to the write dir as the root of the writable filesystem. The specified
  1061. * file is created if it doesn't exist. If it does exist, the writing offset
  1062. * is set to the end of the file, so the first write will be the byte after
  1063. * the end.
  1064. *
  1065. * Note that entries that are symlinks are ignored if
  1066. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1067. * symlink with this function will fail in such a case.
  1068. *
  1069. * \param filename File to open.
  1070. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1071. * of the error can be gleaned from PHYSFS_getLastError().
  1072. *
  1073. * \sa PHYSFS_openRead
  1074. * \sa PHYSFS_openWrite
  1075. * \sa PHYSFS_write
  1076. * \sa PHYSFS_close
  1077. */
  1078. PHYSFS_DECL PHYSFS_File *PHYSFS_openAppend(const char *filename);
  1079. /**
  1080. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  1081. * \brief Open a file for reading.
  1082. *
  1083. * Open a file for reading, in platform-independent notation. The search path
  1084. * is checked one at a time until a matching file is found, in which case an
  1085. * abstract filehandle is associated with it, and reading may be done.
  1086. * The reading offset is set to the first byte of the file.
  1087. *
  1088. * Note that entries that are symlinks are ignored if
  1089. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1090. * symlink with this function will fail in such a case.
  1091. *
  1092. * \param filename File to open.
  1093. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1094. * of the error can be gleaned from PHYSFS_getLastError().
  1095. *
  1096. * \sa PHYSFS_openWrite
  1097. * \sa PHYSFS_openAppend
  1098. * \sa PHYSFS_read
  1099. * \sa PHYSFS_close
  1100. */
  1101. PHYSFS_DECL PHYSFS_File *PHYSFS_openRead(const char *filename);
  1102. /**
  1103. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1104. * \brief Close a PhysicsFS filehandle.
  1105. *
  1106. * This call is capable of failing if the operating system was buffering
  1107. * writes to the physical media, and, now forced to write those changes to
  1108. * physical media, can not store the data for some reason. In such a case,
  1109. * the filehandle stays open. A well-written program should ALWAYS check the
  1110. * return value from the close call in addition to every writing call!
  1111. *
  1112. * \param handle handle returned from PHYSFS_open*().
  1113. * \return nonzero on success, zero on error. Specifics of the error can be
  1114. * gleaned from PHYSFS_getLastError().
  1115. *
  1116. * \sa PHYSFS_openRead
  1117. * \sa PHYSFS_openWrite
  1118. * \sa PHYSFS_openAppend
  1119. */
  1120. PHYSFS_DECL int PHYSFS_close(PHYSFS_File *handle);
  1121. /**
  1122. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1123. * \brief Read data from a PhysicsFS filehandle
  1124. *
  1125. * The file must be opened for reading.
  1126. *
  1127. * \param handle handle returned from PHYSFS_openRead().
  1128. * \param buffer buffer to store read data into.
  1129. * \param objSize size in bytes of objects being read from (handle).
  1130. * \param objCount number of (objSize) objects to read from (handle).
  1131. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1132. * the reason this might be < (objCount), as can PHYSFS_eof().
  1133. * \-1 if complete failure.
  1134. *
  1135. * \sa PHYSFS_eof
  1136. */
  1137. PHYSFS_DECL PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1138. void *buffer,
  1139. PHYSFS_uint32 objSize,
  1140. PHYSFS_uint32 objCount);
  1141. /**
  1142. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1143. * \brief Write data to a PhysicsFS filehandle
  1144. *
  1145. * The file must be opened for writing.
  1146. *
  1147. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1148. * \param buffer buffer to store read data into.
  1149. * \param objSize size in bytes of objects being read from (handle).
  1150. * \param objCount number of (objSize) objects to read from (handle).
  1151. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1152. * the reason this might be < (objCount). \-1 if complete failure.
  1153. */
  1154. PHYSFS_DECL PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1155. const void *buffer,
  1156. PHYSFS_uint32 objSize,
  1157. PHYSFS_uint32 objCount);
  1158. /* File position stuff... */
  1159. /**
  1160. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1161. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1162. *
  1163. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1164. *
  1165. * \param handle handle returned from PHYSFS_openRead().
  1166. * \return nonzero if EOF, zero if not.
  1167. *
  1168. * \sa PHYSFS_read
  1169. * \sa PHYSFS_tell
  1170. */
  1171. PHYSFS_DECL int PHYSFS_eof(PHYSFS_File *handle);
  1172. /**
  1173. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1174. * \brief Determine current position within a PhysicsFS filehandle.
  1175. *
  1176. * \param handle handle returned from PHYSFS_open*().
  1177. * \return offset in bytes from start of file. \-1 if error occurred.
  1178. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1179. *
  1180. * \sa PHYSFS_seek
  1181. */
  1182. PHYSFS_DECL PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1183. /**
  1184. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1185. * \brief Seek to a new position within a PhysicsFS filehandle.
  1186. *
  1187. * The next read or write will occur at that place. Seeking past the
  1188. * beginning or end of the file is not allowed, and causes an error.
  1189. *
  1190. * \param handle handle returned from PHYSFS_open*().
  1191. * \param pos number of bytes from start of file to seek to.
  1192. * \return nonzero on success, zero on error. Specifics of the error can be
  1193. * gleaned from PHYSFS_getLastError().
  1194. *
  1195. * \sa PHYSFS_tell
  1196. */
  1197. PHYSFS_DECL int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1198. /**
  1199. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1200. * \brief Get total length of a file in bytes.
  1201. *
  1202. * Note that if the file size can't be determined (since the archive is
  1203. * "streamed" or whatnot) than this will report (\-1). Also note that if
  1204. * another process/thread is writing to this file at the same time, then
  1205. * the information this function supplies could be incorrect before you
  1206. * get it. Use with caution, or better yet, don't use at all.
  1207. *
  1208. * \param handle handle returned from PHYSFS_open*().
  1209. * \return size in bytes of the file. \-1 if can't be determined.
  1210. *
  1211. * \sa PHYSFS_tell
  1212. * \sa PHYSFS_seek
  1213. */
  1214. PHYSFS_DECL PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1215. /* Buffering stuff... */
  1216. /**
  1217. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1218. * \brief Set up buffering for a PhysicsFS file handle.
  1219. *
  1220. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1221. * will be allocated and associated with (handle).
  1222. *
  1223. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1224. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1225. * from this buffer until it is empty, and then refill it for more reading.
  1226. * Note that compressed files, like ZIP archives, will decompress while
  1227. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1228. * The buffer isn't filled until you do your next read.
  1229. *
  1230. * For files opened for writing, data will be buffered to memory until the
  1231. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1232. * causes a flush...check your return values!
  1233. *
  1234. * Seeking, etc transparently accounts for buffering.
  1235. *
  1236. * You can resize an existing buffer by calling this function more than once
  1237. * on the same file. Setting the buffer size to zero will free an existing
  1238. * buffer.
  1239. *
  1240. * PhysicsFS file handles are unbuffered by default.
  1241. *
  1242. * Please check the return value of this function! Failures can include
  1243. * not being able to seek backwards in a read-only file when removing the
  1244. * buffer, not being able to allocate the buffer, and not being able to
  1245. * flush the buffer to disk, among other unexpected problems.
  1246. *
  1247. * \param handle handle returned from PHYSFS_open*().
  1248. * \param bufsize size, in bytes, of buffer to allocate.
  1249. * \return nonzero if successful, zero on error.
  1250. *
  1251. * \sa PHYSFS_flush
  1252. * \sa PHYSFS_read
  1253. * \sa PHYSFS_write
  1254. * \sa PHYSFS_close
  1255. */
  1256. PHYSFS_DECL int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1257. /**
  1258. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1259. * \brief Flush a buffered PhysicsFS file handle.
  1260. *
  1261. * For buffered files opened for writing, this will put the current contents
  1262. * of the buffer to disk and flag the buffer as empty if possible.
  1263. *
  1264. * For buffered files opened for reading or unbuffered files, this is a safe
  1265. * no-op, and will report success.
  1266. *
  1267. * \param handle handle returned from PHYSFS_open*().
  1268. * \return nonzero if successful, zero on error.
  1269. *
  1270. * \sa PHYSFS_setBuffer
  1271. * \sa PHYSFS_close
  1272. */
  1273. PHYSFS_DECL int PHYSFS_flush(PHYSFS_File *handle);
  1274. /* Byteorder stuff... */
  1275. #ifndef SWIG /* not available from scripting languages. */
  1276. /**
  1277. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1278. * \brief Swap littleendian signed 16 to platform's native byte order.
  1279. *
  1280. * Take a 16-bit signed value in littleendian 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. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1287. /**
  1288. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1289. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1290. *
  1291. * Take a 16-bit unsigned value in littleendian 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. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1298. /**
  1299. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1300. * \brief Swap littleendian signed 32 to platform's native byte order.
  1301. *
  1302. * Take a 32-bit signed value in littleendian 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. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1309. /**
  1310. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1311. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1312. *
  1313. * Take a 32-bit unsigned value in littleendian 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. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1320. /**
  1321. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1322. * \brief Swap littleendian signed 64 to platform's native byte order.
  1323. *
  1324. * Take a 64-bit signed value in littleendian format and convert it to
  1325. * the platform's native byte order.
  1326. *
  1327. * \param val value to convert
  1328. * \return converted value.
  1329. *
  1330. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1331. * any sort of 64-bit support.
  1332. */
  1333. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1334. /**
  1335. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1336. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1337. *
  1338. * Take a 64-bit unsigned value in littleendian format and convert it to
  1339. * the platform's native byte order.
  1340. *
  1341. * \param val value to convert
  1342. * \return converted value.
  1343. *
  1344. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1345. * any sort of 64-bit support.
  1346. */
  1347. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1348. /**
  1349. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1350. * \brief Swap bigendian signed 16 to platform's native byte order.
  1351. *
  1352. * Take a 16-bit signed value in bigendian format and convert it to
  1353. * the platform's native byte order.
  1354. *
  1355. * \param val value to convert
  1356. * \return converted value.
  1357. */
  1358. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1359. /**
  1360. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1361. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1362. *
  1363. * Take a 16-bit unsigned value in bigendian format and convert it to
  1364. * the platform's native byte order.
  1365. *
  1366. * \param val value to convert
  1367. * \return converted value.
  1368. */
  1369. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1370. /**
  1371. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1372. * \brief Swap bigendian signed 32 to platform's native byte order.
  1373. *
  1374. * Take a 32-bit signed value in bigendian format and convert it to
  1375. * the platform's native byte order.
  1376. *
  1377. * \param val value to convert
  1378. * \return converted value.
  1379. */
  1380. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1381. /**
  1382. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1383. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1384. *
  1385. * Take a 32-bit unsigned value in bigendian format and convert it to
  1386. * the platform's native byte order.
  1387. *
  1388. * \param val value to convert
  1389. * \return converted value.
  1390. */
  1391. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1392. /**
  1393. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1394. * \brief Swap bigendian signed 64 to platform's native byte order.
  1395. *
  1396. * Take a 64-bit signed value in bigendian format and convert it to
  1397. * the platform's native byte order.
  1398. *
  1399. * \param val value to convert
  1400. * \return converted value.
  1401. *
  1402. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1403. * any sort of 64-bit support.
  1404. */
  1405. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1406. /**
  1407. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1408. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1409. *
  1410. * Take a 64-bit unsigned value in bigendian format and convert it to
  1411. * the platform's native byte order.
  1412. *
  1413. * \param val value to convert
  1414. * \return converted value.
  1415. *
  1416. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1417. * any sort of 64-bit support.
  1418. */
  1419. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1420. #endif /* SWIG */
  1421. /**
  1422. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1423. * \brief Read and convert a signed 16-bit littleendian value.
  1424. *
  1425. * Convenience function. Read a signed 16-bit littleendian value from a
  1426. * file and convert it to the platform's native byte order.
  1427. *
  1428. * \param file PhysicsFS file handle from which to read.
  1429. * \param val pointer to where value should be stored.
  1430. * \return zero on failure, non-zero on success. If successful, (*val) will
  1431. * store the result. On failure, you can find out what went wrong
  1432. * from PHYSFS_getLastError().
  1433. */
  1434. PHYSFS_DECL int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1435. /**
  1436. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1437. * \brief Read and convert an unsigned 16-bit littleendian value.
  1438. *
  1439. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1440. * file and convert it to the platform's native byte order.
  1441. *
  1442. * \param file PhysicsFS file handle from which to read.
  1443. * \param val pointer to where value should be stored.
  1444. * \return zero on failure, non-zero on success. If successful, (*val) will
  1445. * store the result. On failure, you can find out what went wrong
  1446. * from PHYSFS_getLastError().
  1447. *
  1448. */
  1449. PHYSFS_DECL int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1450. /**
  1451. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1452. * \brief Read and convert a signed 16-bit bigendian value.
  1453. *
  1454. * Convenience function. Read a signed 16-bit bigendian value from a
  1455. * file and convert it to the platform's native byte order.
  1456. *
  1457. * \param file PhysicsFS file handle from which to read.
  1458. * \param val pointer to where value should be stored.
  1459. * \return zero on failure, non-zero on success. If successful, (*val) will
  1460. * store the result. On failure, you can find out what went wrong
  1461. * from PHYSFS_getLastError().
  1462. */
  1463. PHYSFS_DECL int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1464. /**
  1465. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1466. * \brief Read and convert an unsigned 16-bit bigendian value.
  1467. *
  1468. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1469. * file and convert it to the platform's native byte order.
  1470. *
  1471. * \param file PhysicsFS file handle from which to read.
  1472. * \param val pointer to where value should be stored.
  1473. * \return zero on failure, non-zero on success. If successful, (*val) will
  1474. * store the result. On failure, you can find out what went wrong
  1475. * from PHYSFS_getLastError().
  1476. *
  1477. */
  1478. PHYSFS_DECL int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1479. /**
  1480. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1481. * \brief Read and convert a signed 32-bit littleendian value.
  1482. *
  1483. * Convenience function. Read a signed 32-bit littleendian value from a
  1484. * file and convert it to the platform's native byte order.
  1485. *
  1486. * \param file PhysicsFS file handle from which to read.
  1487. * \param val pointer to where value should be stored.
  1488. * \return zero on failure, non-zero on success. If successful, (*val) will
  1489. * store the result. On failure, you can find out what went wrong
  1490. * from PHYSFS_getLastError().
  1491. */
  1492. PHYSFS_DECL int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1493. /**
  1494. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1495. * \brief Read and convert an unsigned 32-bit littleendian value.
  1496. *
  1497. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1498. * file and convert it to the platform's native byte order.
  1499. *
  1500. * \param file PhysicsFS file handle from which to read.
  1501. * \param val pointer to where value should be stored.
  1502. * \return zero on failure, non-zero on success. If successful, (*val) will
  1503. * store the result. On failure, you can find out what went wrong
  1504. * from PHYSFS_getLastError().
  1505. *
  1506. */
  1507. PHYSFS_DECL int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1508. /**
  1509. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1510. * \brief Read and convert a signed 32-bit bigendian value.
  1511. *
  1512. * Convenience function. Read a signed 32-bit bigendian value from a
  1513. * file and convert it to the platform's native byte order.
  1514. *
  1515. * \param file PhysicsFS file handle from which to read.
  1516. * \param val pointer to where value should be stored.
  1517. * \return zero on failure, non-zero on success. If successful, (*val) will
  1518. * store the result. On failure, you can find out what went wrong
  1519. * from PHYSFS_getLastError().
  1520. */
  1521. PHYSFS_DECL int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1522. /**
  1523. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1524. * \brief Read and convert an unsigned 32-bit bigendian value.
  1525. *
  1526. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1527. * file and convert it to the platform's native byte order.
  1528. *
  1529. * \param file PhysicsFS file handle from which to read.
  1530. * \param val pointer to where value should be stored.
  1531. * \return zero on failure, non-zero on success. If successful, (*val) will
  1532. * store the result. On failure, you can find out what went wrong
  1533. * from PHYSFS_getLastError().
  1534. *
  1535. */
  1536. PHYSFS_DECL int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1537. /**
  1538. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1539. * \brief Read and convert a signed 64-bit littleendian value.
  1540. *
  1541. * Convenience function. Read a signed 64-bit littleendian value from a
  1542. * file and convert it to the platform's native byte order.
  1543. *
  1544. * \param file PhysicsFS file handle from which to read.
  1545. * \param val pointer to where value should be stored.
  1546. * \return zero on failure, non-zero on success. If successful, (*val) will
  1547. * store the result. On failure, you can find out what went wrong
  1548. * from PHYSFS_getLastError().
  1549. *
  1550. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1551. * any sort of 64-bit support.
  1552. */
  1553. PHYSFS_DECL int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1554. /**
  1555. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1556. * \brief Read and convert an unsigned 64-bit littleendian value.
  1557. *
  1558. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1559. * file and convert it to the platform's native byte order.
  1560. *
  1561. * \param file PhysicsFS file handle from which to read.
  1562. * \param val pointer to where value should be stored.
  1563. * \return zero on failure, non-zero on success. If successful, (*val) will
  1564. * store the result. On failure, you can find out what went wrong
  1565. * from PHYSFS_getLastError().
  1566. *
  1567. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1568. * any sort of 64-bit support.
  1569. */
  1570. PHYSFS_DECL int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1571. /**
  1572. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1573. * \brief Read and convert a signed 64-bit bigendian value.
  1574. *
  1575. * Convenience function. Read a signed 64-bit bigendian value from a
  1576. * file and convert it to the platform's native byte order.
  1577. *
  1578. * \param file PhysicsFS file handle from which to read.
  1579. * \param val pointer to where value should be stored.
  1580. * \return zero on failure, non-zero on success. If successful, (*val) will
  1581. * store the result. On failure, you can find out what went wrong
  1582. * from PHYSFS_getLastError().
  1583. *
  1584. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1585. * any sort of 64-bit support.
  1586. */
  1587. PHYSFS_DECL int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1588. /**
  1589. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1590. * \brief Read and convert an unsigned 64-bit bigendian value.
  1591. *
  1592. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1593. * file and convert it to the platform's native byte order.
  1594. *
  1595. * \param file PhysicsFS file handle from which to read.
  1596. * \param val pointer to where value should be stored.
  1597. * \return zero on failure, non-zero on success. If successful, (*val) will
  1598. * store the result. On failure, you can find out what went wrong
  1599. * from PHYSFS_getLastError().
  1600. *
  1601. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1602. * any sort of 64-bit support.
  1603. */
  1604. PHYSFS_DECL int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1605. /**
  1606. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1607. * \brief Convert and write a signed 16-bit littleendian value.
  1608. *
  1609. * Convenience function. Convert a signed 16-bit value from the platform's
  1610. * native byte order to littleendian and write it to a file.
  1611. *
  1612. * \param file PhysicsFS file handle to which to write.
  1613. * \param val Value to convert and write.
  1614. * \return zero on failure, non-zero on success. On failure, you can
  1615. * find out what went wrong from PHYSFS_getLastError().
  1616. */
  1617. PHYSFS_DECL int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1618. /**
  1619. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1620. * \brief Convert and write an unsigned 16-bit littleendian value.
  1621. *
  1622. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1623. * native byte order to littleendian and write it to a file.
  1624. *
  1625. * \param file PhysicsFS file handle to which to write.
  1626. * \param val Value to convert and write.
  1627. * \return zero on failure, non-zero on success. On failure, you can
  1628. * find out what went wrong from PHYSFS_getLastError().
  1629. */
  1630. PHYSFS_DECL int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1631. /**
  1632. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1633. * \brief Convert and write a signed 16-bit bigendian value.
  1634. *
  1635. * Convenience function. Convert a signed 16-bit value from the platform's
  1636. * native byte order to bigendian and write it to a file.
  1637. *
  1638. * \param file PhysicsFS file handle to which to write.
  1639. * \param val Value to convert and write.
  1640. * \return zero on failure, non-zero on success. On failure, you can
  1641. * find out what went wrong from PHYSFS_getLastError().
  1642. */
  1643. PHYSFS_DECL int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1644. /**
  1645. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1646. * \brief Convert and write an unsigned 16-bit bigendian value.
  1647. *
  1648. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1649. * native byte order to bigendian and write it to a file.
  1650. *
  1651. * \param file PhysicsFS file handle to which to write.
  1652. * \param val Value to convert and write.
  1653. * \return zero on failure, non-zero on success. On failure, you can
  1654. * find out what went wrong from PHYSFS_getLastError().
  1655. */
  1656. PHYSFS_DECL int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1657. /**
  1658. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1659. * \brief Convert and write a signed 32-bit littleendian value.
  1660. *
  1661. * Convenience function. Convert a signed 32-bit value from the platform's
  1662. * native byte order to littleendian 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. PHYSFS_DECL int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1670. /**
  1671. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1672. * \brief Convert and write an unsigned 32-bit littleendian value.
  1673. *
  1674. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1675. * native byte order to littleendian and write it to a file.
  1676. *
  1677. * \param file PhysicsFS file handle to which to write.
  1678. * \param val Value to convert and write.
  1679. * \return zero on failure, non-zero on success. On failure, you can
  1680. * find out what went wrong from PHYSFS_getLastError().
  1681. */
  1682. PHYSFS_DECL int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1683. /**
  1684. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1685. * \brief Convert and write a signed 32-bit bigendian value.
  1686. *
  1687. * Convenience function. Convert a signed 32-bit value from the platform's
  1688. * native byte order to bigendian and write it to a file.
  1689. *
  1690. * \param file PhysicsFS file handle to which to write.
  1691. * \param val Value to convert and write.
  1692. * \return zero on failure, non-zero on success. On failure, you can
  1693. * find out what went wrong from PHYSFS_getLastError().
  1694. */
  1695. PHYSFS_DECL int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1696. /**
  1697. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1698. * \brief Convert and write an unsigned 32-bit bigendian value.
  1699. *
  1700. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1701. * native byte order to bigendian and write it to a file.
  1702. *
  1703. * \param file PhysicsFS file handle to which to write.
  1704. * \param val Value to convert and write.
  1705. * \return zero on failure, non-zero on success. On failure, you can
  1706. * find out what went wrong from PHYSFS_getLastError().
  1707. */
  1708. PHYSFS_DECL int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1709. /**
  1710. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1711. * \brief Convert and write a signed 64-bit littleendian value.
  1712. *
  1713. * Convenience function. Convert a signed 64-bit value from the platform's
  1714. * native byte order to littleendian and write it to a file.
  1715. *
  1716. * \param file PhysicsFS file handle to which to write.
  1717. * \param val Value to convert and write.
  1718. * \return zero on failure, non-zero on success. On failure, you can
  1719. * find out what went wrong from PHYSFS_getLastError().
  1720. *
  1721. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1722. * any sort of 64-bit support.
  1723. */
  1724. PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1725. /**
  1726. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1727. * \brief Convert and write an unsigned 64-bit littleendian value.
  1728. *
  1729. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1730. * native byte order to littleendian and write it to a file.
  1731. *
  1732. * \param file PhysicsFS file handle to which to write.
  1733. * \param val Value to convert and write.
  1734. * \return zero on failure, non-zero on success. On failure, you can
  1735. * find out what went wrong from PHYSFS_getLastError().
  1736. *
  1737. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1738. * any sort of 64-bit support.
  1739. */
  1740. PHYSFS_DECL int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1741. /**
  1742. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1743. * \brief Convert and write a signed 64-bit bigending value.
  1744. *
  1745. * Convenience function. Convert a signed 64-bit value from the platform's
  1746. * native byte order to bigendian and write it to a file.
  1747. *
  1748. * \param file PhysicsFS file handle to which to write.
  1749. * \param val Value to convert and write.
  1750. * \return zero on failure, non-zero on success. On failure, you can
  1751. * find out what went wrong from PHYSFS_getLastError().
  1752. *
  1753. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1754. * any sort of 64-bit support.
  1755. */
  1756. PHYSFS_DECL int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1757. /**
  1758. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1759. * \brief Convert and write an unsigned 64-bit bigendian value.
  1760. *
  1761. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1762. * native byte order to bigendian and write it to a file.
  1763. *
  1764. * \param file PhysicsFS file handle to which to write.
  1765. * \param val Value to convert and write.
  1766. * \return zero on failure, non-zero on success. On failure, you can
  1767. * find out what went wrong from PHYSFS_getLastError().
  1768. *
  1769. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1770. * any sort of 64-bit support.
  1771. */
  1772. PHYSFS_DECL int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1773. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1774. /**
  1775. * \fn int PHYSFS_isInit(void)
  1776. * \brief Determine if the PhysicsFS library is initialized.
  1777. *
  1778. * Once PHYSFS_init() returns successfully, this will return non-zero.
  1779. * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns
  1780. * successfully, this will return zero. This function is safe to call at
  1781. * any time.
  1782. *
  1783. * \return non-zero if library is initialized, zero if library is not.
  1784. *
  1785. * \sa PHYSFS_init
  1786. * \sa PHYSFS_deinit
  1787. */
  1788. PHYSFS_DECL int PHYSFS_isInit(void);
  1789. /**
  1790. * \fn int PHYSFS_symbolicLinksPermitted(void)
  1791. * \brief Determine if the symbolic links are permitted.
  1792. *
  1793. * This reports the setting from the last call to PHYSFS_permitSymbolicLinks().
  1794. * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was
  1795. * last initialized, symbolic links are implicitly disabled.
  1796. *
  1797. * \return non-zero if symlinks are permitted, zero if not.
  1798. *
  1799. * \sa PHYSFS_permitSymbolicLinks
  1800. */
  1801. PHYSFS_DECL int PHYSFS_symbolicLinksPermitted(void);
  1802. #ifndef SWIG /* not available from scripting languages. */
  1803. /**
  1804. * \struct PHYSFS_Allocator
  1805. * \brief PhysicsFS allocation function pointers.
  1806. *
  1807. * (This is for limited, hardcore use. If you don't immediately see a need
  1808. * for it, you can probably ignore this forever.)
  1809. *
  1810. * You create one of these structures for use with PHYSFS_setAllocator.
  1811. * Allocators are assumed to be reentrant by the caller; please mutex
  1812. * accordingly.
  1813. *
  1814. * Allocations are always discussed in 64-bits, for future expansion...we're
  1815. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1816. * gigabytes like it's nothing sooner or later, and I don't want to change
  1817. * this again at that point. If you're on a 32-bit platform and have to
  1818. * downcast, it's okay to return NULL if the allocation is greater than
  1819. * 4 gigabytes, since you'd have to do so anyhow.
  1820. *
  1821. * \sa PHYSFS_setAllocator
  1822. */
  1823. typedef struct PHYSFS_Allocator
  1824. {
  1825. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1826. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1827. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1828. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1829. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1830. } PHYSFS_Allocator;
  1831. /**
  1832. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1833. * \brief Hook your own allocation routines into PhysicsFS.
  1834. *
  1835. * (This is for limited, hardcore use. If you don't immediately see a need
  1836. * for it, you can probably ignore this forever.)
  1837. *
  1838. * By default, PhysicsFS will use whatever is reasonable for a platform
  1839. * to manage dynamic memory (usually ANSI C malloc/realloc/calloc/free, but
  1840. * some platforms might use something else), but in some uncommon cases, the
  1841. * app might want more control over the library's memory management. This
  1842. * lets you redirect PhysicsFS to use your own allocation routines instead.
  1843. * You can only call this function before PHYSFS_init(); if the library is
  1844. * initialized, it'll reject your efforts to change the allocator mid-stream.
  1845. * You may call this function after PHYSFS_deinit() if you are willing to
  1846. * shut down the library and restart it with a new allocator; this is a safe
  1847. * and supported operation. The allocator remains intact between deinit/init
  1848. * calls. If you want to return to the platform's default allocator, pass a
  1849. * NULL in here.
  1850. *
  1851. * If you aren't immediately sure what to do with this function, you can
  1852. * safely ignore it altogether.
  1853. *
  1854. * \param allocator Structure containing your allocator's entry points.
  1855. * \return zero on failure, non-zero on success. This call only fails
  1856. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1857. */
  1858. PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1859. #endif /* SWIG */
  1860. /**
  1861. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
  1862. * \brief Add an archive or directory to the search path.
  1863. *
  1864. * If this is a duplicate, the entry is not added again, even though the
  1865. * function succeeds. You may not add the same archive to two different
  1866. * mountpoints: duplicate checking is done against the archive and not the
  1867. * mountpoint.
  1868. *
  1869. * When you mount an archive, it is added to a virtual file system...all files
  1870. * in all of the archives are interpolated into a single hierachical file
  1871. * tree. Two archives mounted at the same place (or an archive with files
  1872. * overlapping another mountpoint) may have overlapping files: in such a case,
  1873. * the file earliest in the search path is selected, and the other files are
  1874. * inaccessible to the application. This allows archives to be used to
  1875. * override previous revisions; you can use the mounting mechanism to place
  1876. * archives at a specific point in the file tree and prevent overlap; this
  1877. * is useful for downloadable mods that might trample over application data
  1878. * or each other, for example.
  1879. *
  1880. * The mountpoint does not need to exist prior to mounting, which is different
  1881. * than those familiar with the Unix concept of "mounting" may not expect.
  1882. * As well, more than one archive can be mounted to the same mountpoint, or
  1883. * mountpoints and archive contents can overlap...the interpolation mechanism
  1884. * still functions as usual.
  1885. *
  1886. * \param newDir directory or archive to add to the path, in
  1887. * platform-dependent notation.
  1888. * \param mountPoint Location in the interpolated tree that this archive
  1889. * will be "mounted", in platform-independent notation.
  1890. * NULL or "" is equivalent to "/".
  1891. * \param appendToPath nonzero to append to search path, zero to prepend.
  1892. * \return nonzero if added to path, zero on failure (bogus archive, dir
  1893. * missing, etc). Specifics of the error can be
  1894. * gleaned from PHYSFS_getLastError().
  1895. *
  1896. * \sa PHYSFS_removeFromSearchPath
  1897. * \sa PHYSFS_getSearchPath
  1898. * \sa PHYSFS_getMountPoint
  1899. */
  1900. PHYSFS_DECL int PHYSFS_mount(const char *newDir,
  1901. const char *mountPoint,
  1902. int appendToPath);
  1903. /**
  1904. * \fn int PHYSFS_getMountPoint(const char *dir)
  1905. * \brief Determine a mounted archive's mountpoint.
  1906. *
  1907. * You give this function the name of an archive or dir you successfully
  1908. * added to the search path, and it reports the location in the interpolated
  1909. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  1910. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  1911. * and valid until the archive is removed from the search path.
  1912. *
  1913. * \param dir directory or archive previously added to the path, in
  1914. * platform-dependent notation. This must match the string
  1915. * used when adding, even if your string would also reference
  1916. * the same file with a different string of characters.
  1917. * \return READ-ONLY string of mount point if added to path, NULL on failure
  1918. * (bogus archive, etc) Specifics of the error can be gleaned from
  1919. * PHYSFS_getLastError().
  1920. *
  1921. * \sa PHYSFS_removeFromSearchPath
  1922. * \sa PHYSFS_getSearchPath
  1923. * \sa PHYSFS_getMountPoint
  1924. */
  1925. PHYSFS_DECL const char *PHYSFS_getMountPoint(const char *dir);
  1926. #ifndef SWIG /* not available from scripting languages. */
  1927. /**
  1928. * \typedef PHYSFS_StringCallback
  1929. * \brief Function signature for callbacks that report strings.
  1930. *
  1931. * These are used to report a list of strings to an original caller, one
  1932. * string per callback. All strings are UTF-8 encoded. Functions should not
  1933. * try to modify or free the string's memory.
  1934. *
  1935. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  1936. * functions that would return lists that need to be cleaned up with
  1937. * PHYSFS_freeList(). The callback means that the library doesn't need to
  1938. * allocate an entire list and all the strings up front.
  1939. *
  1940. * Be aware that promises data ordering in the list versions are not
  1941. * necessarily so in the callback versions. Check the documentation on
  1942. * specific APIs, but strings may not be sorted as you expect.
  1943. *
  1944. * \param data User-defined data pointer, passed through from the API
  1945. * that eventually called the callback.
  1946. * \param str The string data about which the callback is meant to inform.
  1947. *
  1948. * \sa PHYSFS_getCdRomDirsCallback
  1949. * \sa PHYSFS_getSearchPathCallback
  1950. */
  1951. typedef void (*PHYSFS_StringCallback)(void *data, const char *str);
  1952. /**
  1953. * \typedef PHYSFS_EnumFilesCallback
  1954. * \brief Function signature for callbacks that enumerate files.
  1955. *
  1956. * These are used to report a list of directory entries to an original caller,
  1957. * one file/dir/symlink per callback. All strings are UTF-8 encoded.
  1958. * Functions should not try to modify or free any string's memory.
  1959. *
  1960. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  1961. * functions that would return lists that need to be cleaned up with
  1962. * PHYSFS_freeList(). The callback means that the library doesn't need to
  1963. * allocate an entire list and all the strings up front.
  1964. *
  1965. * Be aware that promises data ordering in the list versions are not
  1966. * necessarily so in the callback versions. Check the documentation on
  1967. * specific APIs, but strings may not be sorted as you expect.
  1968. *
  1969. * \param data User-defined data pointer, passed through from the API
  1970. * that eventually called the callback.
  1971. * \param origdir A string containing the full path, in platform-independent
  1972. * notation, of the directory containing this file. In most
  1973. * cases, this is the directory on which you requested
  1974. * enumeration, passed in the callback for your convenience.
  1975. * \param fname The filename that is being enumerated. It may not be in
  1976. * alphabetical order compared to other callbacks that have
  1977. * fired, and it will not contain the full path. You can
  1978. * recreate the fullpath with $origdir/$fname ... The file
  1979. * can be a subdirectory, a file, a symlink, etc.
  1980. *
  1981. * \sa PHYSFS_enumerateFilesCallback
  1982. */
  1983. typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir,
  1984. const char *fname);
  1985. /**
  1986. * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d)
  1987. * \brief Enumerate CD-ROM directories, using an application-defined callback.
  1988. *
  1989. * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds
  1990. * a list before returning to the application, so functionality is identical
  1991. * except for how the information is represented to the application.
  1992. *
  1993. * Unlike PHYSFS_getCdRomDirs(), this function does not return an array.
  1994. * Rather, it calls a function specified by the application once per
  1995. * detected disc:
  1996. *
  1997. * \code
  1998. *
  1999. * static void foundDisc(void *data, const char *cddir)
  2000. * {
  2001. * printf("cdrom dir [%s] is available.\n", cddir);
  2002. * }
  2003. *
  2004. * // ...
  2005. * PHYSFS_getCdRomDirsCallback(foundDisc, NULL);
  2006. * \endcode
  2007. *
  2008. * This call may block while drives spin up. Be forewarned.
  2009. *
  2010. * \param c Callback function to notify about detected drives.
  2011. * \param d Application-defined data passed to callback. Can be NULL.
  2012. *
  2013. * \sa PHYSFS_StringCallback
  2014. * \sa PHYSFS_getCdRomDirs
  2015. */
  2016. PHYSFS_DECL void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  2017. /**
  2018. * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d)
  2019. * \brief Enumerate the search path, using an application-defined callback.
  2020. *
  2021. * Internally, PHYSFS_getSearchPath() just calls this function and then builds
  2022. * a list before returning to the application, so functionality is identical
  2023. * except for how the information is represented to the application.
  2024. *
  2025. * Unlike PHYSFS_getSearchPath(), this function does not return an array.
  2026. * Rather, it calls a function specified by the application once per
  2027. * element of the search path:
  2028. *
  2029. * \code
  2030. *
  2031. * static void printSearchPath(void *data, const char *pathItem)
  2032. * {
  2033. * printf("[%s] is in the search path.\n", pathItem);
  2034. * }
  2035. *
  2036. * // ...
  2037. * PHYSFS_getSearchPathCallback(printSearchPath, NULL);
  2038. * \endcode
  2039. *
  2040. * Elements of the search path are reported in order search priority, so the
  2041. * first archive/dir that would be examined when looking for a file is the
  2042. * first element passed through the callback.
  2043. *
  2044. * \param c Callback function to notify about search path elements.
  2045. * \param d Application-defined data passed to callback. Can be NULL.
  2046. *
  2047. * \sa PHYSFS_StringCallback
  2048. * \sa PHYSFS_getSearchPath
  2049. */
  2050. PHYSFS_DECL void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  2051. /**
  2052. * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d)
  2053. * \brief Get a file listing of a search path's directory, using an application-defined callback.
  2054. *
  2055. * Internally, PHYSFS_enumerateFiles() just calls this function and then builds
  2056. * a list before returning to the application, so functionality is identical
  2057. * except for how the information is represented to the application.
  2058. *
  2059. * Unlike PHYSFS_enumerateFiles(), this function does not return an array.
  2060. * Rather, it calls a function specified by the application once per
  2061. * element of the search path:
  2062. *
  2063. * \code
  2064. *
  2065. * static void printDir(void *data, const char *origdir, const char *fname)
  2066. * {
  2067. * printf(" * We've got [%s] in [%s].\n", fname, origdir);
  2068. * }
  2069. *
  2070. * // ...
  2071. * PHYSFS_enumerateFilesCallback("/some/path", printDir, NULL);
  2072. * \endcode
  2073. *
  2074. * !!! FIXME: enumerateFiles() does not promise alphabetical sorting by
  2075. * !!! FIXME: case-sensitivity in the code, and doesn't promise sorting at
  2076. * !!! FIXME: all in the above docs.
  2077. *
  2078. * Items sent to the callback are not guaranteed to be in any order whatsoever.
  2079. * There is no sorting done at this level, and if you need that, you should
  2080. * probably use PHYSFS_enumerateFiles() instead, which guarantees
  2081. * alphabetical sorting. This form reports whatever is discovered in each
  2082. * archive before moving on to the next. Even within one archive, we can't
  2083. * guarantee what order it will discover data. <em>Any sorting you find in
  2084. * these callbacks is just pure luck. Do not rely on it.</em> As this walks
  2085. * the entire list of archives, you may receive duplicate filenames.
  2086. *
  2087. * \param dir Directory, in platform-independent notation, to enumerate.
  2088. * \param c Callback function to notify about search path elements.
  2089. * \param d Application-defined data passed to callback. Can be NULL.
  2090. *
  2091. * \sa PHYSFS_EnumFilesCallback
  2092. * \sa PHYSFS_enumerateFiles
  2093. */
  2094. PHYSFS_DECL void PHYSFS_enumerateFilesCallback(const char *dir,
  2095. PHYSFS_EnumFilesCallback c,
  2096. void *d);
  2097. /**
  2098. * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
  2099. * \brief Convert a UCS-4 string to a UTF-8 string.
  2100. *
  2101. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2102. *
  2103. * To ensure that the destination buffer is large enough for the conversion,
  2104. * please allocate a buffer that is the same size as the source buffer. UTF-8
  2105. * never uses more than 32-bits per character, so while it may shrink a UCS-4
  2106. * string, it will never expand it.
  2107. *
  2108. * Strings that don't fit in the destination buffer will be truncated, but
  2109. * will always be null-terminated and never have an incomplete UTF-8
  2110. * sequence at the end.
  2111. *
  2112. * \param src Null-terminated source string in UCS-4 format.
  2113. * \param dst Buffer to store converted UTF-8 string.
  2114. * \param len Size, in bytes, of destination buffer.
  2115. */
  2116. PHYSFS_DECL void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst,
  2117. PHYSFS_uint64 len);
  2118. /**
  2119. * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
  2120. * \brief Convert a UTF-8 string to a UCS-4 string.
  2121. *
  2122. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2123. *
  2124. * To ensure that the destination buffer is large enough for the conversion,
  2125. * please allocate a buffer that is four times the size of the source buffer.
  2126. * UTF-8 uses from one to four bytes per character, but UCS-4 always uses
  2127. * four, so an entirely low-ASCII string will quadruple in size!
  2128. *
  2129. * Strings that don't fit in the destination buffer will be truncated, but
  2130. * will always be null-terminated and never have an incomplete UCS-4
  2131. * sequence at the end.
  2132. *
  2133. * \param src Null-terminated source string in UTF-8 format.
  2134. * \param dst Buffer to store converted UCS-4 string.
  2135. * \param len Size, in bytes, of destination buffer.
  2136. */
  2137. PHYSFS_DECL void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst,
  2138. PHYSFS_uint64 len);
  2139. /**
  2140. * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2141. * \brief Convert a UCS-2 string to a UTF-8 string.
  2142. *
  2143. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2144. * with Unicode support.
  2145. *
  2146. * To ensure that the destination buffer is large enough for the conversion,
  2147. * please allocate a buffer that is double the size of the source buffer.
  2148. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2149. * a UCS-2 string, it may also expand it.
  2150. *
  2151. * Strings that don't fit in the destination buffer will be truncated, but
  2152. * will always be null-terminated and never have an incomplete UTF-8
  2153. * sequence at the end.
  2154. *
  2155. * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  2156. * values at this time.
  2157. *
  2158. * \param src Null-terminated source string in UCS-2 format.
  2159. * \param dst Buffer to store converted UTF-8 string.
  2160. * \param len Size, in bytes, of destination buffer.
  2161. */
  2162. PHYSFS_DECL void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst,
  2163. PHYSFS_uint64 len);
  2164. /**
  2165. * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2166. * \brief Convert a UTF-8 string to a UCS-2 string.
  2167. *
  2168. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2169. * with Unicode support.
  2170. *
  2171. * To ensure that the destination buffer is large enough for the conversion,
  2172. * please allocate a buffer that is double the size of the source buffer.
  2173. * UTF-8 uses from one to four bytes per character, but UCS-2 always uses
  2174. * two, so an entirely low-ASCII string will double in size!
  2175. *
  2176. * Strings that don't fit in the destination buffer will be truncated, but
  2177. * will always be null-terminated and never have an incomplete UCS-2
  2178. * sequence at the end.
  2179. *
  2180. * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  2181. * values at this time.
  2182. *
  2183. * \param src Null-terminated source string in UTF-8 format.
  2184. * \param dst Buffer to store converted UCS-2 string.
  2185. * \param len Size, in bytes, of destination buffer.
  2186. */
  2187. PHYSFS_DECL void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst,
  2188. PHYSFS_uint64 len);
  2189. /**
  2190. * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
  2191. * \brief Convert a UTF-8 string to a Latin1 string.
  2192. *
  2193. * Latin1 strings are 8-bits per character: a popular "high ASCII"
  2194. * encoding.
  2195. *
  2196. * To ensure that the destination buffer is large enough for the conversion,
  2197. * please allocate a buffer that is double the size of the source buffer.
  2198. * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string
  2199. * may grow in some cases.
  2200. *
  2201. * Strings that don't fit in the destination buffer will be truncated, but
  2202. * will always be null-terminated and never have an incomplete UTF-8
  2203. * sequence at the end.
  2204. *
  2205. * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  2206. * can't express most Unicode codepoints. It's a legacy encoding; you should
  2207. * be converting away from it at all times.
  2208. *
  2209. * \param src Null-terminated source string in Latin1 format.
  2210. * \param dst Buffer to store converted UTF-8 string.
  2211. * \param len Size, in bytes, of destination buffer.
  2212. */
  2213. PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst,
  2214. PHYSFS_uint64 len);
  2215. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  2216. /**
  2217. * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void)
  2218. * \brief Discover the current allocator.
  2219. *
  2220. * (This is for limited, hardcore use. If you don't immediately see a need
  2221. * for it, you can probably ignore this forever.)
  2222. *
  2223. * This function exposes the function pointers that make up the currently used
  2224. * allocator. This can be useful for apps that want to access PhysicsFS's
  2225. * internal, default allocation routines, as well as for external code that
  2226. * wants to share the same allocator, even if the application specified their
  2227. * own.
  2228. *
  2229. * This call is only valid between PHYSFS_init() and PHYSFS_deinit() calls;
  2230. * it will return NULL if the library isn't initialized. As we can't
  2231. * guarantee the state of the internal allocators unless the library is
  2232. * initialized, you shouldn't use any allocator returned here after a call
  2233. * to PHYSFS_deinit().
  2234. *
  2235. * Do not call the returned allocator's Init() or Deinit() methods under any
  2236. * circumstances.
  2237. *
  2238. * If you aren't immediately sure what to do with this function, you can
  2239. * safely ignore it altogether.
  2240. *
  2241. * \return Current allocator, as set by PHYSFS_setAllocator(), or PhysicsFS's
  2242. * internal, default allocator if no application defined allocator
  2243. * is currently set. Will return NULL if the library is not
  2244. * initialized.
  2245. *
  2246. * \sa PHYSFS_Allocator
  2247. * \sa PHYSFS_setAllocator
  2248. */
  2249. PHYSFS_DECL const PHYSFS_Allocator *PHYSFS_getAllocator(void);
  2250. #endif /* SWIG */
  2251. /**
  2252. * \enum PHYSFS_FileType
  2253. * \brief Type of a File
  2254. *
  2255. * Possible types of a file.
  2256. *
  2257. * \sa PHYSFS_stat
  2258. */
  2259. typedef enum PHYSFS_FileType
  2260. {
  2261. PHYSFS_FILETYPE_REGULAR, /**< a normal file */
  2262. PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
  2263. PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
  2264. PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
  2265. } PHYSFS_FileType;
  2266. /**
  2267. * \struct PHYSFS_Stat
  2268. * \brief Meta data for a file or directory
  2269. *
  2270. * Container for various meta data about a file in the virtual file system.
  2271. * PHYSFS_stat() uses this structure for returning the information. The time
  2272. * data will be either a real timestamp or \-1 if there is none. So every value
  2273. * is at least epoch. The FileSize is only valid for real files. And the
  2274. * readonly tells you whether when you open a file for writing you are writing
  2275. * to the same file as if you were opening it, given you have enough
  2276. * filesystem rights to do that.
  2277. *
  2278. * \sa PHYSFS_stat
  2279. * \sa PHYSFS_FileType
  2280. */
  2281. typedef struct PHYSFS_Stat
  2282. {
  2283. PHYSFS_sint64 filesize; /**< size in bytes, \-1 for non-files and unknown */
  2284. PHYSFS_sint64 modtime; /**< same value as PHYSFS_getLastModTime() */
  2285. PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
  2286. PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
  2287. PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
  2288. int readonly; /**< non-zero if read only, zero if writable. */
  2289. } PHYSFS_Stat;
  2290. /**
  2291. * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
  2292. * \brief Get various information about a directory or a file.
  2293. *
  2294. * Obtain various information about a file or directory from the meta data.
  2295. *
  2296. * \param fname filename to check, in platform-indepedent notation.
  2297. * \param stat pointer to structure to fill in with data about (fname).
  2298. * \return 0 on success, non-zero on error.
  2299. *
  2300. * \sa PHYSFS_Stat
  2301. */
  2302. PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
  2303. /* Everything above this line is part of the PhysicsFS 2.1 API. */
  2304. #ifdef __cplusplus
  2305. }
  2306. #endif
  2307. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  2308. /* end of physfs.h ... */