physfs.h 82 KB

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