physfs.h 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692
  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. * This is a legacy call in PhysicsFS 2.0, equivalent to:
  739. * PHYSFS_mount(newDir, NULL, appendToPath);
  740. *
  741. * You must use this and not PHYSFS_mount if binary compatibility with
  742. * PhysicsFS 1.0 is important (which it may not be for many people).
  743. *
  744. * \sa PHYSFS_mount
  745. * \sa PHYSFS_removeFromSearchPath
  746. * \sa PHYSFS_getSearchPath
  747. */
  748. PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  749. /**
  750. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  751. * \brief Remove a directory or archive from the search path.
  752. *
  753. * This must be a (case-sensitive) match to a dir or archive already in the
  754. * search path, specified in platform-dependent notation.
  755. *
  756. * This call will fail (and fail to remove from the path) if the element still
  757. * has files open in it.
  758. *
  759. * \param oldDir dir/archive to remove.
  760. * \return nonzero on success, zero on failure.
  761. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  762. *
  763. * \sa PHYSFS_addToSearchPath
  764. * \sa PHYSFS_getSearchPath
  765. */
  766. PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir);
  767. /**
  768. * \fn char **PHYSFS_getSearchPath(void)
  769. * \brief Get the current search path.
  770. *
  771. * The default search path is an empty list.
  772. *
  773. * The returned value is an array of strings, with a NULL entry to signify the
  774. * end of the list:
  775. *
  776. * \code
  777. * char **i;
  778. *
  779. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  780. * printf("[%s] is in the search path.\n", *i);
  781. * \endcode
  782. *
  783. * When you are done with the returned information, you may dispose of the
  784. * resources by calling PHYSFS_freeList() with the returned pointer.
  785. *
  786. * \return Null-terminated array of null-terminated strings. NULL if there
  787. * was a problem (read: OUT OF MEMORY).
  788. *
  789. * \sa PHYSFS_getSearchPathCallback
  790. * \sa PHYSFS_addToSearchPath
  791. * \sa PHYSFS_removeFromSearchPath
  792. */
  793. PHYSFS_DECL char **PHYSFS_getSearchPath(void);
  794. /**
  795. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  796. * \brief Set up sane, default paths.
  797. *
  798. * Helper function.
  799. *
  800. * The write dir will be set to "userdir/.organization/appName", which is
  801. * created if it doesn't exist.
  802. *
  803. * The above is sufficient to make sure your program's configuration directory
  804. * is separated from other clutter, and platform-independent. The period
  805. * before "mygame" even hides the directory on Unix systems.
  806. *
  807. * The search path will be:
  808. *
  809. * - The Write Dir (created if it doesn't exist)
  810. * - The Base Dir (PHYSFS_getBaseDir())
  811. * - All found CD-ROM dirs (optionally)
  812. *
  813. * These directories are then searched for files ending with the extension
  814. * (archiveExt), which, if they are valid and supported archives, will also
  815. * be added to the search path. If you specified "PKG" for (archiveExt), and
  816. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  817. * can either be appended or prepended to the search path in alphabetical
  818. * order, regardless of which directories they were found in.
  819. *
  820. * All of this can be accomplished from the application, but this just does it
  821. * all for you. Feel free to add more to the search path manually, too.
  822. *
  823. * \param organization Name of your company/group/etc to be used as a
  824. * dirname, so keep it small, and no-frills.
  825. *
  826. * \param appName Program-specific name of your program, to separate it
  827. * from other programs using PhysicsFS.
  828. *
  829. * \param archiveExt File extension used by your program to specify an
  830. * archive. For example, Quake 3 uses "pk3", even though
  831. * they are just zipfiles. Specify NULL to not dig out
  832. * archives automatically. Do not specify the '.' char;
  833. * If you want to look for ZIP files, specify "ZIP" and
  834. * not ".ZIP" ... the archive search is case-insensitive.
  835. *
  836. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  837. * (if (archiveExt) != NULL) search them for archives.
  838. * This may cause a significant amount of blocking
  839. * while discs are accessed, and if there are no discs
  840. * in the drive (or even not mounted on Unix systems),
  841. * then they may not be made available anyhow. You may
  842. * want to specify zero and handle the disc setup
  843. * yourself.
  844. *
  845. * \param archivesFirst Non-zero to prepend the archives to the search path.
  846. * Zero to append them. Ignored if !(archiveExt).
  847. *
  848. * \return nonzero on success, zero on error. Specifics of the error can be
  849. * gleaned from PHYSFS_getLastError().
  850. */
  851. PHYSFS_DECL int PHYSFS_setSaneConfig(const char *organization,
  852. const char *appName,
  853. const char *archiveExt,
  854. int includeCdRoms,
  855. int archivesFirst);
  856. /* Directory management stuff ... */
  857. /**
  858. * \fn int PHYSFS_mkdir(const char *dirName)
  859. * \brief Create a directory.
  860. *
  861. * This is specified in platform-independent notation in relation to the
  862. * write dir. All missing parent directories are also created if they
  863. * don't exist.
  864. *
  865. * So if you've got the write dir set to "C:\mygame\writedir" and call
  866. * PHYSFS_mkdir("downloads/maps") then the directories
  867. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  868. * will be created if possible. If the creation of "maps" fails after we
  869. * have successfully created "downloads", then the function leaves the
  870. * created directory behind and reports failure.
  871. *
  872. * \param dirName New dir to create.
  873. * \return nonzero on success, zero on error. Specifics of the error can be
  874. * gleaned from PHYSFS_getLastError().
  875. *
  876. * \sa PHYSFS_delete
  877. */
  878. PHYSFS_DECL int PHYSFS_mkdir(const char *dirName);
  879. /**
  880. * \fn int PHYSFS_delete(const char *filename)
  881. * \brief Delete a file or directory.
  882. *
  883. * (filename) is specified in platform-independent notation in relation to the
  884. * write dir.
  885. *
  886. * A directory must be empty before this call can delete it.
  887. *
  888. * Deleting a symlink will remove the link, not what it points to, regardless
  889. * of whether you "permitSymLinks" or not.
  890. *
  891. * So if you've got the write dir set to "C:\mygame\writedir" and call
  892. * PHYSFS_delete("downloads/maps/level1.map") then the file
  893. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  894. * physical filesystem, if it exists and the operating system permits the
  895. * deletion.
  896. *
  897. * Note that on Unix systems, deleting a file may be successful, but the
  898. * actual file won't be removed until all processes that have an open
  899. * filehandle to it (including your program) close their handles.
  900. *
  901. * Chances are, the bits that make up the file still exist, they are just
  902. * made available to be written over at a later point. Don't consider this
  903. * a security method or anything. :)
  904. *
  905. * \param filename Filename to delete.
  906. * \return nonzero on success, zero on error. Specifics of the error can be
  907. * gleaned from PHYSFS_getLastError().
  908. */
  909. PHYSFS_DECL int PHYSFS_delete(const char *filename);
  910. /**
  911. * \fn const char *PHYSFS_getRealDir(const char *filename)
  912. * \brief Figure out where in the search path a file resides.
  913. *
  914. * The file is specified in platform-independent notation. The returned
  915. * filename will be the element of the search path where the file was found,
  916. * which may be a directory, or an archive. Even if there are multiple
  917. * matches in different parts of the search path, only the first one found
  918. * is used, just like when opening a file.
  919. *
  920. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  921. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  922. *
  923. * If a any part of a match is a symbolic link, and you've not explicitly
  924. * permitted symlinks, then it will be ignored, and the search for a match
  925. * will continue.
  926. *
  927. * If you specify a fake directory that only exists as a mount point, it'll
  928. * be associated with the first archive mounted there, even though that
  929. * directory isn't necessarily contained in a real archive.
  930. *
  931. * \param filename file to look for.
  932. * \return READ ONLY string of element of search path containing the
  933. * the file in question. NULL if not found.
  934. */
  935. PHYSFS_DECL const char *PHYSFS_getRealDir(const char *filename);
  936. /**
  937. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  938. * \brief Get a file listing of a search path's directory.
  939. *
  940. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  941. * search path and contains a directory "savegames" that contains "x.sav",
  942. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  943. * that has a "savegames" subdirectory with "w.sav", then the following code:
  944. *
  945. * \code
  946. * char **rc = PHYSFS_enumerateFiles("savegames");
  947. * char **i;
  948. *
  949. * for (i = rc; *i != NULL; i++)
  950. * printf(" * We've got [%s].\n", *i);
  951. *
  952. * PHYSFS_freeList(rc);
  953. * \endcode
  954. *
  955. * \...will print:
  956. *
  957. * \verbatim
  958. * We've got [x.sav].
  959. * We've got [y.sav].
  960. * We've got [z.sav].
  961. * We've got [w.sav].\endverbatim
  962. *
  963. * Feel free to sort the list however you like. We only promise there will
  964. * be no duplicates, but not what order the final list will come back in.
  965. *
  966. * Don't forget to call PHYSFS_freeList() with the return value from this
  967. * function when you are done with it.
  968. *
  969. * \param dir directory in platform-independent notation to enumerate.
  970. * \return Null-terminated array of null-terminated strings.
  971. *
  972. * \sa PHYSFS_enumerateFilesCallback
  973. */
  974. PHYSFS_DECL char **PHYSFS_enumerateFiles(const char *dir);
  975. /**
  976. * \fn int PHYSFS_exists(const char *fname)
  977. * \brief Determine if a file exists in the search path.
  978. *
  979. * Reports true if there is an entry anywhere in the search path by the
  980. * name of (fname).
  981. *
  982. * Note that entries that are symlinks are ignored if
  983. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  984. * might end up further down in the search path than expected.
  985. *
  986. * \param fname filename in platform-independent notation.
  987. * \return non-zero if filename exists. zero otherwise.
  988. *
  989. * \sa PHYSFS_isDirectory
  990. * \sa PHYSFS_isSymbolicLink
  991. */
  992. PHYSFS_DECL int PHYSFS_exists(const char *fname);
  993. /**
  994. * \fn int PHYSFS_isDirectory(const char *fname)
  995. * \brief Determine if a file in the search path is really a directory.
  996. *
  997. * Determine if the first occurence of (fname) in the search path is
  998. * really a directory entry.
  999. *
  1000. * Note that entries that are symlinks are ignored if
  1001. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  1002. * might end up further down in the search path than expected.
  1003. *
  1004. * \param fname filename in platform-independent notation.
  1005. * \return non-zero if filename exists and is a directory. zero otherwise.
  1006. *
  1007. * \sa PHYSFS_exists
  1008. * \sa PHYSFS_isSymbolicLink
  1009. */
  1010. PHYSFS_DECL int PHYSFS_isDirectory(const char *fname);
  1011. /**
  1012. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  1013. * \brief Determine if a file in the search path is really a symbolic link.
  1014. *
  1015. * Determine if the first occurence of (fname) in the search path is
  1016. * really a symbolic link.
  1017. *
  1018. * Note that entries that are symlinks are ignored if
  1019. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  1020. * this function will always return 0 in that case.
  1021. *
  1022. * \param fname filename in platform-independent notation.
  1023. * \return non-zero if filename exists and is a symlink. zero otherwise.
  1024. *
  1025. * \sa PHYSFS_exists
  1026. * \sa PHYSFS_isDirectory
  1027. */
  1028. PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname);
  1029. /**
  1030. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1031. * \brief Get the last modification time of a file.
  1032. *
  1033. * The modtime is returned as a number of seconds since the Unix epoch
  1034. * (midnight, Jan 1, 1970). The exact derivation and accuracy of this time
  1035. * depends on the particular archiver. If there is no reasonable way to
  1036. * obtain this information for a particular archiver, or there was some sort
  1037. * of error, this function returns (-1).
  1038. *
  1039. * \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
  1040. * function just wraps it anyhow.
  1041. *
  1042. * \param filename filename to check, in platform-independent notation.
  1043. * \return last modified time of the file. -1 if it can't be determined.
  1044. *
  1045. * \sa PHYSFS_stat
  1046. */
  1047. PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  1048. PHYSFS_DEPRECATED;
  1049. /* i/o stuff... */
  1050. /**
  1051. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  1052. * \brief Open a file for writing.
  1053. *
  1054. * Open a file for writing, in platform-independent notation and in relation
  1055. * to the write dir as the root of the writable filesystem. The specified
  1056. * file is created if it doesn't exist. If it does exist, it is truncated to
  1057. * zero bytes, and the writing offset is set to the start.
  1058. *
  1059. * Note that entries that are symlinks are ignored if
  1060. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1061. * symlink with this function will fail in such a case.
  1062. *
  1063. * \param filename File to open.
  1064. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1065. * of the error can be gleaned from PHYSFS_getLastError().
  1066. *
  1067. * \sa PHYSFS_openRead
  1068. * \sa PHYSFS_openAppend
  1069. * \sa PHYSFS_write
  1070. * \sa PHYSFS_close
  1071. */
  1072. PHYSFS_DECL PHYSFS_File *PHYSFS_openWrite(const char *filename);
  1073. /**
  1074. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  1075. * \brief Open a file for appending.
  1076. *
  1077. * Open a file for writing, in platform-independent notation and in relation
  1078. * to the write dir as the root of the writable filesystem. The specified
  1079. * file is created if it doesn't exist. If it does exist, the writing offset
  1080. * is set to the end of the file, so the first write will be the byte after
  1081. * the end.
  1082. *
  1083. * Note that entries that are symlinks are ignored if
  1084. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1085. * symlink with this function will fail in such a case.
  1086. *
  1087. * \param filename File to open.
  1088. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1089. * of the error can be gleaned from PHYSFS_getLastError().
  1090. *
  1091. * \sa PHYSFS_openRead
  1092. * \sa PHYSFS_openWrite
  1093. * \sa PHYSFS_write
  1094. * \sa PHYSFS_close
  1095. */
  1096. PHYSFS_DECL PHYSFS_File *PHYSFS_openAppend(const char *filename);
  1097. /**
  1098. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  1099. * \brief Open a file for reading.
  1100. *
  1101. * Open a file for reading, in platform-independent notation. The search path
  1102. * is checked one at a time until a matching file is found, in which case an
  1103. * abstract filehandle is associated with it, and reading may be done.
  1104. * The reading offset is set to the first byte of the file.
  1105. *
  1106. * Note that entries that are symlinks are ignored if
  1107. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1108. * symlink with this function will fail in such a case.
  1109. *
  1110. * \param filename File to open.
  1111. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1112. * of the error can be gleaned from PHYSFS_getLastError().
  1113. *
  1114. * \sa PHYSFS_openWrite
  1115. * \sa PHYSFS_openAppend
  1116. * \sa PHYSFS_read
  1117. * \sa PHYSFS_close
  1118. */
  1119. PHYSFS_DECL PHYSFS_File *PHYSFS_openRead(const char *filename);
  1120. /**
  1121. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1122. * \brief Close a PhysicsFS filehandle.
  1123. *
  1124. * This call is capable of failing if the operating system was buffering
  1125. * writes to the physical media, and, now forced to write those changes to
  1126. * physical media, can not store the data for some reason. In such a case,
  1127. * the filehandle stays open. A well-written program should ALWAYS check the
  1128. * return value from the close call in addition to every writing call!
  1129. *
  1130. * \param handle handle returned from PHYSFS_open*().
  1131. * \return nonzero on success, zero on error. Specifics of the error can be
  1132. * gleaned from PHYSFS_getLastError().
  1133. *
  1134. * \sa PHYSFS_openRead
  1135. * \sa PHYSFS_openWrite
  1136. * \sa PHYSFS_openAppend
  1137. */
  1138. PHYSFS_DECL int PHYSFS_close(PHYSFS_File *handle);
  1139. /**
  1140. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1141. * \brief Read data from a PhysicsFS filehandle
  1142. *
  1143. * The file must be opened for reading.
  1144. *
  1145. * \deprecated As of PhysicsFS 2.1, use PHYSFS_readBytes() instead. This
  1146. * function just wraps it anyhow. This function never clarified
  1147. * what would happen if you managed to read a partial object, so
  1148. * working at the byte level makes this cleaner for everyone,
  1149. * especially now that data streams can be supplied by the
  1150. * application.
  1151. *
  1152. * \param handle handle returned from PHYSFS_openRead().
  1153. * \param buffer buffer to store read data into.
  1154. * \param objSize size in bytes of objects being read from (handle).
  1155. * \param objCount number of (objSize) objects to read from (handle).
  1156. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1157. * the reason this might be < (objCount), as can PHYSFS_eof().
  1158. * -1 if complete failure.
  1159. *
  1160. * \sa PHYSFS_readBytes
  1161. * \sa PHYSFS_eof
  1162. */
  1163. PHYSFS_DECL PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1164. void *buffer,
  1165. PHYSFS_uint32 objSize,
  1166. PHYSFS_uint32 objCount)
  1167. PHYSFS_DEPRECATED;
  1168. /**
  1169. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1170. * \brief Write data to a PhysicsFS filehandle
  1171. *
  1172. * The file must be opened for writing.
  1173. *
  1174. * \deprecated As of PhysicsFS 2.1, use PHYSFS_writeBytes() instead. This
  1175. * function just wraps it anyhow. This function never clarified
  1176. * what would happen if you managed to write a partial object, so
  1177. * working at the byte level makes this cleaner for everyone,
  1178. * especially now that data streams can be supplied by the
  1179. * application.
  1180. *
  1181. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1182. * \param buffer buffer of bytes to write to (handle).
  1183. * \param objSize size in bytes of objects being written to (handle).
  1184. * \param objCount number of (objSize) objects to write to (handle).
  1185. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1186. * the reason this might be < (objCount). -1 if complete failure.
  1187. *
  1188. * \sa PHYSFS_writeBytes
  1189. */
  1190. PHYSFS_DECL PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1191. const void *buffer,
  1192. PHYSFS_uint32 objSize,
  1193. PHYSFS_uint32 objCount)
  1194. PHYSFS_DEPRECATED;
  1195. /* File position stuff... */
  1196. /**
  1197. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1198. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1199. *
  1200. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1201. *
  1202. * \param handle handle returned from PHYSFS_openRead().
  1203. * \return nonzero if EOF, zero if not.
  1204. *
  1205. * \sa PHYSFS_read
  1206. * \sa PHYSFS_tell
  1207. */
  1208. PHYSFS_DECL int PHYSFS_eof(PHYSFS_File *handle);
  1209. /**
  1210. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1211. * \brief Determine current position within a PhysicsFS filehandle.
  1212. *
  1213. * \param handle handle returned from PHYSFS_open*().
  1214. * \return offset in bytes from start of file. -1 if error occurred.
  1215. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1216. *
  1217. * \sa PHYSFS_seek
  1218. */
  1219. PHYSFS_DECL PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1220. /**
  1221. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1222. * \brief Seek to a new position within a PhysicsFS filehandle.
  1223. *
  1224. * The next read or write will occur at that place. Seeking past the
  1225. * beginning or end of the file is not allowed, and causes an error.
  1226. *
  1227. * \param handle handle returned from PHYSFS_open*().
  1228. * \param pos number of bytes from start of file to seek to.
  1229. * \return nonzero on success, zero on error. Specifics of the error can be
  1230. * gleaned from PHYSFS_getLastError().
  1231. *
  1232. * \sa PHYSFS_tell
  1233. */
  1234. PHYSFS_DECL int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1235. /**
  1236. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1237. * \brief Get total length of a file in bytes.
  1238. *
  1239. * Note that if the file size can't be determined (since the archive is
  1240. * "streamed" or whatnot) than this will report (-1). Also note that if
  1241. * another process/thread is writing to this file at the same time, then
  1242. * the information this function supplies could be incorrect before you
  1243. * get it. Use with caution, or better yet, don't use at all.
  1244. *
  1245. * \param handle handle returned from PHYSFS_open*().
  1246. * \return size in bytes of the file. -1 if can't be determined.
  1247. *
  1248. * \sa PHYSFS_tell
  1249. * \sa PHYSFS_seek
  1250. */
  1251. PHYSFS_DECL PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1252. /* Buffering stuff... */
  1253. /**
  1254. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1255. * \brief Set up buffering for a PhysicsFS file handle.
  1256. *
  1257. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1258. * will be allocated and associated with (handle).
  1259. *
  1260. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1261. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1262. * from this buffer until it is empty, and then refill it for more reading.
  1263. * Note that compressed files, like ZIP archives, will decompress while
  1264. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1265. * The buffer isn't filled until you do your next read.
  1266. *
  1267. * For files opened for writing, data will be buffered to memory until the
  1268. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1269. * causes a flush...check your return values!
  1270. *
  1271. * Seeking, etc transparently accounts for buffering.
  1272. *
  1273. * You can resize an existing buffer by calling this function more than once
  1274. * on the same file. Setting the buffer size to zero will free an existing
  1275. * buffer.
  1276. *
  1277. * PhysicsFS file handles are unbuffered by default.
  1278. *
  1279. * Please check the return value of this function! Failures can include
  1280. * not being able to seek backwards in a read-only file when removing the
  1281. * buffer, not being able to allocate the buffer, and not being able to
  1282. * flush the buffer to disk, among other unexpected problems.
  1283. *
  1284. * \param handle handle returned from PHYSFS_open*().
  1285. * \param bufsize size, in bytes, of buffer to allocate.
  1286. * \return nonzero if successful, zero on error.
  1287. *
  1288. * \sa PHYSFS_flush
  1289. * \sa PHYSFS_read
  1290. * \sa PHYSFS_write
  1291. * \sa PHYSFS_close
  1292. */
  1293. PHYSFS_DECL int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1294. /**
  1295. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1296. * \brief Flush a buffered PhysicsFS file handle.
  1297. *
  1298. * For buffered files opened for writing, this will put the current contents
  1299. * of the buffer to disk and flag the buffer as empty if possible.
  1300. *
  1301. * For buffered files opened for reading or unbuffered files, this is a safe
  1302. * no-op, and will report success.
  1303. *
  1304. * \param handle handle returned from PHYSFS_open*().
  1305. * \return nonzero if successful, zero on error.
  1306. *
  1307. * \sa PHYSFS_setBuffer
  1308. * \sa PHYSFS_close
  1309. */
  1310. PHYSFS_DECL int PHYSFS_flush(PHYSFS_File *handle);
  1311. /* Byteorder stuff... */
  1312. #ifndef SWIG /* not available from scripting languages. */
  1313. /**
  1314. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1315. * \brief Swap littleendian signed 16 to platform's native byte order.
  1316. *
  1317. * Take a 16-bit signed value in littleendian format and convert it to
  1318. * the platform's native byte order.
  1319. *
  1320. * \param val value to convert
  1321. * \return converted value.
  1322. */
  1323. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1324. /**
  1325. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1326. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1327. *
  1328. * Take a 16-bit unsigned value in littleendian format and convert it to
  1329. * the platform's native byte order.
  1330. *
  1331. * \param val value to convert
  1332. * \return converted value.
  1333. */
  1334. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1335. /**
  1336. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1337. * \brief Swap littleendian signed 32 to platform's native byte order.
  1338. *
  1339. * Take a 32-bit signed value in littleendian format and convert it to
  1340. * the platform's native byte order.
  1341. *
  1342. * \param val value to convert
  1343. * \return converted value.
  1344. */
  1345. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1346. /**
  1347. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1348. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1349. *
  1350. * Take a 32-bit unsigned value in littleendian format and convert it to
  1351. * the platform's native byte order.
  1352. *
  1353. * \param val value to convert
  1354. * \return converted value.
  1355. */
  1356. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1357. /**
  1358. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1359. * \brief Swap littleendian signed 64 to platform's native byte order.
  1360. *
  1361. * Take a 64-bit signed value in littleendian format and convert it to
  1362. * the platform's native byte order.
  1363. *
  1364. * \param val value to convert
  1365. * \return converted value.
  1366. *
  1367. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1368. * any sort of 64-bit support.
  1369. */
  1370. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1371. /**
  1372. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1373. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1374. *
  1375. * Take a 64-bit unsigned value in littleendian format and convert it to
  1376. * the platform's native byte order.
  1377. *
  1378. * \param val value to convert
  1379. * \return converted value.
  1380. *
  1381. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1382. * any sort of 64-bit support.
  1383. */
  1384. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1385. /**
  1386. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1387. * \brief Swap bigendian signed 16 to platform's native byte order.
  1388. *
  1389. * Take a 16-bit signed value in bigendian format and convert it to
  1390. * the platform's native byte order.
  1391. *
  1392. * \param val value to convert
  1393. * \return converted value.
  1394. */
  1395. PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1396. /**
  1397. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1398. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1399. *
  1400. * Take a 16-bit unsigned value in bigendian format and convert it to
  1401. * the platform's native byte order.
  1402. *
  1403. * \param val value to convert
  1404. * \return converted value.
  1405. */
  1406. PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1407. /**
  1408. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1409. * \brief Swap bigendian signed 32 to platform's native byte order.
  1410. *
  1411. * Take a 32-bit signed value in bigendian format and convert it to
  1412. * the platform's native byte order.
  1413. *
  1414. * \param val value to convert
  1415. * \return converted value.
  1416. */
  1417. PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1418. /**
  1419. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1420. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1421. *
  1422. * Take a 32-bit unsigned value in bigendian format and convert it to
  1423. * the platform's native byte order.
  1424. *
  1425. * \param val value to convert
  1426. * \return converted value.
  1427. */
  1428. PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1429. /**
  1430. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1431. * \brief Swap bigendian signed 64 to platform's native byte order.
  1432. *
  1433. * Take a 64-bit signed value in bigendian format and convert it to
  1434. * the platform's native byte order.
  1435. *
  1436. * \param val value to convert
  1437. * \return converted value.
  1438. *
  1439. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1440. * any sort of 64-bit support.
  1441. */
  1442. PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1443. /**
  1444. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1445. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1446. *
  1447. * Take a 64-bit unsigned value in bigendian format and convert it to
  1448. * the platform's native byte order.
  1449. *
  1450. * \param val value to convert
  1451. * \return converted value.
  1452. *
  1453. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1454. * any sort of 64-bit support.
  1455. */
  1456. PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1457. #endif /* SWIG */
  1458. /**
  1459. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1460. * \brief Read and convert a signed 16-bit littleendian value.
  1461. *
  1462. * Convenience function. Read a signed 16-bit littleendian value from a
  1463. * file and convert it to the platform's native byte order.
  1464. *
  1465. * \param file PhysicsFS file handle from which to read.
  1466. * \param val pointer to where value should be stored.
  1467. * \return zero on failure, non-zero on success. If successful, (*val) will
  1468. * store the result. On failure, you can find out what went wrong
  1469. * from PHYSFS_getLastError().
  1470. */
  1471. PHYSFS_DECL int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1472. /**
  1473. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1474. * \brief Read and convert an unsigned 16-bit littleendian value.
  1475. *
  1476. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1477. * file and convert it to the platform's native byte order.
  1478. *
  1479. * \param file PhysicsFS file handle from which to read.
  1480. * \param val pointer to where value should be stored.
  1481. * \return zero on failure, non-zero on success. If successful, (*val) will
  1482. * store the result. On failure, you can find out what went wrong
  1483. * from PHYSFS_getLastError().
  1484. *
  1485. */
  1486. PHYSFS_DECL int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1487. /**
  1488. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1489. * \brief Read and convert a signed 16-bit bigendian value.
  1490. *
  1491. * Convenience function. Read a signed 16-bit bigendian value from a
  1492. * file and convert it to the platform's native byte order.
  1493. *
  1494. * \param file PhysicsFS file handle from which to read.
  1495. * \param val pointer to where value should be stored.
  1496. * \return zero on failure, non-zero on success. If successful, (*val) will
  1497. * store the result. On failure, you can find out what went wrong
  1498. * from PHYSFS_getLastError().
  1499. */
  1500. PHYSFS_DECL int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1501. /**
  1502. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1503. * \brief Read and convert an unsigned 16-bit bigendian value.
  1504. *
  1505. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1506. * file and convert it to the platform's native byte order.
  1507. *
  1508. * \param file PhysicsFS file handle from which to read.
  1509. * \param val pointer to where value should be stored.
  1510. * \return zero on failure, non-zero on success. If successful, (*val) will
  1511. * store the result. On failure, you can find out what went wrong
  1512. * from PHYSFS_getLastError().
  1513. *
  1514. */
  1515. PHYSFS_DECL int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1516. /**
  1517. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1518. * \brief Read and convert a signed 32-bit littleendian value.
  1519. *
  1520. * Convenience function. Read a signed 32-bit littleendian value from a
  1521. * file and convert it to the platform's native byte order.
  1522. *
  1523. * \param file PhysicsFS file handle from which to read.
  1524. * \param val pointer to where value should be stored.
  1525. * \return zero on failure, non-zero on success. If successful, (*val) will
  1526. * store the result. On failure, you can find out what went wrong
  1527. * from PHYSFS_getLastError().
  1528. */
  1529. PHYSFS_DECL int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1530. /**
  1531. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1532. * \brief Read and convert an unsigned 32-bit littleendian value.
  1533. *
  1534. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1535. * file and convert it to the platform's native byte order.
  1536. *
  1537. * \param file PhysicsFS file handle from which to read.
  1538. * \param val pointer to where value should be stored.
  1539. * \return zero on failure, non-zero on success. If successful, (*val) will
  1540. * store the result. On failure, you can find out what went wrong
  1541. * from PHYSFS_getLastError().
  1542. *
  1543. */
  1544. PHYSFS_DECL int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1545. /**
  1546. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1547. * \brief Read and convert a signed 32-bit bigendian value.
  1548. *
  1549. * Convenience function. Read a signed 32-bit bigendian value from a
  1550. * file and convert it to the platform's native byte order.
  1551. *
  1552. * \param file PhysicsFS file handle from which to read.
  1553. * \param val pointer to where value should be stored.
  1554. * \return zero on failure, non-zero on success. If successful, (*val) will
  1555. * store the result. On failure, you can find out what went wrong
  1556. * from PHYSFS_getLastError().
  1557. */
  1558. PHYSFS_DECL int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1559. /**
  1560. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1561. * \brief Read and convert an unsigned 32-bit bigendian value.
  1562. *
  1563. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1564. * file and convert it to the platform's native byte order.
  1565. *
  1566. * \param file PhysicsFS file handle from which to read.
  1567. * \param val pointer to where value should be stored.
  1568. * \return zero on failure, non-zero on success. If successful, (*val) will
  1569. * store the result. On failure, you can find out what went wrong
  1570. * from PHYSFS_getLastError().
  1571. *
  1572. */
  1573. PHYSFS_DECL int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1574. /**
  1575. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1576. * \brief Read and convert a signed 64-bit littleendian value.
  1577. *
  1578. * Convenience function. Read a signed 64-bit littleendian value from a
  1579. * file and convert it to the platform's native byte order.
  1580. *
  1581. * \param file PhysicsFS file handle from which to read.
  1582. * \param val pointer to where value should be stored.
  1583. * \return zero on failure, non-zero on success. If successful, (*val) will
  1584. * store the result. On failure, you can find out what went wrong
  1585. * from PHYSFS_getLastError().
  1586. *
  1587. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1588. * any sort of 64-bit support.
  1589. */
  1590. PHYSFS_DECL int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1591. /**
  1592. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1593. * \brief Read and convert an unsigned 64-bit littleendian value.
  1594. *
  1595. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1596. * file and convert it to the platform's native byte order.
  1597. *
  1598. * \param file PhysicsFS file handle from which to read.
  1599. * \param val pointer to where value should be stored.
  1600. * \return zero on failure, non-zero on success. If successful, (*val) will
  1601. * store the result. On failure, you can find out what went wrong
  1602. * from PHYSFS_getLastError().
  1603. *
  1604. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1605. * any sort of 64-bit support.
  1606. */
  1607. PHYSFS_DECL int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1608. /**
  1609. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1610. * \brief Read and convert a signed 64-bit bigendian value.
  1611. *
  1612. * Convenience function. Read a signed 64-bit bigendian value from a
  1613. * file and convert it to the platform's native byte order.
  1614. *
  1615. * \param file PhysicsFS file handle from which to read.
  1616. * \param val pointer to where value should be stored.
  1617. * \return zero on failure, non-zero on success. If successful, (*val) will
  1618. * store the result. On failure, you can find out what went wrong
  1619. * from PHYSFS_getLastError().
  1620. *
  1621. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1622. * any sort of 64-bit support.
  1623. */
  1624. PHYSFS_DECL int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1625. /**
  1626. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1627. * \brief Read and convert an unsigned 64-bit bigendian value.
  1628. *
  1629. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1630. * file and convert it to the platform's native byte order.
  1631. *
  1632. * \param file PhysicsFS file handle from which to read.
  1633. * \param val pointer to where value should be stored.
  1634. * \return zero on failure, non-zero on success. If successful, (*val) will
  1635. * store the result. On failure, you can find out what went wrong
  1636. * from PHYSFS_getLastError().
  1637. *
  1638. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1639. * any sort of 64-bit support.
  1640. */
  1641. PHYSFS_DECL int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1642. /**
  1643. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1644. * \brief Convert and write a signed 16-bit littleendian value.
  1645. *
  1646. * Convenience function. Convert a signed 16-bit value from the platform's
  1647. * native byte order to littleendian and write it to a file.
  1648. *
  1649. * \param file PhysicsFS file handle to which to write.
  1650. * \param val Value to convert and write.
  1651. * \return zero on failure, non-zero on success. On failure, you can
  1652. * find out what went wrong from PHYSFS_getLastError().
  1653. */
  1654. PHYSFS_DECL int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1655. /**
  1656. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1657. * \brief Convert and write an unsigned 16-bit littleendian value.
  1658. *
  1659. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1660. * native byte order to littleendian and write it to a file.
  1661. *
  1662. * \param file PhysicsFS file handle to which to write.
  1663. * \param val Value to convert and write.
  1664. * \return zero on failure, non-zero on success. On failure, you can
  1665. * find out what went wrong from PHYSFS_getLastError().
  1666. */
  1667. PHYSFS_DECL int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1668. /**
  1669. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1670. * \brief Convert and write a signed 16-bit bigendian value.
  1671. *
  1672. * Convenience function. Convert a signed 16-bit value from the platform's
  1673. * native byte order to bigendian and write it to a file.
  1674. *
  1675. * \param file PhysicsFS file handle to which to write.
  1676. * \param val Value to convert and write.
  1677. * \return zero on failure, non-zero on success. On failure, you can
  1678. * find out what went wrong from PHYSFS_getLastError().
  1679. */
  1680. PHYSFS_DECL int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1681. /**
  1682. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1683. * \brief Convert and write an unsigned 16-bit bigendian value.
  1684. *
  1685. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1686. * native byte order to bigendian and write it to a file.
  1687. *
  1688. * \param file PhysicsFS file handle to which to write.
  1689. * \param val Value to convert and write.
  1690. * \return zero on failure, non-zero on success. On failure, you can
  1691. * find out what went wrong from PHYSFS_getLastError().
  1692. */
  1693. PHYSFS_DECL int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1694. /**
  1695. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1696. * \brief Convert and write a signed 32-bit littleendian value.
  1697. *
  1698. * Convenience function. Convert a signed 32-bit value from the platform's
  1699. * native byte order to littleendian and write it to a file.
  1700. *
  1701. * \param file PhysicsFS file handle to which to write.
  1702. * \param val Value to convert and write.
  1703. * \return zero on failure, non-zero on success. On failure, you can
  1704. * find out what went wrong from PHYSFS_getLastError().
  1705. */
  1706. PHYSFS_DECL int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1707. /**
  1708. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1709. * \brief Convert and write an unsigned 32-bit littleendian value.
  1710. *
  1711. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1712. * native byte order to littleendian and write it to a file.
  1713. *
  1714. * \param file PhysicsFS file handle to which to write.
  1715. * \param val Value to convert and write.
  1716. * \return zero on failure, non-zero on success. On failure, you can
  1717. * find out what went wrong from PHYSFS_getLastError().
  1718. */
  1719. PHYSFS_DECL int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1720. /**
  1721. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1722. * \brief Convert and write a signed 32-bit bigendian value.
  1723. *
  1724. * Convenience function. Convert a signed 32-bit value from the platform's
  1725. * native byte order to bigendian and write it to a file.
  1726. *
  1727. * \param file PhysicsFS file handle to which to write.
  1728. * \param val Value to convert and write.
  1729. * \return zero on failure, non-zero on success. On failure, you can
  1730. * find out what went wrong from PHYSFS_getLastError().
  1731. */
  1732. PHYSFS_DECL int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1733. /**
  1734. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1735. * \brief Convert and write an unsigned 32-bit bigendian value.
  1736. *
  1737. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1738. * native byte order to bigendian and write it to a file.
  1739. *
  1740. * \param file PhysicsFS file handle to which to write.
  1741. * \param val Value to convert and write.
  1742. * \return zero on failure, non-zero on success. On failure, you can
  1743. * find out what went wrong from PHYSFS_getLastError().
  1744. */
  1745. PHYSFS_DECL int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1746. /**
  1747. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1748. * \brief Convert and write a signed 64-bit littleendian value.
  1749. *
  1750. * Convenience function. Convert a signed 64-bit value from the platform's
  1751. * native byte order to littleendian and write it to a file.
  1752. *
  1753. * \param file PhysicsFS file handle to which to write.
  1754. * \param val Value to convert and write.
  1755. * \return zero on failure, non-zero on success. On failure, you can
  1756. * find out what went wrong from PHYSFS_getLastError().
  1757. *
  1758. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1759. * any sort of 64-bit support.
  1760. */
  1761. PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1762. /**
  1763. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1764. * \brief Convert and write an unsigned 64-bit littleendian value.
  1765. *
  1766. * Convenience function. Convert an unsigned 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_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1778. /**
  1779. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1780. * \brief Convert and write a signed 64-bit bigending value.
  1781. *
  1782. * Convenience function. Convert a signed 64-bit value from the platform's
  1783. * native byte order to bigendian 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_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1794. /**
  1795. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1796. * \brief Convert and write an unsigned 64-bit bigendian value.
  1797. *
  1798. * Convenience function. Convert an unsigned 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_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1810. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1811. /**
  1812. * \fn int PHYSFS_isInit(void)
  1813. * \brief Determine if the PhysicsFS library is initialized.
  1814. *
  1815. * Once PHYSFS_init() returns successfully, this will return non-zero.
  1816. * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns
  1817. * successfully, this will return zero. This function is safe to call at
  1818. * any time.
  1819. *
  1820. * \return non-zero if library is initialized, zero if library is not.
  1821. *
  1822. * \sa PHYSFS_init
  1823. * \sa PHYSFS_deinit
  1824. */
  1825. PHYSFS_DECL int PHYSFS_isInit(void);
  1826. /**
  1827. * \fn int PHYSFS_symbolicLinksPermitted(void)
  1828. * \brief Determine if the symbolic links are permitted.
  1829. *
  1830. * This reports the setting from the last call to PHYSFS_permitSymbolicLinks().
  1831. * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was
  1832. * last initialized, symbolic links are implicitly disabled.
  1833. *
  1834. * \return non-zero if symlinks are permitted, zero if not.
  1835. *
  1836. * \sa PHYSFS_permitSymbolicLinks
  1837. */
  1838. PHYSFS_DECL int PHYSFS_symbolicLinksPermitted(void);
  1839. #ifndef SWIG /* not available from scripting languages. */
  1840. /**
  1841. * \struct PHYSFS_Allocator
  1842. * \brief PhysicsFS allocation function pointers.
  1843. *
  1844. * (This is for limited, hardcore use. If you don't immediately see a need
  1845. * for it, you can probably ignore this forever.)
  1846. *
  1847. * You create one of these structures for use with PHYSFS_setAllocator.
  1848. * Allocators are assumed to be reentrant by the caller; please mutex
  1849. * accordingly.
  1850. *
  1851. * Allocations are always discussed in 64-bits, for future expansion...we're
  1852. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1853. * gigabytes like it's nothing sooner or later, and I don't want to change
  1854. * this again at that point. If you're on a 32-bit platform and have to
  1855. * downcast, it's okay to return NULL if the allocation is greater than
  1856. * 4 gigabytes, since you'd have to do so anyhow.
  1857. *
  1858. * \sa PHYSFS_setAllocator
  1859. */
  1860. typedef struct PHYSFS_Allocator
  1861. {
  1862. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1863. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1864. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1865. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1866. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1867. } PHYSFS_Allocator;
  1868. /**
  1869. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1870. * \brief Hook your own allocation routines into PhysicsFS.
  1871. *
  1872. * (This is for limited, hardcore use. If you don't immediately see a need
  1873. * for it, you can probably ignore this forever.)
  1874. *
  1875. * By default, PhysicsFS will use whatever is reasonable for a platform
  1876. * to manage dynamic memory (usually ANSI C malloc/realloc/calloc/free, but
  1877. * some platforms might use something else), but in some uncommon cases, the
  1878. * app might want more control over the library's memory management. This
  1879. * lets you redirect PhysicsFS to use your own allocation routines instead.
  1880. * You can only call this function before PHYSFS_init(); if the library is
  1881. * initialized, it'll reject your efforts to change the allocator mid-stream.
  1882. * You may call this function after PHYSFS_deinit() if you are willing to
  1883. * shut down the library and restart it with a new allocator; this is a safe
  1884. * and supported operation. The allocator remains intact between deinit/init
  1885. * calls. If you want to return to the platform's default allocator, pass a
  1886. * NULL in here.
  1887. *
  1888. * If you aren't immediately sure what to do with this function, you can
  1889. * safely ignore it altogether.
  1890. *
  1891. * \param allocator Structure containing your allocator's entry points.
  1892. * \return zero on failure, non-zero on success. This call only fails
  1893. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1894. */
  1895. PHYSFS_DECL int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1896. #endif /* SWIG */
  1897. /**
  1898. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
  1899. * \brief Add an archive or directory to the search path.
  1900. *
  1901. * If this is a duplicate, the entry is not added again, even though the
  1902. * function succeeds. You may not add the same archive to two different
  1903. * mountpoints: duplicate checking is done against the archive and not the
  1904. * mountpoint.
  1905. *
  1906. * When you mount an archive, it is added to a virtual file system...all files
  1907. * in all of the archives are interpolated into a single hierachical file
  1908. * tree. Two archives mounted at the same place (or an archive with files
  1909. * overlapping another mountpoint) may have overlapping files: in such a case,
  1910. * the file earliest in the search path is selected, and the other files are
  1911. * inaccessible to the application. This allows archives to be used to
  1912. * override previous revisions; you can use the mounting mechanism to place
  1913. * archives at a specific point in the file tree and prevent overlap; this
  1914. * is useful for downloadable mods that might trample over application data
  1915. * or each other, for example.
  1916. *
  1917. * The mountpoint does not need to exist prior to mounting, which is different
  1918. * than those familiar with the Unix concept of "mounting" may not expect.
  1919. * As well, more than one archive can be mounted to the same mountpoint, or
  1920. * mountpoints and archive contents can overlap...the interpolation mechanism
  1921. * still functions as usual.
  1922. *
  1923. * \param newDir directory or archive to add to the path, in
  1924. * platform-dependent notation.
  1925. * \param mountPoint Location in the interpolated tree that this archive
  1926. * will be "mounted", in platform-independent notation.
  1927. * NULL or "" is equivalent to "/".
  1928. * \param appendToPath nonzero to append to search path, zero to prepend.
  1929. * \return nonzero if added to path, zero on failure (bogus archive, dir
  1930. * missing, etc). Specifics of the error can be
  1931. * gleaned from PHYSFS_getLastError().
  1932. *
  1933. * \sa PHYSFS_removeFromSearchPath
  1934. * \sa PHYSFS_getSearchPath
  1935. * \sa PHYSFS_getMountPoint
  1936. */
  1937. PHYSFS_DECL int PHYSFS_mount(const char *newDir,
  1938. const char *mountPoint,
  1939. int appendToPath);
  1940. /**
  1941. * \fn int PHYSFS_getMountPoint(const char *dir)
  1942. * \brief Determine a mounted archive's mountpoint.
  1943. *
  1944. * You give this function the name of an archive or dir you successfully
  1945. * added to the search path, and it reports the location in the interpolated
  1946. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  1947. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  1948. * and valid until the archive is removed from the search path.
  1949. *
  1950. * \param dir directory or archive previously added to the path, in
  1951. * platform-dependent notation. This must match the string
  1952. * used when adding, even if your string would also reference
  1953. * the same file with a different string of characters.
  1954. * \return READ-ONLY string of mount point if added to path, NULL on failure
  1955. * (bogus archive, etc) Specifics of the error can be gleaned from
  1956. * PHYSFS_getLastError().
  1957. *
  1958. * \sa PHYSFS_removeFromSearchPath
  1959. * \sa PHYSFS_getSearchPath
  1960. * \sa PHYSFS_getMountPoint
  1961. */
  1962. PHYSFS_DECL const char *PHYSFS_getMountPoint(const char *dir);
  1963. #ifndef SWIG /* not available from scripting languages. */
  1964. /**
  1965. * \typedef PHYSFS_StringCallback
  1966. * \brief Function signature for callbacks that report strings.
  1967. *
  1968. * These are used to report a list of strings to an original caller, one
  1969. * string per callback. All strings are UTF-8 encoded. Functions should not
  1970. * try to modify or free the string's memory.
  1971. *
  1972. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  1973. * functions that would return lists that need to be cleaned up with
  1974. * PHYSFS_freeList(). The callback means that the library doesn't need to
  1975. * allocate an entire list and all the strings up front.
  1976. *
  1977. * Be aware that promises data ordering in the list versions are not
  1978. * necessarily so in the callback versions. Check the documentation on
  1979. * specific APIs, but strings may not be sorted as you expect.
  1980. *
  1981. * \param data User-defined data pointer, passed through from the API
  1982. * that eventually called the callback.
  1983. * \param str The string data about which the callback is meant to inform.
  1984. *
  1985. * \sa PHYSFS_getCdRomDirsCallback
  1986. * \sa PHYSFS_getSearchPathCallback
  1987. */
  1988. typedef void (*PHYSFS_StringCallback)(void *data, const char *str);
  1989. /**
  1990. * \typedef PHYSFS_EnumFilesCallback
  1991. * \brief Function signature for callbacks that enumerate files.
  1992. *
  1993. * These are used to report a list of directory entries to an original caller,
  1994. * one file/dir/symlink per callback. All strings are UTF-8 encoded.
  1995. * Functions should not try to modify or free any string's memory.
  1996. *
  1997. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  1998. * functions that would return lists that need to be cleaned up with
  1999. * PHYSFS_freeList(). The callback means that the library doesn't need to
  2000. * allocate an entire list and all the strings up front.
  2001. *
  2002. * Be aware that promises data ordering in the list versions are not
  2003. * necessarily so in the callback versions. Check the documentation on
  2004. * specific APIs, but strings may not be sorted as you expect.
  2005. *
  2006. * \param data User-defined data pointer, passed through from the API
  2007. * that eventually called the callback.
  2008. * \param origdir A string containing the full path, in platform-independent
  2009. * notation, of the directory containing this file. In most
  2010. * cases, this is the directory on which you requested
  2011. * enumeration, passed in the callback for your convenience.
  2012. * \param fname The filename that is being enumerated. It may not be in
  2013. * alphabetical order compared to other callbacks that have
  2014. * fired, and it will not contain the full path. You can
  2015. * recreate the fullpath with $origdir/$fname ... The file
  2016. * can be a subdirectory, a file, a symlink, etc.
  2017. *
  2018. * \sa PHYSFS_enumerateFilesCallback
  2019. */
  2020. typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir,
  2021. const char *fname);
  2022. /**
  2023. * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d)
  2024. * \brief Enumerate CD-ROM directories, using an application-defined callback.
  2025. *
  2026. * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds
  2027. * a list before returning to the application, so functionality is identical
  2028. * except for how the information is represented to the application.
  2029. *
  2030. * Unlike PHYSFS_getCdRomDirs(), this function does not return an array.
  2031. * Rather, it calls a function specified by the application once per
  2032. * detected disc:
  2033. *
  2034. * \code
  2035. *
  2036. * static void foundDisc(void *data, const char *cddir)
  2037. * {
  2038. * printf("cdrom dir [%s] is available.\n", cddir);
  2039. * }
  2040. *
  2041. * // ...
  2042. * PHYSFS_getCdRomDirsCallback(foundDisc, NULL);
  2043. * \endcode
  2044. *
  2045. * This call may block while drives spin up. Be forewarned.
  2046. *
  2047. * \param c Callback function to notify about detected drives.
  2048. * \param d Application-defined data passed to callback. Can be NULL.
  2049. *
  2050. * \sa PHYSFS_StringCallback
  2051. * \sa PHYSFS_getCdRomDirs
  2052. */
  2053. PHYSFS_DECL void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  2054. /**
  2055. * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d)
  2056. * \brief Enumerate the search path, using an application-defined callback.
  2057. *
  2058. * Internally, PHYSFS_getSearchPath() just calls this function and then builds
  2059. * a list before returning to the application, so functionality is identical
  2060. * except for how the information is represented to the application.
  2061. *
  2062. * Unlike PHYSFS_getSearchPath(), this function does not return an array.
  2063. * Rather, it calls a function specified by the application once per
  2064. * element of the search path:
  2065. *
  2066. * \code
  2067. *
  2068. * static void printSearchPath(void *data, const char *pathItem)
  2069. * {
  2070. * printf("[%s] is in the search path.\n", pathItem);
  2071. * }
  2072. *
  2073. * // ...
  2074. * PHYSFS_getSearchPathCallback(printSearchPath, NULL);
  2075. * \endcode
  2076. *
  2077. * Elements of the search path are reported in order search priority, so the
  2078. * first archive/dir that would be examined when looking for a file is the
  2079. * first element passed through the callback.
  2080. *
  2081. * \param c Callback function to notify about search path elements.
  2082. * \param d Application-defined data passed to callback. Can be NULL.
  2083. *
  2084. * \sa PHYSFS_StringCallback
  2085. * \sa PHYSFS_getSearchPath
  2086. */
  2087. PHYSFS_DECL void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  2088. /**
  2089. * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d)
  2090. * \brief Get a file listing of a search path's directory, using an application-defined callback.
  2091. *
  2092. * Internally, PHYSFS_enumerateFiles() just calls this function and then builds
  2093. * a list before returning to the application, so functionality is identical
  2094. * except for how the information is represented to the application.
  2095. *
  2096. * Unlike PHYSFS_enumerateFiles(), this function does not return an array.
  2097. * Rather, it calls a function specified by the application once per
  2098. * element of the search path:
  2099. *
  2100. * \code
  2101. *
  2102. * static void printDir(void *data, const char *origdir, const char *fname)
  2103. * {
  2104. * printf(" * We've got [%s] in [%s].\n", fname, origdir);
  2105. * }
  2106. *
  2107. * // ...
  2108. * PHYSFS_enumerateFilesCallback("/some/path", printDir, NULL);
  2109. * \endcode
  2110. *
  2111. * !!! FIXME: enumerateFiles() does not promise alphabetical sorting by
  2112. * !!! FIXME: case-sensitivity in the code, and doesn't promise sorting at
  2113. * !!! FIXME: all in the above docs.
  2114. *
  2115. * Items sent to the callback are not guaranteed to be in any order whatsoever.
  2116. * There is no sorting done at this level, and if you need that, you should
  2117. * probably use PHYSFS_enumerateFiles() instead, which guarantees
  2118. * alphabetical sorting. This form reports whatever is discovered in each
  2119. * archive before moving on to the next. Even within one archive, we can't
  2120. * guarantee what order it will discover data. <em>Any sorting you find in
  2121. * these callbacks is just pure luck. Do not rely on it.</em> As this walks
  2122. * the entire list of archives, you may receive duplicate filenames.
  2123. *
  2124. * \param dir Directory, in platform-independent notation, to enumerate.
  2125. * \param c Callback function to notify about search path elements.
  2126. * \param d Application-defined data passed to callback. Can be NULL.
  2127. *
  2128. * \sa PHYSFS_EnumFilesCallback
  2129. * \sa PHYSFS_enumerateFiles
  2130. */
  2131. PHYSFS_DECL void PHYSFS_enumerateFilesCallback(const char *dir,
  2132. PHYSFS_EnumFilesCallback c,
  2133. void *d);
  2134. /**
  2135. * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
  2136. * \brief Convert a UCS-4 string to a UTF-8 string.
  2137. *
  2138. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2139. *
  2140. * To ensure that the destination buffer is large enough for the conversion,
  2141. * please allocate a buffer that is the same size as the source buffer. UTF-8
  2142. * never uses more than 32-bits per character, so while it may shrink a UCS-4
  2143. * string, it will never expand it.
  2144. *
  2145. * Strings that don't fit in the destination buffer will be truncated, but
  2146. * will always be null-terminated and never have an incomplete UTF-8
  2147. * sequence at the end. If the buffer length is 0, this function does nothing.
  2148. *
  2149. * \param src Null-terminated source string in UCS-4 format.
  2150. * \param dst Buffer to store converted UTF-8 string.
  2151. * \param len Size, in bytes, of destination buffer.
  2152. */
  2153. PHYSFS_DECL void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst,
  2154. PHYSFS_uint64 len);
  2155. /**
  2156. * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
  2157. * \brief Convert a UTF-8 string to a UCS-4 string.
  2158. *
  2159. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2160. *
  2161. * To ensure that the destination buffer is large enough for the conversion,
  2162. * please allocate a buffer that is four times the size of the source buffer.
  2163. * UTF-8 uses from one to four bytes per character, but UCS-4 always uses
  2164. * four, so an entirely low-ASCII string will quadruple in size!
  2165. *
  2166. * Strings that don't fit in the destination buffer will be truncated, but
  2167. * will always be null-terminated and never have an incomplete UCS-4
  2168. * sequence at the end. If the buffer length is 0, this function does nothing.
  2169. *
  2170. * \param src Null-terminated source string in UTF-8 format.
  2171. * \param dst Buffer to store converted UCS-4 string.
  2172. * \param len Size, in bytes, of destination buffer.
  2173. */
  2174. PHYSFS_DECL void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst,
  2175. PHYSFS_uint64 len);
  2176. /**
  2177. * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2178. * \brief Convert a UCS-2 string to a UTF-8 string.
  2179. *
  2180. * \warning you almost certainly should use PHYSFS_utf8FromUtf16(), which
  2181. * became available in PhysicsFS 2.1, unless you know what you're doing.
  2182. *
  2183. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2184. * with Unicode support. Please note that modern versions of Windows use
  2185. * UTF-16, not UCS-2. You almost certainly want PHYSFS_utf8FromUtf16() instead.
  2186. *
  2187. * To ensure that the destination buffer is large enough for the conversion,
  2188. * please allocate a buffer that is double the size of the source buffer.
  2189. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2190. * a UCS-2 string, it may also expand it.
  2191. *
  2192. * Strings that don't fit in the destination buffer will be truncated, but
  2193. * will always be null-terminated and never have an incomplete UTF-8
  2194. * sequence at the end. If the buffer length is 0, this function does nothing.
  2195. *
  2196. * \param src Null-terminated source string in UCS-2 format.
  2197. * \param dst Buffer to store converted UTF-8 string.
  2198. * \param len Size, in bytes, of destination buffer.
  2199. *
  2200. * \sa PHYSFS_utf8FromUtf16
  2201. */
  2202. PHYSFS_DECL void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst,
  2203. PHYSFS_uint64 len);
  2204. /**
  2205. * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2206. * \brief Convert a UTF-8 string to a UCS-2 string.
  2207. *
  2208. * \warning you almost certainly should use PHYSFS_utf8ToUtf16(), which
  2209. * became available in PhysicsFS 2.1, unless you know what you're doing.
  2210. *
  2211. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2212. * with Unicode support. Please note that modern versions of Windows use
  2213. * UTF-16, not UCS-2. You almost certainly want PHYSFS_utf8ToUtf16() instead,
  2214. * but you need to understand how that changes things, too.
  2215. *
  2216. * To ensure that the destination buffer is large enough for the conversion,
  2217. * please allocate a buffer that is double the size of the source buffer.
  2218. * UTF-8 uses from one to four bytes per character, but UCS-2 always uses
  2219. * two, so an entirely low-ASCII string will double in size!
  2220. *
  2221. * Strings that don't fit in the destination buffer will be truncated, but
  2222. * will always be null-terminated and never have an incomplete UCS-2
  2223. * sequence at the end. If the buffer length is 0, this function does nothing.
  2224. *
  2225. * \param src Null-terminated source string in UTF-8 format.
  2226. * \param dst Buffer to store converted UCS-2 string.
  2227. * \param len Size, in bytes, of destination buffer.
  2228. *
  2229. * \sa PHYSFS_utf8ToUtf16
  2230. */
  2231. PHYSFS_DECL void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst,
  2232. PHYSFS_uint64 len);
  2233. /**
  2234. * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
  2235. * \brief Convert a UTF-8 string to a Latin1 string.
  2236. *
  2237. * Latin1 strings are 8-bits per character: a popular "high ASCII"
  2238. * encoding.
  2239. *
  2240. * To ensure that the destination buffer is large enough for the conversion,
  2241. * please allocate a buffer that is double the size of the source buffer.
  2242. * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string
  2243. * may grow in some cases.
  2244. *
  2245. * Strings that don't fit in the destination buffer will be truncated, but
  2246. * will always be null-terminated and never have an incomplete UTF-8
  2247. * sequence at the end. If the buffer length is 0, this function does nothing.
  2248. *
  2249. * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  2250. * can't express most Unicode codepoints. It's a legacy encoding; you should
  2251. * be converting away from it at all times.
  2252. *
  2253. * \param src Null-terminated source string in Latin1 format.
  2254. * \param dst Buffer to store converted UTF-8 string.
  2255. * \param len Size, in bytes, of destination buffer.
  2256. */
  2257. PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst,
  2258. PHYSFS_uint64 len);
  2259. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  2260. /**
  2261. * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void)
  2262. * \brief Discover the current allocator.
  2263. *
  2264. * (This is for limited, hardcore use. If you don't immediately see a need
  2265. * for it, you can probably ignore this forever.)
  2266. *
  2267. * This function exposes the function pointers that make up the currently used
  2268. * allocator. This can be useful for apps that want to access PhysicsFS's
  2269. * internal, default allocation routines, as well as for external code that
  2270. * wants to share the same allocator, even if the application specified their
  2271. * own.
  2272. *
  2273. * This call is only valid between PHYSFS_init() and PHYSFS_deinit() calls;
  2274. * it will return NULL if the library isn't initialized. As we can't
  2275. * guarantee the state of the internal allocators unless the library is
  2276. * initialized, you shouldn't use any allocator returned here after a call
  2277. * to PHYSFS_deinit().
  2278. *
  2279. * Do not call the returned allocator's Init() or Deinit() methods under any
  2280. * circumstances.
  2281. *
  2282. * If you aren't immediately sure what to do with this function, you can
  2283. * safely ignore it altogether.
  2284. *
  2285. * \return Current allocator, as set by PHYSFS_setAllocator(), or PhysicsFS's
  2286. * internal, default allocator if no application defined allocator
  2287. * is currently set. Will return NULL if the library is not
  2288. * initialized.
  2289. *
  2290. * \sa PHYSFS_Allocator
  2291. * \sa PHYSFS_setAllocator
  2292. */
  2293. PHYSFS_DECL const PHYSFS_Allocator *PHYSFS_getAllocator(void);
  2294. #endif /* SWIG */
  2295. /**
  2296. * \enum PHYSFS_FileType
  2297. * \brief Type of a File
  2298. *
  2299. * Possible types of a file.
  2300. *
  2301. * \sa PHYSFS_stat
  2302. */
  2303. typedef enum PHYSFS_FileType
  2304. {
  2305. PHYSFS_FILETYPE_REGULAR, /**< a normal file */
  2306. PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
  2307. PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
  2308. PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
  2309. } PHYSFS_FileType;
  2310. /**
  2311. * \struct PHYSFS_Stat
  2312. * \brief Meta data for a file or directory
  2313. *
  2314. * Container for various meta data about a file in the virtual file system.
  2315. * PHYSFS_stat() uses this structure for returning the information. The time
  2316. * data will be either the number of seconds since the Unix epoch (midnight,
  2317. * Jan 1, 1970), or -1 if there the information isn't available or applicable.
  2318. * The (filesize) field is measured in bytes.
  2319. * The (readonly) field tells you whether when you open a file for writing you
  2320. * are writing to the same file as if you were opening it, given you have
  2321. * enough filesystem rights to do that. !!! FIXME: this might change.
  2322. *
  2323. * \sa PHYSFS_stat
  2324. * \sa PHYSFS_FileType
  2325. */
  2326. typedef struct PHYSFS_Stat
  2327. {
  2328. PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
  2329. PHYSFS_sint64 modtime; /**< last modification time */
  2330. PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
  2331. PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
  2332. PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
  2333. int readonly; /**< non-zero if read only, zero if writable. */
  2334. } PHYSFS_Stat;
  2335. /**
  2336. * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
  2337. * \brief Get various information about a directory or a file.
  2338. *
  2339. * Obtain various information about a file or directory from the meta data.
  2340. *
  2341. * \param fname filename to check, in platform-indepedent notation.
  2342. * \param stat pointer to structure to fill in with data about (fname).
  2343. * \return 0 on success, non-zero on error. // !!! FIXME: arg, that's backwards from everything else in PhysicsFS!
  2344. *
  2345. * \sa PHYSFS_Stat
  2346. */
  2347. PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
  2348. #ifndef SWIG /* not available from scripting languages. */
  2349. /**
  2350. * \fn void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2351. * \brief Convert a UTF-16 string to a UTF-8 string.
  2352. *
  2353. * UTF-16 strings are 16-bits per character (except some chars, which are
  2354. * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern
  2355. * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but
  2356. * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that
  2357. * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you
  2358. * aren't sure, you should be using UTF-16 at this point on Windows.
  2359. *
  2360. * To ensure that the destination buffer is large enough for the conversion,
  2361. * please allocate a buffer that is double the size of the source buffer.
  2362. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2363. * a UTF-16 string, it may also expand it.
  2364. *
  2365. * Strings that don't fit in the destination buffer will be truncated, but
  2366. * will always be null-terminated and never have an incomplete UTF-8
  2367. * sequence at the end. If the buffer length is 0, this function does nothing.
  2368. *
  2369. * \param src Null-terminated source string in UTF-16 format.
  2370. * \param dst Buffer to store converted UTF-8 string.
  2371. * \param len Size, in bytes, of destination buffer.
  2372. */
  2373. PHYSFS_DECL void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst,
  2374. PHYSFS_uint64 len);
  2375. /**
  2376. * \fn PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2377. * \brief Convert a UTF-8 string to a UTF-16 string.
  2378. *
  2379. * UTF-16 strings are 16-bits per character (except some chars, which are
  2380. * 32-bits): \c TCHAR on Windows, when building with Unicode support. Modern
  2381. * Windows releases use UTF-16. Windows releases before 2000 used TCHAR, but
  2382. * only handled UCS-2. UTF-16 _is_ UCS-2, except for the characters that
  2383. * are 4 bytes, which aren't representable in UCS-2 at all anyhow. If you
  2384. * aren't sure, you should be using UTF-16 at this point on Windows.
  2385. *
  2386. * To ensure that the destination buffer is large enough for the conversion,
  2387. * please allocate a buffer that is double the size of the source buffer.
  2388. * UTF-8 uses from one to four bytes per character, but UTF-16 always uses
  2389. * two to four, so an entirely low-ASCII string will double in size! The
  2390. * UTF-16 characters that would take four bytes also take four bytes in UTF-8,
  2391. * so you don't need to allocate 4x the space just in case: double will do.
  2392. *
  2393. * Strings that don't fit in the destination buffer will be truncated, but
  2394. * will always be null-terminated and never have an incomplete UTF-16
  2395. * surrogate pair at the end. If the buffer length is 0, this function does
  2396. * nothing.
  2397. *
  2398. * \param src Null-terminated source string in UTF-8 format.
  2399. * \param dst Buffer to store converted UTF-16 string.
  2400. * \param len Size, in bytes, of destination buffer.
  2401. *
  2402. * \sa PHYSFS_utf8ToUtf16
  2403. */
  2404. PHYSFS_DECL void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst,
  2405. PHYSFS_uint64 len);
  2406. #endif /* SWIG */
  2407. /**
  2408. * \fn PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer, PHYSFS_uint64 len)
  2409. * \brief Read bytes from a PhysicsFS filehandle
  2410. *
  2411. * The file must be opened for reading.
  2412. *
  2413. * \param handle handle returned from PHYSFS_openRead().
  2414. * \param buffer buffer of at least (len) bytes to store read data into.
  2415. * \param len number of bytes being read from (handle).
  2416. * \return number of bytes read. This may be less than (len); this does not
  2417. * signify an error, necessarily (a short read may mean EOF).
  2418. * PHYSFS_getLastError() can shed light on the reason this might
  2419. * be < (len), as can PHYSFS_eof(). -1 if complete failure.
  2420. *
  2421. * \sa PHYSFS_eof
  2422. */
  2423. PHYSFS_DECL PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer,
  2424. PHYSFS_uint64 len);
  2425. /**
  2426. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint64 len)
  2427. * \brief Write data to a PhysicsFS filehandle
  2428. *
  2429. * The file must be opened for writing.
  2430. *
  2431. * Please note that while (len) is an unsigned 64-bit integer, you are limited
  2432. * to 63 bits (9223372036854775807 bytes), so we can return a negative value
  2433. * on error. If length is greater than 0x7FFFFFFFFFFFFFFF, this function will
  2434. * immediately fail. For systems without a 64-bit datatype, you are limited
  2435. * to 31 bits (0x7FFFFFFF, or 2147483647 bytes). We trust most things won't
  2436. * need to do multiple gigabytes of i/o in one call anyhow, but why limit
  2437. * things?
  2438. *
  2439. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  2440. * \param buffer buffer of (len) bytes to write to (handle).
  2441. * \param len number of bytes being written to (handle).
  2442. * \return number of bytes written. This may be less than (len); in the case
  2443. * of an error, the system may try to write as many bytes as possible,
  2444. * so an incomplete write might occur. PHYSFS_getLastError() can shed
  2445. * light on the reason this might be < (len). -1 if complete failure.
  2446. */
  2447. PHYSFS_DECL PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle,
  2448. const void *buffer,
  2449. PHYSFS_uint64 len);
  2450. /* Everything above this line is part of the PhysicsFS 2.1 API. */
  2451. #ifdef __cplusplus
  2452. }
  2453. #endif
  2454. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  2455. /* end of physfs.h ... */