physfs.h 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324
  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_getPrefDir() 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 before Win2000 and build with Unicode
  168. * support, your TCHAR strings are two bytes per character (this is called
  169. * "UCS-2 encoding"). Any modern Windows uses UTF-16, which is two bytes
  170. * per character for most characters, but some characters are four. You
  171. * should convert them to UTF-8 before handing them to PhysicsFS with
  172. * PHYSFS_utf8FromUtf16(), which handles both UTF-16 and UCS-2. If you're
  173. * using Unix or Mac OS X, your wchar_t strings are four bytes per character
  174. * ("UCS-4 encoding"). Use PHYSFS_utf8FromUcs4(). Mac OS X can give you UTF-8
  175. * directly from a CFString or NSString, and many Unixes generally give you C
  176. * strings in UTF-8 format everywhere. If you have a single-byte high ASCII
  177. * charset, like so-many European "codepages" you may be out of luck. We'll
  178. * convert from "Latin1" to UTF-8 only, and never back to Latin1. If you're
  179. * above ASCII 127, all bets are off: move to Unicode or use your platform's
  180. * facilities. Passing a C string with high-ASCII data that isn't UTF-8
  181. * encoded will NOT do what you expect!
  182. *
  183. * Naturally, there's also PHYSFS_utf8ToUcs2(), PHYSFS_utf8ToUtf16(), and
  184. * PHYSFS_utf8ToUcs4() to get data back into a format you like. Behind the
  185. * scenes, PhysicsFS will use Unicode where possible: the UTF-8 strings on
  186. * Windows will be converted and used with the multibyte Windows APIs, for
  187. * example.
  188. *
  189. * PhysicsFS offers basic encoding conversion support, but not a whole string
  190. * library. Get your stuff into whatever format you can work with.
  191. *
  192. * All platforms supported by PhysicsFS 2.1 and later fully support Unicode.
  193. * We have dropped platforms that don't (OS/2, Mac OS 9, Windows 95, etc), as
  194. * even an OS that's over a decade old should be expected to handle this well.
  195. * If you absolutely must support one of these platforms, you should use an
  196. * older release of PhysicsFS.
  197. *
  198. * Many game-specific archivers are seriously unprepared for Unicode (the
  199. * Descent HOG/MVL and Build Engine GRP archivers, for example, only offer a
  200. * DOS 8.3 filename, for example). Nothing can be done for these, but they
  201. * tend to be legacy formats for existing content that was all ASCII (and
  202. * thus, valid UTF-8) anyhow. Other formats, like .ZIP, don't explicitly
  203. * offer Unicode support, but unofficially expect filenames to be UTF-8
  204. * encoded, and thus Just Work. Most everything does the right thing without
  205. * bothering you, but it's good to be aware of these nuances in case they
  206. * don't.
  207. *
  208. *
  209. * Other stuff:
  210. *
  211. * Please see the file LICENSE.txt in the source's root directory for
  212. * licensing and redistribution rights.
  213. *
  214. * Please see the file CREDITS.txt in the source's "docs" directory for
  215. * a more or less complete list of who's responsible for this.
  216. *
  217. * \author Ryan C. Gordon.
  218. */
  219. #ifndef _INCLUDE_PHYSFS_H_
  220. #define _INCLUDE_PHYSFS_H_
  221. #ifdef __cplusplus
  222. extern "C" {
  223. #endif
  224. #if defined(PHYSFS_DECL)
  225. /* do nothing. */
  226. #elif (defined SWIG)
  227. #define PHYSFS_DECL extern
  228. #elif (defined _MSC_VER)
  229. #define PHYSFS_DECL __declspec(dllexport)
  230. #elif (defined __SUNPRO_C)
  231. #define PHYSFS_DECL __global
  232. #elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun))
  233. #define PHYSFS_DECL __attribute__((visibility("default")))
  234. #else
  235. #define PHYSFS_DECL
  236. #endif
  237. #if defined(PHYSFS_DEPRECATED)
  238. /* do nothing. */
  239. #elif (defined SWIG) /* ignore deprecated, since bindings use everything. */
  240. #define PHYSFS_DEPRECATED
  241. #elif (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
  242. #define PHYSFS_DEPRECATED __attribute__((deprecated))
  243. #else
  244. #define PHYSFS_DEPRECATED
  245. #endif
  246. #if 0 /* !!! FIXME: look into this later. */
  247. #if defined(PHYSFS_CALL)
  248. /* do nothing. */
  249. #elif defined(__WIN32__) && !defined(__GNUC__)
  250. #define PHYSFS_CALL __cdecl
  251. #else
  252. #define PHYSFS_CALL
  253. #endif
  254. #endif
  255. /**
  256. * \typedef PHYSFS_uint8
  257. * \brief An unsigned, 8-bit integer type.
  258. */
  259. typedef unsigned char PHYSFS_uint8;
  260. /**
  261. * \typedef PHYSFS_sint8
  262. * \brief A signed, 8-bit integer type.
  263. */
  264. typedef signed char PHYSFS_sint8;
  265. /**
  266. * \typedef PHYSFS_uint16
  267. * \brief An unsigned, 16-bit integer type.
  268. */
  269. typedef unsigned short PHYSFS_uint16;
  270. /**
  271. * \typedef PHYSFS_sint16
  272. * \brief A signed, 16-bit integer type.
  273. */
  274. typedef signed short PHYSFS_sint16;
  275. /**
  276. * \typedef PHYSFS_uint32
  277. * \brief An unsigned, 32-bit integer type.
  278. */
  279. typedef unsigned int PHYSFS_uint32;
  280. /**
  281. * \typedef PHYSFS_sint32
  282. * \brief A signed, 32-bit integer type.
  283. */
  284. typedef signed int PHYSFS_sint32;
  285. /**
  286. * \typedef PHYSFS_uint64
  287. * \brief An unsigned, 64-bit integer type.
  288. * \warning on platforms without any sort of 64-bit datatype, this is
  289. * equivalent to PHYSFS_uint32!
  290. */
  291. /**
  292. * \typedef PHYSFS_sint64
  293. * \brief A signed, 64-bit integer type.
  294. * \warning on platforms without any sort of 64-bit datatype, this is
  295. * equivalent to PHYSFS_sint32!
  296. */
  297. #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */
  298. typedef PHYSFS_uint32 PHYSFS_uint64;
  299. typedef PHYSFS_sint32 PHYSFS_sint64;
  300. #elif (defined _MSC_VER)
  301. typedef signed __int64 PHYSFS_sint64;
  302. typedef unsigned __int64 PHYSFS_uint64;
  303. #else
  304. typedef unsigned long long PHYSFS_uint64;
  305. typedef signed long long PHYSFS_sint64;
  306. #endif
  307. #ifndef SWIG
  308. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  309. /* Make sure the types really have the right sizes */
  310. #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \
  311. typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1]
  312. PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1);
  313. PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1);
  314. PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2);
  315. PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2);
  316. PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4);
  317. PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4);
  318. #ifndef PHYSFS_NO_64BIT_SUPPORT
  319. PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8);
  320. PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8);
  321. #endif
  322. #undef PHYSFS_COMPILE_TIME_ASSERT
  323. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  324. #endif /* SWIG */
  325. /**
  326. * \struct PHYSFS_File
  327. * \brief A PhysicsFS file handle.
  328. *
  329. * You get a pointer to one of these when you open a file for reading,
  330. * writing, or appending via PhysicsFS.
  331. *
  332. * As you can see from the lack of meaningful fields, you should treat this
  333. * as opaque data. Don't try to manipulate the file handle, just pass the
  334. * pointer you got, unmolested, to various PhysicsFS APIs.
  335. *
  336. * \sa PHYSFS_openRead
  337. * \sa PHYSFS_openWrite
  338. * \sa PHYSFS_openAppend
  339. * \sa PHYSFS_close
  340. * \sa PHYSFS_read
  341. * \sa PHYSFS_write
  342. * \sa PHYSFS_seek
  343. * \sa PHYSFS_tell
  344. * \sa PHYSFS_eof
  345. * \sa PHYSFS_setBuffer
  346. * \sa PHYSFS_flush
  347. */
  348. typedef struct PHYSFS_File
  349. {
  350. void *opaque; /**< That's all you get. Don't touch. */
  351. } PHYSFS_File;
  352. /**
  353. * \def PHYSFS_file
  354. * \brief 1.0 API compatibility define.
  355. *
  356. * PHYSFS_file is identical to PHYSFS_File. This #define is here for backwards
  357. * compatibility with the 1.0 API, which had an inconsistent capitalization
  358. * convention in this case. New code should use PHYSFS_File, as this #define
  359. * may go away someday.
  360. *
  361. * \sa PHYSFS_File
  362. */
  363. #define PHYSFS_file PHYSFS_File
  364. /**
  365. * \struct PHYSFS_ArchiveInfo
  366. * \brief Information on various PhysicsFS-supported archives.
  367. *
  368. * This structure gives you details on what sort of archives are supported
  369. * by this implementation of PhysicsFS. Archives tend to be things like
  370. * ZIP files and such.
  371. *
  372. * \warning Not all binaries are created equal! PhysicsFS can be built with
  373. * or without support for various archives. You can check with
  374. * PHYSFS_supportedArchiveTypes() to see if your archive type is
  375. * supported.
  376. *
  377. * \sa PHYSFS_supportedArchiveTypes
  378. */
  379. typedef struct PHYSFS_ArchiveInfo
  380. {
  381. const char *extension; /**< Archive file extension: "ZIP", for example. */
  382. const char *description; /**< Human-readable archive description. */
  383. const char *author; /**< Person who did support for this archive. */
  384. const char *url; /**< URL related to this archive */
  385. } PHYSFS_ArchiveInfo;
  386. /**
  387. * \struct PHYSFS_Version
  388. * \brief Information the version of PhysicsFS in use.
  389. *
  390. * Represents the library's version as three levels: major revision
  391. * (increments with massive changes, additions, and enhancements),
  392. * minor revision (increments with backwards-compatible changes to the
  393. * major revision), and patchlevel (increments with fixes to the minor
  394. * revision).
  395. *
  396. * \sa PHYSFS_VERSION
  397. * \sa PHYSFS_getLinkedVersion
  398. */
  399. typedef struct PHYSFS_Version
  400. {
  401. PHYSFS_uint8 major; /**< major revision */
  402. PHYSFS_uint8 minor; /**< minor revision */
  403. PHYSFS_uint8 patch; /**< patchlevel */
  404. } PHYSFS_Version;
  405. #ifndef SWIG /* not available from scripting languages. */
  406. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  407. #define PHYSFS_VER_MAJOR 2
  408. #define PHYSFS_VER_MINOR 1
  409. #define PHYSFS_VER_PATCH 0
  410. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  411. /* PhysicsFS state stuff ... */
  412. /**
  413. * \def PHYSFS_VERSION(x)
  414. * \brief Macro to determine PhysicsFS version program was compiled against.
  415. *
  416. * This macro fills in a PHYSFS_Version structure with the version of the
  417. * library you compiled against. This is determined by what header the
  418. * compiler uses. Note that if you dynamically linked the library, you might
  419. * have a slightly newer or older version at runtime. That version can be
  420. * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION,
  421. * is not a macro.
  422. *
  423. * \param x A pointer to a PHYSFS_Version struct to initialize.
  424. *
  425. * \sa PHYSFS_Version
  426. * \sa PHYSFS_getLinkedVersion
  427. */
  428. #define PHYSFS_VERSION(x) \
  429. { \
  430. (x)->major = PHYSFS_VER_MAJOR; \
  431. (x)->minor = PHYSFS_VER_MINOR; \
  432. (x)->patch = PHYSFS_VER_PATCH; \
  433. }
  434. #endif /* SWIG */
  435. /**
  436. * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  437. * \brief Get the version of PhysicsFS that is linked against your program.
  438. *
  439. * If you are using a shared library (DLL) version of PhysFS, then it is
  440. * possible that it will be different than the version you compiled against.
  441. *
  442. * This is a real function; the macro PHYSFS_VERSION tells you what version
  443. * of PhysFS you compiled against:
  444. *
  445. * \code
  446. * PHYSFS_Version compiled;
  447. * PHYSFS_Version linked;
  448. *
  449. * PHYSFS_VERSION(&compiled);
  450. * PHYSFS_getLinkedVersion(&linked);
  451. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  452. * compiled.major, compiled.minor, compiled.patch);
  453. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  454. * linked.major, linked.minor, linked.patch);
  455. * \endcode
  456. *
  457. * This function may be called safely at any time, even before PHYSFS_init().
  458. *
  459. * \sa PHYSFS_VERSION
  460. */
  461. PHYSFS_DECL void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  462. /**
  463. * \fn int PHYSFS_init(const char *argv0)
  464. * \brief Initialize the PhysicsFS library.
  465. *
  466. * This must be called before any other PhysicsFS function.
  467. *
  468. * This should be called prior to any attempts to change your process's
  469. * current working directory.
  470. *
  471. * \param argv0 the argv[0] string passed to your program's mainline.
  472. * This may be NULL on most platforms (such as ones without a
  473. * standard main() function), but you should always try to pass
  474. * something in here. Unix-like systems such as Linux _need_ to
  475. * pass argv[0] from main() in here.
  476. * \return nonzero on success, zero on error. Specifics of the error can be
  477. * gleaned from PHYSFS_getLastError().
  478. *
  479. * \sa PHYSFS_deinit
  480. * \sa PHYSFS_isInit
  481. */
  482. PHYSFS_DECL int PHYSFS_init(const char *argv0);
  483. /**
  484. * \fn int PHYSFS_deinit(void)
  485. * \brief Deinitialize the PhysicsFS library.
  486. *
  487. * This closes any files opened via PhysicsFS, blanks the search/write paths,
  488. * frees memory, and invalidates all of your file handles.
  489. *
  490. * Note that this call can FAIL if there's a file open for writing that
  491. * refuses to close (for example, the underlying operating system was
  492. * buffering writes to network filesystem, and the fileserver has crashed,
  493. * or a hard drive has failed, etc). It is usually best to close all write
  494. * handles yourself before calling this function, so that you can gracefully
  495. * handle a specific failure.
  496. *
  497. * Once successfully deinitialized, PHYSFS_init() can be called again to
  498. * restart the subsystem. All default API states are restored at this
  499. * point, with the exception of any custom allocator you might have
  500. * specified, which survives between initializations.
  501. *
  502. * \return nonzero on success, zero on error. Specifics of the error can be
  503. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  504. * undefined, and probably badly screwed up.
  505. *
  506. * \sa PHYSFS_init
  507. * \sa PHYSFS_isInit
  508. */
  509. PHYSFS_DECL int PHYSFS_deinit(void);
  510. /**
  511. * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
  512. * \brief Get a list of supported archive types.
  513. *
  514. * Get a list of archive types supported by this implementation of PhysicFS.
  515. * These are the file formats usable for search path entries. This is for
  516. * informational purposes only. Note that the extension listed is merely
  517. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  518. * with an extension of "XYZ", if you like.
  519. *
  520. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  521. * with a NULL entry to signify the end of the list:
  522. *
  523. * \code
  524. * PHYSFS_ArchiveInfo **i;
  525. *
  526. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  527. * {
  528. * printf("Supported archive: [%s], which is [%s].\n",
  529. * (*i)->extension, (*i)->description);
  530. * }
  531. * \endcode
  532. *
  533. * The return values are pointers to internal memory, and should
  534. * be considered READ ONLY, and never freed. The returned values are
  535. * valid until the next call to PHYSFS_deinit().
  536. *
  537. * \return READ ONLY Null-terminated array of READ ONLY structures.
  538. */
  539. PHYSFS_DECL const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  540. /**
  541. * \fn void PHYSFS_freeList(void *listVar)
  542. * \brief Deallocate resources of lists returned by PhysicsFS.
  543. *
  544. * Certain PhysicsFS functions return lists of information that are
  545. * dynamically allocated. Use this function to free those resources.
  546. *
  547. * It is safe to pass a NULL here, but doing so will cause a crash in versions
  548. * before PhysicsFS 2.1.0.
  549. *
  550. * \param listVar List of information specified as freeable by this function.
  551. * Passing NULL is safe; it is a valid no-op.
  552. *
  553. * \sa PHYSFS_getCdRomDirs
  554. * \sa PHYSFS_enumerateFiles
  555. * \sa PHYSFS_getSearchPath
  556. */
  557. PHYSFS_DECL void PHYSFS_freeList(void *listVar);
  558. /**
  559. * \fn const char *PHYSFS_getLastError(void)
  560. * \brief Get human-readable error information.
  561. *
  562. * \warning As of PhysicsFS 2.1, this function has been nerfed.
  563. * Before PhysicsFS 2.1, this function was the only way to get
  564. * error details beyond a given function's basic return value.
  565. * This was meant to be a human-readable string in one of several
  566. * languages, and was not useful for application parsing. This was
  567. * a problem, because the developer and not the user chose the
  568. * language at compile time, and the PhysicsFS maintainers had
  569. * to (poorly) maintain a significant amount of localization work.
  570. * The app couldn't parse the strings, even if they counted on a
  571. * specific language, since some were dynamically generated.
  572. * In 2.1 and later, this always returns a static string in
  573. * English; you may use it as a key string for your own
  574. * localizations if you like, as we'll promise not to change
  575. * existing error strings. Also, if your application wants to
  576. * look at specific errors, we now offer a better option:
  577. * use PHYSFS_getLastErrorCode() instead.
  578. *
  579. * Get the last PhysicsFS error message as a human-readable, null-terminated
  580. * string. This will return NULL if there's been no error since the last call
  581. * to this function. The pointer returned by this call points to an internal
  582. * buffer. Each thread has a unique error state associated with it, but each
  583. * time a new error message is set, it will overwrite the previous one
  584. * associated with that thread. It is safe to call this function at anytime,
  585. * even before PHYSFS_init().
  586. *
  587. * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same
  588. * thread-specific error state. Calling one will wipe out the other's
  589. * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that
  590. * value to PHYSFS_getErrorByCode().
  591. *
  592. * As of PhysicsFS 2.1, this function only presents text in the English
  593. * language, but the strings are static, so you can use them as keys into
  594. * your own localization dictionary. These strings are meant to be passed on
  595. * directly to the user.
  596. *
  597. * Generally, applications should only concern themselves with whether a
  598. * given function failed; however, if your code require more specifics, you
  599. * should use PHYSFS_getLastErrorCode() instead of this function.
  600. *
  601. * \return READ ONLY string of last error message.
  602. *
  603. * \sa PHYSFS_getLastErrorCode
  604. * \sa PHYSFS_getErrorByCode
  605. */
  606. PHYSFS_DECL const char *PHYSFS_getLastError(void);
  607. /**
  608. * \fn const char *PHYSFS_getDirSeparator(void)
  609. * \brief Get platform-dependent dir separator string.
  610. *
  611. * This returns "\\" on win32, "/" on Unix, and ":" on MacOS. It may be more
  612. * than one character, depending on the platform, and your code should take
  613. * that into account. Note that this is only useful for setting up the
  614. * search/write paths, since access into those dirs always use '/'
  615. * (platform-independent notation) to separate directories. This is also
  616. * handy for getting platform-independent access when using stdio calls.
  617. *
  618. * \return READ ONLY null-terminated string of platform's dir separator.
  619. */
  620. PHYSFS_DECL const char *PHYSFS_getDirSeparator(void);
  621. /**
  622. * \fn void PHYSFS_permitSymbolicLinks(int allow)
  623. * \brief Enable or disable following of symbolic links.
  624. *
  625. * Some physical filesystems and archives contain files that are just pointers
  626. * to other files. On the physical filesystem, opening such a link will
  627. * (transparently) open the file that is pointed to.
  628. *
  629. * By default, PhysicsFS will check if a file is really a symlink during open
  630. * calls and fail if it is. Otherwise, the link could take you outside the
  631. * write and search paths, and compromise security.
  632. *
  633. * If you want to take that risk, call this function with a non-zero parameter.
  634. * Note that this is more for sandboxing a program's scripting language, in
  635. * case untrusted scripts try to compromise the system. Generally speaking,
  636. * a user could very well have a legitimate reason to set up a symlink, so
  637. * unless you feel there's a specific danger in allowing them, you should
  638. * permit them.
  639. *
  640. * Symlinks are only explicitly checked when dealing with filenames
  641. * in platform-independent notation. That is, when setting up your
  642. * search and write paths, etc, symlinks are never checked for.
  643. *
  644. * Please note that PHYSFS_stat() will always check the path specified; if
  645. * that path is a symlink, it will not be followed in any case. If symlinks
  646. * aren't permitted through this function, PHYSFS_stat() ignores them, and
  647. * would treat the query as if the path didn't exist at all.
  648. *
  649. * Symbolic link permission can be enabled or disabled at any time after
  650. * you've called PHYSFS_init(), and is disabled by default.
  651. *
  652. * \param allow nonzero to permit symlinks, zero to deny linking.
  653. *
  654. * \sa PHYSFS_symbolicLinksPermitted
  655. */
  656. PHYSFS_DECL void PHYSFS_permitSymbolicLinks(int allow);
  657. /* !!! FIXME: const this? */
  658. /**
  659. * \fn char **PHYSFS_getCdRomDirs(void)
  660. * \brief Get an array of paths to available CD-ROM drives.
  661. *
  662. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  663. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  664. * accessible in the drive. So if you've got two drives (D: and E:), and only
  665. * E: has a disc in it, then that's all you get. If the user inserts a disc
  666. * in D: and you call this function again, you get both drives. If, on a
  667. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  668. * call to this function will reflect that change.
  669. *
  670. * This function refers to "CD-ROM" media, but it really means "inserted disc
  671. * media," such as DVD-ROM, HD-DVD, CDRW, and Blu-Ray discs. It looks for
  672. * filesystems, and as such won't report an audio CD, unless there's a
  673. * mounted filesystem track on it.
  674. *
  675. * The returned value is an array of strings, with a NULL entry to signify the
  676. * end of the list:
  677. *
  678. * \code
  679. * char **cds = PHYSFS_getCdRomDirs();
  680. * char **i;
  681. *
  682. * for (i = cds; *i != NULL; i++)
  683. * printf("cdrom dir [%s] is available.\n", *i);
  684. *
  685. * PHYSFS_freeList(cds);
  686. * \endcode
  687. *
  688. * This call may block while drives spin up. Be forewarned.
  689. *
  690. * When you are done with the returned information, you may dispose of the
  691. * resources by calling PHYSFS_freeList() with the returned pointer.
  692. *
  693. * \return Null-terminated array of null-terminated strings.
  694. *
  695. * \sa PHYSFS_getCdRomDirsCallback
  696. */
  697. PHYSFS_DECL char **PHYSFS_getCdRomDirs(void);
  698. /**
  699. * \fn const char *PHYSFS_getBaseDir(void)
  700. * \brief Get the path where the application resides.
  701. *
  702. * Helper function.
  703. *
  704. * Get the "base dir". This is the directory where the application was run
  705. * from, which is probably the installation directory, and may or may not
  706. * be the process's current working directory.
  707. *
  708. * You should probably use the base dir in your search path.
  709. *
  710. * \return READ ONLY string of base dir in platform-dependent notation.
  711. *
  712. * \sa PHYSFS_getPrefDir
  713. */
  714. PHYSFS_DECL const char *PHYSFS_getBaseDir(void);
  715. /**
  716. * \fn const char *PHYSFS_getUserDir(void)
  717. * \brief Get the path where user's home directory resides.
  718. *
  719. * \deprecated As of PhysicsFS 2.1, you probably want PHYSFS_getPrefDir().
  720. *
  721. * Helper function.
  722. *
  723. * Get the "user dir". This is meant to be a suggestion of where a specific
  724. * user of the system can store files. On Unix, this is her home directory.
  725. * On systems with no concept of multiple home directories (MacOS, win95),
  726. * this will default to something like "C:\mybasedir\users\username"
  727. * where "username" will either be the login name, or "default" if the
  728. * platform doesn't support multiple users, either.
  729. *
  730. * \return READ ONLY string of user dir in platform-dependent notation.
  731. *
  732. * \sa PHYSFS_getBaseDir
  733. * \sa PHYSFS_getPrefDir
  734. */
  735. PHYSFS_DECL const char *PHYSFS_getUserDir(void) PHYSFS_DEPRECATED;
  736. /**
  737. * \fn const char *PHYSFS_getWriteDir(void)
  738. * \brief Get path where PhysicsFS will allow file writing.
  739. *
  740. * Get the current write dir. The default write dir is NULL.
  741. *
  742. * \return READ ONLY string of write dir in platform-dependent notation,
  743. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  744. *
  745. * \sa PHYSFS_setWriteDir
  746. */
  747. PHYSFS_DECL const char *PHYSFS_getWriteDir(void);
  748. /**
  749. * \fn int PHYSFS_setWriteDir(const char *newDir)
  750. * \brief Tell PhysicsFS where it may write files.
  751. *
  752. * Set a new write dir. This will override the previous setting.
  753. *
  754. * This call will fail (and fail to change the write dir) if the current
  755. * write dir still has files open in it.
  756. *
  757. * \param newDir The new directory to be the root of the write dir,
  758. * specified in platform-dependent notation. Setting to NULL
  759. * disables the write dir, so no files can be opened for
  760. * writing via PhysicsFS.
  761. * \return non-zero on success, zero on failure. All attempts to open a file
  762. * for writing via PhysicsFS will fail until this call succeeds.
  763. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  764. *
  765. * \sa PHYSFS_getWriteDir
  766. */
  767. PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
  768. /**
  769. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  770. * \brief Add an archive or directory to the search path.
  771. *
  772. * \deprecated As of PhysicsFS 2.0, use PHYSFS_mount() instead. This
  773. * function just wraps it anyhow.
  774. *
  775. * This function is equivalent to:
  776. *
  777. * \code
  778. * PHYSFS_mount(newDir, NULL, appendToPath);
  779. * \endcode
  780. *
  781. * You must use this and not PHYSFS_mount if binary compatibility with
  782. * PhysicsFS 1.0 is important (which it may not be for many people).
  783. *
  784. * \sa PHYSFS_mount
  785. * \sa PHYSFS_removeFromSearchPath
  786. * \sa PHYSFS_getSearchPath
  787. */
  788. PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  789. PHYSFS_DEPRECATED;
  790. /**
  791. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  792. * \brief Remove a directory or archive from the search path.
  793. *
  794. * \deprecated As of PhysicsFS 2.1, use PHYSFS_unmount() instead. This
  795. * function just wraps it anyhow. There's no functional difference
  796. * except the vocabulary changed from "adding to the search path"
  797. * to "mounting" when that functionality was extended, and thus
  798. * the preferred way to accomplish this function's work is now
  799. * called "unmounting."
  800. *
  801. * This function is equivalent to:
  802. *
  803. * \code
  804. * PHYSFS_unmount(oldDir);
  805. * \endcode
  806. *
  807. * You must use this and not PHYSFS_unmount if binary compatibility with
  808. * PhysicsFS 1.0 is important (which it may not be for many people).
  809. *
  810. * \sa PHYSFS_addToSearchPath
  811. * \sa PHYSFS_getSearchPath
  812. * \sa PHYSFS_unmount
  813. */
  814. PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir)
  815. PHYSFS_DEPRECATED;
  816. /**
  817. * \fn char **PHYSFS_getSearchPath(void)
  818. * \brief Get the current search path.
  819. *
  820. * The default search path is an empty list.
  821. *
  822. * The returned value is an array of strings, with a NULL entry to signify the
  823. * end of the list:
  824. *
  825. * \code
  826. * char **i;
  827. *
  828. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  829. * printf("[%s] is in the search path.\n", *i);
  830. * \endcode
  831. *
  832. * When you are done with the returned information, you may dispose of the
  833. * resources by calling PHYSFS_freeList() with the returned pointer.
  834. *
  835. * \return Null-terminated array of null-terminated strings. NULL if there
  836. * was a problem (read: OUT OF MEMORY).
  837. *
  838. * \sa PHYSFS_getSearchPathCallback
  839. * \sa PHYSFS_addToSearchPath
  840. * \sa PHYSFS_removeFromSearchPath
  841. */
  842. PHYSFS_DECL char **PHYSFS_getSearchPath(void);
  843. /**
  844. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  845. * \brief Set up sane, default paths.
  846. *
  847. * Helper function.
  848. *
  849. * The write dir will be set to the pref dir returned by
  850. * \code PHYSFS_getPrefDir(organization, appName) \endcode, which is
  851. * created if it doesn't exist.
  852. *
  853. * The above is sufficient to make sure your program's configuration directory
  854. * is separated from other clutter, and platform-independent.
  855. *
  856. * The search path will be:
  857. *
  858. * - The Write Dir (created if it doesn't exist)
  859. * - The Base Dir (PHYSFS_getBaseDir())
  860. * - All found CD-ROM dirs (optionally)
  861. *
  862. * These directories are then searched for files ending with the extension
  863. * (archiveExt), which, if they are valid and supported archives, will also
  864. * be added to the search path. If you specified "PKG" for (archiveExt), and
  865. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  866. * can either be appended or prepended to the search path in alphabetical
  867. * order, regardless of which directories they were found in. All archives
  868. * are mounted in the root of the virtual file system ("/").
  869. *
  870. * All of this can be accomplished from the application, but this just does it
  871. * all for you. Feel free to add more to the search path manually, too.
  872. *
  873. * \param organization Name of your company/group/etc to be used as a
  874. * dirname, so keep it small, and no-frills.
  875. *
  876. * \param appName Program-specific name of your program, to separate it
  877. * from other programs using PhysicsFS.
  878. *
  879. * \param archiveExt File extension used by your program to specify an
  880. * archive. For example, Quake 3 uses "pk3", even though
  881. * they are just zipfiles. Specify NULL to not dig out
  882. * archives automatically. Do not specify the '.' char;
  883. * If you want to look for ZIP files, specify "ZIP" and
  884. * not ".ZIP" ... the archive search is case-insensitive.
  885. *
  886. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  887. * (if (archiveExt) != NULL) search them for archives.
  888. * This may cause a significant amount of blocking
  889. * while discs are accessed, and if there are no discs
  890. * in the drive (or even not mounted on Unix systems),
  891. * then they may not be made available anyhow. You may
  892. * want to specify zero and handle the disc setup
  893. * yourself.
  894. *
  895. * \param archivesFirst Non-zero to prepend the archives to the search path.
  896. * Zero to append them. Ignored if !(archiveExt).
  897. *
  898. * \return nonzero on success, zero on error. Specifics of the error can be
  899. * gleaned from PHYSFS_getLastError().
  900. */
  901. PHYSFS_DECL int PHYSFS_setSaneConfig(const char *organization,
  902. const char *appName,
  903. const char *archiveExt,
  904. int includeCdRoms,
  905. int archivesFirst);
  906. /* Directory management stuff ... */
  907. /**
  908. * \fn int PHYSFS_mkdir(const char *dirName)
  909. * \brief Create a directory.
  910. *
  911. * This is specified in platform-independent notation in relation to the
  912. * write dir. All missing parent directories are also created if they
  913. * don't exist.
  914. *
  915. * So if you've got the write dir set to "C:\mygame\writedir" and call
  916. * PHYSFS_mkdir("downloads/maps") then the directories
  917. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  918. * will be created if possible. If the creation of "maps" fails after we
  919. * have successfully created "downloads", then the function leaves the
  920. * created directory behind and reports failure.
  921. *
  922. * \param dirName New dir to create.
  923. * \return nonzero on success, zero on error. Specifics of the error can be
  924. * gleaned from PHYSFS_getLastError().
  925. *
  926. * \sa PHYSFS_delete
  927. */
  928. PHYSFS_DECL int PHYSFS_mkdir(const char *dirName);
  929. /**
  930. * \fn int PHYSFS_delete(const char *filename)
  931. * \brief Delete a file or directory.
  932. *
  933. * (filename) is specified in platform-independent notation in relation to the
  934. * write dir.
  935. *
  936. * A directory must be empty before this call can delete it.
  937. *
  938. * Deleting a symlink will remove the link, not what it points to, regardless
  939. * of whether you "permitSymLinks" or not.
  940. *
  941. * So if you've got the write dir set to "C:\mygame\writedir" and call
  942. * PHYSFS_delete("downloads/maps/level1.map") then the file
  943. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  944. * physical filesystem, if it exists and the operating system permits the
  945. * deletion.
  946. *
  947. * Note that on Unix systems, deleting a file may be successful, but the
  948. * actual file won't be removed until all processes that have an open
  949. * filehandle to it (including your program) close their handles.
  950. *
  951. * Chances are, the bits that make up the file still exist, they are just
  952. * made available to be written over at a later point. Don't consider this
  953. * a security method or anything. :)
  954. *
  955. * \param filename Filename to delete.
  956. * \return nonzero on success, zero on error. Specifics of the error can be
  957. * gleaned from PHYSFS_getLastError().
  958. */
  959. PHYSFS_DECL int PHYSFS_delete(const char *filename);
  960. /**
  961. * \fn const char *PHYSFS_getRealDir(const char *filename)
  962. * \brief Figure out where in the search path a file resides.
  963. *
  964. * The file is specified in platform-independent notation. The returned
  965. * filename will be the element of the search path where the file was found,
  966. * which may be a directory, or an archive. Even if there are multiple
  967. * matches in different parts of the search path, only the first one found
  968. * is used, just like when opening a file.
  969. *
  970. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  971. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  972. *
  973. * If a any part of a match is a symbolic link, and you've not explicitly
  974. * permitted symlinks, then it will be ignored, and the search for a match
  975. * will continue.
  976. *
  977. * If you specify a fake directory that only exists as a mount point, it'll
  978. * be associated with the first archive mounted there, even though that
  979. * directory isn't necessarily contained in a real archive.
  980. *
  981. * \warning This will return NULL if there is no real directory associated
  982. * with (filename). Specifically, PHYSFS_mountIo(),
  983. * PHYSFS_mountMemory(), and PHYSFS_mountHandle() will return NULL
  984. * even if the filename is found in the search path. Plan accordingly.
  985. *
  986. * \param filename file to look for.
  987. * \return READ ONLY string of element of search path containing the
  988. * the file in question. NULL if not found.
  989. */
  990. PHYSFS_DECL const char *PHYSFS_getRealDir(const char *filename);
  991. /**
  992. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  993. * \brief Get a file listing of a search path's directory.
  994. *
  995. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  996. * search path and contains a directory "savegames" that contains "x.sav",
  997. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  998. * that has a "savegames" subdirectory with "w.sav", then the following code:
  999. *
  1000. * \code
  1001. * char **rc = PHYSFS_enumerateFiles("savegames");
  1002. * char **i;
  1003. *
  1004. * for (i = rc; *i != NULL; i++)
  1005. * printf(" * We've got [%s].\n", *i);
  1006. *
  1007. * PHYSFS_freeList(rc);
  1008. * \endcode
  1009. *
  1010. * \...will print:
  1011. *
  1012. * \verbatim
  1013. * We've got [x.sav].
  1014. * We've got [y.sav].
  1015. * We've got [z.sav].
  1016. * We've got [w.sav].\endverbatim
  1017. *
  1018. * Feel free to sort the list however you like. We only promise there will
  1019. * be no duplicates, but not what order the final list will come back in.
  1020. *
  1021. * Don't forget to call PHYSFS_freeList() with the return value from this
  1022. * function when you are done with it.
  1023. *
  1024. * \param dir directory in platform-independent notation to enumerate.
  1025. * \return Null-terminated array of null-terminated strings.
  1026. *
  1027. * \sa PHYSFS_enumerateFilesCallback
  1028. */
  1029. PHYSFS_DECL char **PHYSFS_enumerateFiles(const char *dir);
  1030. /**
  1031. * \fn int PHYSFS_exists(const char *fname)
  1032. * \brief Determine if a file exists in the search path.
  1033. *
  1034. * Reports true if there is an entry anywhere in the search path by the
  1035. * name of (fname).
  1036. *
  1037. * Note that entries that are symlinks are ignored if
  1038. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  1039. * might end up further down in the search path than expected.
  1040. *
  1041. * \param fname filename in platform-independent notation.
  1042. * \return non-zero if filename exists. zero otherwise.
  1043. */
  1044. PHYSFS_DECL int PHYSFS_exists(const char *fname);
  1045. /**
  1046. * \fn int PHYSFS_isDirectory(const char *fname)
  1047. * \brief Determine if a file in the search path is really a directory.
  1048. *
  1049. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1050. * function just wraps it anyhow.
  1051. *
  1052. * Determine if the first occurence of (fname) in the search path is
  1053. * really a directory entry.
  1054. *
  1055. * Note that entries that are symlinks are ignored if
  1056. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  1057. * might end up further down in the search path than expected.
  1058. *
  1059. * \param fname filename in platform-independent notation.
  1060. * \return non-zero if filename exists and is a directory. zero otherwise.
  1061. *
  1062. * \sa PHYSFS_stat
  1063. * \sa PHYSFS_exists
  1064. */
  1065. PHYSFS_DECL int PHYSFS_isDirectory(const char *fname) PHYSFS_DEPRECATED;
  1066. /**
  1067. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  1068. * \brief Determine if a file in the search path is really a symbolic link.
  1069. *
  1070. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1071. * function just wraps it anyhow.
  1072. *
  1073. * Determine if the first occurence of (fname) in the search path is
  1074. * really a symbolic link.
  1075. *
  1076. * Note that entries that are symlinks are ignored if
  1077. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  1078. * this function will always return 0 in that case.
  1079. *
  1080. * \param fname filename in platform-independent notation.
  1081. * \return non-zero if filename exists and is a symlink. zero otherwise.
  1082. *
  1083. * \sa PHYSFS_stat
  1084. * \sa PHYSFS_exists
  1085. */
  1086. PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname) PHYSFS_DEPRECATED;
  1087. /**
  1088. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1089. * \brief Get the last modification time of a file.
  1090. *
  1091. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1092. * function just wraps it anyhow.
  1093. *
  1094. * The modtime is returned as a number of seconds since the Unix epoch
  1095. * (midnight, Jan 1, 1970). The exact derivation and accuracy of this time
  1096. * depends on the particular archiver. If there is no reasonable way to
  1097. * obtain this information for a particular archiver, or there was some sort
  1098. * of error, this function returns (-1).
  1099. *
  1100. * You must use this and not PHYSFS_stat() if binary compatibility with
  1101. * PhysicsFS 2.0 is important (which it may not be for many people).
  1102. *
  1103. * \param filename filename to check, in platform-independent notation.
  1104. * \return last modified time of the file. -1 if it can't be determined.
  1105. *
  1106. * \sa PHYSFS_stat
  1107. */
  1108. PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1109. PHYSFS_DEPRECATED;
  1110. /* i/o stuff... */
  1111. /**
  1112. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  1113. * \brief Open a file for writing.
  1114. *
  1115. * Open a file for writing, in platform-independent notation and in relation
  1116. * to the write dir as the root of the writable filesystem. The specified
  1117. * file is created if it doesn't exist. If it does exist, it is truncated to
  1118. * zero bytes, and the writing offset is set to the start.
  1119. *
  1120. * Note that entries that are symlinks are ignored if
  1121. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1122. * symlink with this function will fail in such a case.
  1123. *
  1124. * \param filename File to open.
  1125. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1126. * of the error can be gleaned from PHYSFS_getLastError().
  1127. *
  1128. * \sa PHYSFS_openRead
  1129. * \sa PHYSFS_openAppend
  1130. * \sa PHYSFS_write
  1131. * \sa PHYSFS_close
  1132. */
  1133. PHYSFS_DECL PHYSFS_File *PHYSFS_openWrite(const char *filename);
  1134. /**
  1135. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  1136. * \brief Open a file for appending.
  1137. *
  1138. * Open a file for writing, in platform-independent notation and in relation
  1139. * to the write dir as the root of the writable filesystem. The specified
  1140. * file is created if it doesn't exist. If it does exist, the writing offset
  1141. * is set to the end of the file, so the first write will be the byte after
  1142. * the end.
  1143. *
  1144. * Note that entries that are symlinks are ignored if
  1145. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1146. * symlink with this function will fail in such a case.
  1147. *
  1148. * \param filename File to open.
  1149. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1150. * of the error can be gleaned from PHYSFS_getLastError().
  1151. *
  1152. * \sa PHYSFS_openRead
  1153. * \sa PHYSFS_openWrite
  1154. * \sa PHYSFS_write
  1155. * \sa PHYSFS_close
  1156. */
  1157. PHYSFS_DECL PHYSFS_File *PHYSFS_openAppend(const char *filename);
  1158. /**
  1159. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  1160. * \brief Open a file for reading.
  1161. *
  1162. * Open a file for reading, in platform-independent notation. The search path
  1163. * is checked one at a time until a matching file is found, in which case an
  1164. * abstract filehandle is associated with it, and reading may be done.
  1165. * The reading offset is set to the first byte of the file.
  1166. *
  1167. * Note that entries that are symlinks are ignored if
  1168. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1169. * symlink with this function will fail in such a case.
  1170. *
  1171. * \param filename File to open.
  1172. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1173. * of the error can be gleaned from PHYSFS_getLastError().
  1174. *
  1175. * \sa PHYSFS_openWrite
  1176. * \sa PHYSFS_openAppend
  1177. * \sa PHYSFS_read
  1178. * \sa PHYSFS_close
  1179. */
  1180. PHYSFS_DECL PHYSFS_File *PHYSFS_openRead(const char *filename);
  1181. /**
  1182. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1183. * \brief Close a PhysicsFS filehandle.
  1184. *
  1185. * This call is capable of failing if the operating system was buffering
  1186. * writes to the physical media, and, now forced to write those changes to
  1187. * physical media, can not store the data for some reason. In such a case,
  1188. * the filehandle stays open. A well-written program should ALWAYS check the
  1189. * return value from the close call in addition to every writing call!
  1190. *
  1191. * \param handle handle returned from PHYSFS_open*().
  1192. * \return nonzero on success, zero on error. Specifics of the error can be
  1193. * gleaned from PHYSFS_getLastError().
  1194. *
  1195. * \sa PHYSFS_openRead
  1196. * \sa PHYSFS_openWrite
  1197. * \sa PHYSFS_openAppend
  1198. */
  1199. PHYSFS_DECL int PHYSFS_close(PHYSFS_File *handle);
  1200. /**
  1201. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1202. * \brief Read data from a PhysicsFS filehandle
  1203. *
  1204. * The file must be opened for reading.
  1205. *
  1206. * \deprecated As of PhysicsFS 2.1, use PHYSFS_readBytes() instead. This
  1207. * function just wraps it anyhow. This function never clarified
  1208. * what would happen if you managed to read a partial object, so
  1209. * working at the byte level makes this cleaner for everyone,
  1210. * especially now that PHYSFS_Io interfaces can be supplied by the
  1211. * application.
  1212. *
  1213. * \param handle handle returned from PHYSFS_openRead().
  1214. * \param buffer buffer to store read data into.
  1215. * \param objSize size in bytes of objects being read from (handle).
  1216. * \param objCount number of (objSize) objects to read from (handle).
  1217. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1218. * the reason this might be < (objCount), as can PHYSFS_eof().
  1219. * -1 if complete failure.
  1220. *
  1221. * \sa PHYSFS_readBytes
  1222. * \sa PHYSFS_eof
  1223. */
  1224. PHYSFS_DECL PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1225. void *buffer,
  1226. PHYSFS_uint32 objSize,
  1227. PHYSFS_uint32 objCount)
  1228. PHYSFS_DEPRECATED;
  1229. /**
  1230. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1231. * \brief Write data to a PhysicsFS filehandle
  1232. *
  1233. * The file must be opened for writing.
  1234. *
  1235. * \deprecated As of PhysicsFS 2.1, use PHYSFS_writeBytes() instead. This
  1236. * function just wraps it anyhow. This function never clarified
  1237. * what would happen if you managed to write a partial object, so
  1238. * working at the byte level makes this cleaner for everyone,
  1239. * especially now that PHYSFS_Io interfaces can be supplied by the
  1240. * application.
  1241. *
  1242. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1243. * \param buffer buffer of bytes to write to (handle).
  1244. * \param objSize size in bytes of objects being written to (handle).
  1245. * \param objCount number of (objSize) objects to write to (handle).
  1246. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1247. * the reason this might be < (objCount). -1 if complete failure.
  1248. *
  1249. * \sa PHYSFS_writeBytes
  1250. */
  1251. PHYSFS_DECL PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1252. const void *buffer,
  1253. PHYSFS_uint32 objSize,
  1254. PHYSFS_uint32 objCount)
  1255. PHYSFS_DEPRECATED;
  1256. /* File position stuff... */
  1257. /**
  1258. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1259. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1260. *
  1261. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1262. *
  1263. * \param handle handle returned from PHYSFS_openRead().
  1264. * \return nonzero if EOF, zero if not.
  1265. *
  1266. * \sa PHYSFS_read
  1267. * \sa PHYSFS_tell
  1268. */
  1269. PHYSFS_DECL int PHYSFS_eof(PHYSFS_File *handle);
  1270. /**
  1271. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1272. * \brief Determine current position within a PhysicsFS filehandle.
  1273. *
  1274. * \param handle handle returned from PHYSFS_open*().
  1275. * \return offset in bytes from start of file. -1 if error occurred.
  1276. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1277. *
  1278. * \sa PHYSFS_seek
  1279. */
  1280. PHYSFS_DECL PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1281. /**
  1282. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1283. * \brief Seek to a new position within a PhysicsFS filehandle.
  1284. *
  1285. * The next read or write will occur at that place. Seeking past the
  1286. * beginning or end of the file is not allowed, and causes an error.
  1287. *
  1288. * \param handle handle returned from PHYSFS_open*().
  1289. * \param pos number of bytes from start of file to seek to.
  1290. * \return nonzero on success, zero on error. Specifics of the error can be
  1291. * gleaned from PHYSFS_getLastError().
  1292. *
  1293. * \sa PHYSFS_tell
  1294. */
  1295. PHYSFS_DECL int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1296. /**
  1297. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1298. * \brief Get total length of a file in bytes.
  1299. *
  1300. * Note that if another process/thread is writing to this file at the same
  1301. * time, then the information this function supplies could be incorrect
  1302. * before you get it. Use with caution, or better yet, don't use at all.
  1303. *
  1304. * \param handle handle returned from PHYSFS_open*().
  1305. * \return size in bytes of the file. -1 if can't be determined.
  1306. *
  1307. * \sa PHYSFS_tell
  1308. * \sa PHYSFS_seek
  1309. */
  1310. PHYSFS_DECL PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1311. /* Buffering stuff... */
  1312. /**
  1313. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1314. * \brief Set up buffering for a PhysicsFS file handle.
  1315. *
  1316. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1317. * will be allocated and associated with (handle).
  1318. *
  1319. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1320. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1321. * from this buffer until it is empty, and then refill it for more reading.
  1322. * Note that compressed files, like ZIP archives, will decompress while
  1323. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1324. * The buffer isn't filled until you do your next read.
  1325. *
  1326. * For files opened for writing, data will be buffered to memory until the
  1327. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1328. * causes a flush...check your return values!
  1329. *
  1330. * Seeking, etc transparently accounts for buffering.
  1331. *
  1332. * You can resize an existing buffer by calling this function more than once
  1333. * on the same file. Setting the buffer size to zero will free an existing
  1334. * buffer.
  1335. *
  1336. * PhysicsFS file handles are unbuffered by default.
  1337. *
  1338. * Please check the return value of this function! Failures can include
  1339. * not being able to seek backwards in a read-only file when removing the
  1340. * buffer, not being able to allocate the buffer, and not being able to
  1341. * flush the buffer to disk, among other unexpected problems.
  1342. *
  1343. * \param handle handle returned from PHYSFS_open*().
  1344. * \param bufsize size, in bytes, of buffer to allocate.
  1345. * \return nonzero if successful, zero on error.
  1346. *
  1347. * \sa PHYSFS_flush
  1348. * \sa PHYSFS_read
  1349. * \sa PHYSFS_write
  1350. * \sa PHYSFS_close
  1351. */
  1352. PHYSFS_DECL int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1353. /**
  1354. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1355. * \brief Flush a buffered PhysicsFS file handle.
  1356. *
  1357. * For buffered files opened for writing, this will put the current contents
  1358. * of the buffer to disk and flag the buffer as empty if possible.
  1359. *
  1360. * For buffered files opened for reading or unbuffered files, this is a safe
  1361. * no-op, and will report success.
  1362. *
  1363. * \param handle handle returned from PHYSFS_open*().
  1364. * \return nonzero if successful, zero on error.
  1365. *
  1366. * \sa PHYSFS_setBuffer
  1367. * \sa PHYSFS_close
  1368. */
  1369. PHYSFS_DECL int PHYSFS_flush(PHYSFS_File *handle);
  1370. /* Byteorder stuff... */
  1371. #ifndef SWIG /* not available from scripting languages. */
  1372. /**
  1373. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1374. * \brief Swap littleendian signed 16 to platform's native byte order.
  1375. *
  1376. * Take a 16-bit signed value in littleendian format and convert it to
  1377. * the platform's native byte order.
  1378. *
  1379. * \param val value to convert
  1380. * \return converted value.
  1381. */
  1382. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1383. /**
  1384. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1385. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1386. *
  1387. * Take a 16-bit unsigned value in littleendian format and convert it to
  1388. * the platform's native byte order.
  1389. *
  1390. * \param val value to convert
  1391. * \return converted value.
  1392. */
  1393. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1394. /**
  1395. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1396. * \brief Swap littleendian signed 32 to platform's native byte order.
  1397. *
  1398. * Take a 32-bit signed value in littleendian format and convert it to
  1399. * the platform's native byte order.
  1400. *
  1401. * \param val value to convert
  1402. * \return converted value.
  1403. */
  1404. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1405. /**
  1406. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1407. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1408. *
  1409. * Take a 32-bit unsigned value in littleendian format and convert it to
  1410. * the platform's native byte order.
  1411. *
  1412. * \param val value to convert
  1413. * \return converted value.
  1414. */
  1415. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1416. /**
  1417. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1418. * \brief Swap littleendian signed 64 to platform's native byte order.
  1419. *
  1420. * Take a 64-bit signed value in littleendian format and convert it to
  1421. * the platform's native byte order.
  1422. *
  1423. * \param val value to convert
  1424. * \return converted value.
  1425. *
  1426. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1427. * any sort of 64-bit support.
  1428. */
  1429. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1430. /**
  1431. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1432. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1433. *
  1434. * Take a 64-bit unsigned value in littleendian format and convert it to
  1435. * the platform's native byte order.
  1436. *
  1437. * \param val value to convert
  1438. * \return converted value.
  1439. *
  1440. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1441. * any sort of 64-bit support.
  1442. */
  1443. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1444. /**
  1445. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1446. * \brief Swap bigendian signed 16 to platform's native byte order.
  1447. *
  1448. * Take a 16-bit signed value in bigendian format and convert it to
  1449. * the platform's native byte order.
  1450. *
  1451. * \param val value to convert
  1452. * \return converted value.
  1453. */
  1454. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1455. /**
  1456. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1457. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1458. *
  1459. * Take a 16-bit unsigned value in bigendian format and convert it to
  1460. * the platform's native byte order.
  1461. *
  1462. * \param val value to convert
  1463. * \return converted value.
  1464. */
  1465. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1466. /**
  1467. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1468. * \brief Swap bigendian signed 32 to platform's native byte order.
  1469. *
  1470. * Take a 32-bit signed value in bigendian format and convert it to
  1471. * the platform's native byte order.
  1472. *
  1473. * \param val value to convert
  1474. * \return converted value.
  1475. */
  1476. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1477. /**
  1478. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1479. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1480. *
  1481. * Take a 32-bit unsigned value in bigendian format and convert it to
  1482. * the platform's native byte order.
  1483. *
  1484. * \param val value to convert
  1485. * \return converted value.
  1486. */
  1487. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1488. /**
  1489. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1490. * \brief Swap bigendian signed 64 to platform's native byte order.
  1491. *
  1492. * Take a 64-bit signed value in bigendian format and convert it to
  1493. * the platform's native byte order.
  1494. *
  1495. * \param val value to convert
  1496. * \return converted value.
  1497. *
  1498. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1499. * any sort of 64-bit support.
  1500. */
  1501. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1502. /**
  1503. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1504. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1505. *
  1506. * Take a 64-bit unsigned value in bigendian format and convert it to
  1507. * the platform's native byte order.
  1508. *
  1509. * \param val value to convert
  1510. * \return converted value.
  1511. *
  1512. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1513. * any sort of 64-bit support.
  1514. */
  1515. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1516. #endif /* SWIG */
  1517. /**
  1518. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1519. * \brief Read and convert a signed 16-bit littleendian value.
  1520. *
  1521. * Convenience function. Read a signed 16-bit littleendian value from a
  1522. * file and convert it to the platform's native byte order.
  1523. *
  1524. * \param file PhysicsFS file handle from which to read.
  1525. * \param val pointer to where value should be stored.
  1526. * \return zero on failure, non-zero on success. If successful, (*val) will
  1527. * store the result. On failure, you can find out what went wrong
  1528. * from PHYSFS_getLastError().
  1529. */
  1530. PHYSFS_DECL int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1531. /**
  1532. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1533. * \brief Read and convert an unsigned 16-bit littleendian value.
  1534. *
  1535. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1536. * file and convert it to the platform's native byte order.
  1537. *
  1538. * \param file PhysicsFS file handle from which to read.
  1539. * \param val pointer to where value should be stored.
  1540. * \return zero on failure, non-zero on success. If successful, (*val) will
  1541. * store the result. On failure, you can find out what went wrong
  1542. * from PHYSFS_getLastError().
  1543. *
  1544. */
  1545. PHYSFS_DECL int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1546. /**
  1547. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1548. * \brief Read and convert a signed 16-bit bigendian value.
  1549. *
  1550. * Convenience function. Read a signed 16-bit bigendian value from a
  1551. * file and convert it to the platform's native byte order.
  1552. *
  1553. * \param file PhysicsFS file handle from which to read.
  1554. * \param val pointer to where value should be stored.
  1555. * \return zero on failure, non-zero on success. If successful, (*val) will
  1556. * store the result. On failure, you can find out what went wrong
  1557. * from PHYSFS_getLastError().
  1558. */
  1559. PHYSFS_DECL int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1560. /**
  1561. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1562. * \brief Read and convert an unsigned 16-bit bigendian value.
  1563. *
  1564. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1565. * file and convert it to the platform's native byte order.
  1566. *
  1567. * \param file PhysicsFS file handle from which to read.
  1568. * \param val pointer to where value should be stored.
  1569. * \return zero on failure, non-zero on success. If successful, (*val) will
  1570. * store the result. On failure, you can find out what went wrong
  1571. * from PHYSFS_getLastError().
  1572. *
  1573. */
  1574. PHYSFS_DECL int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1575. /**
  1576. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1577. * \brief Read and convert a signed 32-bit littleendian value.
  1578. *
  1579. * Convenience function. Read a signed 32-bit littleendian value from a
  1580. * file and convert it to the platform's native byte order.
  1581. *
  1582. * \param file PhysicsFS file handle from which to read.
  1583. * \param val pointer to where value should be stored.
  1584. * \return zero on failure, non-zero on success. If successful, (*val) will
  1585. * store the result. On failure, you can find out what went wrong
  1586. * from PHYSFS_getLastError().
  1587. */
  1588. PHYSFS_DECL int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1589. /**
  1590. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1591. * \brief Read and convert an unsigned 32-bit littleendian value.
  1592. *
  1593. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1594. * file and convert it to the platform's native byte order.
  1595. *
  1596. * \param file PhysicsFS file handle from which to read.
  1597. * \param val pointer to where value should be stored.
  1598. * \return zero on failure, non-zero on success. If successful, (*val) will
  1599. * store the result. On failure, you can find out what went wrong
  1600. * from PHYSFS_getLastError().
  1601. *
  1602. */
  1603. PHYSFS_DECL int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1604. /**
  1605. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1606. * \brief Read and convert a signed 32-bit bigendian value.
  1607. *
  1608. * Convenience function. Read a signed 32-bit bigendian value from a
  1609. * file and convert it to the platform's native byte order.
  1610. *
  1611. * \param file PhysicsFS file handle from which to read.
  1612. * \param val pointer to where value should be stored.
  1613. * \return zero on failure, non-zero on success. If successful, (*val) will
  1614. * store the result. On failure, you can find out what went wrong
  1615. * from PHYSFS_getLastError().
  1616. */
  1617. PHYSFS_DECL int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1618. /**
  1619. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1620. * \brief Read and convert an unsigned 32-bit bigendian value.
  1621. *
  1622. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1623. * file and convert it to the platform's native byte order.
  1624. *
  1625. * \param file PhysicsFS file handle from which to read.
  1626. * \param val pointer to where value should be stored.
  1627. * \return zero on failure, non-zero on success. If successful, (*val) will
  1628. * store the result. On failure, you can find out what went wrong
  1629. * from PHYSFS_getLastError().
  1630. *
  1631. */
  1632. PHYSFS_DECL int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1633. /**
  1634. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1635. * \brief Read and convert a signed 64-bit littleendian value.
  1636. *
  1637. * Convenience function. Read a signed 64-bit littleendian value from a
  1638. * file and convert it to the platform's native byte order.
  1639. *
  1640. * \param file PhysicsFS file handle from which to read.
  1641. * \param val pointer to where value should be stored.
  1642. * \return zero on failure, non-zero on success. If successful, (*val) will
  1643. * store the result. On failure, you can find out what went wrong
  1644. * from PHYSFS_getLastError().
  1645. *
  1646. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1647. * any sort of 64-bit support.
  1648. */
  1649. PHYSFS_DECL int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1650. /**
  1651. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1652. * \brief Read and convert an unsigned 64-bit littleendian value.
  1653. *
  1654. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1655. * file and convert it to the platform's native byte order.
  1656. *
  1657. * \param file PhysicsFS file handle from which to read.
  1658. * \param val pointer to where value should be stored.
  1659. * \return zero on failure, non-zero on success. If successful, (*val) will
  1660. * store the result. On failure, you can find out what went wrong
  1661. * from PHYSFS_getLastError().
  1662. *
  1663. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1664. * any sort of 64-bit support.
  1665. */
  1666. PHYSFS_DECL int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1667. /**
  1668. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1669. * \brief Read and convert a signed 64-bit bigendian value.
  1670. *
  1671. * Convenience function. Read a signed 64-bit bigendian value from a
  1672. * file and convert it to the platform's native byte order.
  1673. *
  1674. * \param file PhysicsFS file handle from which to read.
  1675. * \param val pointer to where value should be stored.
  1676. * \return zero on failure, non-zero on success. If successful, (*val) will
  1677. * store the result. On failure, you can find out what went wrong
  1678. * from PHYSFS_getLastError().
  1679. *
  1680. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1681. * any sort of 64-bit support.
  1682. */
  1683. PHYSFS_DECL int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1684. /**
  1685. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1686. * \brief Read and convert an unsigned 64-bit bigendian value.
  1687. *
  1688. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1689. * file and convert it to the platform's native byte order.
  1690. *
  1691. * \param file PhysicsFS file handle from which to read.
  1692. * \param val pointer to where value should be stored.
  1693. * \return zero on failure, non-zero on success. If successful, (*val) will
  1694. * store the result. On failure, you can find out what went wrong
  1695. * from PHYSFS_getLastError().
  1696. *
  1697. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1698. * any sort of 64-bit support.
  1699. */
  1700. PHYSFS_DECL int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1701. /**
  1702. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1703. * \brief Convert and write a signed 16-bit littleendian value.
  1704. *
  1705. * Convenience function. Convert a signed 16-bit value from the platform's
  1706. * native byte order to littleendian and write it to a file.
  1707. *
  1708. * \param file PhysicsFS file handle to which to write.
  1709. * \param val Value to convert and write.
  1710. * \return zero on failure, non-zero on success. On failure, you can
  1711. * find out what went wrong from PHYSFS_getLastError().
  1712. */
  1713. PHYSFS_DECL int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1714. /**
  1715. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1716. * \brief Convert and write an unsigned 16-bit littleendian value.
  1717. *
  1718. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1719. * native byte order to littleendian and write it to a file.
  1720. *
  1721. * \param file PhysicsFS file handle to which to write.
  1722. * \param val Value to convert and write.
  1723. * \return zero on failure, non-zero on success. On failure, you can
  1724. * find out what went wrong from PHYSFS_getLastError().
  1725. */
  1726. PHYSFS_DECL int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1727. /**
  1728. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1729. * \brief Convert and write a signed 16-bit bigendian value.
  1730. *
  1731. * Convenience function. Convert a signed 16-bit value from the platform's
  1732. * native byte order to bigendian and write it to a file.
  1733. *
  1734. * \param file PhysicsFS file handle to which to write.
  1735. * \param val Value to convert and write.
  1736. * \return zero on failure, non-zero on success. On failure, you can
  1737. * find out what went wrong from PHYSFS_getLastError().
  1738. */
  1739. PHYSFS_DECL int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1740. /**
  1741. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1742. * \brief Convert and write an unsigned 16-bit bigendian value.
  1743. *
  1744. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1745. * native byte order to bigendian and write it to a file.
  1746. *
  1747. * \param file PhysicsFS file handle to which to write.
  1748. * \param val Value to convert and write.
  1749. * \return zero on failure, non-zero on success. On failure, you can
  1750. * find out what went wrong from PHYSFS_getLastError().
  1751. */
  1752. PHYSFS_DECL int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1753. /**
  1754. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1755. * \brief Convert and write a signed 32-bit littleendian value.
  1756. *
  1757. * Convenience function. Convert a signed 32-bit value from the platform's
  1758. * native byte order to littleendian and write it to a file.
  1759. *
  1760. * \param file PhysicsFS file handle to which to write.
  1761. * \param val Value to convert and write.
  1762. * \return zero on failure, non-zero on success. On failure, you can
  1763. * find out what went wrong from PHYSFS_getLastError().
  1764. */
  1765. PHYSFS_DECL int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1766. /**
  1767. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1768. * \brief Convert and write an unsigned 32-bit littleendian value.
  1769. *
  1770. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1771. * native byte order to littleendian and write it to a file.
  1772. *
  1773. * \param file PhysicsFS file handle to which to write.
  1774. * \param val Value to convert and write.
  1775. * \return zero on failure, non-zero on success. On failure, you can
  1776. * find out what went wrong from PHYSFS_getLastError().
  1777. */
  1778. PHYSFS_DECL int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1779. /**
  1780. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1781. * \brief Convert and write a signed 32-bit bigendian value.
  1782. *
  1783. * Convenience function. Convert a signed 32-bit value from the platform's
  1784. * native byte order to bigendian and write it to a file.
  1785. *
  1786. * \param file PhysicsFS file handle to which to write.
  1787. * \param val Value to convert and write.
  1788. * \return zero on failure, non-zero on success. On failure, you can
  1789. * find out what went wrong from PHYSFS_getLastError().
  1790. */
  1791. PHYSFS_DECL int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1792. /**
  1793. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1794. * \brief Convert and write an unsigned 32-bit bigendian value.
  1795. *
  1796. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1797. * native byte order to bigendian and write it to a file.
  1798. *
  1799. * \param file PhysicsFS file handle to which to write.
  1800. * \param val Value to convert and write.
  1801. * \return zero on failure, non-zero on success. On failure, you can
  1802. * find out what went wrong from PHYSFS_getLastError().
  1803. */
  1804. PHYSFS_DECL int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1805. /**
  1806. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1807. * \brief Convert and write a signed 64-bit littleendian value.
  1808. *
  1809. * Convenience function. Convert a signed 64-bit value from the platform's
  1810. * native byte order to littleendian and write it to a file.
  1811. *
  1812. * \param file PhysicsFS file handle to which to write.
  1813. * \param val Value to convert and write.
  1814. * \return zero on failure, non-zero on success. On failure, you can
  1815. * find out what went wrong from PHYSFS_getLastError().
  1816. *
  1817. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1818. * any sort of 64-bit support.
  1819. */
  1820. PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1821. /**
  1822. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1823. * \brief Convert and write an unsigned 64-bit littleendian value.
  1824. *
  1825. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1826. * native byte order to littleendian and write it to a file.
  1827. *
  1828. * \param file PhysicsFS file handle to which to write.
  1829. * \param val Value to convert and write.
  1830. * \return zero on failure, non-zero on success. On failure, you can
  1831. * find out what went wrong from PHYSFS_getLastError().
  1832. *
  1833. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1834. * any sort of 64-bit support.
  1835. */
  1836. PHYSFS_DECL int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1837. /**
  1838. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1839. * \brief Convert and write a signed 64-bit bigending value.
  1840. *
  1841. * Convenience function. Convert a signed 64-bit value from the platform's
  1842. * native byte order to bigendian and write it to a file.
  1843. *
  1844. * \param file PhysicsFS file handle to which to write.
  1845. * \param val Value to convert and write.
  1846. * \return zero on failure, non-zero on success. On failure, you can
  1847. * find out what went wrong from PHYSFS_getLastError().
  1848. *
  1849. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1850. * any sort of 64-bit support.
  1851. */
  1852. PHYSFS_DECL int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1853. /**
  1854. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1855. * \brief Convert and write an unsigned 64-bit bigendian value.
  1856. *
  1857. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1858. * native byte order to bigendian and write it to a file.
  1859. *
  1860. * \param file PhysicsFS file handle to which to write.
  1861. * \param val Value to convert and write.
  1862. * \return zero on failure, non-zero on success. On failure, you can
  1863. * find out what went wrong from PHYSFS_getLastError().
  1864. *
  1865. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1866. * any sort of 64-bit support.
  1867. */
  1868. PHYSFS_DECL int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1869. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1870. /**
  1871. * \fn int PHYSFS_isInit(void)
  1872. * \brief Determine if the PhysicsFS library is initialized.
  1873. *
  1874. * Once PHYSFS_init() returns successfully, this will return non-zero.
  1875. * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns
  1876. * successfully, this will return zero. This function is safe to call at
  1877. * any time.
  1878. *
  1879. * \return non-zero if library is initialized, zero if library is not.
  1880. *
  1881. * \sa PHYSFS_init
  1882. * \sa PHYSFS_deinit
  1883. */
  1884. PHYSFS_DECL int PHYSFS_isInit(void);
  1885. /**
  1886. * \fn int PHYSFS_symbolicLinksPermitted(void)
  1887. * \brief Determine if the symbolic links are permitted.
  1888. *
  1889. * This reports the setting from the last call to PHYSFS_permitSymbolicLinks().
  1890. * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was
  1891. * last initialized, symbolic links are implicitly disabled.
  1892. *
  1893. * \return non-zero if symlinks are permitted, zero if not.
  1894. *
  1895. * \sa PHYSFS_permitSymbolicLinks
  1896. */
  1897. PHYSFS_DECL int PHYSFS_symbolicLinksPermitted(void);
  1898. #ifndef SWIG /* not available from scripting languages. */
  1899. /**
  1900. * \struct PHYSFS_Allocator
  1901. * \brief PhysicsFS allocation function pointers.
  1902. *
  1903. * (This is for limited, hardcore use. If you don't immediately see a need
  1904. * for it, you can probably ignore this forever.)
  1905. *
  1906. * You create one of these structures for use with PHYSFS_setAllocator.
  1907. * Allocators are assumed to be reentrant by the caller; please mutex
  1908. * accordingly.
  1909. *
  1910. * Allocations are always discussed in 64-bits, for future expansion...we're
  1911. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1912. * gigabytes like it's nothing sooner or later, and I don't want to change
  1913. * this again at that point. If you're on a 32-bit platform and have to
  1914. * downcast, it's okay to return NULL if the allocation is greater than
  1915. * 4 gigabytes, since you'd have to do so anyhow.
  1916. *
  1917. * \sa PHYSFS_setAllocator
  1918. */
  1919. typedef struct PHYSFS_Allocator
  1920. {
  1921. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1922. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1923. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1924. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1925. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1926. } PHYSFS_Allocator;
  1927. /**
  1928. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1929. * \brief Hook your own allocation routines into PhysicsFS.
  1930. *
  1931. * (This is for limited, hardcore use. If you don't immediately see a need
  1932. * for it, you can probably ignore this forever.)
  1933. *
  1934. * By default, PhysicsFS will use whatever is reasonable for a platform
  1935. * to manage dynamic memory (usually ANSI C malloc/realloc/free, but
  1936. * some platforms might use something else), but in some uncommon cases, the
  1937. * app might want more control over the library's memory management. This
  1938. * lets you redirect PhysicsFS to use your own allocation routines instead.
  1939. * You can only call this function before PHYSFS_init(); if the library is
  1940. * initialized, it'll reject your efforts to change the allocator mid-stream.
  1941. * You may call this function after PHYSFS_deinit() if you are willing to
  1942. * shut down the library and restart it with a new allocator; this is a safe
  1943. * and supported operation. The allocator remains intact between deinit/init
  1944. * calls. If you want to return to the platform's default allocator, pass a
  1945. * NULL in here.
  1946. *
  1947. * If you aren't immediately sure what to do with this function, you can
  1948. * safely ignore it altogether.
  1949. *
  1950. * \param allocator Structure containing your allocator's entry points.
  1951. * \return zero on failure, non-zero on success. This call only fails
  1952. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1953. */
  1954. PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1955. #endif /* SWIG */
  1956. /**
  1957. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
  1958. * \brief Add an archive or directory to the search path.
  1959. *
  1960. * If this is a duplicate, the entry is not added again, even though the
  1961. * function succeeds. You may not add the same archive to two different
  1962. * mountpoints: duplicate checking is done against the archive and not the
  1963. * mountpoint.
  1964. *
  1965. * When you mount an archive, it is added to a virtual file system...all files
  1966. * in all of the archives are interpolated into a single hierachical file
  1967. * tree. Two archives mounted at the same place (or an archive with files
  1968. * overlapping another mountpoint) may have overlapping files: in such a case,
  1969. * the file earliest in the search path is selected, and the other files are
  1970. * inaccessible to the application. This allows archives to be used to
  1971. * override previous revisions; you can use the mounting mechanism to place
  1972. * archives at a specific point in the file tree and prevent overlap; this
  1973. * is useful for downloadable mods that might trample over application data
  1974. * or each other, for example.
  1975. *
  1976. * The mountpoint does not need to exist prior to mounting, which is different
  1977. * than those familiar with the Unix concept of "mounting" may not expect.
  1978. * As well, more than one archive can be mounted to the same mountpoint, or
  1979. * mountpoints and archive contents can overlap...the interpolation mechanism
  1980. * still functions as usual.
  1981. *
  1982. * \param newDir directory or archive to add to the path, in
  1983. * platform-dependent notation.
  1984. * \param mountPoint Location in the interpolated tree that this archive
  1985. * will be "mounted", in platform-independent notation.
  1986. * NULL or "" is equivalent to "/".
  1987. * \param appendToPath nonzero to append to search path, zero to prepend.
  1988. * \return nonzero if added to path, zero on failure (bogus archive, dir
  1989. * missing, etc). Specifics of the error can be
  1990. * gleaned from PHYSFS_getLastError().
  1991. *
  1992. * \sa PHYSFS_removeFromSearchPath
  1993. * \sa PHYSFS_getSearchPath
  1994. * \sa PHYSFS_getMountPoint
  1995. * \sa PHYSFS_mountIo
  1996. */
  1997. PHYSFS_DECL int PHYSFS_mount(const char *newDir,
  1998. const char *mountPoint,
  1999. int appendToPath);
  2000. /**
  2001. * \fn int PHYSFS_getMountPoint(const char *dir)
  2002. * \brief Determine a mounted archive's mountpoint.
  2003. *
  2004. * You give this function the name of an archive or dir you successfully
  2005. * added to the search path, and it reports the location in the interpolated
  2006. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  2007. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  2008. * and valid until the archive is removed from the search path.
  2009. *
  2010. * \param dir directory or archive previously added to the path, in
  2011. * platform-dependent notation. This must match the string
  2012. * used when adding, even if your string would also reference
  2013. * the same file with a different string of characters.
  2014. * \return READ-ONLY string of mount point if added to path, NULL on failure
  2015. * (bogus archive, etc) Specifics of the error can be gleaned from
  2016. * PHYSFS_getLastError().
  2017. *
  2018. * \sa PHYSFS_removeFromSearchPath
  2019. * \sa PHYSFS_getSearchPath
  2020. * \sa PHYSFS_getMountPoint
  2021. */
  2022. PHYSFS_DECL const char *PHYSFS_getMountPoint(const char *dir);
  2023. #ifndef SWIG /* not available from scripting languages. */
  2024. /**
  2025. * \typedef PHYSFS_StringCallback
  2026. * \brief Function signature for callbacks that report strings.
  2027. *
  2028. * These are used to report a list of strings to an original caller, one
  2029. * string per callback. All strings are UTF-8 encoded. Functions should not
  2030. * try to modify or free the string's memory.
  2031. *
  2032. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  2033. * functions that would return lists that need to be cleaned up with
  2034. * PHYSFS_freeList(). The callback means that the library doesn't need to
  2035. * allocate an entire list and all the strings up front.
  2036. *
  2037. * Be aware that promises data ordering in the list versions are not
  2038. * necessarily so in the callback versions. Check the documentation on
  2039. * specific APIs, but strings may not be sorted as you expect.
  2040. *
  2041. * \param data User-defined data pointer, passed through from the API
  2042. * that eventually called the callback.
  2043. * \param str The string data about which the callback is meant to inform.
  2044. *
  2045. * \sa PHYSFS_getCdRomDirsCallback
  2046. * \sa PHYSFS_getSearchPathCallback
  2047. */
  2048. typedef void (*PHYSFS_StringCallback)(void *data, const char *str);
  2049. /**
  2050. * \typedef PHYSFS_EnumFilesCallback
  2051. * \brief Function signature for callbacks that enumerate files.
  2052. *
  2053. * These are used to report a list of directory entries to an original caller,
  2054. * one file/dir/symlink per callback. All strings are UTF-8 encoded.
  2055. * Functions should not try to modify or free any string's memory.
  2056. *
  2057. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  2058. * functions that would return lists that need to be cleaned up with
  2059. * PHYSFS_freeList(). The callback means that the library doesn't need to
  2060. * allocate an entire list and all the strings up front.
  2061. *
  2062. * Be aware that promises data ordering in the list versions are not
  2063. * necessarily so in the callback versions. Check the documentation on
  2064. * specific APIs, but strings may not be sorted as you expect.
  2065. *
  2066. * \param data User-defined data pointer, passed through from the API
  2067. * that eventually called the callback.
  2068. * \param origdir A string containing the full path, in platform-independent
  2069. * notation, of the directory containing this file. In most
  2070. * cases, this is the directory on which you requested
  2071. * enumeration, passed in the callback for your convenience.
  2072. * \param fname The filename that is being enumerated. It may not be in
  2073. * alphabetical order compared to other callbacks that have
  2074. * fired, and it will not contain the full path. You can
  2075. * recreate the fullpath with $origdir/$fname ... The file
  2076. * can be a subdirectory, a file, a symlink, etc.
  2077. *
  2078. * \sa PHYSFS_enumerateFilesCallback
  2079. */
  2080. typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir,
  2081. const char *fname);
  2082. /**
  2083. * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d)
  2084. * \brief Enumerate CD-ROM directories, using an application-defined callback.
  2085. *
  2086. * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds
  2087. * a list before returning to the application, so functionality is identical
  2088. * except for how the information is represented to the application.
  2089. *
  2090. * Unlike PHYSFS_getCdRomDirs(), this function does not return an array.
  2091. * Rather, it calls a function specified by the application once per
  2092. * detected disc:
  2093. *
  2094. * \code
  2095. *
  2096. * static void foundDisc(void *data, const char *cddir)
  2097. * {
  2098. * printf("cdrom dir [%s] is available.\n", cddir);
  2099. * }
  2100. *
  2101. * // ...
  2102. * PHYSFS_getCdRomDirsCallback(foundDisc, NULL);
  2103. * \endcode
  2104. *
  2105. * This call may block while drives spin up. Be forewarned.
  2106. *
  2107. * \param c Callback function to notify about detected drives.
  2108. * \param d Application-defined data passed to callback. Can be NULL.
  2109. *
  2110. * \sa PHYSFS_StringCallback
  2111. * \sa PHYSFS_getCdRomDirs
  2112. */
  2113. PHYSFS_DECL void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  2114. /**
  2115. * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d)
  2116. * \brief Enumerate the search path, using an application-defined callback.
  2117. *
  2118. * Internally, PHYSFS_getSearchPath() just calls this function and then builds
  2119. * a list before returning to the application, so functionality is identical
  2120. * except for how the information is represented to the application.
  2121. *
  2122. * Unlike PHYSFS_getSearchPath(), this function does not return an array.
  2123. * Rather, it calls a function specified by the application once per
  2124. * element of the search path:
  2125. *
  2126. * \code
  2127. *
  2128. * static void printSearchPath(void *data, const char *pathItem)
  2129. * {
  2130. * printf("[%s] is in the search path.\n", pathItem);
  2131. * }
  2132. *
  2133. * // ...
  2134. * PHYSFS_getSearchPathCallback(printSearchPath, NULL);
  2135. * \endcode
  2136. *
  2137. * Elements of the search path are reported in order search priority, so the
  2138. * first archive/dir that would be examined when looking for a file is the
  2139. * first element passed through the callback.
  2140. *
  2141. * \param c Callback function to notify about search path elements.
  2142. * \param d Application-defined data passed to callback. Can be NULL.
  2143. *
  2144. * \sa PHYSFS_StringCallback
  2145. * \sa PHYSFS_getSearchPath
  2146. */
  2147. PHYSFS_DECL void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  2148. /**
  2149. * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d)
  2150. * \brief Get a file listing of a search path's directory, using an application-defined callback.
  2151. *
  2152. * Internally, PHYSFS_enumerateFiles() just calls this function and then builds
  2153. * a list before returning to the application, so functionality is identical
  2154. * except for how the information is represented to the application.
  2155. *
  2156. * Unlike PHYSFS_enumerateFiles(), this function does not return an array.
  2157. * Rather, it calls a function specified by the application once per
  2158. * element of the search path:
  2159. *
  2160. * \code
  2161. *
  2162. * static void printDir(void *data, const char *origdir, const char *fname)
  2163. * {
  2164. * printf(" * We've got [%s] in [%s].\n", fname, origdir);
  2165. * }
  2166. *
  2167. * // ...
  2168. * PHYSFS_enumerateFilesCallback("/some/path", printDir, NULL);
  2169. * \endcode
  2170. *
  2171. * !!! FIXME: enumerateFiles() does not promise alphabetical sorting by
  2172. * !!! FIXME: case-sensitivity in the code, and doesn't promise sorting at
  2173. * !!! FIXME: all in the above docs.
  2174. *
  2175. * Items sent to the callback are not guaranteed to be in any order whatsoever.
  2176. * There is no sorting done at this level, and if you need that, you should
  2177. * probably use PHYSFS_enumerateFiles() instead, which guarantees
  2178. * alphabetical sorting. This form reports whatever is discovered in each
  2179. * archive before moving on to the next. Even within one archive, we can't
  2180. * guarantee what order it will discover data. <em>Any sorting you find in
  2181. * these callbacks is just pure luck. Do not rely on it.</em> As this walks
  2182. * the entire list of archives, you may receive duplicate filenames.
  2183. *
  2184. * \param dir Directory, in platform-independent notation, to enumerate.
  2185. * \param c Callback function to notify about search path elements.
  2186. * \param d Application-defined data passed to callback. Can be NULL.
  2187. *
  2188. * \sa PHYSFS_EnumFilesCallback
  2189. * \sa PHYSFS_enumerateFiles
  2190. */
  2191. PHYSFS_DECL void PHYSFS_enumerateFilesCallback(const char *dir,
  2192. PHYSFS_EnumFilesCallback c,
  2193. void *d);
  2194. /**
  2195. * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
  2196. * \brief Convert a UCS-4 string to a UTF-8 string.
  2197. *
  2198. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2199. *
  2200. * To ensure that the destination buffer is large enough for the conversion,
  2201. * please allocate a buffer that is the same size as the source buffer. UTF-8
  2202. * never uses more than 32-bits per character, so while it may shrink a UCS-4
  2203. * string, it will never expand it.
  2204. *
  2205. * Strings that don't fit in the destination buffer will be truncated, but
  2206. * will always be null-terminated and never have an incomplete UTF-8
  2207. * sequence at the end. If the buffer length is 0, this function does nothing.
  2208. *
  2209. * \param src Null-terminated source string in UCS-4 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_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst,
  2214. PHYSFS_uint64 len);
  2215. /**
  2216. * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
  2217. * \brief Convert a UTF-8 string to a UCS-4 string.
  2218. *
  2219. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2220. *
  2221. * To ensure that the destination buffer is large enough for the conversion,
  2222. * please allocate a buffer that is four times the size of the source buffer.
  2223. * UTF-8 uses from one to four bytes per character, but UCS-4 always uses
  2224. * four, so an entirely low-ASCII string will quadruple in size!
  2225. *
  2226. * Strings that don't fit in the destination buffer will be truncated, but
  2227. * will always be null-terminated and never have an incomplete UCS-4
  2228. * sequence at the end. If the buffer length is 0, this function does nothing.
  2229. *
  2230. * \param src Null-terminated source string in UTF-8 format.
  2231. * \param dst Buffer to store converted UCS-4 string.
  2232. * \param len Size, in bytes, of destination buffer.
  2233. */
  2234. PHYSFS_DECL void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst,
  2235. PHYSFS_uint64 len);
  2236. /**
  2237. * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2238. * \brief Convert a UCS-2 string to a UTF-8 string.
  2239. *
  2240. * \warning you almost certainly should use PHYSFS_utf8FromUtf16(), which
  2241. * became available in PhysicsFS 2.1, unless you know what you're doing.
  2242. *
  2243. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2244. * with Unicode support. Please note that modern versions of Windows use
  2245. * UTF-16, which is an extended form of UCS-2, and not UCS-2 itself. You
  2246. * almost certainly want PHYSFS_utf8FromUtf16() instead.
  2247. *
  2248. * To ensure that the destination buffer is large enough for the conversion,
  2249. * please allocate a buffer that is double the size of the source buffer.
  2250. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2251. * a UCS-2 string, it may also expand it.
  2252. *
  2253. * Strings that don't fit in the destination buffer will be truncated, but
  2254. * will always be null-terminated and never have an incomplete UTF-8
  2255. * sequence at the end. If the buffer length is 0, this function does nothing.
  2256. *
  2257. * \param src Null-terminated source string in UCS-2 format.
  2258. * \param dst Buffer to store converted UTF-8 string.
  2259. * \param len Size, in bytes, of destination buffer.
  2260. *
  2261. * \sa PHYSFS_utf8FromUtf16
  2262. */
  2263. PHYSFS_DECL void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst,
  2264. PHYSFS_uint64 len);
  2265. /**
  2266. * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2267. * \brief Convert a UTF-8 string to a UCS-2 string.
  2268. *
  2269. * \warning you almost certainly should use PHYSFS_utf8ToUtf16(), which
  2270. * became available in PhysicsFS 2.1, unless you know what you're doing.
  2271. *
  2272. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2273. * with Unicode support. Please note that modern versions of Windows use
  2274. * UTF-16, which is an extended form of UCS-2, and not UCS-2 itself. You
  2275. * almost certainly want PHYSFS_utf8ToUtf16() instead, but you need to
  2276. * understand how that changes things, too.
  2277. *
  2278. * To ensure that the destination buffer is large enough for the conversion,
  2279. * please allocate a buffer that is double the size of the source buffer.
  2280. * UTF-8 uses from one to four bytes per character, but UCS-2 always uses
  2281. * two, so an entirely low-ASCII string will double in size!
  2282. *
  2283. * Strings that don't fit in the destination buffer will be truncated, but
  2284. * will always be null-terminated and never have an incomplete UCS-2
  2285. * sequence at the end. If the buffer length is 0, this function does nothing.
  2286. *
  2287. * \param src Null-terminated source string in UTF-8 format.
  2288. * \param dst Buffer to store converted UCS-2 string.
  2289. * \param len Size, in bytes, of destination buffer.
  2290. *
  2291. * \sa PHYSFS_utf8ToUtf16
  2292. */
  2293. PHYSFS_DECL void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst,
  2294. PHYSFS_uint64 len);
  2295. /**
  2296. * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
  2297. * \brief Convert a UTF-8 string to a Latin1 string.
  2298. *
  2299. * Latin1 strings are 8-bits per character: a popular "high ASCII" encoding.
  2300. *
  2301. * To ensure that the destination buffer is large enough for the conversion,
  2302. * please allocate a buffer that is double the size of the source buffer.
  2303. * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string
  2304. * may grow in some cases.
  2305. *
  2306. * Strings that don't fit in the destination buffer will be truncated, but
  2307. * will always be null-terminated and never have an incomplete UTF-8
  2308. * sequence at the end. If the buffer length is 0, this function does nothing.
  2309. *
  2310. * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  2311. * can't express most Unicode codepoints. It's a legacy encoding; you should
  2312. * be converting away from it at all times.
  2313. *
  2314. * \param src Null-terminated source string in Latin1 format.
  2315. * \param dst Buffer to store converted UTF-8 string.
  2316. * \param len Size, in bytes, of destination buffer.
  2317. */
  2318. PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst,
  2319. PHYSFS_uint64 len);
  2320. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  2321. /**
  2322. * \fn int PHYSFS_unmount(const char *oldDir)
  2323. * \brief Remove a directory or archive from the search path.
  2324. *
  2325. * This is functionally equivalent to PHYSFS_removeFromSearchPath(), but that
  2326. * function is deprecated to keep the vocabulary paired with PHYSFS_mount().
  2327. *
  2328. * This must be a (case-sensitive) match to a dir or archive already in the
  2329. * search path, specified in platform-dependent notation.
  2330. *
  2331. * This call will fail (and fail to remove from the path) if the element still
  2332. * has files open in it.
  2333. *
  2334. * \param oldDir dir/archive to remove.
  2335. * \return nonzero on success, zero on failure.
  2336. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  2337. *
  2338. * \sa PHYSFS_getSearchPath
  2339. * \sa PHYSFS_mount
  2340. */
  2341. PHYSFS_DECL int PHYSFS_unmount(const char *oldDir);
  2342. /**
  2343. * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void)
  2344. * \brief Discover the current allocator.
  2345. *
  2346. * (This is for limited, hardcore use. If you don't immediately see a need
  2347. * for it, you can probably ignore this forever.)
  2348. *
  2349. * This function exposes the function pointers that make up the currently used
  2350. * allocator. This can be useful for apps that want to access PhysicsFS's
  2351. * internal, default allocation routines, as well as for external code that
  2352. * wants to share the same allocator, even if the application specified their
  2353. * own.
  2354. *
  2355. * This call is only valid between PHYSFS_init() and PHYSFS_deinit() calls;
  2356. * it will return NULL if the library isn't initialized. As we can't
  2357. * guarantee the state of the internal allocators unless the library is
  2358. * initialized, you shouldn't use any allocator returned here after a call
  2359. * to PHYSFS_deinit().
  2360. *
  2361. * Do not call the returned allocator's Init() or Deinit() methods under any
  2362. * circumstances.
  2363. *
  2364. * If you aren't immediately sure what to do with this function, you can
  2365. * safely ignore it altogether.
  2366. *
  2367. * \return Current allocator, as set by PHYSFS_setAllocator(), or PhysicsFS's
  2368. * internal, default allocator if no application defined allocator
  2369. * is currently set. Will return NULL if the library is not
  2370. * initialized.
  2371. *
  2372. * \sa PHYSFS_Allocator
  2373. * \sa PHYSFS_setAllocator
  2374. */
  2375. PHYSFS_DECL const PHYSFS_Allocator *PHYSFS_getAllocator(void);
  2376. #endif /* SWIG */
  2377. /**
  2378. * \enum PHYSFS_FileType
  2379. * \brief Type of a File
  2380. *
  2381. * Possible types of a file.
  2382. *
  2383. * \sa PHYSFS_stat
  2384. */
  2385. typedef enum PHYSFS_FileType
  2386. {
  2387. PHYSFS_FILETYPE_REGULAR, /**< a normal file */
  2388. PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
  2389. PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
  2390. PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
  2391. } PHYSFS_FileType;
  2392. /**
  2393. * \struct PHYSFS_Stat
  2394. * \brief Meta data for a file or directory
  2395. *
  2396. * Container for various meta data about a file in the virtual file system.
  2397. * PHYSFS_stat() uses this structure for returning the information. The time
  2398. * data will be either the number of seconds since the Unix epoch (midnight,
  2399. * Jan 1, 1970), or -1 if the information isn't available or applicable.
  2400. * The (filesize) field is measured in bytes.
  2401. * The (readonly) field tells you whether when you open a file for writing you
  2402. * are writing to the same file as if you were opening it, given you have
  2403. * enough filesystem rights to do that. !!! FIXME: this might change.
  2404. *
  2405. * \sa PHYSFS_stat
  2406. * \sa PHYSFS_FileType
  2407. */
  2408. typedef struct PHYSFS_Stat
  2409. {
  2410. PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
  2411. PHYSFS_sint64 modtime; /**< last modification time */
  2412. PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
  2413. PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
  2414. PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
  2415. int readonly; /**< non-zero if read only, zero if writable. */
  2416. } PHYSFS_Stat;
  2417. /**
  2418. * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
  2419. * \brief Get various information about a directory or a file.
  2420. *
  2421. * Obtain various information about a file or directory from the meta data.
  2422. *
  2423. * This function will never follow symbolic links. If you haven't enabled
  2424. * symlinks with PHYSFS_permitSymbolicLinks(), stat'ing a symlink will be
  2425. * treated like stat'ing a non-existant file. If symlinks are enabled,
  2426. * stat'ing a symlink will give you information on the link itself and not
  2427. * what it points to.
  2428. *
  2429. * \param fname filename to check, in platform-indepedent notation.
  2430. * \param stat pointer to structure to fill in with data about (fname).
  2431. * \return non-zero on success, zero on failure. On failure, (stat)'s
  2432. * contents are undefined.
  2433. *
  2434. * \sa PHYSFS_Stat
  2435. */
  2436. PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
  2437. #ifndef SWIG /* not available from scripting languages. */
  2438. /**
  2439. * \fn void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2440. * \brief Convert a UTF-16 string to a UTF-8 string.
  2441. *
  2442. * UTF-16 strings are 16-bits per character (except some chars, which are
  2443. * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern
  2444. * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but
  2445. * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that
  2446. * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you
  2447. * aren't sure, you should be using UTF-16 at this point on Windows.
  2448. *
  2449. * To ensure that the destination buffer is large enough for the conversion,
  2450. * please allocate a buffer that is double the size of the source buffer.
  2451. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2452. * a UTF-16 string, it may also expand it.
  2453. *
  2454. * Strings that don't fit in the destination buffer will be truncated, but
  2455. * will always be null-terminated and never have an incomplete UTF-8
  2456. * sequence at the end. If the buffer length is 0, this function does nothing.
  2457. *
  2458. * \param src Null-terminated source string in UTF-16 format.
  2459. * \param dst Buffer to store converted UTF-8 string.
  2460. * \param len Size, in bytes, of destination buffer.
  2461. */
  2462. PHYSFS_DECL void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst,
  2463. PHYSFS_uint64 len);
  2464. /**
  2465. * \fn PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2466. * \brief Convert a UTF-8 string to a UTF-16 string.
  2467. *
  2468. * UTF-16 strings are 16-bits per character (except some chars, which are
  2469. * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern
  2470. * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but
  2471. * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that
  2472. * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you
  2473. * aren't sure, you should be using UTF-16 at this point on Windows.
  2474. *
  2475. * To ensure that the destination buffer is large enough for the conversion,
  2476. * please allocate a buffer that is double the size of the source buffer.
  2477. * UTF-8 uses from one to four bytes per character, but UTF-16 always uses
  2478. * two to four, so an entirely low-ASCII string will double in size! The
  2479. * UTF-16 characters that would take four bytes also take four bytes in UTF-8,
  2480. * so you don't need to allocate 4x the space just in case: double will do.
  2481. *
  2482. * Strings that don't fit in the destination buffer will be truncated, but
  2483. * will always be null-terminated and never have an incomplete UTF-16
  2484. * surrogate pair at the end. If the buffer length is 0, this function does
  2485. * nothing.
  2486. *
  2487. * \param src Null-terminated source string in UTF-8 format.
  2488. * \param dst Buffer to store converted UTF-16 string.
  2489. * \param len Size, in bytes, of destination buffer.
  2490. *
  2491. * \sa PHYSFS_utf8ToUtf16
  2492. */
  2493. PHYSFS_DECL void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst,
  2494. PHYSFS_uint64 len);
  2495. #endif /* SWIG */
  2496. /**
  2497. * \fn PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer, PHYSFS_uint64 len)
  2498. * \brief Read bytes from a PhysicsFS filehandle
  2499. *
  2500. * The file must be opened for reading.
  2501. *
  2502. * \param handle handle returned from PHYSFS_openRead().
  2503. * \param buffer buffer of at least (len) bytes to store read data into.
  2504. * \param len number of bytes being read from (handle).
  2505. * \return number of bytes read. This may be less than (len); this does not
  2506. * signify an error, necessarily (a short read may mean EOF).
  2507. * PHYSFS_getLastError() can shed light on the reason this might
  2508. * be < (len), as can PHYSFS_eof(). -1 if complete failure.
  2509. *
  2510. * \sa PHYSFS_eof
  2511. */
  2512. PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
  2513. PHYSFS_uint64 len);
  2514. /**
  2515. * \fn PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle, const void *buffer, PHYSFS_uint64 len)
  2516. * \brief Write data to a PhysicsFS filehandle
  2517. *
  2518. * The file must be opened for writing.
  2519. *
  2520. * Please note that while (len) is an unsigned 64-bit integer, you are limited
  2521. * to 63 bits (9223372036854775807 bytes), so we can return a negative value
  2522. * on error. If length is greater than 0x7FFFFFFFFFFFFFFF, this function will
  2523. * immediately fail. For systems without a 64-bit datatype, you are limited
  2524. * to 31 bits (0x7FFFFFFF, or 2147483647 bytes). We trust most things won't
  2525. * need to do multiple gigabytes of i/o in one call anyhow, but why limit
  2526. * things?
  2527. *
  2528. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  2529. * \param buffer buffer of (len) bytes to write to (handle).
  2530. * \param len number of bytes being written to (handle).
  2531. * \return number of bytes written. This may be less than (len); in the case
  2532. * of an error, the system may try to write as many bytes as possible,
  2533. * so an incomplete write might occur. PHYSFS_getLastError() can shed
  2534. * light on the reason this might be < (len). -1 if complete failure.
  2535. */
  2536. PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
  2537. const void *buffer,
  2538. PHYSFS_uint64 len);
  2539. #ifndef SWIG /* not available from scripting languages. */
  2540. /**
  2541. * \struct PHYSFS_Io
  2542. * \brief An abstract i/o interface.
  2543. *
  2544. * \warning This is advanced, hardcore stuff. You don't need this unless you
  2545. * really know what you're doing. Most apps will not need this.
  2546. *
  2547. * Historically, PhysicsFS provided access to the physical filesystem and
  2548. * archives within that filesystem. However, sometimes you need more power
  2549. * than this. Perhaps you need to provide an archive that is entirely
  2550. * contained in RAM, or you need to bridge some other file i/o API to
  2551. * PhysicsFS, or you need to translate the bits (perhaps you have a
  2552. * a standard .zip file that's encrypted, and you need to decrypt on the fly
  2553. * for the unsuspecting zip archiver).
  2554. *
  2555. * A PHYSFS_Io is the interface that Archivers use to get archive data.
  2556. * Historically, this has mapped to file i/o to the physical filesystem, but
  2557. * as of PhysicsFS 2.1, applications can provide their own i/o implementations
  2558. * at runtime.
  2559. *
  2560. * This interface isn't necessarily a good universal fit for i/o. There are a
  2561. * few requirements of note:
  2562. *
  2563. * - They only do blocking i/o (at least, for now).
  2564. * - They need to be able to duplicate. If you have a file handle from
  2565. * fopen(), you need to be able to create a unique clone of it (so we
  2566. * have two handles to the same file that can both seek/read/etc without
  2567. * stepping on each other).
  2568. * - They need to know the size of their entire data set.
  2569. * - They need to be able to seek and rewind on demand.
  2570. *
  2571. * ...in short, you're probably not going to write an HTTP implementation.
  2572. *
  2573. * Thread safety: TO BE DECIDED. !!! FIXME
  2574. *
  2575. * \sa PHYSFS_mountIo
  2576. */
  2577. typedef struct PHYSFS_Io
  2578. {
  2579. /**
  2580. * \brief Binary compatibility information.
  2581. *
  2582. * This must be set to zero at this time. Future versions of this
  2583. * struct will increment this field, so we know what a given
  2584. * implementation supports. We'll presumably keep supporting older
  2585. * versions as we offer new features, though.
  2586. */
  2587. PHYSFS_uint32 version;
  2588. /**
  2589. * \brief Instance data for this struct.
  2590. *
  2591. * Each instance has a pointer associated with it that can be used to
  2592. * store anything it likes. This pointer is per-instance of the stream,
  2593. * so presumably it will change when calling duplicate(). This can be
  2594. * deallocated during the destroy() method.
  2595. */
  2596. void *opaque;
  2597. /**
  2598. * \brief Read more data.
  2599. *
  2600. * Read (len) bytes from the interface, at the current i/o position, and
  2601. * store them in (buffer). The current i/o position should move ahead
  2602. * by the number of bytes successfully read.
  2603. *
  2604. * You don't have to implement this; set it to NULL if not implemented.
  2605. * This will only be used if the file is opened for reading. If set to
  2606. * NULL, a default implementation that immediately reports failure will
  2607. * be used.
  2608. *
  2609. * \param io The i/o instance to read from.
  2610. * \param buf The buffer to store data into. It must be at least
  2611. * (len) bytes long and can't be NULL.
  2612. * \param len The number of bytes to read from the interface.
  2613. * \return number of bytes read from file, 0 on EOF, -1 if complete
  2614. * failure.
  2615. */
  2616. PHYSFS_sint64 (*read)(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len);
  2617. /**
  2618. * \brief Write more data.
  2619. *
  2620. * Write (len) bytes from (buffer) to the interface at the current i/o
  2621. * position. The current i/o position should move ahead by the number of
  2622. * bytes successfully written.
  2623. *
  2624. * You don't have to implement this; set it to NULL if not implemented.
  2625. * This will only be used if the file is opened for writing. If set to
  2626. * NULL, a default implementation that immediately reports failure will
  2627. * be used.
  2628. *
  2629. * You are allowed to buffer; a write can succeed here and then later
  2630. * fail when flushing. Note that PHYSFS_setBuffer() may be operating a
  2631. * level above your i/o, so you should usually not implement your
  2632. * own buffering routines.
  2633. *
  2634. * \param io The i/o instance to write to.
  2635. * \param buffer The buffer to read data from. It must be at least
  2636. * (len) bytes long and can't be NULL.
  2637. * \param len The number of bytes to read from (buffer).
  2638. * \return number of bytes written to file, -1 if complete failure.
  2639. */
  2640. PHYSFS_sint64 (*write)(struct PHYSFS_Io *io, const void *buffer,
  2641. PHYSFS_uint64 len);
  2642. /**
  2643. * \brief Move i/o position to a given byte offset from start.
  2644. *
  2645. * This method moves the i/o position, so the next read/write will
  2646. * be of the byte at (offset) offset. Seeks past the end of file should
  2647. * be treated as an error condition.
  2648. *
  2649. * \param io The i/o instance to seek.
  2650. * \param offset The new byte offset for the i/o position.
  2651. * \return non-zero on success, zero on error.
  2652. */
  2653. int (*seek)(struct PHYSFS_Io *io, PHYSFS_uint64 offset);
  2654. /**
  2655. * \brief Report current i/o position.
  2656. *
  2657. * Return bytes offset, or -1 if you aren't able to determine. A failure
  2658. * will almost certainly be fatal to further use of this stream, so you
  2659. * may not leave this unimplemented.
  2660. *
  2661. * \param io The i/o instance to query.
  2662. * \return The current byte offset for the i/o position, -1 if unknown.
  2663. */
  2664. PHYSFS_sint64 (*tell)(struct PHYSFS_Io *io);
  2665. /**
  2666. * \brief Determine size of the i/o instance's dataset.
  2667. *
  2668. * Return number of bytes available in the file, or -1 if you
  2669. * aren't able to determine. A failure will almost certainly be fatal
  2670. * to further use of this stream, so you may not leave this unimplemented.
  2671. *
  2672. * \param io The i/o instance to query.
  2673. * \return Total size, in bytes, of the dataset.
  2674. */
  2675. PHYSFS_sint64 (*length)(struct PHYSFS_Io *io);
  2676. /**
  2677. * \brief Duplicate this i/o instance.
  2678. *
  2679. * // !!! FIXME: write me.
  2680. *
  2681. * \param io The i/o instance to duplicate.
  2682. * \return A new value for a stream's (opaque) field, or NULL on error.
  2683. */
  2684. struct PHYSFS_Io *(*duplicate)(struct PHYSFS_Io *io);
  2685. /**
  2686. * \brief Flush resources to media, or wherever.
  2687. *
  2688. * This is the chance to report failure for writes that had claimed
  2689. * success earlier, but still had a chance to actually fail. This method
  2690. * can be NULL if flushing isn't necessary.
  2691. *
  2692. * This function may be called before destroy(), as it can report failure
  2693. * and destroy() can not. It may be called at other times, too.
  2694. *
  2695. * \param io The i/o instance to flush.
  2696. * \return Zero on error, non-zero on success.
  2697. */
  2698. int (*flush)(struct PHYSFS_Io *io);
  2699. /**
  2700. * \brief Cleanup and deallocate i/o instance.
  2701. *
  2702. * Free associated resources, including (opaque) if applicable.
  2703. *
  2704. * This function must always succeed: as such, it returns void. The
  2705. * system may call your flush() method before this. You may report
  2706. * failure there if necessary. This method may still be called if
  2707. * flush() fails, in which case you'll have to abandon unflushed data
  2708. * and other failing conditions and clean up.
  2709. *
  2710. * Once this method is called for a given instance, the system will assume
  2711. * it is unsafe to touch that instance again and will discard any
  2712. * references to it.
  2713. *
  2714. * \param s The i/o instance to destroy.
  2715. */
  2716. void (*destroy)(struct PHYSFS_Io *io);
  2717. } PHYSFS_Io;
  2718. /**
  2719. * \fn int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname, const char *mountPoint, int appendToPath)
  2720. * \brief Add an archive, built on a PHYSFS_Io, to the search path.
  2721. *
  2722. * \warning Unless you have some special, low-level need, you should be using
  2723. * PHYSFS_mount() instead of this.
  2724. *
  2725. * This function operates just like PHYSFS_mount(), but takes a PHYSFS_Io
  2726. * instead of a pathname. Behind the scenes, PHYSFS_mount() calls this
  2727. * function with a physical-filesystem-based PHYSFS_Io.
  2728. *
  2729. * (filename) is only used here to optimize archiver selection (if you name it
  2730. * XXXXX.zip, we might try the ZIP archiver first, for example). It doesn't
  2731. * need to refer to a real file at all, and can even be NULL. If the filename
  2732. * isn't helpful, the system will try every archiver until one works or none
  2733. * of them do.
  2734. *
  2735. * (io) must remain until the archive is unmounted. When the archive is
  2736. * unmounted, the system will call (io)->destroy(io), which will give you
  2737. * a chance to free your resources.
  2738. *
  2739. * If this function fails, (io)->destroy(io) is not called.
  2740. *
  2741. * \param io i/o instance for archive to add to the path.
  2742. * \param fname Filename that can represent this stream. Can be NULL.
  2743. * \param mountPoint Location in the interpolated tree that this archive
  2744. * will be "mounted", in platform-independent notation.
  2745. * NULL or "" is equivalent to "/".
  2746. * \param appendToPath nonzero to append to search path, zero to prepend.
  2747. * \return nonzero if added to path, zero on failure (bogus archive, stream
  2748. * i/o issue, etc). Specifics of the error can be
  2749. * gleaned from PHYSFS_getLastError().
  2750. *
  2751. * \sa PHYSFS_unmount
  2752. * \sa PHYSFS_getSearchPath
  2753. * \sa PHYSFS_getMountPoint
  2754. */
  2755. PHYSFS_DECL int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname,
  2756. const char *mountPoint, int appendToPath);
  2757. #endif /* SWIG */
  2758. /**
  2759. * \fn int PHYSFS_mountMemory(const void *ptr, PHYSFS_uint64 len, void (*del)(void *), const char *fname, const char *mountPoint, int appendToPath)
  2760. * \brief Add an archive, contained in a memory buffer, to the search path.
  2761. *
  2762. * \warning Unless you have some special, low-level need, you should be using
  2763. * PHYSFS_mount() instead of this.
  2764. *
  2765. * This function operates just like PHYSFS_mount(), but takes a memory buffer
  2766. * instead of a pathname. This buffer contains all the data of the archive,
  2767. * and is used instead of a real file in the physical filesystem.
  2768. *
  2769. * (filename) is only used here to optimize archiver selection (if you name it
  2770. * XXXXX.zip, we might try the ZIP archiver first, for example). It doesn't
  2771. * need to refer to a real file at all, and can even be NULL. If the filename
  2772. * isn't helpful, the system will try every archiver until one works or none
  2773. * of them do.
  2774. *
  2775. * (ptr) must remain until the archive is unmounted. When the archive is
  2776. * unmounted, the system will call (del)(ptr), which will notify you that
  2777. * the system is done with the buffer, and give you a chance to free your
  2778. * resources. (del) can be NULL, in which case the system will make no
  2779. * attempt to free the buffer.
  2780. *
  2781. * If this function fails, (del) is not called.
  2782. *
  2783. * \param ptr Address of the memory buffer containing the archive data.
  2784. * \param len Size of memory buffer, in bytes.
  2785. * \param del A callback that triggers upon unmount. Can be NULL.
  2786. * \param fname Filename that can represent this stream. Can be NULL.
  2787. * \param mountPoint Location in the interpolated tree that this archive
  2788. * will be "mounted", in platform-independent notation.
  2789. * NULL or "" is equivalent to "/".
  2790. * \param appendToPath nonzero to append to search path, zero to prepend.
  2791. * \return nonzero if added to path, zero on failure (bogus archive, etc).
  2792. * Specifics of the error can be gleaned from
  2793. * PHYSFS_getLastError().
  2794. *
  2795. * \sa PHYSFS_unmount
  2796. * \sa PHYSFS_getSearchPath
  2797. * \sa PHYSFS_getMountPoint
  2798. */
  2799. PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len,
  2800. void (*del)(void *), const char *fname,
  2801. const char *mountPoint, int appendToPath);
  2802. /**
  2803. * \fn int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname, const char *mountPoint, int appendToPath)
  2804. * \brief Add an archive, contained in a PHYSFS_File handle, to the search path.
  2805. *
  2806. * \warning Unless you have some special, low-level need, you should be using
  2807. * PHYSFS_mount() instead of this.
  2808. *
  2809. * \warning Archives-in-archives may be very slow! While a PHYSFS_File can
  2810. * seek even when the data is compressed, it may do so by rewinding
  2811. * to the start and decompressing everything before the seek point.
  2812. * Normal archive usage may do a lot of seeking behind the scenes.
  2813. * As such, you might find normal archive usage extremely painful
  2814. * if mounted this way. Plan accordingly: if you, say, have a
  2815. * self-extracting .zip file, and want to mount something in it,
  2816. * compress the contents of the inner archive and make sure the outer
  2817. * .zip file doesn't compress the inner archive too.
  2818. *
  2819. * This function operates just like PHYSFS_mount(), but takes a PHYSFS_File
  2820. * handle instead of a pathname. This handle contains all the data of the
  2821. * archive, and is used instead of a real file in the physical filesystem.
  2822. * The PHYSFS_File may be backed by a real file in the physical filesystem,
  2823. * but isn't necessarily. The most popular use for this is likely to mount
  2824. * archives stored inside other archives.
  2825. *
  2826. * (filename) is only used here to optimize archiver selection (if you name it
  2827. * XXXXX.zip, we might try the ZIP archiver first, for example). It doesn't
  2828. * need to refer to a real file at all, and can even be NULL. If the filename
  2829. * isn't helpful, the system will try every archiver until one works or none
  2830. * of them do.
  2831. *
  2832. * (file) must remain until the archive is unmounted. When the archive is
  2833. * unmounted, the system will call PHYSFS_close(file). If you need this
  2834. * handle to survive, you will have to wrap this in a PHYSFS_Io and use
  2835. * PHYSFS_mountIo() instead.
  2836. *
  2837. * If this function fails, PHYSFS_close(file) is not called.
  2838. *
  2839. * \param file The PHYSFS_File handle containing archive data.
  2840. * \param fname Filename that can represent this stream. Can be NULL.
  2841. * \param mountPoint Location in the interpolated tree that this archive
  2842. * will be "mounted", in platform-independent notation.
  2843. * NULL or "" is equivalent to "/".
  2844. * \param appendToPath nonzero to append to search path, zero to prepend.
  2845. * \return nonzero if added to path, zero on failure (bogus archive, etc).
  2846. * Specifics of the error can be gleaned from
  2847. * PHYSFS_getLastError().
  2848. *
  2849. * \sa PHYSFS_unmount
  2850. * \sa PHYSFS_getSearchPath
  2851. * \sa PHYSFS_getMountPoint
  2852. */
  2853. PHYSFS_DECL int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname,
  2854. const char *mountPoint, int appendToPath);
  2855. /**
  2856. * \enum PHYSFS_ErrorCode
  2857. * \brief Values that represent specific causes of failure.
  2858. *
  2859. * Most of the time, you should only concern yourself with whether a given
  2860. * operation failed or not, but there may be occasions where you plan to
  2861. * handle a specific failure case gracefully, so we provide specific error
  2862. * codes.
  2863. *
  2864. * Most of these errors are a little vague, and most aren't things you can
  2865. * fix...if there's a permission error, for example, all you can really do
  2866. * is pass that information on to the user and let them figure out how to
  2867. * handle it. In most these cases, your program should only care that it
  2868. * failed to accomplish its goals, and not care specifically why.
  2869. *
  2870. * \sa PHYSFS_getLastErrorCode
  2871. * \sa PHYSFS_getErrorByCode
  2872. */
  2873. typedef enum PHYSFS_ErrorCode
  2874. {
  2875. PHYSFS_ERR_OK, /**< Success; no error. */
  2876. PHYSFS_ERR_OTHER_ERROR, /**< Error not otherwise covered here. */
  2877. PHYSFS_ERR_OUT_OF_MEMORY, /**< Memory allocation failed. */
  2878. PHYSFS_ERR_NOT_INITIALIZED, /**< PhysicsFS is not initialized. */
  2879. PHYSFS_ERR_IS_INITIALIZED, /**< PhysicsFS is already initialized. */
  2880. PHYSFS_ERR_ARGV0_IS_NULL, /**< Needed argv[0], but it is NULL. */
  2881. PHYSFS_ERR_UNSUPPORTED, /**< Operation or feature unsupported. */
  2882. PHYSFS_ERR_PAST_EOF, /**< Attempted to access past end of file. */
  2883. PHYSFS_ERR_FILES_STILL_OPEN, /**< Files still open. */
  2884. PHYSFS_ERR_INVALID_ARGUMENT, /**< Bad parameter passed to an function. */
  2885. PHYSFS_ERR_NOT_MOUNTED, /**< Requested archive/dir not mounted. */
  2886. PHYSFS_ERR_NO_SUCH_PATH, /**< No such file, directory, or parent. */
  2887. PHYSFS_ERR_SYMLINK_FORBIDDEN,/**< Symlink seen when not permitted. */
  2888. PHYSFS_ERR_NO_WRITE_DIR, /**< No write dir has been specified. */
  2889. PHYSFS_ERR_OPEN_FOR_READING, /**< Wrote to a file opened for reading. */
  2890. PHYSFS_ERR_OPEN_FOR_WRITING, /**< Read from a file opened for writing. */
  2891. PHYSFS_ERR_NOT_A_FILE, /**< Needed a file, got a directory (etc). */
  2892. PHYSFS_ERR_READ_ONLY, /**< Wrote to a read-only filesystem. */
  2893. PHYSFS_ERR_CORRUPT, /**< Corrupted data encountered. */
  2894. PHYSFS_ERR_SYMLINK_LOOP, /**< Infinite symbolic link loop. */
  2895. PHYSFS_ERR_IO, /**< i/o error (hardware failure, etc). */
  2896. PHYSFS_ERR_PERMISSION, /**< Permission denied. */
  2897. PHYSFS_ERR_NO_SPACE, /**< No space (disk full, over quota, etc) */
  2898. PHYSFS_ERR_BAD_FILENAME, /**< Filename is bogus/insecure. */
  2899. PHYSFS_ERR_BUSY, /**< Tried to modify a file the OS needs. */
  2900. PHYSFS_ERR_DIR_NOT_EMPTY, /**< Tried to delete dir with files in it. */
  2901. PHYSFS_ERR_OS_ERROR /**< Unspecified OS-level error. */
  2902. } PHYSFS_ErrorCode;
  2903. /**
  2904. * \fn PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
  2905. * \brief Get machine-readable error information.
  2906. *
  2907. * Get the last PhysicsFS error message as an integer value. This will return
  2908. * PHYSFS_ERR_OK if there's been no error since the last call to this
  2909. * function. Each thread has a unique error state associated with it, but
  2910. * each time a new error message is set, it will overwrite the previous one
  2911. * associated with that thread. It is safe to call this function at anytime,
  2912. * even before PHYSFS_init().
  2913. *
  2914. * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same
  2915. * thread-specific error state. Calling one will wipe out the other's
  2916. * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that
  2917. * value to PHYSFS_getErrorByCode().
  2918. *
  2919. * Generally, applications should only concern themselves with whether a
  2920. * given function failed; however, if you require more specifics, you can
  2921. * try this function to glean information, if there's some specific problem
  2922. * you're expecting and plan to handle. But with most things that involve
  2923. * file systems, the best course of action is usually to give up, report the
  2924. * problem to the user, and let them figure out what should be done about it.
  2925. * For that, you might prefer PHYSFS_getLastError() instead.
  2926. *
  2927. * \return Enumeration value that represents last reported error.
  2928. *
  2929. * \sa PHYSFS_getErrorByCode
  2930. */
  2931. PHYSFS_DECL PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void);
  2932. /**
  2933. * \fn const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code)
  2934. * \brief Get human-readable description string for a given error code.
  2935. *
  2936. * Get a static string, in UTF-8 format, that represents an English
  2937. * description of a given error code.
  2938. *
  2939. * This string is guaranteed to never change (although we may add new strings
  2940. * for new error codes in later versions of PhysicsFS), so you can use it
  2941. * for keying a localization dictionary.
  2942. *
  2943. * It is safe to call this function at anytime, even before PHYSFS_init().
  2944. *
  2945. * These strings are meant to be passed on directly to the user.
  2946. * Generally, applications should only concern themselves with whether a
  2947. * given function failed, but not care about the specifics much.
  2948. *
  2949. * Do not attempt to free the returned strings; they are read-only and you
  2950. * don't own their memory pages.
  2951. *
  2952. * \param code Error code to convert to a string.
  2953. * \return READ ONLY string of requested error message, NULL if this
  2954. * is not a valid PhysicsFS error code. Always check for NULL if
  2955. * you might be looking up an error code that didn't exist in an
  2956. * earlier version of PhysicsFS.
  2957. *
  2958. * \sa PHYSFS_getLastErrorCode
  2959. */
  2960. PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code);
  2961. /**
  2962. * \fn void PHYSFS_setErrorCode(PHYSFS_ErrorCode code)
  2963. * \brief Set the current thread's error code.
  2964. *
  2965. * This lets you set the value that will be returned by the next call to
  2966. * PHYSFS_getLastErrorCode(). This will replace any existing error code,
  2967. * whether set by your application or internally by PhysicsFS.
  2968. *
  2969. * Error codes are stored per-thread; what you set here will not be
  2970. * accessible to another thread.
  2971. *
  2972. * Any call into PhysicsFS may change the current error code, so any code you
  2973. * set here is somewhat fragile, and thus you shouldn't build any serious
  2974. * error reporting framework on this function. The primary goal of this
  2975. * function is to allow PHYSFS_Io implementations to set the error state,
  2976. * which generally will be passed back to your application when PhysicsFS
  2977. * makes a PHYSFS_Io call that fails internally.
  2978. *
  2979. * This function doesn't care if the error code is a value known to PhysicsFS
  2980. * or not (but PHYSFS_getErrorByCode() will return NULL for unknown values).
  2981. * The value will be reported unmolested by PHYSFS_getLastErrorCode().
  2982. *
  2983. * \param code Error code to become the current thread's new error state.
  2984. *
  2985. * \sa PHYSFS_getLastErrorCode
  2986. * \sa PHYSFS_getErrorByCode
  2987. */
  2988. PHYSFS_DECL void PHYSFS_setErrorCode(PHYSFS_ErrorCode code);
  2989. /**
  2990. * \fn const char *PHYSFS_getPrefDir(const char *org, const char *app)
  2991. * \brief Get the user-and-app-specific path where files can be written.
  2992. *
  2993. * Helper function.
  2994. *
  2995. * Get the "pref dir". This is meant to be where users can write personal
  2996. * files (preferences and save games, etc) that are specific to your
  2997. * application. This directory is unique per user, per application.
  2998. *
  2999. * This function will decide the appropriate location in the native filesystem,
  3000. * create the directory if necessary, and return a string in
  3001. * platform-dependent notation, suitable for passing to PHYSFS_setWriteDir().
  3002. *
  3003. * On Windows, this might look like:
  3004. * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name"
  3005. *
  3006. * On Linux, this might look like:
  3007. * "/home/bob/.local/share/My Program Name"
  3008. *
  3009. * On Mac OS X, this might look like:
  3010. * "/Users/bob/Library/Application Support/My Program Name"
  3011. *
  3012. * (etc.)
  3013. *
  3014. * You should probably use the pref dir for your write dir, and also put it
  3015. * near the beginning of your search path. Older versions of PhysicsFS
  3016. * offered only PHYSFS_getUserDir() and left you to figure out where the
  3017. * files should go under that tree. This finds the correct location
  3018. * for whatever platform, which not only changes between operating systems,
  3019. * but also versions of the same operating system.
  3020. *
  3021. * You specify the name of your organization (if it's not a real organization,
  3022. * your name or an Internet domain you own might do) and the name of your
  3023. * application. These should be proper names.
  3024. *
  3025. * Both the (org) and (app) strings may become part of a directory name, so
  3026. * please follow these rules:
  3027. *
  3028. * - Try to use the same org string (including case-sensitivity) for
  3029. * all your applications that use this function.
  3030. * - Always use a unique app string for each one, and make sure it never
  3031. * changes for an app once you've decided on it.
  3032. * - Unicode characters are legal, as long as it's UTF-8 encoded, but...
  3033. * - ...only use letters, numbers, and spaces. Avoid punctuation like
  3034. * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
  3035. *
  3036. * The pointer returned by this function remains valid until you call this
  3037. * function again, or call PHYSFS_deinit(). This is not necessarily a fast
  3038. * call, though, so you should call this once at startup and copy the string
  3039. * if you need it.
  3040. *
  3041. * You should assume the path returned by this function is the only safe
  3042. * place to write files (and that PHYSFS_getUserDir() and PHYSFS_getBaseDir(),
  3043. * while they might be writable, or even parents of the returned path, aren't
  3044. * where you should be writing things).
  3045. *
  3046. * \param org The name of your organization.
  3047. * \param app The name of your application.
  3048. * \return READ ONLY string of user dir in platform-dependent notation. NULL
  3049. * if there's a problem (creating directory failed, etc).
  3050. *
  3051. * \sa PHYSFS_getBaseDir
  3052. * \sa PHYSFS_getUserDir
  3053. */
  3054. PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app);
  3055. /* Everything above this line is part of the PhysicsFS 2.1 API. */
  3056. #ifdef __cplusplus
  3057. }
  3058. #endif
  3059. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  3060. /* end of physfs.h ... */