1
0

physfs.h 148 KB

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