physfs.h 154 KB

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