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