physfs.h 162 KB

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