physfs.h 92 KB

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