physfs.h 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  1. /** \file physfs.h */
  2. /**
  3. * \mainpage PhysicsFS
  4. *
  5. * The latest version of PhysicsFS can be found at:
  6. * http://icculus.org/physfs/
  7. *
  8. * PhysicsFS; a portable, flexible file i/o abstraction.
  9. *
  10. * This API gives you access to a system file system in ways superior to the
  11. * stdio or system i/o calls. The brief benefits:
  12. *
  13. * - It's portable.
  14. * - It's safe. No file access is permitted outside the specified dirs.
  15. * - It's flexible. Archives (.ZIP files) can be used transparently as
  16. * directory structures.
  17. *
  18. * This system is largely inspired by Quake 3's PK3 files and the related
  19. * fs_* cvars. If you've ever tinkered with these, then this API will be
  20. * familiar to you.
  21. *
  22. * With PhysicsFS, you have a single writing directory and multiple
  23. * directories (the "search path") for reading. You can think of this as a
  24. * filesystem within a filesystem. If (on Windows) you were to set the
  25. * writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
  26. * could touch anything above this directory, including the "C:\MyGame" and
  27. * "C:\" directories. This prevents an application's internal scripting
  28. * language from piddling over c:\\config.sys, for example. If you'd rather
  29. * give PHYSFS full access to the system's REAL file system, set the writing
  30. * dir to "C:\", but that's generally A Bad Thing for several reasons.
  31. *
  32. * Drive letters are hidden in PhysicsFS once you set up your initial paths.
  33. * The search path creates a single, hierarchical directory structure.
  34. * Not only does this lend itself well to general abstraction with archives,
  35. * it also gives better support to operating systems like MacOS and Unix.
  36. * Generally speaking, you shouldn't ever hardcode a drive letter; not only
  37. * does this hurt portability to non-Microsoft OSes, but it limits your win32
  38. * users to a single drive, too. Use the PhysicsFS abstraction functions and
  39. * allow user-defined configuration options, too. When opening a file, you
  40. * specify it like it was on a Unix filesystem: if you want to write to
  41. * "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write dir to
  42. * "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
  43. * abstraction across all platforms. Specifying a file in this way is termed
  44. * "platform-independent notation" in this documentation. Specifying a
  45. * a filename in a form such as "C:\mydir\myfile" or
  46. * "MacOS hard drive:My Directory:My File" is termed "platform-dependent
  47. * notation". The only time you use platform-dependent notation is when
  48. * setting up your write directory and search path; after that, all file
  49. * access into those directories are done with platform-independent notation.
  50. *
  51. * All files opened for writing are opened in relation to the write directory,
  52. * which is the root of the writable filesystem. When opening a file for
  53. * reading, PhysicsFS goes through the search path. This is NOT the
  54. * same thing as the PATH environment variable. An application using
  55. * PhysicsFS specifies directories to be searched which may be actual
  56. * directories, or archive files that contain files and subdirectories of
  57. * their own. See the end of these docs for currently supported archive
  58. * formats.
  59. *
  60. * Once the search path is defined, you may open files for reading. If you've
  61. * got the following search path defined (to use a win32 example again):
  62. *
  63. * - C:\\mygame
  64. * - C:\\mygame\\myuserfiles
  65. * - D:\\mygamescdromdatafiles
  66. * - C:\\mygame\\installeddatafiles.zip
  67. *
  68. * Then a call to PHYSFS_openRead("textfiles/myfile.txt") (note the directory
  69. * separator, lack of drive letter, and lack of dir separator at the start of
  70. * the string; this is platform-independent notation) will check for
  71. * C:\\mygame\\textfiles\\myfile.txt, then
  72. * C:\\mygame\\myuserfiles\\textfiles\\myfile.txt, then
  73. * D:\\mygamescdromdatafiles\\textfiles\\myfile.txt, then, finally, for
  74. * textfiles\\myfile.txt inside of C:\\mygame\\installeddatafiles.zip.
  75. * Remember that most archive types and platform filesystems store their
  76. * filenames in a case-sensitive manner, so you should be careful to specify
  77. * it correctly.
  78. *
  79. * Files opened through PhysicsFS may NOT contain "." or ".." or ":" as dir
  80. * elements. Not only are these meaningless on MacOS Classic and/or Unix,
  81. * they are a security hole. Also, symbolic links (which can be found in
  82. * some archive types and directly in the filesystem on Unix platforms) are
  83. * NOT followed until you call PHYSFS_permitSymbolicLinks(). That's left to
  84. * your own discretion, as following a symlink can allow for access outside
  85. * the write dir and search paths. For portability, there is no mechanism for
  86. * creating new symlinks in PhysicsFS.
  87. *
  88. * The write dir is not included in the search path unless you specifically
  89. * add it. While you CAN change the write dir as many times as you like,
  90. * you should probably set it once and stick to it. Remember that your
  91. * program will not have permission to write in every directory on Unix and
  92. * NT systems.
  93. *
  94. * All files are opened in binary mode; there is no endline conversion for
  95. * textfiles. Other than that, PhysicsFS has some convenience functions for
  96. * platform-independence. There is a function to tell you the current
  97. * platform's dir separator ("\\" on windows, "/" on Unix, ":" on MacOS),
  98. * which is needed only to set up your search/write paths. There is a
  99. * function to tell you what CD-ROM drives contain accessible discs, and a
  100. * function to recommend a good search path, etc.
  101. *
  102. * A recommended order for the search path is the write dir, then the base dir,
  103. * then the cdrom dir, then any archives discovered. Quake 3 does something
  104. * like this, but moves the archives to the start of the search path. Build
  105. * Engine games, like Duke Nukem 3D and Blood, place the archives last, and
  106. * use the base dir for both searching and writing. There is a helper
  107. * function (PHYSFS_setSaneConfig()) that puts together a basic configuration
  108. * for you, based on a few parameters. Also see the comments on
  109. * PHYSFS_getBaseDir(), and PHYSFS_getUserDir() for info on what those
  110. * are and how they can help you determine an optimal search path.
  111. *
  112. * PhysicsFS 2.0 adds the concept of "mounting" archives to arbitrary points
  113. * in the search path. If a zipfile contains "maps/level.map" and you mount
  114. * that archive at "mods/mymod", then you would have to open
  115. * "mods/mymod/maps/level.map" to access the file, even though "mods/mymod"
  116. * isn't actually specified in the .zip file. Unlike the Unix mentality of
  117. * mounting a filesystem, "mods/mymod" doesn't actually have to exist when
  118. * mounting the zipfile. It's a "virtual" directory. The mounting mechanism
  119. * allows the developer to seperate archives in the tree and avoid trampling
  120. * over files when added new archives, such as including mod support in a
  121. * game...keeping external content on a tight leash in this manner can be of
  122. * utmost importance to some applications.
  123. *
  124. * PhysicsFS is mostly thread safe. The error messages returned by
  125. * PHYSFS_getLastError are unique by thread, and library-state-setting
  126. * functions are mutex'd. For efficiency, individual file accesses are
  127. * not locked, so you can not safely read/write/seek/close/etc the same
  128. * file from two threads at the same time. Other race conditions are bugs
  129. * that should be reported/patched.
  130. *
  131. * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
  132. * calls, doing so is not recommended, and you can not use system
  133. * filehandles with PhysicsFS and vice versa.
  134. *
  135. * Note that archives need not be named as such: if you have a ZIP file and
  136. * rename it with a .PKG extension, the file will still be recognized as a
  137. * ZIP archive by PhysicsFS; the file's contents are used to determine its
  138. * type where possible.
  139. *
  140. * Currently supported archive types:
  141. * - .ZIP (pkZip/WinZip/Info-ZIP compatible)
  142. * - .GRP (Build Engine groupfile archives)
  143. * - .PAK (Quake I/II archive format)
  144. * - .HOG (Descent I/II HOG file archives)
  145. * - .MVL (Descent II movielib archives)
  146. * - .WAD (DOOM engine archives)
  147. *
  148. *
  149. * String policy for PhysicsFS 2.0 and later:
  150. *
  151. * PhysicsFS 1.0 could only deal with null-terminated ASCII strings. All high
  152. * ASCII chars resulted in undefined behaviour, and there was no Unicode
  153. * support at all. PhysicsFS 2.0 supports Unicode without breaking binary
  154. * compatibility with the 1.0 API by using UTF-8 encoding of all strings
  155. * passed in and out of the library.
  156. *
  157. * All strings passed through PhysicsFS are in null-terminated UTF-8 format.
  158. * This means that if all you care about is English (ASCII characters <= 127)
  159. * then you just use regular C strings. If you care about Unicode (and you
  160. * should!) then you need to figure out what your platform wants, needs, and
  161. * offers. If you are on Windows and build with Unicode support, your TCHAR
  162. * strings are two bytes per character (this is called "UCS-2 encoding"). You
  163. * should convert them to UTF-8 before handing them to PhysicsFS with
  164. * PHYSFS_utf8FromUcs2(). If you're using Unix or Mac OS X, your wchar_t
  165. * strings are four bytes per character ("UCS-4 encoding"). Use
  166. * PHYSFS_utf8FromUcs4(). Mac OS X can give you UTF-8 directly from a
  167. * CFString, and many Unixes generally give you C strings in UTF-8 format
  168. * everywhere. If you have a single-byte high ASCII charset, like so-many
  169. * European "codepages" you may be out of luck. We'll convert from "Latin1"
  170. * to UTF-8 only, and never back to Latin1. If you're above ASCII 127, all
  171. * bets are off: move to Unicode or use your platform's facilities. Passing a
  172. * C string with high-ASCII data that isn't UTF-8 encoded will NOT do what
  173. * you expect!
  174. *
  175. * Naturally, there's also PHYSFS_utf8ToUcs2() and PHYSFS_utf8ToUcs4() to get
  176. * data back into a format you like. Behind the scenes, PhysicsFS will use
  177. * Unicode where possible: the UTF-8 strings on Windows will be converted
  178. * and used with the multibyte Windows APIs, for example.
  179. *
  180. * PhysicsFS offers basic encoding conversion support, but not a whole string
  181. * library. Get your stuff into whatever format you can work with.
  182. *
  183. * Some platforms and archivers don't offer full Unicode support behind the
  184. * scenes. For example, OS/2 only offers "codepages" and the filesystem
  185. * itself doesn't support multibyte encodings. We make an earnest effort to
  186. * convert to/from the current locale here, but all bets are off if
  187. * you want to hand an arbitrary Japanese character through to these systems.
  188. * Modern OSes (Mac OS X, Linux, Windows, PocketPC, etc) should all be fine.
  189. * Many game-specific archivers are seriously unprepared for Unicode (the
  190. * Descent HOG/MVL and Build Engine GRP archivers, for example, only offer a
  191. * DOS 8.3 filename, for example). Nothing can be done for these, but they
  192. * tend to be legacy formats for existing content that was all ASCII (and
  193. * thus, valid UTF-8) anyhow. Other formats, like .ZIP, don't explicitly
  194. * offer Unicode support, but unofficially expect filenames to be UTF-8
  195. * encoded, and thus Just Work. Most everything does the right thing without
  196. * bothering you, but it's good to be aware of these nuances in case they
  197. * don't.
  198. *
  199. *
  200. * Other stuff:
  201. *
  202. * Please see the file LICENSE.txt in the source's root directory for licensing
  203. * and redistribution rights.
  204. *
  205. * Please see the file CREDITS.txt in the source's root directory for a more or
  206. * less complete list of who's responsible for this.
  207. *
  208. * \author Ryan C. Gordon.
  209. */
  210. #ifndef _INCLUDE_PHYSFS_H_
  211. #define _INCLUDE_PHYSFS_H_
  212. #ifdef __cplusplus
  213. extern "C" {
  214. #endif
  215. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  216. #if (defined _MSC_VER)
  217. #define __EXPORT__ __declspec(dllexport)
  218. #elif (__GNUC__ >= 3)
  219. #define __EXPORT__ __attribute__((visibility("default")))
  220. #else
  221. #define __EXPORT__
  222. #endif
  223. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  224. /**
  225. * \typedef PHYSFS_uint8
  226. * \brief An unsigned, 8-bit integer type.
  227. */
  228. typedef unsigned char PHYSFS_uint8;
  229. /**
  230. * \typedef PHYSFS_sint8
  231. * \brief A signed, 8-bit integer type.
  232. */
  233. typedef signed char PHYSFS_sint8;
  234. /**
  235. * \typedef PHYSFS_uint16
  236. * \brief An unsigned, 16-bit integer type.
  237. */
  238. typedef unsigned short PHYSFS_uint16;
  239. /**
  240. * \typedef PHYSFS_sint16
  241. * \brief A signed, 16-bit integer type.
  242. */
  243. typedef signed short PHYSFS_sint16;
  244. /**
  245. * \typedef PHYSFS_uint32
  246. * \brief An unsigned, 32-bit integer type.
  247. */
  248. typedef unsigned int PHYSFS_uint32;
  249. /**
  250. * \typedef PHYSFS_sint32
  251. * \brief A signed, 32-bit integer type.
  252. */
  253. typedef signed int PHYSFS_sint32;
  254. /**
  255. * \typedef PHYSFS_uint64
  256. * \brief An unsigned, 64-bit integer type.
  257. * \warning on platforms without any sort of 64-bit datatype, this is
  258. * equivalent to PHYSFS_uint32!
  259. */
  260. /**
  261. * \typedef PHYSFS_sint64
  262. * \brief A signed, 64-bit integer type.
  263. * \warning on platforms without any sort of 64-bit datatype, this is
  264. * equivalent to PHYSFS_sint32!
  265. */
  266. #if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */
  267. typedef PHYSFS_uint32 PHYSFS_uint64;
  268. typedef PHYSFS_sint32 PHYSFS_sint64;
  269. #elif (defined _MSC_VER)
  270. typedef signed __int64 PHYSFS_sint64;
  271. typedef unsigned __int64 PHYSFS_uint64;
  272. #else
  273. typedef unsigned long long PHYSFS_uint64;
  274. typedef signed long long PHYSFS_sint64;
  275. #endif
  276. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  277. /* Make sure the types really have the right sizes */
  278. #define PHYSFS_COMPILE_TIME_ASSERT(name, x) \
  279. typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1]
  280. PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1);
  281. PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1);
  282. PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2);
  283. PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2);
  284. PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4);
  285. PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4);
  286. #ifndef PHYSFS_NO_64BIT_SUPPORT
  287. PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8);
  288. PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8);
  289. #endif
  290. #undef PHYSFS_COMPILE_TIME_ASSERT
  291. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  292. /**
  293. * \struct PHYSFS_File
  294. * \brief A PhysicsFS file handle.
  295. *
  296. * You get a pointer to one of these when you open a file for reading,
  297. * writing, or appending via PhysicsFS.
  298. *
  299. * As you can see from the lack of meaningful fields, you should treat this
  300. * as opaque data. Don't try to manipulate the file handle, just pass the
  301. * pointer you got, unmolested, to various PhysicsFS APIs.
  302. *
  303. * \sa PHYSFS_openRead
  304. * \sa PHYSFS_openWrite
  305. * \sa PHYSFS_openAppend
  306. * \sa PHYSFS_close
  307. * \sa PHYSFS_read
  308. * \sa PHYSFS_write
  309. * \sa PHYSFS_seek
  310. * \sa PHYSFS_tell
  311. * \sa PHYSFS_eof
  312. * \sa PHYSFS_setBuffer
  313. * \sa PHYSFS_flush
  314. */
  315. typedef struct
  316. {
  317. void *opaque; /**< That's all you get. Don't touch. */
  318. } PHYSFS_File;
  319. /**
  320. * \def PHYSFS_file
  321. * \brief 1.0 API compatibility define.
  322. *
  323. * PHYSFS_file is identical to PHYSFS_File. This #define is here for backwards
  324. * compatibility with the 1.0 API, which had an inconsistent capitalization
  325. * convention in this case. New code should use PHYSFS_File, as this #define
  326. * may go away someday.
  327. *
  328. * \sa PHYSFS_File
  329. */
  330. #define PHYSFS_file PHYSFS_File
  331. /**
  332. * \struct PHYSFS_ArchiveInfo
  333. * \brief Information on various PhysicsFS-supported archives.
  334. *
  335. * This structure gives you details on what sort of archives are supported
  336. * by this implementation of PhysicsFS. Archives tend to be things like
  337. * ZIP files and such.
  338. *
  339. * \warning Not all binaries are created equal! PhysicsFS can be built with
  340. * or without support for various archives. You can check with
  341. * PHYSFS_supportedArchiveTypes() to see if your archive type is
  342. * supported.
  343. *
  344. * \sa PHYSFS_supportedArchiveTypes
  345. */
  346. typedef struct
  347. {
  348. const char *extension; /**< Archive file extension: "ZIP", for example. */
  349. const char *description; /**< Human-readable archive description. */
  350. const char *author; /**< Person who did support for this archive. */
  351. const char *url; /**< URL related to this archive */
  352. } PHYSFS_ArchiveInfo;
  353. /**
  354. * \struct PHYSFS_Version
  355. * \brief Information the version of PhysicsFS in use.
  356. *
  357. * Represents the library's version as three levels: major revision
  358. * (increments with massive changes, additions, and enhancements),
  359. * minor revision (increments with backwards-compatible changes to the
  360. * major revision), and patchlevel (increments with fixes to the minor
  361. * revision).
  362. *
  363. * \sa PHYSFS_VERSION
  364. * \sa PHYSFS_getLinkedVersion
  365. */
  366. typedef struct
  367. {
  368. PHYSFS_uint8 major; /**< major revision */
  369. PHYSFS_uint8 minor; /**< minor revision */
  370. PHYSFS_uint8 patch; /**< patchlevel */
  371. } PHYSFS_Version;
  372. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  373. #define PHYSFS_VER_MAJOR 1
  374. #define PHYSFS_VER_MINOR 1
  375. #define PHYSFS_VER_PATCH 1
  376. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  377. /* PhysicsFS state stuff ... */
  378. /**
  379. * \def PHYSFS_VERSION(x)
  380. * \brief Macro to determine PhysicsFS version program was compiled against.
  381. *
  382. * This macro fills in a PHYSFS_Version structure with the version of the
  383. * library you compiled against. This is determined by what header the
  384. * compiler uses. Note that if you dynamically linked the library, you might
  385. * have a slightly newer or older version at runtime. That version can be
  386. * determined with PHYSFS_getLinkedVersion(), which, unlike PHYSFS_VERSION,
  387. * is not a macro.
  388. *
  389. * \param x A pointer to a PHYSFS_Version struct to initialize.
  390. *
  391. * \sa PHYSFS_Version
  392. * \sa PHYSFS_getLinkedVersion
  393. */
  394. #define PHYSFS_VERSION(x) \
  395. { \
  396. (x)->major = PHYSFS_VER_MAJOR; \
  397. (x)->minor = PHYSFS_VER_MINOR; \
  398. (x)->patch = PHYSFS_VER_PATCH; \
  399. }
  400. /**
  401. * \fn void PHYSFS_getLinkedVersion(PHYSFS_Version *ver)
  402. * \brief Get the version of PhysicsFS that is linked against your program.
  403. *
  404. * If you are using a shared library (DLL) version of PhysFS, then it is
  405. * possible that it will be different than the version you compiled against.
  406. *
  407. * This is a real function; the macro PHYSFS_VERSION tells you what version
  408. * of PhysFS you compiled against:
  409. *
  410. * \code
  411. * PHYSFS_Version compiled;
  412. * PHYSFS_Version linked;
  413. *
  414. * PHYSFS_VERSION(&compiled);
  415. * PHYSFS_getLinkedVersion(&linked);
  416. * printf("We compiled against PhysFS version %d.%d.%d ...\n",
  417. * compiled.major, compiled.minor, compiled.patch);
  418. * printf("But we linked against PhysFS version %d.%d.%d.\n",
  419. * linked.major, linked.minor, linked.patch);
  420. * \endcode
  421. *
  422. * This function may be called safely at any time, even before PHYSFS_init().
  423. *
  424. * \sa PHYSFS_VERSION
  425. */
  426. __EXPORT__ void PHYSFS_getLinkedVersion(PHYSFS_Version *ver);
  427. /**
  428. * \fn int PHYSFS_init(const char *argv0)
  429. * \brief Initialize the PhysicsFS library.
  430. *
  431. * This must be called before any other PhysicsFS function.
  432. *
  433. * This should be called prior to any attempts to change your process's
  434. * current working directory.
  435. *
  436. * \param argv0 the argv[0] string passed to your program's mainline.
  437. * This may be NULL on most platforms (such as ones without a
  438. * standard main() function), but you should always try to pass
  439. * something in here. Unix-like systems such as Linux _need_ to
  440. * pass argv[0] from main() in here.
  441. * \return nonzero on success, zero on error. Specifics of the error can be
  442. * gleaned from PHYSFS_getLastError().
  443. *
  444. * \sa PHYSFS_deinit
  445. * \sa PHYSFS_isInit
  446. */
  447. __EXPORT__ int PHYSFS_init(const char *argv0);
  448. /**
  449. * \fn int PHYSFS_deinit(void)
  450. * \brief Deinitialize the PhysicsFS library.
  451. *
  452. * This closes any files opened via PhysicsFS, blanks the search/write paths,
  453. * frees memory, and invalidates all of your file handles.
  454. *
  455. * Note that this call can FAIL if there's a file open for writing that
  456. * refuses to close (for example, the underlying operating system was
  457. * buffering writes to network filesystem, and the fileserver has crashed,
  458. * or a hard drive has failed, etc). It is usually best to close all write
  459. * handles yourself before calling this function, so that you can gracefully
  460. * handle a specific failure.
  461. *
  462. * Once successfully deinitialized, PHYSFS_init() can be called again to
  463. * restart the subsystem. All defaults API states are restored at this
  464. * point.
  465. *
  466. * \return nonzero on success, zero on error. Specifics of the error can be
  467. * gleaned from PHYSFS_getLastError(). If failure, state of PhysFS is
  468. * undefined, and probably badly screwed up.
  469. *
  470. * \sa PHYSFS_init
  471. * \sa PHYSFS_isInit
  472. */
  473. __EXPORT__ int PHYSFS_deinit(void);
  474. /**
  475. * \fn const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void)
  476. * \brief Get a list of supported archive types.
  477. *
  478. * Get a list of archive types supported by this implementation of PhysicFS.
  479. * These are the file formats usable for search path entries. This is for
  480. * informational purposes only. Note that the extension listed is merely
  481. * convention: if we list "ZIP", you can open a PkZip-compatible archive
  482. * with an extension of "XYZ", if you like.
  483. *
  484. * The returned value is an array of pointers to PHYSFS_ArchiveInfo structures,
  485. * with a NULL entry to signify the end of the list:
  486. *
  487. * \code
  488. * PHYSFS_ArchiveInfo **i;
  489. *
  490. * for (i = PHYSFS_supportedArchiveTypes(); *i != NULL; i++)
  491. * {
  492. * printf("Supported archive: [%s], which is [%s].\n",
  493. * i->extension, i->description);
  494. * }
  495. * \endcode
  496. *
  497. * The return values are pointers to static internal memory, and should
  498. * be considered READ ONLY, and never freed.
  499. *
  500. * \return READ ONLY Null-terminated array of READ ONLY structures.
  501. */
  502. __EXPORT__ const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
  503. /**
  504. * \fn void PHYSFS_freeList(void *listVar)
  505. * \brief Deallocate resources of lists returned by PhysicsFS.
  506. *
  507. * Certain PhysicsFS functions return lists of information that are
  508. * dynamically allocated. Use this function to free those resources.
  509. *
  510. * \param listVar List of information specified as freeable by this function.
  511. *
  512. * \sa PHYSFS_getCdRomDirs
  513. * \sa PHYSFS_enumerateFiles
  514. * \sa PHYSFS_getSearchPath
  515. */
  516. __EXPORT__ void PHYSFS_freeList(void *listVar);
  517. /**
  518. * \fn const char *PHYSFS_getLastError(void)
  519. * \brief Get human-readable error information.
  520. *
  521. * Get the last PhysicsFS error message as a human-readable, null-terminated
  522. * string. This will be NULL if there's been no error since the last call to
  523. * this function. The pointer returned by this call points to an internal
  524. * buffer. Each thread has a unique error state associated with it, but each
  525. * time a new error message is set, it will overwrite the previous one
  526. * associated with that thread. It is safe to call this function at anytime,
  527. * even before PHYSFS_init().
  528. *
  529. * It is not wise to expect a specific string of characters here, since the
  530. * error message may be localized into an unfamiliar language. These strings
  531. * are meant to be passed on directly to the user.
  532. *
  533. * \return READ ONLY string of last error message.
  534. */
  535. __EXPORT__ const char *PHYSFS_getLastError(void);
  536. /**
  537. * \fn const char *PHYSFS_getDirSeparator(void)
  538. * \brief Get platform-dependent dir separator string.
  539. *
  540. * This returns "\\\\" on win32, "/" on Unix, and ":" on MacOS. It may be more
  541. * than one character, depending on the platform, and your code should take
  542. * that into account. Note that this is only useful for setting up the
  543. * search/write paths, since access into those dirs always use '/'
  544. * (platform-independent notation) to separate directories. This is also
  545. * handy for getting platform-independent access when using stdio calls.
  546. *
  547. * \return READ ONLY null-terminated string of platform's dir separator.
  548. */
  549. __EXPORT__ const char *PHYSFS_getDirSeparator(void);
  550. /**
  551. * \fn void PHYSFS_permitSymbolicLinks(int allow)
  552. * \brief Enable or disable following of symbolic links.
  553. *
  554. * Some physical filesystems and archives contain files that are just pointers
  555. * to other files. On the physical filesystem, opening such a link will
  556. * (transparently) open the file that is pointed to.
  557. *
  558. * By default, PhysicsFS will check if a file is really a symlink during open
  559. * calls and fail if it is. Otherwise, the link could take you outside the
  560. * write and search paths, and compromise security.
  561. *
  562. * If you want to take that risk, call this function with a non-zero parameter.
  563. * Note that this is more for sandboxing a program's scripting language, in
  564. * case untrusted scripts try to compromise the system. Generally speaking,
  565. * a user could very well have a legitimate reason to set up a symlink, so
  566. * unless you feel there's a specific danger in allowing them, you should
  567. * permit them.
  568. *
  569. * Symlinks are only explicitly checked when dealing with filenames
  570. * in platform-independent notation. That is, when setting up your
  571. * search and write paths, etc, symlinks are never checked for.
  572. *
  573. * Symbolic link permission can be enabled or disabled at any time after
  574. * you've called PHYSFS_init(), and is disabled by default.
  575. *
  576. * \param allow nonzero to permit symlinks, zero to deny linking.
  577. */
  578. __EXPORT__ void PHYSFS_permitSymbolicLinks(int allow);
  579. /**
  580. * \fn char **PHYSFS_getCdRomDirs(void)
  581. * \brief Get an array of paths to available CD-ROM drives.
  582. *
  583. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  584. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  585. * accessible in the drive. So if you've got two drives (D: and E:), and only
  586. * E: has a disc in it, then that's all you get. If the user inserts a disc
  587. * in D: and you call this function again, you get both drives. If, on a
  588. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  589. * call to this function will reflect that change. Fun.
  590. *
  591. * The returned value is an array of strings, with a NULL entry to signify the
  592. * end of the list:
  593. *
  594. * \code
  595. * char **cds = PHYSFS_getCdRomDirs();
  596. * char **i;
  597. *
  598. * for (i = cds; *i != NULL; i++)
  599. * printf("cdrom dir [%s] is available.\n", *i);
  600. *
  601. * PHYSFS_freeList(cds);
  602. * \endcode
  603. *
  604. * This call may block while drives spin up. Be forewarned.
  605. *
  606. * When you are done with the returned information, you may dispose of the
  607. * resources by calling PHYSFS_freeList() with the returned pointer.
  608. *
  609. * \return Null-terminated array of null-terminated strings.
  610. *
  611. * \sa PHYSFS_getCdRomDirsCallback
  612. */
  613. __EXPORT__ char **PHYSFS_getCdRomDirs(void);
  614. /**
  615. * \fn const char *PHYSFS_getBaseDir(void)
  616. * \brief Get the path where the application resides.
  617. *
  618. * Helper function.
  619. *
  620. * Get the "base dir". This is the directory where the application was run
  621. * from, which is probably the installation directory, and may or may not
  622. * be the process's current working directory.
  623. *
  624. * You should probably use the base dir in your search path.
  625. *
  626. * \return READ ONLY string of base dir in platform-dependent notation.
  627. *
  628. * \sa PHYSFS_getUserDir
  629. */
  630. __EXPORT__ const char *PHYSFS_getBaseDir(void);
  631. /**
  632. * \fn const char *PHYSFS_getUserDir(void)
  633. * \brief Get the path where user's home directory resides.
  634. *
  635. * Helper function.
  636. *
  637. * Get the "user dir". This is meant to be a suggestion of where a specific
  638. * user of the system can store files. On Unix, this is her home directory.
  639. * On systems with no concept of multiple home directories (MacOS, win95),
  640. * this will default to something like "C:\mybasedir\users\username"
  641. * where "username" will either be the login name, or "default" if the
  642. * platform doesn't support multiple users, either.
  643. *
  644. * You should probably use the user dir as the basis for your write dir, and
  645. * also put it near the beginning of your search path.
  646. *
  647. * \return READ ONLY string of user dir in platform-dependent notation.
  648. *
  649. * \sa PHYSFS_getBaseDir
  650. */
  651. __EXPORT__ const char *PHYSFS_getUserDir(void);
  652. /**
  653. * \fn const char *PHYSFS_getWriteDir(void)
  654. * \brief Get path where PhysicsFS will allow file writing.
  655. *
  656. * Get the current write dir. The default write dir is NULL.
  657. *
  658. * \return READ ONLY string of write dir in platform-dependent notation,
  659. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  660. *
  661. * \sa PHYSFS_setWriteDir
  662. */
  663. __EXPORT__ const char *PHYSFS_getWriteDir(void);
  664. /**
  665. * \fn int PHYSFS_setWriteDir(const char *newDir)
  666. * \brief Tell PhysicsFS where it may write files.
  667. *
  668. * Set a new write dir. This will override the previous setting.
  669. *
  670. * This call will fail (and fail to change the write dir) if the current
  671. * write dir still has files open in it.
  672. *
  673. * \param newDir The new directory to be the root of the write dir,
  674. * specified in platform-dependent notation. Setting to NULL
  675. * disables the write dir, so no files can be opened for
  676. * writing via PhysicsFS.
  677. * \return non-zero on success, zero on failure. All attempts to open a file
  678. * for writing via PhysicsFS will fail until this call succeeds.
  679. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  680. *
  681. * \sa PHYSFS_getWriteDir
  682. */
  683. __EXPORT__ int PHYSFS_setWriteDir(const char *newDir);
  684. /**
  685. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  686. * \brief Add an archive or directory to the search path.
  687. *
  688. * This is a legacy call in PhysicsFS 2.0, equivalent to:
  689. * PHYSFS_mount(newDir, NULL, appendToPath);
  690. *
  691. * You must use this and not PHYSFS_mount if binary compatibility with
  692. * PhysicsFS 1.0 is important (which it may not be for many people).
  693. *
  694. * \sa PHYSFS_mount
  695. * \sa PHYSFS_removeFromSearchPath
  696. * \sa PHYSFS_getSearchPath
  697. */
  698. __EXPORT__ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  699. /**
  700. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  701. * \brief Remove a directory or archive from the search path.
  702. *
  703. * This must be a (case-sensitive) match to a dir or archive already in the
  704. * search path, specified in platform-dependent notation.
  705. *
  706. * This call will fail (and fail to remove from the path) if the element still
  707. * has files open in it.
  708. *
  709. * \param oldDir dir/archive to remove.
  710. * \return nonzero on success, zero on failure.
  711. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  712. *
  713. * \sa PHYSFS_addToSearchPath
  714. * \sa PHYSFS_getSearchPath
  715. */
  716. __EXPORT__ int PHYSFS_removeFromSearchPath(const char *oldDir);
  717. /**
  718. * \fn char **PHYSFS_getSearchPath(void)
  719. * \brief Get the current search path.
  720. *
  721. * The default search path is an empty list.
  722. *
  723. * The returned value is an array of strings, with a NULL entry to signify the
  724. * end of the list:
  725. *
  726. * \code
  727. * char **i;
  728. *
  729. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  730. * printf("[%s] is in the search path.\n", *i);
  731. * \endcode
  732. *
  733. * When you are done with the returned information, you may dispose of the
  734. * resources by calling PHYSFS_freeList() with the returned pointer.
  735. *
  736. * \return Null-terminated array of null-terminated strings. NULL if there
  737. * was a problem (read: OUT OF MEMORY).
  738. *
  739. * \sa PHYSFS_getSearchPathCallback
  740. * \sa PHYSFS_addToSearchPath
  741. * \sa PHYSFS_removeFromSearchPath
  742. */
  743. __EXPORT__ char **PHYSFS_getSearchPath(void);
  744. /**
  745. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  746. * \brief Set up sane, default paths.
  747. *
  748. * Helper function.
  749. *
  750. * The write dir will be set to "userdir/.organization/appName", which is
  751. * created if it doesn't exist.
  752. *
  753. * The above is sufficient to make sure your program's configuration directory
  754. * is separated from other clutter, and platform-independent. The period
  755. * before "mygame" even hides the directory on Unix systems.
  756. *
  757. * The search path will be:
  758. *
  759. * - The Write Dir (created if it doesn't exist)
  760. * - The Base Dir (PHYSFS_getBaseDir())
  761. * - All found CD-ROM dirs (optionally)
  762. *
  763. * These directories are then searched for files ending with the extension
  764. * (archiveExt), which, if they are valid and supported archives, will also
  765. * be added to the search path. If you specified "PKG" for (archiveExt), and
  766. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  767. * can either be appended or prepended to the search path in alphabetical
  768. * order, regardless of which directories they were found in.
  769. *
  770. * All of this can be accomplished from the application, but this just does it
  771. * all for you. Feel free to add more to the search path manually, too.
  772. *
  773. * \param organization Name of your company/group/etc to be used as a
  774. * dirname, so keep it small, and no-frills.
  775. *
  776. * \param appName Program-specific name of your program, to separate it
  777. * from other programs using PhysicsFS.
  778. *
  779. * \param archiveExt File extension used by your program to specify an
  780. * archive. For example, Quake 3 uses "pk3", even though
  781. * they are just zipfiles. Specify NULL to not dig out
  782. * archives automatically. Do not specify the '.' char;
  783. * If you want to look for ZIP files, specify "ZIP" and
  784. * not ".ZIP" ... the archive search is case-insensitive.
  785. *
  786. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  787. * (if (archiveExt) != NULL) search them for archives.
  788. * This may cause a significant amount of blocking
  789. * while discs are accessed, and if there are no discs
  790. * in the drive (or even not mounted on Unix systems),
  791. * then they may not be made available anyhow. You may
  792. * want to specify zero and handle the disc setup
  793. * yourself.
  794. *
  795. * \param archivesFirst Non-zero to prepend the archives to the search path.
  796. * Zero to append them. Ignored if !(archiveExt).
  797. *
  798. * \return nonzero on success, zero on error. Specifics of the error can be
  799. * gleaned from PHYSFS_getLastError().
  800. */
  801. __EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
  802. const char *appName,
  803. const char *archiveExt,
  804. int includeCdRoms,
  805. int archivesFirst);
  806. /* Directory management stuff ... */
  807. /**
  808. * \fn int PHYSFS_mkdir(const char *dirName)
  809. * \brief Create a directory.
  810. *
  811. * This is specified in platform-independent notation in relation to the
  812. * write dir. All missing parent directories are also created if they
  813. * don't exist.
  814. *
  815. * So if you've got the write dir set to "C:\mygame\writedir" and call
  816. * PHYSFS_mkdir("downloads/maps") then the directories
  817. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  818. * will be created if possible. If the creation of "maps" fails after we
  819. * have successfully created "downloads", then the function leaves the
  820. * created directory behind and reports failure.
  821. *
  822. * \param dirName New dir to create.
  823. * \return nonzero on success, zero on error. Specifics of the error can be
  824. * gleaned from PHYSFS_getLastError().
  825. *
  826. * \sa PHYSFS_delete
  827. */
  828. __EXPORT__ int PHYSFS_mkdir(const char *dirName);
  829. /**
  830. * \fn int PHYSFS_delete(const char *filename)
  831. * \brief Delete a file or directory.
  832. *
  833. * (filename) is specified in platform-independent notation in relation to the
  834. * write dir.
  835. *
  836. * A directory must be empty before this call can delete it.
  837. *
  838. * Deleting a symlink will remove the link, not what it points to, regardless
  839. * of whether you "permitSymLinks" or not.
  840. *
  841. * So if you've got the write dir set to "C:\mygame\writedir" and call
  842. * PHYSFS_delete("downloads/maps/level1.map") then the file
  843. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  844. * physical filesystem, if it exists and the operating system permits the
  845. * deletion.
  846. *
  847. * Note that on Unix systems, deleting a file may be successful, but the
  848. * actual file won't be removed until all processes that have an open
  849. * filehandle to it (including your program) close their handles.
  850. *
  851. * Chances are, the bits that make up the file still exist, they are just
  852. * made available to be written over at a later point. Don't consider this
  853. * a security method or anything. :)
  854. *
  855. * \param filename Filename to delete.
  856. * \return nonzero on success, zero on error. Specifics of the error can be
  857. * gleaned from PHYSFS_getLastError().
  858. */
  859. __EXPORT__ int PHYSFS_delete(const char *filename);
  860. /**
  861. * \fn const char *PHYSFS_getRealDir(const char *filename)
  862. * \brief Figure out where in the search path a file resides.
  863. *
  864. * The file is specified in platform-independent notation. The returned
  865. * filename will be the element of the search path where the file was found,
  866. * which may be a directory, or an archive. Even if there are multiple
  867. * matches in different parts of the search path, only the first one found
  868. * is used, just like when opening a file.
  869. *
  870. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  871. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  872. *
  873. * If a any part of a match is a symbolic link, and you've not explicitly
  874. * permitted symlinks, then it will be ignored, and the search for a match
  875. * will continue.
  876. *
  877. * If you specify a fake directory that only exists as a mount point, it'll
  878. * be associated with the first archive mounted there, even though that
  879. * directory isn't necessarily contained in a real archive.
  880. *
  881. * \param filename file to look for.
  882. * \return READ ONLY string of element of search path containing the
  883. * the file in question. NULL if not found.
  884. */
  885. __EXPORT__ const char *PHYSFS_getRealDir(const char *filename);
  886. /**
  887. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  888. * \brief Get a file listing of a search path's directory.
  889. *
  890. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  891. * search path and contains a directory "savegames" that contains "x.sav",
  892. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  893. * that has a "savegames" subdirectory with "w.sav", then the following code:
  894. *
  895. * \code
  896. * char **rc = PHYSFS_enumerateFiles("savegames");
  897. * char **i;
  898. *
  899. * for (i = rc; *i != NULL; i++)
  900. * printf(" * We've got [%s].\n", *i);
  901. *
  902. * PHYSFS_freeList(rc);
  903. * \endcode
  904. *
  905. * ...will print:
  906. *
  907. * \verbatim
  908. * We've got [x.sav].
  909. * We've got [y.sav].
  910. * We've got [z.sav].
  911. * We've got [w.sav].\endverbatim
  912. *
  913. * Feel free to sort the list however you like. We only promise there will
  914. * be no duplicates, but not what order the final list will come back in.
  915. *
  916. * Don't forget to call PHYSFS_freeList() with the return value from this
  917. * function when you are done with it.
  918. *
  919. * \param dir directory in platform-independent notation to enumerate.
  920. * \return Null-terminated array of null-terminated strings.
  921. *
  922. * \sa PHYSFS_enumerateFilesCallback
  923. */
  924. __EXPORT__ char **PHYSFS_enumerateFiles(const char *dir);
  925. /**
  926. * \fn int PHYSFS_exists(const char *fname)
  927. * \brief Determine if a file exists in the search path.
  928. *
  929. * Reports true if there is an entry anywhere in the search path by the
  930. * name of (fname).
  931. *
  932. * Note that entries that are symlinks are ignored if
  933. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  934. * might end up further down in the search path than expected.
  935. *
  936. * \param fname filename in platform-independent notation.
  937. * \return non-zero if filename exists. zero otherwise.
  938. *
  939. * \sa PHYSFS_isDirectory
  940. * \sa PHYSFS_isSymbolicLink
  941. */
  942. __EXPORT__ int PHYSFS_exists(const char *fname);
  943. /**
  944. * \fn int PHYSFS_isDirectory(const char *fname)
  945. * \brief Determine if a file in the search path is really a directory.
  946. *
  947. * Determine if the first occurence of (fname) in the search path is
  948. * really a directory entry.
  949. *
  950. * Note that entries that are symlinks are ignored if
  951. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  952. * might end up further down in the search path than expected.
  953. *
  954. * \param fname filename in platform-independent notation.
  955. * \return non-zero if filename exists and is a directory. zero otherwise.
  956. *
  957. * \sa PHYSFS_exists
  958. * \sa PHYSFS_isSymbolicLink
  959. */
  960. __EXPORT__ int PHYSFS_isDirectory(const char *fname);
  961. /**
  962. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  963. * \brief Determine if a file in the search path is really a symbolic link.
  964. *
  965. * Determine if the first occurence of (fname) in the search path is
  966. * really a symbolic link.
  967. *
  968. * Note that entries that are symlinks are ignored if
  969. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  970. * this function will always return 0 in that case.
  971. *
  972. * \param fname filename in platform-independent notation.
  973. * \return non-zero if filename exists and is a symlink. zero otherwise.
  974. *
  975. * \sa PHYSFS_exists
  976. * \sa PHYSFS_isDirectory
  977. */
  978. __EXPORT__ int PHYSFS_isSymbolicLink(const char *fname);
  979. /**
  980. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  981. * \brief Get the last modification time of a file.
  982. *
  983. * The modtime is returned as a number of seconds since the epoch
  984. * (Jan 1, 1970). The exact derivation and accuracy of this time depends on
  985. * the particular archiver. If there is no reasonable way to obtain this
  986. * information for a particular archiver, or there was some sort of error,
  987. * this function returns (-1).
  988. *
  989. * \param filename filename to check, in platform-independent notation.
  990. * \return last modified time of the file. -1 if it can't be determined.
  991. */
  992. __EXPORT__ PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename);
  993. /* i/o stuff... */
  994. /**
  995. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  996. * \brief Open a file for writing.
  997. *
  998. * Open a file for writing, in platform-independent notation and in relation
  999. * to the write dir as the root of the writable filesystem. The specified
  1000. * file is created if it doesn't exist. If it does exist, it is truncated to
  1001. * zero bytes, and the writing offset is set to the start.
  1002. *
  1003. * Note that entries that are symlinks are ignored if
  1004. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1005. * symlink with this function will fail in such a case.
  1006. *
  1007. * \param filename File to open.
  1008. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1009. * of the error can be gleaned from PHYSFS_getLastError().
  1010. *
  1011. * \sa PHYSFS_openRead
  1012. * \sa PHYSFS_openAppend
  1013. * \sa PHYSFS_write
  1014. * \sa PHYSFS_close
  1015. */
  1016. __EXPORT__ PHYSFS_File *PHYSFS_openWrite(const char *filename);
  1017. /**
  1018. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  1019. * \brief Open a file for appending.
  1020. *
  1021. * Open a file for writing, in platform-independent notation and in relation
  1022. * to the write dir as the root of the writable filesystem. The specified
  1023. * file is created if it doesn't exist. If it does exist, the writing offset
  1024. * is set to the end of the file, so the first write will be the byte after
  1025. * the end.
  1026. *
  1027. * Note that entries that are symlinks are ignored if
  1028. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1029. * symlink with this function will fail in such a case.
  1030. *
  1031. * \param filename File to open.
  1032. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1033. * of the error can be gleaned from PHYSFS_getLastError().
  1034. *
  1035. * \sa PHYSFS_openRead
  1036. * \sa PHYSFS_openWrite
  1037. * \sa PHYSFS_write
  1038. * \sa PHYSFS_close
  1039. */
  1040. __EXPORT__ PHYSFS_File *PHYSFS_openAppend(const char *filename);
  1041. /**
  1042. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  1043. * \brief Open a file for reading.
  1044. *
  1045. * Open a file for reading, in platform-independent notation. The search path
  1046. * is checked one at a time until a matching file is found, in which case an
  1047. * abstract filehandle is associated with it, and reading may be done.
  1048. * The reading offset is set to the first byte of the file.
  1049. *
  1050. * Note that entries that are symlinks are ignored if
  1051. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1052. * symlink with this function will fail in such a case.
  1053. *
  1054. * \param filename File to open.
  1055. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1056. * of the error can be gleaned from PHYSFS_getLastError().
  1057. *
  1058. * \sa PHYSFS_openWrite
  1059. * \sa PHYSFS_openAppend
  1060. * \sa PHYSFS_read
  1061. * \sa PHYSFS_close
  1062. */
  1063. __EXPORT__ PHYSFS_File *PHYSFS_openRead(const char *filename);
  1064. /**
  1065. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1066. * \brief Close a PhysicsFS filehandle.
  1067. *
  1068. * This call is capable of failing if the operating system was buffering
  1069. * writes to the physical media, and, now forced to write those changes to
  1070. * physical media, can not store the data for some reason. In such a case,
  1071. * the filehandle stays open. A well-written program should ALWAYS check the
  1072. * return value from the close call in addition to every writing call!
  1073. *
  1074. * \param handle handle returned from PHYSFS_open*().
  1075. * \return nonzero on success, zero on error. Specifics of the error can be
  1076. * gleaned from PHYSFS_getLastError().
  1077. *
  1078. * \sa PHYSFS_openRead
  1079. * \sa PHYSFS_openWrite
  1080. * \sa PHYSFS_openAppend
  1081. */
  1082. __EXPORT__ int PHYSFS_close(PHYSFS_File *handle);
  1083. /**
  1084. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1085. * \brief Read data from a PhysicsFS filehandle
  1086. *
  1087. * The file must be opened for reading.
  1088. *
  1089. * \param handle handle returned from PHYSFS_openRead().
  1090. * \param buffer buffer to store read data into.
  1091. * \param objSize size in bytes of objects being read from (handle).
  1092. * \param objCount number of (objSize) objects to read from (handle).
  1093. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1094. * the reason this might be < (objCount), as can PHYSFS_eof().
  1095. * -1 if complete failure.
  1096. *
  1097. * \sa PHYSFS_eof
  1098. */
  1099. __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1100. void *buffer,
  1101. PHYSFS_uint32 objSize,
  1102. PHYSFS_uint32 objCount);
  1103. /**
  1104. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1105. * \brief Write data to a PhysicsFS filehandle
  1106. *
  1107. * The file must be opened for writing.
  1108. *
  1109. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1110. * \param buffer buffer to store read data into.
  1111. * \param objSize size in bytes of objects being read from (handle).
  1112. * \param objCount number of (objSize) objects to read from (handle).
  1113. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1114. * the reason this might be < (objCount). -1 if complete failure.
  1115. */
  1116. __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1117. const void *buffer,
  1118. PHYSFS_uint32 objSize,
  1119. PHYSFS_uint32 objCount);
  1120. /* File position stuff... */
  1121. /**
  1122. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1123. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1124. *
  1125. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1126. *
  1127. * \param handle handle returned from PHYSFS_openRead().
  1128. * \return nonzero if EOF, zero if not.
  1129. *
  1130. * \sa PHYSFS_read
  1131. * \sa PHYSFS_tell
  1132. */
  1133. __EXPORT__ int PHYSFS_eof(PHYSFS_File *handle);
  1134. /**
  1135. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1136. * \brief Determine current position within a PhysicsFS filehandle.
  1137. *
  1138. * \param handle handle returned from PHYSFS_open*().
  1139. * \return offset in bytes from start of file. -1 if error occurred.
  1140. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1141. *
  1142. * \sa PHYSFS_seek
  1143. */
  1144. __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1145. /**
  1146. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1147. * \brief Seek to a new position within a PhysicsFS filehandle.
  1148. *
  1149. * The next read or write will occur at that place. Seeking past the
  1150. * beginning or end of the file is not allowed, and causes an error.
  1151. *
  1152. * \param handle handle returned from PHYSFS_open*().
  1153. * \param pos number of bytes from start of file to seek to.
  1154. * \return nonzero on success, zero on error. Specifics of the error can be
  1155. * gleaned from PHYSFS_getLastError().
  1156. *
  1157. * \sa PHYSFS_tell
  1158. */
  1159. __EXPORT__ int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1160. /**
  1161. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1162. * \brief Get total length of a file in bytes.
  1163. *
  1164. * Note that if the file size can't be determined (since the archive is
  1165. * "streamed" or whatnot) than this will report (-1). Also note that if
  1166. * another process/thread is writing to this file at the same time, then
  1167. * the information this function supplies could be incorrect before you
  1168. * get it. Use with caution, or better yet, don't use at all.
  1169. *
  1170. * \param handle handle returned from PHYSFS_open*().
  1171. * \return size in bytes of the file. -1 if can't be determined.
  1172. *
  1173. * \sa PHYSFS_tell
  1174. * \sa PHYSFS_seek
  1175. */
  1176. __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1177. /* Buffering stuff... */
  1178. /**
  1179. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1180. * \brief Set up buffering for a PhysicsFS file handle.
  1181. *
  1182. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1183. * will be allocated and associated with (handle).
  1184. *
  1185. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1186. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1187. * from this buffer until it is empty, and then refill it for more reading.
  1188. * Note that compressed files, like ZIP archives, will decompress while
  1189. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1190. * The buffer isn't filled until you do your next read.
  1191. *
  1192. * For files opened for writing, data will be buffered to memory until the
  1193. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1194. * causes a flush...check your return values!
  1195. *
  1196. * Seeking, etc transparently accounts for buffering.
  1197. *
  1198. * You can resize an existing buffer by calling this function more than once
  1199. * on the same file. Setting the buffer size to zero will free an existing
  1200. * buffer.
  1201. *
  1202. * PhysicsFS file handles are unbuffered by default.
  1203. *
  1204. * Please check the return value of this function! Failures can include
  1205. * not being able to seek backwards in a read-only file when removing the
  1206. * buffer, not being able to allocate the buffer, and not being able to
  1207. * flush the buffer to disk, among other unexpected problems.
  1208. *
  1209. * \param handle handle returned from PHYSFS_open*().
  1210. * \param bufsize size, in bytes, of buffer to allocate.
  1211. * \return nonzero if successful, zero on error.
  1212. *
  1213. * \sa PHYSFS_flush
  1214. * \sa PHYSFS_read
  1215. * \sa PHYSFS_write
  1216. * \sa PHYSFS_close
  1217. */
  1218. __EXPORT__ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1219. /**
  1220. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1221. * \brief Flush a buffered PhysicsFS file handle.
  1222. *
  1223. * For buffered files opened for writing, this will put the current contents
  1224. * of the buffer to disk and flag the buffer as empty if possible.
  1225. *
  1226. * For buffered files opened for reading or unbuffered files, this is a safe
  1227. * no-op, and will report success.
  1228. *
  1229. * \param handle handle returned from PHYSFS_open*().
  1230. * \return nonzero if successful, zero on error.
  1231. *
  1232. * \sa PHYSFS_setBuffer
  1233. * \sa PHYSFS_close
  1234. */
  1235. __EXPORT__ int PHYSFS_flush(PHYSFS_File *handle);
  1236. /* Byteorder stuff... */
  1237. /**
  1238. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1239. * \brief Swap littleendian signed 16 to platform's native byte order.
  1240. *
  1241. * Take a 16-bit signed value in littleendian format and convert it to
  1242. * the platform's native byte order.
  1243. *
  1244. * \param val value to convert
  1245. * \return converted value.
  1246. */
  1247. __EXPORT__ PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1248. /**
  1249. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1250. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1251. *
  1252. * Take a 16-bit unsigned value in littleendian format and convert it to
  1253. * the platform's native byte order.
  1254. *
  1255. * \param val value to convert
  1256. * \return converted value.
  1257. */
  1258. __EXPORT__ PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1259. /**
  1260. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1261. * \brief Swap littleendian signed 32 to platform's native byte order.
  1262. *
  1263. * Take a 32-bit signed value in littleendian format and convert it to
  1264. * the platform's native byte order.
  1265. *
  1266. * \param val value to convert
  1267. * \return converted value.
  1268. */
  1269. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1270. /**
  1271. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1272. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1273. *
  1274. * Take a 32-bit unsigned value in littleendian format and convert it to
  1275. * the platform's native byte order.
  1276. *
  1277. * \param val value to convert
  1278. * \return converted value.
  1279. */
  1280. __EXPORT__ PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1281. /**
  1282. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1283. * \brief Swap littleendian signed 64 to platform's native byte order.
  1284. *
  1285. * Take a 64-bit signed value in littleendian format and convert it to
  1286. * the platform's native byte order.
  1287. *
  1288. * \param val value to convert
  1289. * \return converted value.
  1290. *
  1291. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1292. * any sort of 64-bit support.
  1293. */
  1294. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1295. /**
  1296. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1297. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1298. *
  1299. * Take a 64-bit unsigned value in littleendian format and convert it to
  1300. * the platform's native byte order.
  1301. *
  1302. * \param val value to convert
  1303. * \return converted value.
  1304. *
  1305. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1306. * any sort of 64-bit support.
  1307. */
  1308. __EXPORT__ PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1309. /**
  1310. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1311. * \brief Swap bigendian signed 16 to platform's native byte order.
  1312. *
  1313. * Take a 16-bit signed value in bigendian format and convert it to
  1314. * the platform's native byte order.
  1315. *
  1316. * \param val value to convert
  1317. * \return converted value.
  1318. */
  1319. __EXPORT__ PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1320. /**
  1321. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1322. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1323. *
  1324. * Take a 16-bit unsigned value in bigendian format and convert it to
  1325. * the platform's native byte order.
  1326. *
  1327. * \param val value to convert
  1328. * \return converted value.
  1329. */
  1330. __EXPORT__ PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1331. /**
  1332. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1333. * \brief Swap bigendian signed 32 to platform's native byte order.
  1334. *
  1335. * Take a 32-bit signed value in bigendian format and convert it to
  1336. * the platform's native byte order.
  1337. *
  1338. * \param val value to convert
  1339. * \return converted value.
  1340. */
  1341. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1342. /**
  1343. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1344. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1345. *
  1346. * Take a 32-bit unsigned value in bigendian format and convert it to
  1347. * the platform's native byte order.
  1348. *
  1349. * \param val value to convert
  1350. * \return converted value.
  1351. */
  1352. __EXPORT__ PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1353. /**
  1354. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1355. * \brief Swap bigendian signed 64 to platform's native byte order.
  1356. *
  1357. * Take a 64-bit signed value in bigendian format and convert it to
  1358. * the platform's native byte order.
  1359. *
  1360. * \param val value to convert
  1361. * \return converted value.
  1362. *
  1363. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1364. * any sort of 64-bit support.
  1365. */
  1366. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1367. /**
  1368. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1369. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1370. *
  1371. * Take a 64-bit unsigned value in bigendian format and convert it to
  1372. * the platform's native byte order.
  1373. *
  1374. * \param val value to convert
  1375. * \return converted value.
  1376. *
  1377. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1378. * any sort of 64-bit support.
  1379. */
  1380. __EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1381. /**
  1382. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1383. * \brief Read and convert a signed 16-bit littleendian value.
  1384. *
  1385. * Convenience function. Read a signed 16-bit littleendian value from a
  1386. * file and convert it to the platform's native byte order.
  1387. *
  1388. * \param file PhysicsFS file handle from which to read.
  1389. * \param val pointer to where value should be stored.
  1390. * \return zero on failure, non-zero on success. If successful, (*val) will
  1391. * store the result. On failure, you can find out what went wrong
  1392. * from PHYSFS_getLastError().
  1393. */
  1394. __EXPORT__ int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1395. /**
  1396. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1397. * \brief Read and convert an unsigned 16-bit littleendian value.
  1398. *
  1399. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1400. * file and convert it to the platform's native byte order.
  1401. *
  1402. * \param file PhysicsFS file handle from which to read.
  1403. * \param val pointer to where value should be stored.
  1404. * \return zero on failure, non-zero on success. If successful, (*val) will
  1405. * store the result. On failure, you can find out what went wrong
  1406. * from PHYSFS_getLastError().
  1407. *
  1408. */
  1409. __EXPORT__ int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1410. /**
  1411. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1412. * \brief Read and convert a signed 16-bit bigendian value.
  1413. *
  1414. * Convenience function. Read a signed 16-bit bigendian value from a
  1415. * file and convert it to the platform's native byte order.
  1416. *
  1417. * \param file PhysicsFS file handle from which to read.
  1418. * \param val pointer to where value should be stored.
  1419. * \return zero on failure, non-zero on success. If successful, (*val) will
  1420. * store the result. On failure, you can find out what went wrong
  1421. * from PHYSFS_getLastError().
  1422. */
  1423. __EXPORT__ int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1424. /**
  1425. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1426. * \brief Read and convert an unsigned 16-bit bigendian value.
  1427. *
  1428. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1429. * file and convert it to the platform's native byte order.
  1430. *
  1431. * \param file PhysicsFS file handle from which to read.
  1432. * \param val pointer to where value should be stored.
  1433. * \return zero on failure, non-zero on success. If successful, (*val) will
  1434. * store the result. On failure, you can find out what went wrong
  1435. * from PHYSFS_getLastError().
  1436. *
  1437. */
  1438. __EXPORT__ int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1439. /**
  1440. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1441. * \brief Read and convert a signed 32-bit littleendian value.
  1442. *
  1443. * Convenience function. Read a signed 32-bit littleendian value from a
  1444. * file and convert it to the platform's native byte order.
  1445. *
  1446. * \param file PhysicsFS file handle from which to read.
  1447. * \param val pointer to where value should be stored.
  1448. * \return zero on failure, non-zero on success. If successful, (*val) will
  1449. * store the result. On failure, you can find out what went wrong
  1450. * from PHYSFS_getLastError().
  1451. */
  1452. __EXPORT__ int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1453. /**
  1454. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1455. * \brief Read and convert an unsigned 32-bit littleendian value.
  1456. *
  1457. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1458. * file and convert it to the platform's native byte order.
  1459. *
  1460. * \param file PhysicsFS file handle from which to read.
  1461. * \param val pointer to where value should be stored.
  1462. * \return zero on failure, non-zero on success. If successful, (*val) will
  1463. * store the result. On failure, you can find out what went wrong
  1464. * from PHYSFS_getLastError().
  1465. *
  1466. */
  1467. __EXPORT__ int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1468. /**
  1469. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1470. * \brief Read and convert a signed 32-bit bigendian value.
  1471. *
  1472. * Convenience function. Read a signed 32-bit bigendian value from a
  1473. * file and convert it to the platform's native byte order.
  1474. *
  1475. * \param file PhysicsFS file handle from which to read.
  1476. * \param val pointer to where value should be stored.
  1477. * \return zero on failure, non-zero on success. If successful, (*val) will
  1478. * store the result. On failure, you can find out what went wrong
  1479. * from PHYSFS_getLastError().
  1480. */
  1481. __EXPORT__ int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1482. /**
  1483. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1484. * \brief Read and convert an unsigned 32-bit bigendian value.
  1485. *
  1486. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1487. * file and convert it to the platform's native byte order.
  1488. *
  1489. * \param file PhysicsFS file handle from which to read.
  1490. * \param val pointer to where value should be stored.
  1491. * \return zero on failure, non-zero on success. If successful, (*val) will
  1492. * store the result. On failure, you can find out what went wrong
  1493. * from PHYSFS_getLastError().
  1494. *
  1495. */
  1496. __EXPORT__ int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1497. /**
  1498. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1499. * \brief Read and convert a signed 64-bit littleendian value.
  1500. *
  1501. * Convenience function. Read a signed 64-bit littleendian value from a
  1502. * file and convert it to the platform's native byte order.
  1503. *
  1504. * \param file PhysicsFS file handle from which to read.
  1505. * \param val pointer to where value should be stored.
  1506. * \return zero on failure, non-zero on success. If successful, (*val) will
  1507. * store the result. On failure, you can find out what went wrong
  1508. * from PHYSFS_getLastError().
  1509. *
  1510. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1511. * any sort of 64-bit support.
  1512. */
  1513. __EXPORT__ int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1514. /**
  1515. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1516. * \brief Read and convert an unsigned 64-bit littleendian value.
  1517. *
  1518. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1519. * file and convert it to the platform's native byte order.
  1520. *
  1521. * \param file PhysicsFS file handle from which to read.
  1522. * \param val pointer to where value should be stored.
  1523. * \return zero on failure, non-zero on success. If successful, (*val) will
  1524. * store the result. On failure, you can find out what went wrong
  1525. * from PHYSFS_getLastError().
  1526. *
  1527. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1528. * any sort of 64-bit support.
  1529. */
  1530. __EXPORT__ int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1531. /**
  1532. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1533. * \brief Read and convert a signed 64-bit bigendian value.
  1534. *
  1535. * Convenience function. Read a signed 64-bit bigendian value from a
  1536. * file and convert it to the platform's native byte order.
  1537. *
  1538. * \param file PhysicsFS file handle from which to read.
  1539. * \param val pointer to where value should be stored.
  1540. * \return zero on failure, non-zero on success. If successful, (*val) will
  1541. * store the result. On failure, you can find out what went wrong
  1542. * from PHYSFS_getLastError().
  1543. *
  1544. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1545. * any sort of 64-bit support.
  1546. */
  1547. __EXPORT__ int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1548. /**
  1549. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1550. * \brief Read and convert an unsigned 64-bit bigendian value.
  1551. *
  1552. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1553. * file and convert it to the platform's native byte order.
  1554. *
  1555. * \param file PhysicsFS file handle from which to read.
  1556. * \param val pointer to where value should be stored.
  1557. * \return zero on failure, non-zero on success. If successful, (*val) will
  1558. * store the result. On failure, you can find out what went wrong
  1559. * from PHYSFS_getLastError().
  1560. *
  1561. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1562. * any sort of 64-bit support.
  1563. */
  1564. __EXPORT__ int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1565. /**
  1566. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1567. * \brief Convert and write a signed 16-bit littleendian value.
  1568. *
  1569. * Convenience function. Convert a signed 16-bit value from the platform's
  1570. * native byte order to littleendian and write it to a file.
  1571. *
  1572. * \param file PhysicsFS file handle to which to write.
  1573. * \param val Value to convert and write.
  1574. * \return zero on failure, non-zero on success. On failure, you can
  1575. * find out what went wrong from PHYSFS_getLastError().
  1576. */
  1577. __EXPORT__ int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1578. /**
  1579. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1580. * \brief Convert and write an unsigned 16-bit littleendian value.
  1581. *
  1582. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1583. * native byte order to littleendian and write it to a file.
  1584. *
  1585. * \param file PhysicsFS file handle to which to write.
  1586. * \param val Value to convert and write.
  1587. * \return zero on failure, non-zero on success. On failure, you can
  1588. * find out what went wrong from PHYSFS_getLastError().
  1589. */
  1590. __EXPORT__ int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1591. /**
  1592. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1593. * \brief Convert and write a signed 16-bit bigendian value.
  1594. *
  1595. * Convenience function. Convert a signed 16-bit value from the platform's
  1596. * native byte order to bigendian and write it to a file.
  1597. *
  1598. * \param file PhysicsFS file handle to which to write.
  1599. * \param val Value to convert and write.
  1600. * \return zero on failure, non-zero on success. On failure, you can
  1601. * find out what went wrong from PHYSFS_getLastError().
  1602. */
  1603. __EXPORT__ int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1604. /**
  1605. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1606. * \brief Convert and write an unsigned 16-bit bigendian value.
  1607. *
  1608. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1609. * native byte order to bigendian and write it to a file.
  1610. *
  1611. * \param file PhysicsFS file handle to which to write.
  1612. * \param val Value to convert and write.
  1613. * \return zero on failure, non-zero on success. On failure, you can
  1614. * find out what went wrong from PHYSFS_getLastError().
  1615. */
  1616. __EXPORT__ int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1617. /**
  1618. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1619. * \brief Convert and write a signed 32-bit littleendian value.
  1620. *
  1621. * Convenience function. Convert a signed 32-bit value from the platform's
  1622. * native byte order to littleendian and write it to a file.
  1623. *
  1624. * \param file PhysicsFS file handle to which to write.
  1625. * \param val Value to convert and write.
  1626. * \return zero on failure, non-zero on success. On failure, you can
  1627. * find out what went wrong from PHYSFS_getLastError().
  1628. */
  1629. __EXPORT__ int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1630. /**
  1631. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1632. * \brief Convert and write an unsigned 32-bit littleendian value.
  1633. *
  1634. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1635. * native byte order to littleendian and write it to a file.
  1636. *
  1637. * \param file PhysicsFS file handle to which to write.
  1638. * \param val Value to convert and write.
  1639. * \return zero on failure, non-zero on success. On failure, you can
  1640. * find out what went wrong from PHYSFS_getLastError().
  1641. */
  1642. __EXPORT__ int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1643. /**
  1644. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1645. * \brief Convert and write a signed 32-bit bigendian value.
  1646. *
  1647. * Convenience function. Convert a signed 32-bit value from the platform's
  1648. * native byte order to bigendian and write it to a file.
  1649. *
  1650. * \param file PhysicsFS file handle to which to write.
  1651. * \param val Value to convert and write.
  1652. * \return zero on failure, non-zero on success. On failure, you can
  1653. * find out what went wrong from PHYSFS_getLastError().
  1654. */
  1655. __EXPORT__ int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1656. /**
  1657. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1658. * \brief Convert and write an unsigned 32-bit bigendian value.
  1659. *
  1660. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1661. * native byte order to bigendian and write it to a file.
  1662. *
  1663. * \param file PhysicsFS file handle to which to write.
  1664. * \param val Value to convert and write.
  1665. * \return zero on failure, non-zero on success. On failure, you can
  1666. * find out what went wrong from PHYSFS_getLastError().
  1667. */
  1668. __EXPORT__ int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1669. /**
  1670. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1671. * \brief Convert and write a signed 64-bit littleendian value.
  1672. *
  1673. * Convenience function. Convert a signed 64-bit value from the platform's
  1674. * native byte order to littleendian and write it to a file.
  1675. *
  1676. * \param file PhysicsFS file handle to which to write.
  1677. * \param val Value to convert and write.
  1678. * \return zero on failure, non-zero on success. On failure, you can
  1679. * find out what went wrong from PHYSFS_getLastError().
  1680. *
  1681. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1682. * any sort of 64-bit support.
  1683. */
  1684. __EXPORT__ int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1685. /**
  1686. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1687. * \brief Convert and write an unsigned 64-bit littleendian value.
  1688. *
  1689. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1690. * native byte order to littleendian and write it to a file.
  1691. *
  1692. * \param file PhysicsFS file handle to which to write.
  1693. * \param val Value to convert and write.
  1694. * \return zero on failure, non-zero on success. On failure, you can
  1695. * find out what went wrong from PHYSFS_getLastError().
  1696. *
  1697. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1698. * any sort of 64-bit support.
  1699. */
  1700. __EXPORT__ int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1701. /**
  1702. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1703. * \brief Convert and write a signed 64-bit bigending value.
  1704. *
  1705. * Convenience function. Convert a signed 64-bit value from the platform's
  1706. * native byte order to bigendian and write it to a file.
  1707. *
  1708. * \param file PhysicsFS file handle to which to write.
  1709. * \param val Value to convert and write.
  1710. * \return zero on failure, non-zero on success. On failure, you can
  1711. * find out what went wrong from PHYSFS_getLastError().
  1712. *
  1713. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1714. * any sort of 64-bit support.
  1715. */
  1716. __EXPORT__ int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1717. /**
  1718. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1719. * \brief Convert and write an unsigned 64-bit bigendian value.
  1720. *
  1721. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1722. * native byte order to bigendian and write it to a file.
  1723. *
  1724. * \param file PhysicsFS file handle to which to write.
  1725. * \param val Value to convert and write.
  1726. * \return zero on failure, non-zero on success. On failure, you can
  1727. * find out what went wrong from PHYSFS_getLastError().
  1728. *
  1729. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1730. * any sort of 64-bit support.
  1731. */
  1732. __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1733. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1734. /**
  1735. * \fn int PHYSFS_isInit(void)
  1736. * \brief Determine if the PhysicsFS library is initialized.
  1737. *
  1738. * Once PHYSFS_init() returns successfully, this will return non-zero.
  1739. * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns
  1740. * successfully, this will return zero. This function is safe to call at
  1741. * any time.
  1742. *
  1743. * \return non-zero if library is initialized, zero if library is not.
  1744. *
  1745. * \sa PHYSFS_init
  1746. * \sa PHYSFS_deinit
  1747. */
  1748. __EXPORT__ int PHYSFS_isInit(void);
  1749. /**
  1750. * \struct PHYSFS_Allocator
  1751. * \brief PhysicsFS allocation function pointers.
  1752. *
  1753. * (This is for limited, hardcore use. If you don't immediately see a need
  1754. * for it, you can probably ignore this forever.)
  1755. *
  1756. * You create one of these structures for use with PHYSFS_setAllocator.
  1757. * Allocators are assumed to be reentrant by the caller; please mutex
  1758. * accordingly.
  1759. *
  1760. * Allocations are always discussed in 64-bits, for future expansion...we're
  1761. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1762. * gigabytes like it's nothing sooner or later, and I don't want to change
  1763. * this again at that point. If you're on a 32-bit platform and have to
  1764. * downcast, it's okay to return NULL if the allocation is greater than
  1765. * 4 gigabytes, since you'd have to do so anyhow.
  1766. *
  1767. * \sa PHYSFS_setAllocator
  1768. */
  1769. typedef struct
  1770. {
  1771. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1772. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1773. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1774. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1775. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1776. } PHYSFS_Allocator;
  1777. /**
  1778. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1779. * \brief Hook your own allocation routines into PhysicsFS.
  1780. *
  1781. * (This is for limited, hardcore use. If you don't immediately see a need
  1782. * for it, you can probably ignore this forever.)
  1783. *
  1784. * By default, PhysicsFS will use whatever is reasonable for a platform
  1785. * to manage dynamic memory (usually ANSI C malloc/realloc/calloc/free, but
  1786. * some platforms might use something else), but in some uncommon cases, the
  1787. * app might want more control over the library's memory management. This
  1788. * lets you redirect PhysicsFS to use your own allocation routines instead.
  1789. * You can only call this function before PHYSFS_init(); if the library is
  1790. * initialized, it'll reject your efforts to change the allocator mid-stream.
  1791. * You may call this function after PHYSFS_deinit() if you are willing to
  1792. * shut down the library and restart it with a new allocator; this is a safe
  1793. * and supported operation. The allocator remains intact between deinit/init
  1794. * calls. If you want to return to the platform's default allocator, pass a
  1795. * NULL in here.
  1796. *
  1797. * If you aren't immediately sure what to do with this function, you can
  1798. * safely ignore it altogether.
  1799. *
  1800. * \param allocator Structure containing your allocator's entry points.
  1801. * \return zero on failure, non-zero on success. This call only fails
  1802. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1803. */
  1804. __EXPORT__ int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1805. /**
  1806. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  1807. * \brief Add an archive or directory to the search path.
  1808. *
  1809. * If this is a duplicate, the entry is not added again, even though the
  1810. * function succeeds. You may not add the same archive to two different
  1811. * mountpoints: duplicate checking is done against the archive and not the
  1812. * mountpoint.
  1813. *
  1814. * When you mount an archive, it is added to a virtual file system...all files
  1815. * in all of the archives are interpolated into a single hierachical file
  1816. * tree. Two archives mounted at the same place (or an archive with files
  1817. * overlapping another mountpoint) may have overlapping files: in such a case,
  1818. * the file earliest in the search path is selected, and the other files are
  1819. * inaccessible to the application. This allows archives to be used to
  1820. * override previous revisions; you can use the mounting mechanism to place
  1821. * archives at a specific point in the file tree and prevent overlap; this
  1822. * is useful for downloadable mods that might trample over application data
  1823. * or each other, for example.
  1824. *
  1825. * The mountpoint does not need to exist prior to mounting, which is different
  1826. * than those familiar with the Unix concept of "mounting" may not expect.
  1827. * As well, more than one archive can be mounted to the same mountpoint, or
  1828. * mountpoints and archive contents can overlap...the interpolation mechanism
  1829. * still functions as usual.
  1830. *
  1831. * \param newDir directory or archive to add to the path, in
  1832. * platform-dependent notation.
  1833. * \param mountPoint Location in the interpolated tree that this archive
  1834. * will be "mounted", in platform-independent notation.
  1835. * NULL or "" is equivalent to "/".
  1836. * \param appendToPath nonzero to append to search path, zero to prepend.
  1837. * \return nonzero if added to path, zero on failure (bogus archive, dir
  1838. * missing, etc). Specifics of the error can be
  1839. * gleaned from PHYSFS_getLastError().
  1840. *
  1841. * \sa PHYSFS_removeFromSearchPath
  1842. * \sa PHYSFS_getSearchPath
  1843. * \sa PHYSFS_getMountPoint
  1844. */
  1845. __EXPORT__ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  1846. /**
  1847. * \fn int PHYSFS_getMountPoint(const char *dir);
  1848. * \brief Determine a mounted archive's mountpoint.
  1849. *
  1850. * You give this function the name of an archive or dir you successfully
  1851. * added to the search path, and it reports the location in the interpolated
  1852. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  1853. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  1854. * and valid until the archive is removed from the search path.
  1855. *
  1856. * \param dir directory or archive previously added to the path, in
  1857. * platform-dependent notation. This must match the string
  1858. * used when adding, even if your string would also reference
  1859. * the same file with a different string of characters.
  1860. * \return READ-ONLY string of mount point if added to path, NULL on failure
  1861. * (bogus archive, etc) Specifics of the error can be gleaned from
  1862. * PHYSFS_getLastError().
  1863. *
  1864. * \sa PHYSFS_removeFromSearchPath
  1865. * \sa PHYSFS_getSearchPath
  1866. * \sa PHYSFS_getMountPoint
  1867. */
  1868. __EXPORT__ const char *PHYSFS_getMountPoint(const char *dir);
  1869. /*
  1870. * it is not safe to call physfs functions in these callbacks, as they may
  1871. * be holding non recursive mutexes.
  1872. */
  1873. /* !!! FIXME: comment! */
  1874. typedef void (*PHYSFS_StringCallback)(void *, const char *);
  1875. typedef void (*PHYSFS_EnumFilesCallback)(void *, const char *, const char *);
  1876. __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  1877. __EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  1878. __EXPORT__ void PHYSFS_enumerateFilesCallback(const char *dir,
  1879. PHYSFS_EnumFilesCallback c,
  1880. void *d);
  1881. /**
  1882. * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
  1883. * \brief Convert a UCS-4 string to a UTF-8 string.
  1884. *
  1885. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  1886. *
  1887. * To ensure that the destination buffer is large enough for the conversion,
  1888. * please allocate a buffer that is the same size as the source buffer. UTF-8
  1889. * never uses more than 32-bits per character, so while it may shrink a UCS-4
  1890. * string, it will never expand it.
  1891. *
  1892. * Strings that don't fit in the destination buffer will be truncated, but
  1893. * will always be null-terminated and never have an incomplete UTF-8
  1894. * sequence at the end.
  1895. *
  1896. * \param src Null-terminated source string in UCS-4 format.
  1897. * \param dst Buffer to store converted UTF-8 string.
  1898. * \param len Size, in bytes, of destination buffer.
  1899. */
  1900. __EXPORT__ void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst,
  1901. PHYSFS_uint64 len);
  1902. /**
  1903. * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
  1904. * \brief Convert a UTF-8 string to a UCS-4 string.
  1905. *
  1906. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  1907. *
  1908. * To ensure that the destination buffer is large enough for the conversion,
  1909. * please allocate a buffer that is four times the size of the source buffer.
  1910. * UTF-8 uses from one to four bytes per character, but UCS-4 always uses
  1911. * four, so an entirely low-ASCII string will quadruple in size!
  1912. *
  1913. * Strings that don't fit in the destination buffer will be truncated, but
  1914. * will always be null-terminated and never have an incomplete UCS-4
  1915. * sequence at the end.
  1916. *
  1917. * \param src Null-terminated source string in UTF-8 format.
  1918. * \param dst Buffer to store converted UCS-4 string.
  1919. * \param len Size, in bytes, of destination buffer.
  1920. */
  1921. __EXPORT__ void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst,
  1922. PHYSFS_uint64 len);
  1923. /**
  1924. * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  1925. * \brief Convert a UCS-2 string to a UTF-8 string.
  1926. *
  1927. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  1928. * with Unicode support.
  1929. *
  1930. * To ensure that the destination buffer is large enough for the conversion,
  1931. * please allocate a buffer that is double the size of the source buffer.
  1932. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  1933. * a UCS-2 string, it may also expand it.
  1934. *
  1935. * Strings that don't fit in the destination buffer will be truncated, but
  1936. * will always be null-terminated and never have an incomplete UTF-8
  1937. * sequence at the end.
  1938. *
  1939. * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  1940. * values at this time.
  1941. *
  1942. * \param src Null-terminated source string in UCS-2 format.
  1943. * \param dst Buffer to store converted UTF-8 string.
  1944. * \param len Size, in bytes, of destination buffer.
  1945. */
  1946. __EXPORT__ void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst,
  1947. PHYSFS_uint64 len);
  1948. /**
  1949. * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  1950. * \brief Convert a UTF-8 string to a UCS-2 string.
  1951. *
  1952. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  1953. * with Unicode support.
  1954. *
  1955. * To ensure that the destination buffer is large enough for the conversion,
  1956. * please allocate a buffer that is double the size of the source buffer.
  1957. * UTF-8 uses from one to four bytes per character, but UCS-2 always uses
  1958. * two, so an entirely low-ASCII string will double in size!
  1959. *
  1960. * Strings that don't fit in the destination buffer will be truncated, but
  1961. * will always be null-terminated and never have an incomplete UCS-2
  1962. * sequence at the end.
  1963. *
  1964. * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  1965. * values at this time.
  1966. *
  1967. * \param src Null-terminated source string in UTF-8 format.
  1968. * \param dst Buffer to store converted UCS-2 string.
  1969. * \param len Size, in bytes, of destination buffer.
  1970. */
  1971. __EXPORT__ void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst,
  1972. PHYSFS_uint64 len);
  1973. /**
  1974. * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
  1975. * \brief Convert a UTF-8 string to a Latin1 string.
  1976. *
  1977. * Latin1 strings are 8-bits per character: a popular "high ASCII"
  1978. * encoding.
  1979. *
  1980. * To ensure that the destination buffer is large enough for the conversion,
  1981. * please allocate a buffer that is double the size of the source buffer.
  1982. * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string
  1983. * may grow in some cases.
  1984. *
  1985. * Strings that don't fit in the destination buffer will be truncated, but
  1986. * will always be null-terminated and never have an incomplete UTF-8
  1987. * sequence at the end.
  1988. *
  1989. * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  1990. * can't express most Unicode codepoints. It's a legacy encoding; you should
  1991. * be converting away from it at all times.
  1992. *
  1993. * \param src Null-terminated source string in Latin1 format.
  1994. * \param dst Buffer to store converted UTF-8 string.
  1995. * \param len Size, in bytes, of destination buffer.
  1996. */
  1997. __EXPORT__ void PHYSFS_utf8FromLatin1(const char *src, char *dst,
  1998. PHYSFS_uint64 len);
  1999. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  2000. #ifdef __cplusplus
  2001. }
  2002. #endif
  2003. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  2004. /* end of physfs.h ... */