physfs.h 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  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. * \sa PHYSFS_symbolicLinksPermitted
  579. */
  580. __EXPORT__ void PHYSFS_permitSymbolicLinks(int allow);
  581. /* !!! FIXME: const this? */
  582. /**
  583. * \fn char **PHYSFS_getCdRomDirs(void)
  584. * \brief Get an array of paths to available CD-ROM drives.
  585. *
  586. * The dirs returned are platform-dependent ("D:\" on Win32, "/cdrom" or
  587. * whatnot on Unix). Dirs are only returned if there is a disc ready and
  588. * accessible in the drive. So if you've got two drives (D: and E:), and only
  589. * E: has a disc in it, then that's all you get. If the user inserts a disc
  590. * in D: and you call this function again, you get both drives. If, on a
  591. * Unix box, the user unmounts a disc and remounts it elsewhere, the next
  592. * call to this function will reflect that change.
  593. *
  594. * This function refers to "CD-ROM" media, but it really means "inserted disc
  595. * media," such as DVD-ROM, HD-DVD, CDRW, and Blu-Ray discs. It looks for
  596. * filesystems, and as such won't report an audio CD, unless there's a
  597. * mounted filesystem track on it.
  598. *
  599. * The returned value is an array of strings, with a NULL entry to signify the
  600. * end of the list:
  601. *
  602. * \code
  603. * char **cds = PHYSFS_getCdRomDirs();
  604. * char **i;
  605. *
  606. * for (i = cds; *i != NULL; i++)
  607. * printf("cdrom dir [%s] is available.\n", *i);
  608. *
  609. * PHYSFS_freeList(cds);
  610. * \endcode
  611. *
  612. * This call may block while drives spin up. Be forewarned.
  613. *
  614. * When you are done with the returned information, you may dispose of the
  615. * resources by calling PHYSFS_freeList() with the returned pointer.
  616. *
  617. * \return Null-terminated array of null-terminated strings.
  618. *
  619. * \sa PHYSFS_getCdRomDirsCallback
  620. */
  621. __EXPORT__ char **PHYSFS_getCdRomDirs(void);
  622. /**
  623. * \fn const char *PHYSFS_getBaseDir(void)
  624. * \brief Get the path where the application resides.
  625. *
  626. * Helper function.
  627. *
  628. * Get the "base dir". This is the directory where the application was run
  629. * from, which is probably the installation directory, and may or may not
  630. * be the process's current working directory.
  631. *
  632. * You should probably use the base dir in your search path.
  633. *
  634. * \return READ ONLY string of base dir in platform-dependent notation.
  635. *
  636. * \sa PHYSFS_getUserDir
  637. */
  638. __EXPORT__ const char *PHYSFS_getBaseDir(void);
  639. /**
  640. * \fn const char *PHYSFS_getUserDir(void)
  641. * \brief Get the path where user's home directory resides.
  642. *
  643. * Helper function.
  644. *
  645. * Get the "user dir". This is meant to be a suggestion of where a specific
  646. * user of the system can store files. On Unix, this is her home directory.
  647. * On systems with no concept of multiple home directories (MacOS, win95),
  648. * this will default to something like "C:\mybasedir\users\username"
  649. * where "username" will either be the login name, or "default" if the
  650. * platform doesn't support multiple users, either.
  651. *
  652. * You should probably use the user dir as the basis for your write dir, and
  653. * also put it near the beginning of your search path.
  654. *
  655. * \return READ ONLY string of user dir in platform-dependent notation.
  656. *
  657. * \sa PHYSFS_getBaseDir
  658. */
  659. __EXPORT__ const char *PHYSFS_getUserDir(void);
  660. /**
  661. * \fn const char *PHYSFS_getWriteDir(void)
  662. * \brief Get path where PhysicsFS will allow file writing.
  663. *
  664. * Get the current write dir. The default write dir is NULL.
  665. *
  666. * \return READ ONLY string of write dir in platform-dependent notation,
  667. * OR NULL IF NO WRITE PATH IS CURRENTLY SET.
  668. *
  669. * \sa PHYSFS_setWriteDir
  670. */
  671. __EXPORT__ const char *PHYSFS_getWriteDir(void);
  672. /**
  673. * \fn int PHYSFS_setWriteDir(const char *newDir)
  674. * \brief Tell PhysicsFS where it may write files.
  675. *
  676. * Set a new write dir. This will override the previous setting.
  677. *
  678. * This call will fail (and fail to change the write dir) if the current
  679. * write dir still has files open in it.
  680. *
  681. * \param newDir The new directory to be the root of the write dir,
  682. * specified in platform-dependent notation. Setting to NULL
  683. * disables the write dir, so no files can be opened for
  684. * writing via PhysicsFS.
  685. * \return non-zero on success, zero on failure. All attempts to open a file
  686. * for writing via PhysicsFS will fail until this call succeeds.
  687. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  688. *
  689. * \sa PHYSFS_getWriteDir
  690. */
  691. __EXPORT__ int PHYSFS_setWriteDir(const char *newDir);
  692. /**
  693. * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
  694. * \brief Add an archive or directory to the search path.
  695. *
  696. * This is a legacy call in PhysicsFS 2.0, equivalent to:
  697. * PHYSFS_mount(newDir, NULL, appendToPath);
  698. *
  699. * You must use this and not PHYSFS_mount if binary compatibility with
  700. * PhysicsFS 1.0 is important (which it may not be for many people).
  701. *
  702. * \sa PHYSFS_mount
  703. * \sa PHYSFS_removeFromSearchPath
  704. * \sa PHYSFS_getSearchPath
  705. */
  706. __EXPORT__ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);
  707. /**
  708. * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
  709. * \brief Remove a directory or archive from the search path.
  710. *
  711. * This must be a (case-sensitive) match to a dir or archive already in the
  712. * search path, specified in platform-dependent notation.
  713. *
  714. * This call will fail (and fail to remove from the path) if the element still
  715. * has files open in it.
  716. *
  717. * \param oldDir dir/archive to remove.
  718. * \return nonzero on success, zero on failure.
  719. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  720. *
  721. * \sa PHYSFS_addToSearchPath
  722. * \sa PHYSFS_getSearchPath
  723. */
  724. __EXPORT__ int PHYSFS_removeFromSearchPath(const char *oldDir);
  725. /**
  726. * \fn char **PHYSFS_getSearchPath(void)
  727. * \brief Get the current search path.
  728. *
  729. * The default search path is an empty list.
  730. *
  731. * The returned value is an array of strings, with a NULL entry to signify the
  732. * end of the list:
  733. *
  734. * \code
  735. * char **i;
  736. *
  737. * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
  738. * printf("[%s] is in the search path.\n", *i);
  739. * \endcode
  740. *
  741. * When you are done with the returned information, you may dispose of the
  742. * resources by calling PHYSFS_freeList() with the returned pointer.
  743. *
  744. * \return Null-terminated array of null-terminated strings. NULL if there
  745. * was a problem (read: OUT OF MEMORY).
  746. *
  747. * \sa PHYSFS_getSearchPathCallback
  748. * \sa PHYSFS_addToSearchPath
  749. * \sa PHYSFS_removeFromSearchPath
  750. */
  751. __EXPORT__ char **PHYSFS_getSearchPath(void);
  752. /**
  753. * \fn int PHYSFS_setSaneConfig(const char *organization, const char *appName, const char *archiveExt, int includeCdRoms, int archivesFirst)
  754. * \brief Set up sane, default paths.
  755. *
  756. * Helper function.
  757. *
  758. * The write dir will be set to "userdir/.organization/appName", which is
  759. * created if it doesn't exist.
  760. *
  761. * The above is sufficient to make sure your program's configuration directory
  762. * is separated from other clutter, and platform-independent. The period
  763. * before "mygame" even hides the directory on Unix systems.
  764. *
  765. * The search path will be:
  766. *
  767. * - The Write Dir (created if it doesn't exist)
  768. * - The Base Dir (PHYSFS_getBaseDir())
  769. * - All found CD-ROM dirs (optionally)
  770. *
  771. * These directories are then searched for files ending with the extension
  772. * (archiveExt), which, if they are valid and supported archives, will also
  773. * be added to the search path. If you specified "PKG" for (archiveExt), and
  774. * there's a file named data.PKG in the base dir, it'll be checked. Archives
  775. * can either be appended or prepended to the search path in alphabetical
  776. * order, regardless of which directories they were found in.
  777. *
  778. * All of this can be accomplished from the application, but this just does it
  779. * all for you. Feel free to add more to the search path manually, too.
  780. *
  781. * \param organization Name of your company/group/etc to be used as a
  782. * dirname, so keep it small, and no-frills.
  783. *
  784. * \param appName Program-specific name of your program, to separate it
  785. * from other programs using PhysicsFS.
  786. *
  787. * \param archiveExt File extension used by your program to specify an
  788. * archive. For example, Quake 3 uses "pk3", even though
  789. * they are just zipfiles. Specify NULL to not dig out
  790. * archives automatically. Do not specify the '.' char;
  791. * If you want to look for ZIP files, specify "ZIP" and
  792. * not ".ZIP" ... the archive search is case-insensitive.
  793. *
  794. * \param includeCdRoms Non-zero to include CD-ROMs in the search path, and
  795. * (if (archiveExt) != NULL) search them for archives.
  796. * This may cause a significant amount of blocking
  797. * while discs are accessed, and if there are no discs
  798. * in the drive (or even not mounted on Unix systems),
  799. * then they may not be made available anyhow. You may
  800. * want to specify zero and handle the disc setup
  801. * yourself.
  802. *
  803. * \param archivesFirst Non-zero to prepend the archives to the search path.
  804. * Zero to append them. Ignored if !(archiveExt).
  805. *
  806. * \return nonzero on success, zero on error. Specifics of the error can be
  807. * gleaned from PHYSFS_getLastError().
  808. */
  809. __EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
  810. const char *appName,
  811. const char *archiveExt,
  812. int includeCdRoms,
  813. int archivesFirst);
  814. /* Directory management stuff ... */
  815. /**
  816. * \fn int PHYSFS_mkdir(const char *dirName)
  817. * \brief Create a directory.
  818. *
  819. * This is specified in platform-independent notation in relation to the
  820. * write dir. All missing parent directories are also created if they
  821. * don't exist.
  822. *
  823. * So if you've got the write dir set to "C:\mygame\writedir" and call
  824. * PHYSFS_mkdir("downloads/maps") then the directories
  825. * "C:\mygame\writedir\downloads" and "C:\mygame\writedir\downloads\maps"
  826. * will be created if possible. If the creation of "maps" fails after we
  827. * have successfully created "downloads", then the function leaves the
  828. * created directory behind and reports failure.
  829. *
  830. * \param dirName New dir to create.
  831. * \return nonzero on success, zero on error. Specifics of the error can be
  832. * gleaned from PHYSFS_getLastError().
  833. *
  834. * \sa PHYSFS_delete
  835. */
  836. __EXPORT__ int PHYSFS_mkdir(const char *dirName);
  837. /**
  838. * \fn int PHYSFS_delete(const char *filename)
  839. * \brief Delete a file or directory.
  840. *
  841. * (filename) is specified in platform-independent notation in relation to the
  842. * write dir.
  843. *
  844. * A directory must be empty before this call can delete it.
  845. *
  846. * Deleting a symlink will remove the link, not what it points to, regardless
  847. * of whether you "permitSymLinks" or not.
  848. *
  849. * So if you've got the write dir set to "C:\mygame\writedir" and call
  850. * PHYSFS_delete("downloads/maps/level1.map") then the file
  851. * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
  852. * physical filesystem, if it exists and the operating system permits the
  853. * deletion.
  854. *
  855. * Note that on Unix systems, deleting a file may be successful, but the
  856. * actual file won't be removed until all processes that have an open
  857. * filehandle to it (including your program) close their handles.
  858. *
  859. * Chances are, the bits that make up the file still exist, they are just
  860. * made available to be written over at a later point. Don't consider this
  861. * a security method or anything. :)
  862. *
  863. * \param filename Filename to delete.
  864. * \return nonzero on success, zero on error. Specifics of the error can be
  865. * gleaned from PHYSFS_getLastError().
  866. */
  867. __EXPORT__ int PHYSFS_delete(const char *filename);
  868. /**
  869. * \fn const char *PHYSFS_getRealDir(const char *filename)
  870. * \brief Figure out where in the search path a file resides.
  871. *
  872. * The file is specified in platform-independent notation. The returned
  873. * filename will be the element of the search path where the file was found,
  874. * which may be a directory, or an archive. Even if there are multiple
  875. * matches in different parts of the search path, only the first one found
  876. * is used, just like when opening a file.
  877. *
  878. * So, if you look for "maps/level1.map", and C:\\mygame is in your search
  879. * path and C:\\mygame\\maps\\level1.map exists, then "C:\mygame" is returned.
  880. *
  881. * If a any part of a match is a symbolic link, and you've not explicitly
  882. * permitted symlinks, then it will be ignored, and the search for a match
  883. * will continue.
  884. *
  885. * If you specify a fake directory that only exists as a mount point, it'll
  886. * be associated with the first archive mounted there, even though that
  887. * directory isn't necessarily contained in a real archive.
  888. *
  889. * \param filename file to look for.
  890. * \return READ ONLY string of element of search path containing the
  891. * the file in question. NULL if not found.
  892. */
  893. __EXPORT__ const char *PHYSFS_getRealDir(const char *filename);
  894. /**
  895. * \fn char **PHYSFS_enumerateFiles(const char *dir)
  896. * \brief Get a file listing of a search path's directory.
  897. *
  898. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  899. * search path and contains a directory "savegames" that contains "x.sav",
  900. * "y.sav", and "z.sav", and there is also a "C:\userdir" in the search path
  901. * that has a "savegames" subdirectory with "w.sav", then the following code:
  902. *
  903. * \code
  904. * char **rc = PHYSFS_enumerateFiles("savegames");
  905. * char **i;
  906. *
  907. * for (i = rc; *i != NULL; i++)
  908. * printf(" * We've got [%s].\n", *i);
  909. *
  910. * PHYSFS_freeList(rc);
  911. * \endcode
  912. *
  913. * ...will print:
  914. *
  915. * \verbatim
  916. * We've got [x.sav].
  917. * We've got [y.sav].
  918. * We've got [z.sav].
  919. * We've got [w.sav].\endverbatim
  920. *
  921. * Feel free to sort the list however you like. We only promise there will
  922. * be no duplicates, but not what order the final list will come back in.
  923. *
  924. * Don't forget to call PHYSFS_freeList() with the return value from this
  925. * function when you are done with it.
  926. *
  927. * \param dir directory in platform-independent notation to enumerate.
  928. * \return Null-terminated array of null-terminated strings.
  929. *
  930. * \sa PHYSFS_enumerateFilesCallback
  931. */
  932. __EXPORT__ char **PHYSFS_enumerateFiles(const char *dir);
  933. /**
  934. * \fn int PHYSFS_exists(const char *fname)
  935. * \brief Determine if a file exists in the search path.
  936. *
  937. * Reports true if there is an entry anywhere in the search path by the
  938. * name of (fname).
  939. *
  940. * Note that entries that are symlinks are ignored if
  941. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  942. * might end up further down in the search path than expected.
  943. *
  944. * \param fname filename in platform-independent notation.
  945. * \return non-zero if filename exists. zero otherwise.
  946. *
  947. * \sa PHYSFS_isDirectory
  948. * \sa PHYSFS_isSymbolicLink
  949. */
  950. __EXPORT__ int PHYSFS_exists(const char *fname);
  951. /**
  952. * \fn int PHYSFS_isDirectory(const char *fname)
  953. * \brief Determine if a file in the search path is really a directory.
  954. *
  955. * Determine if the first occurence of (fname) in the search path is
  956. * really a directory entry.
  957. *
  958. * Note that entries that are symlinks are ignored if
  959. * PHYSFS_permitSymbolicLinks(1) hasn't been called, so you
  960. * might end up further down in the search path than expected.
  961. *
  962. * \param fname filename in platform-independent notation.
  963. * \return non-zero if filename exists and is a directory. zero otherwise.
  964. *
  965. * \sa PHYSFS_exists
  966. * \sa PHYSFS_isSymbolicLink
  967. */
  968. __EXPORT__ int PHYSFS_isDirectory(const char *fname);
  969. /**
  970. * \fn int PHYSFS_isSymbolicLink(const char *fname)
  971. * \brief Determine if a file in the search path is really a symbolic link.
  972. *
  973. * Determine if the first occurence of (fname) in the search path is
  974. * really a symbolic link.
  975. *
  976. * Note that entries that are symlinks are ignored if
  977. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and as such,
  978. * this function will always return 0 in that case.
  979. *
  980. * \param fname filename in platform-independent notation.
  981. * \return non-zero if filename exists and is a symlink. zero otherwise.
  982. *
  983. * \sa PHYSFS_exists
  984. * \sa PHYSFS_isDirectory
  985. */
  986. __EXPORT__ int PHYSFS_isSymbolicLink(const char *fname);
  987. /**
  988. * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
  989. * \brief Get the last modification time of a file.
  990. *
  991. * The modtime is returned as a number of seconds since the epoch
  992. * (Jan 1, 1970). The exact derivation and accuracy of this time depends on
  993. * the particular archiver. If there is no reasonable way to obtain this
  994. * information for a particular archiver, or there was some sort of error,
  995. * this function returns (-1).
  996. *
  997. * \param filename filename to check, in platform-independent notation.
  998. * \return last modified time of the file. -1 if it can't be determined.
  999. */
  1000. __EXPORT__ PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename);
  1001. /* i/o stuff... */
  1002. /**
  1003. * \fn PHYSFS_File *PHYSFS_openWrite(const char *filename)
  1004. * \brief Open a file for writing.
  1005. *
  1006. * Open a file for writing, in platform-independent notation and in relation
  1007. * to the write dir as the root of the writable filesystem. The specified
  1008. * file is created if it doesn't exist. If it does exist, it is truncated to
  1009. * zero bytes, and the writing offset is set to the start.
  1010. *
  1011. * Note that entries that are symlinks are ignored if
  1012. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1013. * symlink with this function will fail in such a case.
  1014. *
  1015. * \param filename File to open.
  1016. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1017. * of the error can be gleaned from PHYSFS_getLastError().
  1018. *
  1019. * \sa PHYSFS_openRead
  1020. * \sa PHYSFS_openAppend
  1021. * \sa PHYSFS_write
  1022. * \sa PHYSFS_close
  1023. */
  1024. __EXPORT__ PHYSFS_File *PHYSFS_openWrite(const char *filename);
  1025. /**
  1026. * \fn PHYSFS_File *PHYSFS_openAppend(const char *filename)
  1027. * \brief Open a file for appending.
  1028. *
  1029. * Open a file for writing, in platform-independent notation and in relation
  1030. * to the write dir as the root of the writable filesystem. The specified
  1031. * file is created if it doesn't exist. If it does exist, the writing offset
  1032. * is set to the end of the file, so the first write will be the byte after
  1033. * the end.
  1034. *
  1035. * Note that entries that are symlinks are ignored if
  1036. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1037. * symlink with this function will fail in such a case.
  1038. *
  1039. * \param filename File to open.
  1040. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1041. * of the error can be gleaned from PHYSFS_getLastError().
  1042. *
  1043. * \sa PHYSFS_openRead
  1044. * \sa PHYSFS_openWrite
  1045. * \sa PHYSFS_write
  1046. * \sa PHYSFS_close
  1047. */
  1048. __EXPORT__ PHYSFS_File *PHYSFS_openAppend(const char *filename);
  1049. /**
  1050. * \fn PHYSFS_File *PHYSFS_openRead(const char *filename)
  1051. * \brief Open a file for reading.
  1052. *
  1053. * Open a file for reading, in platform-independent notation. The search path
  1054. * is checked one at a time until a matching file is found, in which case an
  1055. * abstract filehandle is associated with it, and reading may be done.
  1056. * The reading offset is set to the first byte of the file.
  1057. *
  1058. * Note that entries that are symlinks are ignored if
  1059. * PHYSFS_permitSymbolicLinks(1) hasn't been called, and opening a
  1060. * symlink with this function will fail in such a case.
  1061. *
  1062. * \param filename File to open.
  1063. * \return A valid PhysicsFS filehandle on success, NULL on error. Specifics
  1064. * of the error can be gleaned from PHYSFS_getLastError().
  1065. *
  1066. * \sa PHYSFS_openWrite
  1067. * \sa PHYSFS_openAppend
  1068. * \sa PHYSFS_read
  1069. * \sa PHYSFS_close
  1070. */
  1071. __EXPORT__ PHYSFS_File *PHYSFS_openRead(const char *filename);
  1072. /**
  1073. * \fn int PHYSFS_close(PHYSFS_File *handle)
  1074. * \brief Close a PhysicsFS filehandle.
  1075. *
  1076. * This call is capable of failing if the operating system was buffering
  1077. * writes to the physical media, and, now forced to write those changes to
  1078. * physical media, can not store the data for some reason. In such a case,
  1079. * the filehandle stays open. A well-written program should ALWAYS check the
  1080. * return value from the close call in addition to every writing call!
  1081. *
  1082. * \param handle handle returned from PHYSFS_open*().
  1083. * \return nonzero on success, zero on error. Specifics of the error can be
  1084. * gleaned from PHYSFS_getLastError().
  1085. *
  1086. * \sa PHYSFS_openRead
  1087. * \sa PHYSFS_openWrite
  1088. * \sa PHYSFS_openAppend
  1089. */
  1090. __EXPORT__ int PHYSFS_close(PHYSFS_File *handle);
  1091. /**
  1092. * \fn PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1093. * \brief Read data from a PhysicsFS filehandle
  1094. *
  1095. * The file must be opened for reading.
  1096. *
  1097. * \param handle handle returned from PHYSFS_openRead().
  1098. * \param buffer buffer to store read data into.
  1099. * \param objSize size in bytes of objects being read from (handle).
  1100. * \param objCount number of (objSize) objects to read from (handle).
  1101. * \return number of objects read. PHYSFS_getLastError() can shed light on
  1102. * the reason this might be < (objCount), as can PHYSFS_eof().
  1103. * -1 if complete failure.
  1104. *
  1105. * \sa PHYSFS_eof
  1106. */
  1107. __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle,
  1108. void *buffer,
  1109. PHYSFS_uint32 objSize,
  1110. PHYSFS_uint32 objCount);
  1111. /**
  1112. * \fn PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer, PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  1113. * \brief Write data to a PhysicsFS filehandle
  1114. *
  1115. * The file must be opened for writing.
  1116. *
  1117. * \param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
  1118. * \param buffer buffer to store read data into.
  1119. * \param objSize size in bytes of objects being read from (handle).
  1120. * \param objCount number of (objSize) objects to read from (handle).
  1121. * \return number of objects written. PHYSFS_getLastError() can shed light on
  1122. * the reason this might be < (objCount). -1 if complete failure.
  1123. */
  1124. __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle,
  1125. const void *buffer,
  1126. PHYSFS_uint32 objSize,
  1127. PHYSFS_uint32 objCount);
  1128. /* File position stuff... */
  1129. /**
  1130. * \fn int PHYSFS_eof(PHYSFS_File *handle)
  1131. * \brief Check for end-of-file state on a PhysicsFS filehandle.
  1132. *
  1133. * Determine if the end of file has been reached in a PhysicsFS filehandle.
  1134. *
  1135. * \param handle handle returned from PHYSFS_openRead().
  1136. * \return nonzero if EOF, zero if not.
  1137. *
  1138. * \sa PHYSFS_read
  1139. * \sa PHYSFS_tell
  1140. */
  1141. __EXPORT__ int PHYSFS_eof(PHYSFS_File *handle);
  1142. /**
  1143. * \fn PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle)
  1144. * \brief Determine current position within a PhysicsFS filehandle.
  1145. *
  1146. * \param handle handle returned from PHYSFS_open*().
  1147. * \return offset in bytes from start of file. -1 if error occurred.
  1148. * Specifics of the error can be gleaned from PHYSFS_getLastError().
  1149. *
  1150. * \sa PHYSFS_seek
  1151. */
  1152. __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle);
  1153. /**
  1154. * \fn int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos)
  1155. * \brief Seek to a new position within a PhysicsFS filehandle.
  1156. *
  1157. * The next read or write will occur at that place. Seeking past the
  1158. * beginning or end of the file is not allowed, and causes an error.
  1159. *
  1160. * \param handle handle returned from PHYSFS_open*().
  1161. * \param pos number of bytes from start of file to seek to.
  1162. * \return nonzero on success, zero on error. Specifics of the error can be
  1163. * gleaned from PHYSFS_getLastError().
  1164. *
  1165. * \sa PHYSFS_tell
  1166. */
  1167. __EXPORT__ int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos);
  1168. /**
  1169. * \fn PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle)
  1170. * \brief Get total length of a file in bytes.
  1171. *
  1172. * Note that if the file size can't be determined (since the archive is
  1173. * "streamed" or whatnot) than this will report (-1). Also note that if
  1174. * another process/thread is writing to this file at the same time, then
  1175. * the information this function supplies could be incorrect before you
  1176. * get it. Use with caution, or better yet, don't use at all.
  1177. *
  1178. * \param handle handle returned from PHYSFS_open*().
  1179. * \return size in bytes of the file. -1 if can't be determined.
  1180. *
  1181. * \sa PHYSFS_tell
  1182. * \sa PHYSFS_seek
  1183. */
  1184. __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_File *handle);
  1185. /* Buffering stuff... */
  1186. /**
  1187. * \fn int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize)
  1188. * \brief Set up buffering for a PhysicsFS file handle.
  1189. *
  1190. * Define an i/o buffer for a file handle. A memory block of (bufsize) bytes
  1191. * will be allocated and associated with (handle).
  1192. *
  1193. * For files opened for reading, up to (bufsize) bytes are read from (handle)
  1194. * and stored in the internal buffer. Calls to PHYSFS_read() will pull
  1195. * from this buffer until it is empty, and then refill it for more reading.
  1196. * Note that compressed files, like ZIP archives, will decompress while
  1197. * buffering, so this can be handy for offsetting CPU-intensive operations.
  1198. * The buffer isn't filled until you do your next read.
  1199. *
  1200. * For files opened for writing, data will be buffered to memory until the
  1201. * buffer is full or the buffer is flushed. Closing a handle implicitly
  1202. * causes a flush...check your return values!
  1203. *
  1204. * Seeking, etc transparently accounts for buffering.
  1205. *
  1206. * You can resize an existing buffer by calling this function more than once
  1207. * on the same file. Setting the buffer size to zero will free an existing
  1208. * buffer.
  1209. *
  1210. * PhysicsFS file handles are unbuffered by default.
  1211. *
  1212. * Please check the return value of this function! Failures can include
  1213. * not being able to seek backwards in a read-only file when removing the
  1214. * buffer, not being able to allocate the buffer, and not being able to
  1215. * flush the buffer to disk, among other unexpected problems.
  1216. *
  1217. * \param handle handle returned from PHYSFS_open*().
  1218. * \param bufsize size, in bytes, of buffer to allocate.
  1219. * \return nonzero if successful, zero on error.
  1220. *
  1221. * \sa PHYSFS_flush
  1222. * \sa PHYSFS_read
  1223. * \sa PHYSFS_write
  1224. * \sa PHYSFS_close
  1225. */
  1226. __EXPORT__ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 bufsize);
  1227. /**
  1228. * \fn int PHYSFS_flush(PHYSFS_File *handle)
  1229. * \brief Flush a buffered PhysicsFS file handle.
  1230. *
  1231. * For buffered files opened for writing, this will put the current contents
  1232. * of the buffer to disk and flag the buffer as empty if possible.
  1233. *
  1234. * For buffered files opened for reading or unbuffered files, this is a safe
  1235. * no-op, and will report success.
  1236. *
  1237. * \param handle handle returned from PHYSFS_open*().
  1238. * \return nonzero if successful, zero on error.
  1239. *
  1240. * \sa PHYSFS_setBuffer
  1241. * \sa PHYSFS_close
  1242. */
  1243. __EXPORT__ int PHYSFS_flush(PHYSFS_File *handle);
  1244. /* Byteorder stuff... */
  1245. /**
  1246. * \fn PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val)
  1247. * \brief Swap littleendian signed 16 to platform's native byte order.
  1248. *
  1249. * Take a 16-bit signed value in littleendian format and convert it to
  1250. * the platform's native byte order.
  1251. *
  1252. * \param val value to convert
  1253. * \return converted value.
  1254. */
  1255. __EXPORT__ PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
  1256. /**
  1257. * \fn PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val)
  1258. * \brief Swap littleendian unsigned 16 to platform's native byte order.
  1259. *
  1260. * Take a 16-bit unsigned value in littleendian format and convert it to
  1261. * the platform's native byte order.
  1262. *
  1263. * \param val value to convert
  1264. * \return converted value.
  1265. */
  1266. __EXPORT__ PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
  1267. /**
  1268. * \fn PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val)
  1269. * \brief Swap littleendian signed 32 to platform's native byte order.
  1270. *
  1271. * Take a 32-bit signed value in littleendian format and convert it to
  1272. * the platform's native byte order.
  1273. *
  1274. * \param val value to convert
  1275. * \return converted value.
  1276. */
  1277. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
  1278. /**
  1279. * \fn PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val)
  1280. * \brief Swap littleendian unsigned 32 to platform's native byte order.
  1281. *
  1282. * Take a 32-bit unsigned value in littleendian format and convert it to
  1283. * the platform's native byte order.
  1284. *
  1285. * \param val value to convert
  1286. * \return converted value.
  1287. */
  1288. __EXPORT__ PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
  1289. /**
  1290. * \fn PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val)
  1291. * \brief Swap littleendian signed 64 to platform's native byte order.
  1292. *
  1293. * Take a 64-bit signed value in littleendian format and convert it to
  1294. * the platform's native byte order.
  1295. *
  1296. * \param val value to convert
  1297. * \return converted value.
  1298. *
  1299. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1300. * any sort of 64-bit support.
  1301. */
  1302. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1303. /**
  1304. * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1305. * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1306. *
  1307. * Take a 64-bit unsigned value in littleendian format and convert it to
  1308. * the platform's native byte order.
  1309. *
  1310. * \param val value to convert
  1311. * \return converted value.
  1312. *
  1313. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1314. * any sort of 64-bit support.
  1315. */
  1316. __EXPORT__ PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1317. /**
  1318. * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1319. * \brief Swap bigendian signed 16 to platform's native byte order.
  1320. *
  1321. * Take a 16-bit signed value in bigendian format and convert it to
  1322. * the platform's native byte order.
  1323. *
  1324. * \param val value to convert
  1325. * \return converted value.
  1326. */
  1327. __EXPORT__ PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1328. /**
  1329. * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1330. * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1331. *
  1332. * Take a 16-bit unsigned value in bigendian format and convert it to
  1333. * the platform's native byte order.
  1334. *
  1335. * \param val value to convert
  1336. * \return converted value.
  1337. */
  1338. __EXPORT__ PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1339. /**
  1340. * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1341. * \brief Swap bigendian signed 32 to platform's native byte order.
  1342. *
  1343. * Take a 32-bit signed value in bigendian format and convert it to
  1344. * the platform's native byte order.
  1345. *
  1346. * \param val value to convert
  1347. * \return converted value.
  1348. */
  1349. __EXPORT__ PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1350. /**
  1351. * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1352. * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1353. *
  1354. * Take a 32-bit unsigned value in bigendian format and convert it to
  1355. * the platform's native byte order.
  1356. *
  1357. * \param val value to convert
  1358. * \return converted value.
  1359. */
  1360. __EXPORT__ PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1361. /**
  1362. * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1363. * \brief Swap bigendian signed 64 to platform's native byte order.
  1364. *
  1365. * Take a 64-bit signed value in bigendian format and convert it to
  1366. * the platform's native byte order.
  1367. *
  1368. * \param val value to convert
  1369. * \return converted value.
  1370. *
  1371. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1372. * any sort of 64-bit support.
  1373. */
  1374. __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1375. /**
  1376. * \fn PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val)
  1377. * \brief Swap bigendian unsigned 64 to platform's native byte order.
  1378. *
  1379. * Take a 64-bit unsigned value in bigendian format and convert it to
  1380. * the platform's native byte order.
  1381. *
  1382. * \param val value to convert
  1383. * \return converted value.
  1384. *
  1385. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1386. * any sort of 64-bit support.
  1387. */
  1388. __EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
  1389. /**
  1390. * \fn int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1391. * \brief Read and convert a signed 16-bit littleendian value.
  1392. *
  1393. * Convenience function. Read a signed 16-bit littleendian value from a
  1394. * file and convert it to the platform's native byte order.
  1395. *
  1396. * \param file PhysicsFS file handle from which to read.
  1397. * \param val pointer to where value should be stored.
  1398. * \return zero on failure, non-zero on success. If successful, (*val) will
  1399. * store the result. On failure, you can find out what went wrong
  1400. * from PHYSFS_getLastError().
  1401. */
  1402. __EXPORT__ int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1403. /**
  1404. * \fn int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1405. * \brief Read and convert an unsigned 16-bit littleendian value.
  1406. *
  1407. * Convenience function. Read an unsigned 16-bit littleendian value from a
  1408. * file and convert it to the platform's native byte order.
  1409. *
  1410. * \param file PhysicsFS file handle from which to read.
  1411. * \param val pointer to where value should be stored.
  1412. * \return zero on failure, non-zero on success. If successful, (*val) will
  1413. * store the result. On failure, you can find out what went wrong
  1414. * from PHYSFS_getLastError().
  1415. *
  1416. */
  1417. __EXPORT__ int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1418. /**
  1419. * \fn int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
  1420. * \brief Read and convert a signed 16-bit bigendian value.
  1421. *
  1422. * Convenience function. Read a signed 16-bit bigendian value from a
  1423. * file and convert it to the platform's native byte order.
  1424. *
  1425. * \param file PhysicsFS file handle from which to read.
  1426. * \param val pointer to where value should be stored.
  1427. * \return zero on failure, non-zero on success. If successful, (*val) will
  1428. * store the result. On failure, you can find out what went wrong
  1429. * from PHYSFS_getLastError().
  1430. */
  1431. __EXPORT__ int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val);
  1432. /**
  1433. * \fn int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
  1434. * \brief Read and convert an unsigned 16-bit bigendian value.
  1435. *
  1436. * Convenience function. Read an unsigned 16-bit bigendian value from a
  1437. * file and convert it to the platform's native byte order.
  1438. *
  1439. * \param file PhysicsFS file handle from which to read.
  1440. * \param val pointer to where value should be stored.
  1441. * \return zero on failure, non-zero on success. If successful, (*val) will
  1442. * store the result. On failure, you can find out what went wrong
  1443. * from PHYSFS_getLastError().
  1444. *
  1445. */
  1446. __EXPORT__ int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val);
  1447. /**
  1448. * \fn int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1449. * \brief Read and convert a signed 32-bit littleendian value.
  1450. *
  1451. * Convenience function. Read a signed 32-bit littleendian value from a
  1452. * file and convert it to the platform's native byte order.
  1453. *
  1454. * \param file PhysicsFS file handle from which to read.
  1455. * \param val pointer to where value should be stored.
  1456. * \return zero on failure, non-zero on success. If successful, (*val) will
  1457. * store the result. On failure, you can find out what went wrong
  1458. * from PHYSFS_getLastError().
  1459. */
  1460. __EXPORT__ int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1461. /**
  1462. * \fn int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1463. * \brief Read and convert an unsigned 32-bit littleendian value.
  1464. *
  1465. * Convenience function. Read an unsigned 32-bit littleendian value from a
  1466. * file and convert it to the platform's native byte order.
  1467. *
  1468. * \param file PhysicsFS file handle from which to read.
  1469. * \param val pointer to where value should be stored.
  1470. * \return zero on failure, non-zero on success. If successful, (*val) will
  1471. * store the result. On failure, you can find out what went wrong
  1472. * from PHYSFS_getLastError().
  1473. *
  1474. */
  1475. __EXPORT__ int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1476. /**
  1477. * \fn int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
  1478. * \brief Read and convert a signed 32-bit bigendian value.
  1479. *
  1480. * Convenience function. Read a signed 32-bit bigendian value from a
  1481. * file and convert it to the platform's native byte order.
  1482. *
  1483. * \param file PhysicsFS file handle from which to read.
  1484. * \param val pointer to where value should be stored.
  1485. * \return zero on failure, non-zero on success. If successful, (*val) will
  1486. * store the result. On failure, you can find out what went wrong
  1487. * from PHYSFS_getLastError().
  1488. */
  1489. __EXPORT__ int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val);
  1490. /**
  1491. * \fn int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
  1492. * \brief Read and convert an unsigned 32-bit bigendian value.
  1493. *
  1494. * Convenience function. Read an unsigned 32-bit bigendian value from a
  1495. * file and convert it to the platform's native byte order.
  1496. *
  1497. * \param file PhysicsFS file handle from which to read.
  1498. * \param val pointer to where value should be stored.
  1499. * \return zero on failure, non-zero on success. If successful, (*val) will
  1500. * store the result. On failure, you can find out what went wrong
  1501. * from PHYSFS_getLastError().
  1502. *
  1503. */
  1504. __EXPORT__ int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val);
  1505. /**
  1506. * \fn int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1507. * \brief Read and convert a signed 64-bit littleendian value.
  1508. *
  1509. * Convenience function. Read a signed 64-bit littleendian value from a
  1510. * file and convert it to the platform's native byte order.
  1511. *
  1512. * \param file PhysicsFS file handle from which to read.
  1513. * \param val pointer to where value should be stored.
  1514. * \return zero on failure, non-zero on success. If successful, (*val) will
  1515. * store the result. On failure, you can find out what went wrong
  1516. * from PHYSFS_getLastError().
  1517. *
  1518. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1519. * any sort of 64-bit support.
  1520. */
  1521. __EXPORT__ int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1522. /**
  1523. * \fn int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1524. * \brief Read and convert an unsigned 64-bit littleendian value.
  1525. *
  1526. * Convenience function. Read an unsigned 64-bit littleendian value from a
  1527. * file and convert it to the platform's native byte order.
  1528. *
  1529. * \param file PhysicsFS file handle from which to read.
  1530. * \param val pointer to where value should be stored.
  1531. * \return zero on failure, non-zero on success. If successful, (*val) will
  1532. * store the result. On failure, you can find out what went wrong
  1533. * from PHYSFS_getLastError().
  1534. *
  1535. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1536. * any sort of 64-bit support.
  1537. */
  1538. __EXPORT__ int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1539. /**
  1540. * \fn int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
  1541. * \brief Read and convert a signed 64-bit bigendian value.
  1542. *
  1543. * Convenience function. Read a signed 64-bit bigendian value from a
  1544. * file and convert it to the platform's native byte order.
  1545. *
  1546. * \param file PhysicsFS file handle from which to read.
  1547. * \param val pointer to where value should be stored.
  1548. * \return zero on failure, non-zero on success. If successful, (*val) will
  1549. * store the result. On failure, you can find out what went wrong
  1550. * from PHYSFS_getLastError().
  1551. *
  1552. * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1553. * any sort of 64-bit support.
  1554. */
  1555. __EXPORT__ int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val);
  1556. /**
  1557. * \fn int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
  1558. * \brief Read and convert an unsigned 64-bit bigendian value.
  1559. *
  1560. * Convenience function. Read an unsigned 64-bit bigendian value from a
  1561. * file and convert it to the platform's native byte order.
  1562. *
  1563. * \param file PhysicsFS file handle from which to read.
  1564. * \param val pointer to where value should be stored.
  1565. * \return zero on failure, non-zero on success. If successful, (*val) will
  1566. * store the result. On failure, you can find out what went wrong
  1567. * from PHYSFS_getLastError().
  1568. *
  1569. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1570. * any sort of 64-bit support.
  1571. */
  1572. __EXPORT__ int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val);
  1573. /**
  1574. * \fn int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1575. * \brief Convert and write a signed 16-bit littleendian value.
  1576. *
  1577. * Convenience function. Convert a signed 16-bit value from the platform's
  1578. * native byte order to littleendian and write it to a file.
  1579. *
  1580. * \param file PhysicsFS file handle to which to write.
  1581. * \param val Value to convert and write.
  1582. * \return zero on failure, non-zero on success. On failure, you can
  1583. * find out what went wrong from PHYSFS_getLastError().
  1584. */
  1585. __EXPORT__ int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1586. /**
  1587. * \fn int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1588. * \brief Convert and write an unsigned 16-bit littleendian value.
  1589. *
  1590. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1591. * native byte order to littleendian and write it to a file.
  1592. *
  1593. * \param file PhysicsFS file handle to which to write.
  1594. * \param val Value to convert and write.
  1595. * \return zero on failure, non-zero on success. On failure, you can
  1596. * find out what went wrong from PHYSFS_getLastError().
  1597. */
  1598. __EXPORT__ int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1599. /**
  1600. * \fn int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
  1601. * \brief Convert and write a signed 16-bit bigendian value.
  1602. *
  1603. * Convenience function. Convert a signed 16-bit value from the platform's
  1604. * native byte order to bigendian and write it to a file.
  1605. *
  1606. * \param file PhysicsFS file handle to which to write.
  1607. * \param val Value to convert and write.
  1608. * \return zero on failure, non-zero on success. On failure, you can
  1609. * find out what went wrong from PHYSFS_getLastError().
  1610. */
  1611. __EXPORT__ int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val);
  1612. /**
  1613. * \fn int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
  1614. * \brief Convert and write an unsigned 16-bit bigendian value.
  1615. *
  1616. * Convenience function. Convert an unsigned 16-bit value from the platform's
  1617. * native byte order to bigendian and write it to a file.
  1618. *
  1619. * \param file PhysicsFS file handle to which to write.
  1620. * \param val Value to convert and write.
  1621. * \return zero on failure, non-zero on success. On failure, you can
  1622. * find out what went wrong from PHYSFS_getLastError().
  1623. */
  1624. __EXPORT__ int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val);
  1625. /**
  1626. * \fn int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1627. * \brief Convert and write a signed 32-bit littleendian value.
  1628. *
  1629. * Convenience function. Convert a signed 32-bit value from the platform's
  1630. * native byte order to littleendian and write it to a file.
  1631. *
  1632. * \param file PhysicsFS file handle to which to write.
  1633. * \param val Value to convert and write.
  1634. * \return zero on failure, non-zero on success. On failure, you can
  1635. * find out what went wrong from PHYSFS_getLastError().
  1636. */
  1637. __EXPORT__ int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1638. /**
  1639. * \fn int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1640. * \brief Convert and write an unsigned 32-bit littleendian value.
  1641. *
  1642. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1643. * native byte order to littleendian and write it to a file.
  1644. *
  1645. * \param file PhysicsFS file handle to which to write.
  1646. * \param val Value to convert and write.
  1647. * \return zero on failure, non-zero on success. On failure, you can
  1648. * find out what went wrong from PHYSFS_getLastError().
  1649. */
  1650. __EXPORT__ int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1651. /**
  1652. * \fn int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
  1653. * \brief Convert and write a signed 32-bit bigendian value.
  1654. *
  1655. * Convenience function. Convert a signed 32-bit value from the platform's
  1656. * native byte order to bigendian and write it to a file.
  1657. *
  1658. * \param file PhysicsFS file handle to which to write.
  1659. * \param val Value to convert and write.
  1660. * \return zero on failure, non-zero on success. On failure, you can
  1661. * find out what went wrong from PHYSFS_getLastError().
  1662. */
  1663. __EXPORT__ int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val);
  1664. /**
  1665. * \fn int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
  1666. * \brief Convert and write an unsigned 32-bit bigendian value.
  1667. *
  1668. * Convenience function. Convert an unsigned 32-bit value from the platform's
  1669. * native byte order to bigendian and write it to a file.
  1670. *
  1671. * \param file PhysicsFS file handle to which to write.
  1672. * \param val Value to convert and write.
  1673. * \return zero on failure, non-zero on success. On failure, you can
  1674. * find out what went wrong from PHYSFS_getLastError().
  1675. */
  1676. __EXPORT__ int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val);
  1677. /**
  1678. * \fn int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1679. * \brief Convert and write a signed 64-bit littleendian value.
  1680. *
  1681. * Convenience function. Convert a signed 64-bit value from the platform's
  1682. * native byte order to littleendian and write it to a file.
  1683. *
  1684. * \param file PhysicsFS file handle to which to write.
  1685. * \param val Value to convert and write.
  1686. * \return zero on failure, non-zero on success. On failure, you can
  1687. * find out what went wrong from PHYSFS_getLastError().
  1688. *
  1689. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1690. * any sort of 64-bit support.
  1691. */
  1692. __EXPORT__ int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1693. /**
  1694. * \fn int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1695. * \brief Convert and write an unsigned 64-bit littleendian value.
  1696. *
  1697. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1698. * native byte order to littleendian and write it to a file.
  1699. *
  1700. * \param file PhysicsFS file handle to which to write.
  1701. * \param val Value to convert and write.
  1702. * \return zero on failure, non-zero on success. On failure, you can
  1703. * find out what went wrong from PHYSFS_getLastError().
  1704. *
  1705. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1706. * any sort of 64-bit support.
  1707. */
  1708. __EXPORT__ int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1709. /**
  1710. * \fn int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
  1711. * \brief Convert and write a signed 64-bit bigending value.
  1712. *
  1713. * Convenience function. Convert a signed 64-bit value from the platform's
  1714. * native byte order to bigendian and write it to a file.
  1715. *
  1716. * \param file PhysicsFS file handle to which to write.
  1717. * \param val Value to convert and write.
  1718. * \return zero on failure, non-zero on success. On failure, you can
  1719. * find out what went wrong from PHYSFS_getLastError().
  1720. *
  1721. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1722. * any sort of 64-bit support.
  1723. */
  1724. __EXPORT__ int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  1725. /**
  1726. * \fn int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
  1727. * \brief Convert and write an unsigned 64-bit bigendian value.
  1728. *
  1729. * Convenience function. Convert an unsigned 64-bit value from the platform's
  1730. * native byte order to bigendian and write it to a file.
  1731. *
  1732. * \param file PhysicsFS file handle to which to write.
  1733. * \param val Value to convert and write.
  1734. * \return zero on failure, non-zero on success. On failure, you can
  1735. * find out what went wrong from PHYSFS_getLastError().
  1736. *
  1737. * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1738. * any sort of 64-bit support.
  1739. */
  1740. __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
  1741. /* Everything above this line is part of the PhysicsFS 1.0 API. */
  1742. /**
  1743. * \fn int PHYSFS_isInit(void)
  1744. * \brief Determine if the PhysicsFS library is initialized.
  1745. *
  1746. * Once PHYSFS_init() returns successfully, this will return non-zero.
  1747. * Before a successful PHYSFS_init() and after PHYSFS_deinit() returns
  1748. * successfully, this will return zero. This function is safe to call at
  1749. * any time.
  1750. *
  1751. * \return non-zero if library is initialized, zero if library is not.
  1752. *
  1753. * \sa PHYSFS_init
  1754. * \sa PHYSFS_deinit
  1755. */
  1756. __EXPORT__ int PHYSFS_isInit(void);
  1757. /**
  1758. * \fn int PHYSFS_symbolicLinksPermitted(void)
  1759. * \brief Determine if the symbolic links are permitted.
  1760. *
  1761. * This reports the setting from the last call to PHYSFS_permitSymbolicLinks().
  1762. * If PHYSFS_permitSymbolicLinks() hasn't been called since the library was
  1763. * last initialized, symbolic links are implicitly disabled.
  1764. *
  1765. * \return non-zero if symlinks are permitted, zero if not.
  1766. *
  1767. * \sa PHYSFS_permitSymbolicLinks
  1768. */
  1769. __EXPORT__ int PHYSFS_symbolicLinksPermitted(void);
  1770. /**
  1771. * \struct PHYSFS_Allocator
  1772. * \brief PhysicsFS allocation function pointers.
  1773. *
  1774. * (This is for limited, hardcore use. If you don't immediately see a need
  1775. * for it, you can probably ignore this forever.)
  1776. *
  1777. * You create one of these structures for use with PHYSFS_setAllocator.
  1778. * Allocators are assumed to be reentrant by the caller; please mutex
  1779. * accordingly.
  1780. *
  1781. * Allocations are always discussed in 64-bits, for future expansion...we're
  1782. * on the cusp of a 64-bit transition, and we'll probably be allocating 6
  1783. * gigabytes like it's nothing sooner or later, and I don't want to change
  1784. * this again at that point. If you're on a 32-bit platform and have to
  1785. * downcast, it's okay to return NULL if the allocation is greater than
  1786. * 4 gigabytes, since you'd have to do so anyhow.
  1787. *
  1788. * \sa PHYSFS_setAllocator
  1789. */
  1790. typedef struct
  1791. {
  1792. int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */
  1793. void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */
  1794. void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */
  1795. void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */
  1796. void (*Free)(void *); /**< Free memory from Malloc or Realloc. */
  1797. } PHYSFS_Allocator;
  1798. /**
  1799. * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator)
  1800. * \brief Hook your own allocation routines into PhysicsFS.
  1801. *
  1802. * (This is for limited, hardcore use. If you don't immediately see a need
  1803. * for it, you can probably ignore this forever.)
  1804. *
  1805. * By default, PhysicsFS will use whatever is reasonable for a platform
  1806. * to manage dynamic memory (usually ANSI C malloc/realloc/calloc/free, but
  1807. * some platforms might use something else), but in some uncommon cases, the
  1808. * app might want more control over the library's memory management. This
  1809. * lets you redirect PhysicsFS to use your own allocation routines instead.
  1810. * You can only call this function before PHYSFS_init(); if the library is
  1811. * initialized, it'll reject your efforts to change the allocator mid-stream.
  1812. * You may call this function after PHYSFS_deinit() if you are willing to
  1813. * shut down the library and restart it with a new allocator; this is a safe
  1814. * and supported operation. The allocator remains intact between deinit/init
  1815. * calls. If you want to return to the platform's default allocator, pass a
  1816. * NULL in here.
  1817. *
  1818. * If you aren't immediately sure what to do with this function, you can
  1819. * safely ignore it altogether.
  1820. *
  1821. * \param allocator Structure containing your allocator's entry points.
  1822. * \return zero on failure, non-zero on success. This call only fails
  1823. * when used between PHYSFS_init() and PHYSFS_deinit() calls.
  1824. */
  1825. __EXPORT__ int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator);
  1826. /**
  1827. * \fn int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath)
  1828. * \brief Add an archive or directory to the search path.
  1829. *
  1830. * If this is a duplicate, the entry is not added again, even though the
  1831. * function succeeds. You may not add the same archive to two different
  1832. * mountpoints: duplicate checking is done against the archive and not the
  1833. * mountpoint.
  1834. *
  1835. * When you mount an archive, it is added to a virtual file system...all files
  1836. * in all of the archives are interpolated into a single hierachical file
  1837. * tree. Two archives mounted at the same place (or an archive with files
  1838. * overlapping another mountpoint) may have overlapping files: in such a case,
  1839. * the file earliest in the search path is selected, and the other files are
  1840. * inaccessible to the application. This allows archives to be used to
  1841. * override previous revisions; you can use the mounting mechanism to place
  1842. * archives at a specific point in the file tree and prevent overlap; this
  1843. * is useful for downloadable mods that might trample over application data
  1844. * or each other, for example.
  1845. *
  1846. * The mountpoint does not need to exist prior to mounting, which is different
  1847. * than those familiar with the Unix concept of "mounting" may not expect.
  1848. * As well, more than one archive can be mounted to the same mountpoint, or
  1849. * mountpoints and archive contents can overlap...the interpolation mechanism
  1850. * still functions as usual.
  1851. *
  1852. * \param newDir directory or archive to add to the path, in
  1853. * platform-dependent notation.
  1854. * \param mountPoint Location in the interpolated tree that this archive
  1855. * will be "mounted", in platform-independent notation.
  1856. * NULL or "" is equivalent to "/".
  1857. * \param appendToPath nonzero to append to search path, zero to prepend.
  1858. * \return nonzero if added to path, zero on failure (bogus archive, dir
  1859. * missing, etc). Specifics of the error can be
  1860. * gleaned from PHYSFS_getLastError().
  1861. *
  1862. * \sa PHYSFS_removeFromSearchPath
  1863. * \sa PHYSFS_getSearchPath
  1864. * \sa PHYSFS_getMountPoint
  1865. */
  1866. __EXPORT__ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath);
  1867. /**
  1868. * \fn int PHYSFS_getMountPoint(const char *dir)
  1869. * \brief Determine a mounted archive's mountpoint.
  1870. *
  1871. * You give this function the name of an archive or dir you successfully
  1872. * added to the search path, and it reports the location in the interpolated
  1873. * tree where it is mounted. Files mounted with a NULL mountpoint or through
  1874. * PHYSFS_addToSearchPath() will report "/". The return value is READ ONLY
  1875. * and valid until the archive is removed from the search path.
  1876. *
  1877. * \param dir directory or archive previously added to the path, in
  1878. * platform-dependent notation. This must match the string
  1879. * used when adding, even if your string would also reference
  1880. * the same file with a different string of characters.
  1881. * \return READ-ONLY string of mount point if added to path, NULL on failure
  1882. * (bogus archive, etc) Specifics of the error can be gleaned from
  1883. * PHYSFS_getLastError().
  1884. *
  1885. * \sa PHYSFS_removeFromSearchPath
  1886. * \sa PHYSFS_getSearchPath
  1887. * \sa PHYSFS_getMountPoint
  1888. */
  1889. __EXPORT__ const char *PHYSFS_getMountPoint(const char *dir);
  1890. /**
  1891. * \typedef PHYSFS_StringCallback
  1892. * \brief Function signature for callbacks that report strings.
  1893. *
  1894. * These are used to report a list of strings to an original caller, one
  1895. * string per callback. All strings are UTF-8 encoded. Functions should not
  1896. * try to modify or free the string's memory.
  1897. *
  1898. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  1899. * functions that would return lists that need to be cleaned up with
  1900. * PHYSFS_freeList(). The callback means that the library doesn't need to
  1901. * allocate an entire list and all the strings up front.
  1902. *
  1903. * Be aware that promises data ordering in the list versions are not
  1904. * necessarily so in the callback versions. Check the documentation on
  1905. * specific APIs, but strings may not be sorted as you expect.
  1906. *
  1907. * \param data User-defined data pointer, passed through from the API
  1908. * that eventually called the callback.
  1909. * \param str The string data about which the callback is meant to inform.
  1910. *
  1911. * \sa PHYSFS_getCdRomDirsCallback
  1912. * \sa PHYSFS_getSearchPathCallback
  1913. */
  1914. typedef void (*PHYSFS_StringCallback)(void *data, const char *str);
  1915. /**
  1916. * \typedef PHYSFS_EnumFilesCallback
  1917. * \brief Function signature for callbacks that enumerate files.
  1918. *
  1919. * These are used to report a list of directory entries to an original caller,
  1920. * one file/dir/symlink per callback. All strings are UTF-8 encoded.
  1921. * Functions should not try to modify or free any string's memory.
  1922. *
  1923. * These callbacks are used, starting in PhysicsFS 1.1, as an alternative to
  1924. * functions that would return lists that need to be cleaned up with
  1925. * PHYSFS_freeList(). The callback means that the library doesn't need to
  1926. * allocate an entire list and all the strings up front.
  1927. *
  1928. * Be aware that promises data ordering in the list versions are not
  1929. * necessarily so in the callback versions. Check the documentation on
  1930. * specific APIs, but strings may not be sorted as you expect.
  1931. *
  1932. * \param data User-defined data pointer, passed through from the API
  1933. * that eventually called the callback.
  1934. * \param origdir A string containing the full path, in platform-independent
  1935. * notation, of the directory containing this file. In most
  1936. * cases, this is the directory on which you requested
  1937. * enumeration, passed in the callback for your convenience.
  1938. * \param fname The filename that is being enumerated. It may not be in
  1939. * alphabetical order compared to other callbacks that have
  1940. * fired, and it will not contain the full path. You can
  1941. * recreate the fullpath with $origdir/$fname ... The file
  1942. * can be a subdirectory, a file, a symlink, etc.
  1943. *
  1944. * \sa PHYSFS_enumerateFilesCallback
  1945. */
  1946. typedef void (*PHYSFS_EnumFilesCallback)(void *data, const char *origdir,
  1947. const char *fname);
  1948. /**
  1949. * \fn void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d)
  1950. * \brief Enumerate CD-ROM directories, using an application-defined callback.
  1951. *
  1952. * Internally, PHYSFS_getCdRomDirs() just calls this function and then builds
  1953. * a list before returning to the application, so functionality is identical
  1954. * except for how the information is represented to the application.
  1955. *
  1956. * Unlike PHYSFS_getCdRomDirs(), this function does not return an array.
  1957. * Rather, it calls a function specified by the application once per
  1958. * detected disc:
  1959. *
  1960. * \code
  1961. *
  1962. * static void foundDisc(void *data, const char *cddir)
  1963. * {
  1964. * printf("cdrom dir [%s] is available.\n", cddir);
  1965. * }
  1966. *
  1967. * // ...
  1968. * PHYSFS_getCdRomDirsCallback(foundDisc, NULL);
  1969. * \endcode
  1970. *
  1971. * This call may block while drives spin up. Be forewarned.
  1972. *
  1973. * \param c Callback function to notify about detected drives.
  1974. * \param d Application-defined data passed to callback. Can be NULL.
  1975. *
  1976. * \sa PHYSFS_StringCallback
  1977. * \sa PHYSFS_getCdRomDirs
  1978. */
  1979. __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d);
  1980. /**
  1981. * \fn void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d)
  1982. * \brief Enumerate the search path, using an application-defined callback.
  1983. *
  1984. * Internally, PHYSFS_getSearchPath() just calls this function and then builds
  1985. * a list before returning to the application, so functionality is identical
  1986. * except for how the information is represented to the application.
  1987. *
  1988. * Unlike PHYSFS_getSearchPath(), this function does not return an array.
  1989. * Rather, it calls a function specified by the application once per
  1990. * element of the search path:
  1991. *
  1992. * \code
  1993. *
  1994. * static void printSearchPath(void *data, const char *pathItem)
  1995. * {
  1996. * printf("[%s] is in the search path.\n", pathItem);
  1997. * }
  1998. *
  1999. * // ...
  2000. * PHYSFS_getSearchPathCallback(printSearchPath, NULL);
  2001. * \endcode
  2002. *
  2003. * Elements of the search path are reported in order search priority, so the
  2004. * first archive/dir that would be examined when looking for a file is the
  2005. * first element passed through the callback.
  2006. *
  2007. * \param c Callback function to notify about search path elements.
  2008. * \param d Application-defined data passed to callback. Can be NULL.
  2009. *
  2010. * \sa PHYSFS_StringCallback
  2011. * \sa PHYSFS_getSearchPath
  2012. */
  2013. __EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d);
  2014. /**
  2015. * \fn void PHYSFS_enumerateFilesCallback(const char *dir, PHYSFS_EnumFilesCallback c, void *d)
  2016. * \brief Get a file listing of a search path's directory, using an application-defined callback.
  2017. *
  2018. * Internally, PHYSFS_enumerateFiles() just calls this function and then builds
  2019. * a list before returning to the application, so functionality is identical
  2020. * except for how the information is represented to the application.
  2021. *
  2022. * Unlike PHYSFS_enumerateFiles(), this function does not return an array.
  2023. * Rather, it calls a function specified by the application once per
  2024. * element of the search path:
  2025. *
  2026. * \code
  2027. *
  2028. * static void printDir(void *data, const char *origdir, const char *fname)
  2029. * {
  2030. * printf(" * We've got [%s] in [%s].\n", fname, origdir);
  2031. * }
  2032. *
  2033. * // ...
  2034. * PHYSFS_enumerateFilesCallback("/some/path", printDir, NULL);
  2035. * \endcode
  2036. *
  2037. * Items sent to the callback are not guaranteed to be in any order whatsoever.
  2038. * There is no sorting done at this level, and if you need that, you should
  2039. * probably use PHYSFS_enumerateFiles() instead, which guarantees
  2040. * alphabetical sorting. This form reports whatever is discovered in each
  2041. * archive before moving on to the next. Even within one archive, we can't
  2042. * guarantee what order it will discover data. <em>Any sorting you find in
  2043. * these callbacks is just pure luck. Do not rely on it.</em>
  2044. *
  2045. * \param dir Directory, in platform-independent notation, to enumerate.
  2046. * \param c Callback function to notify about search path elements.
  2047. * \param d Application-defined data passed to callback. Can be NULL.
  2048. *
  2049. * \sa PHYSFS_EnumFilesCallback
  2050. * \sa PHYSFS_enumerateFiles
  2051. */
  2052. __EXPORT__ void PHYSFS_enumerateFilesCallback(const char *dir,
  2053. PHYSFS_EnumFilesCallback c,
  2054. void *d);
  2055. /**
  2056. * \fn void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
  2057. * \brief Convert a UCS-4 string to a UTF-8 string.
  2058. *
  2059. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2060. *
  2061. * To ensure that the destination buffer is large enough for the conversion,
  2062. * please allocate a buffer that is the same size as the source buffer. UTF-8
  2063. * never uses more than 32-bits per character, so while it may shrink a UCS-4
  2064. * string, it will never expand it.
  2065. *
  2066. * Strings that don't fit in the destination buffer will be truncated, but
  2067. * will always be null-terminated and never have an incomplete UTF-8
  2068. * sequence at the end.
  2069. *
  2070. * \param src Null-terminated source string in UCS-4 format.
  2071. * \param dst Buffer to store converted UTF-8 string.
  2072. * \param len Size, in bytes, of destination buffer.
  2073. */
  2074. __EXPORT__ void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst,
  2075. PHYSFS_uint64 len);
  2076. /**
  2077. * \fn void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
  2078. * \brief Convert a UTF-8 string to a UCS-4 string.
  2079. *
  2080. * UCS-4 strings are 32-bits per character: \c wchar_t on Unix.
  2081. *
  2082. * To ensure that the destination buffer is large enough for the conversion,
  2083. * please allocate a buffer that is four times the size of the source buffer.
  2084. * UTF-8 uses from one to four bytes per character, but UCS-4 always uses
  2085. * four, so an entirely low-ASCII string will quadruple in size!
  2086. *
  2087. * Strings that don't fit in the destination buffer will be truncated, but
  2088. * will always be null-terminated and never have an incomplete UCS-4
  2089. * sequence at the end.
  2090. *
  2091. * \param src Null-terminated source string in UTF-8 format.
  2092. * \param dst Buffer to store converted UCS-4 string.
  2093. * \param len Size, in bytes, of destination buffer.
  2094. */
  2095. __EXPORT__ void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst,
  2096. PHYSFS_uint64 len);
  2097. /**
  2098. * \fn void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
  2099. * \brief Convert a UCS-2 string to a UTF-8 string.
  2100. *
  2101. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2102. * with Unicode support.
  2103. *
  2104. * To ensure that the destination buffer is large enough for the conversion,
  2105. * please allocate a buffer that is double the size of the source buffer.
  2106. * UTF-8 never uses more than 32-bits per character, so while it may shrink
  2107. * a UCS-2 string, it may also expand it.
  2108. *
  2109. * Strings that don't fit in the destination buffer will be truncated, but
  2110. * will always be null-terminated and never have an incomplete UTF-8
  2111. * sequence at the end.
  2112. *
  2113. * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  2114. * values at this time.
  2115. *
  2116. * \param src Null-terminated source string in UCS-2 format.
  2117. * \param dst Buffer to store converted UTF-8 string.
  2118. * \param len Size, in bytes, of destination buffer.
  2119. */
  2120. __EXPORT__ void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst,
  2121. PHYSFS_uint64 len);
  2122. /**
  2123. * \fn PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
  2124. * \brief Convert a UTF-8 string to a UCS-2 string.
  2125. *
  2126. * UCS-2 strings are 16-bits per character: \c TCHAR on Windows, when building
  2127. * with Unicode support.
  2128. *
  2129. * To ensure that the destination buffer is large enough for the conversion,
  2130. * please allocate a buffer that is double the size of the source buffer.
  2131. * UTF-8 uses from one to four bytes per character, but UCS-2 always uses
  2132. * two, so an entirely low-ASCII string will double in size!
  2133. *
  2134. * Strings that don't fit in the destination buffer will be truncated, but
  2135. * will always be null-terminated and never have an incomplete UCS-2
  2136. * sequence at the end.
  2137. *
  2138. * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  2139. * values at this time.
  2140. *
  2141. * \param src Null-terminated source string in UTF-8 format.
  2142. * \param dst Buffer to store converted UCS-2 string.
  2143. * \param len Size, in bytes, of destination buffer.
  2144. */
  2145. __EXPORT__ void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst,
  2146. PHYSFS_uint64 len);
  2147. /**
  2148. * \fn void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
  2149. * \brief Convert a UTF-8 string to a Latin1 string.
  2150. *
  2151. * Latin1 strings are 8-bits per character: a popular "high ASCII"
  2152. * encoding.
  2153. *
  2154. * To ensure that the destination buffer is large enough for the conversion,
  2155. * please allocate a buffer that is double the size of the source buffer.
  2156. * UTF-8 expands latin1 codepoints over 127 from 1 to 2 bytes, so the string
  2157. * may grow in some cases.
  2158. *
  2159. * Strings that don't fit in the destination buffer will be truncated, but
  2160. * will always be null-terminated and never have an incomplete UTF-8
  2161. * sequence at the end.
  2162. *
  2163. * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  2164. * can't express most Unicode codepoints. It's a legacy encoding; you should
  2165. * be converting away from it at all times.
  2166. *
  2167. * \param src Null-terminated source string in Latin1 format.
  2168. * \param dst Buffer to store converted UTF-8 string.
  2169. * \param len Size, in bytes, of destination buffer.
  2170. */
  2171. __EXPORT__ void PHYSFS_utf8FromLatin1(const char *src, char *dst,
  2172. PHYSFS_uint64 len);
  2173. /* Everything above this line is part of the PhysicsFS 2.0 API. */
  2174. #ifdef __cplusplus
  2175. }
  2176. #endif
  2177. #endif /* !defined _INCLUDE_PHYSFS_H_ */
  2178. /* end of physfs.h ... */