physfs.h 114 KB

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