physfs.h 140 KB

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