physfs.h
changeset 1 b5ce9d35fdb4
child 2 24ba671694af
equal deleted inserted replaced
0:7672c9962ce6 1:b5ce9d35fdb4
       
     1 /**
       
     2  * PhysicsFS; a portable, flexible file i/o abstraction.
       
     3  *
       
     4  * This API gives you access to a system file system in ways superior to the
       
     5  *  stdio or system i/o calls. The brief benefits:
       
     6  *
       
     7  *   - It's portable.
       
     8  *   - It can handle byte ordering on alternative processors.
       
     9  *   - It's safe. No file access is permitted outside the specified dirs.
       
    10  *   - It's flexible. Archives (.ZIP files) can be used transparently as
       
    11  *      directory structures.
       
    12  *
       
    13  * This system is largely inspired by Quake 3's PK3 files and the related
       
    14  *  fs_* cvars. If you've ever tinkered with these, then this API will be very
       
    15  *  familiar to you.
       
    16  *
       
    17  * With the PhysicsFS, you have a single writing directory and multiple
       
    18  *  "search paths" for reading. You can think of this as a filesystem within a
       
    19  *  filesystem. If (on Windows) you were to set the writing directory to
       
    20  *  "C:\MyGame\MyWritingDirectory", then no PHYSFS calls could touch anything
       
    21  *  above this directory, including the "C:\MyGame" and "C:\" directories.
       
    22  *  This prevents an application's internal scripting language from piddling
       
    23  *  over c:\config.sys, for example. If you'd rather give PHYSFS full access
       
    24  *  to the system's REAL file system, set the writing path to "C:\", but
       
    25  *  that's generally A Bad Thing for several reasons.
       
    26  *
       
    27  * Drive letters are hidden in PhysicsFS once you set up your initial paths.
       
    28  *  The search paths create a single, hierarchical directory structure.
       
    29  *  Not only does this lend itself well to general abstraction with archives,
       
    30  *  it also gives better support to operating systems like MacOS and Unix.
       
    31  *  Generally speaking, you shouldn't ever hardcode a drive letter; not only
       
    32  *  does this hurt portability to non-Microsoft OSes, but it limits your win32
       
    33  *  users to a single drive, too. Use the PhysicsFS abstraction functions and
       
    34  *  allow user-defined configuration options, too. When opening a file, you
       
    35  *  specify it like it was on a Unix filesystem: if you want to write to
       
    36  *  "C:\MyGame\MyConfigFiles\game.cfg", then you might set the write path to
       
    37  *  "C:\MyGame" and then open "MyConfigFiles/game.cfg". This gives an
       
    38  *  abstraction across all platforms.
       
    39  *
       
    40  * All files opened for writing are opened in relation to the write path,
       
    41  *  which is the root of the writable filesystem. When opening a file for
       
    42  *  reading, PhysicsFS goes through it's internal search path. This is NOT the
       
    43  *  same thing as the PATH environment variable. An application using
       
    44  *  PhysicsFS specifies directories to be searched which may be actual
       
    45  *  directories, or archive files that contain files and subdirectories of
       
    46  *  their own. See the end of these docs for currently supported archive
       
    47  *  formats.
       
    48  *
       
    49  * Once a search path is defined, you may open files for reading. If you've
       
    50  *  got the following search path defined (to use a win32 example again):
       
    51  *
       
    52  *    C:\mygame
       
    53  *    C:\mygame\myuserfiles
       
    54  *    D:\mygamescdromdatafiles
       
    55  *    C:\mygame\installeddatafiles.zip
       
    56  *
       
    57  * Then a call to PHYSFS_openread("textfiles/myfile.txt") (note the directory
       
    58  *  separator) will check for C:\mygame\textfiles\myfile.txt, then
       
    59  *  C:\mygame\myuserfiles\textfiles\myfile.txt, then
       
    60  *  D:\mygamescdromdatafiles\textfiles\myfile.txt, then, finally, for
       
    61  *  textfiles\myfile.txt inside of C:\mygame\installeddatafiles.zip. Remember
       
    62  *  that most archive types and platform filesystems store their filenames in
       
    63  *  a case-sensitive manner.
       
    64  *
       
    65  * Files opened through PhysicsFS may NOT contain "." or ".." as path
       
    66  *  elements. Not only are these meaningless on MacOS, they are a security
       
    67  *  hole. Also, symbolic links (which can be found in some archive types and
       
    68  *  directly in the filesystem on Unix platforms) are NOT followed until you
       
    69  *  call PHYSFS_permitSymbolicLinks(). That's left to your own discretion, as
       
    70  *  following a symlink can allow for access outside the write and search
       
    71  *  paths. There is no mechanism for creating new symlinks in PhysicsFS.
       
    72  *
       
    73  * The write path is not included in the search path unless you specifically
       
    74  *  add it. While you CAN change the write path as many times as you like,
       
    75  *  you should probably set it once and stick to that path.
       
    76  *
       
    77  * All files are opened in binary mode; there is no endline conversion for
       
    78  *  textfiles. Other than that, PhysicsFS has some convenience functions for
       
    79  *  platform-independence. There are functions that give you the current
       
    80  *  platform's path separator ("\\" on windows, "/" on Unix, ":" on MacOS),
       
    81  *  which is needed only to set up your search/write paths. There are
       
    82  *  functions to tell you what CD-ROM drives contain accessible discs, and
       
    83  *  functions to recommend good search paths, etc. There are also functions
       
    84  *  to read 16 and 32 bit numbers from files and convert them to the native
       
    85  *  byte order of your processor.
       
    86  *
       
    87  * A recommended order for a search path is the write path, then the base path,
       
    88  *  then the cdrom path, then any archives discovered. Quake 3 does something
       
    89  *  like this, but moves the archives to the start of the search path. There
       
    90  *  is a helper function (PHYSFS_setSanePaths()) that does this for you,
       
    91  *  based on a few parameters. Also see the comments on PHYSFS_getBasePath(),
       
    92  *  and PHYSFS_getUserPath() for info on what those are and how they can help
       
    93  *  you determine an optimal searchpath.
       
    94  *
       
    95  * While you CAN mix stdio/syscall file access with PHYSFS_* calls in a
       
    96  *  program, doing so is not recommended, and you can not use system
       
    97  *  filehandles with PhysicsFS filehandles and vice versa.
       
    98  *
       
    99  * Note that archives need not be named as such: if you have a ZIP file and
       
   100  *  rename it with a .PKG extention, the file will still be recognized as a
       
   101  *  ZIP archive by PhysicsFS; the file's contents are used to determine its
       
   102  *  type.
       
   103  *
       
   104  * Currently supported archive types:
       
   105  *   - .ZIP (pkZip/WinZip/Info-ZIP compatible)
       
   106  *
       
   107  * Please see the file LICENSE in the source's root directory.
       
   108  *
       
   109  *  This file written by Ryan C. Gordon.
       
   110  */
       
   111 
       
   112 #ifndef _INCLUDE_PHYSFS_H_
       
   113 #define _INCLUDE_PHYSFS_H_
       
   114 
       
   115 #ifdef __cplusplus
       
   116 extern "C" {
       
   117 #endif
       
   118 
       
   119 
       
   120 /* functions... */
       
   121 
       
   122 
       
   123 /**
       
   124  * Get the last PhysicsFS error message as a null-terminated string.
       
   125  *  This will be NULL if there's been no error since the last call to this
       
   126  *  function. The pointer returned by this call points to a static buffer
       
   127  *  internal buffer, and this call is not thread safe.
       
   128  *
       
   129  *   @return READ ONLY string of last error message.
       
   130  */
       
   131 const char *PHYSFS_getLastError(void);
       
   132 
       
   133 
       
   134 /**
       
   135  * Get a platform-dependent path separator. This is "\\" on win32, "/" on Unix,
       
   136  *  and ":" on MacOS. It may be more than one character, depending on the
       
   137  *  platform, and your code should take that into account. Note that this is
       
   138  *  only useful for setting up the search/write paths, since access into those
       
   139  *  paths always use '/' to separate directories. This is also handy for
       
   140  *  getting platform-independent access when using stdio calls.
       
   141  *
       
   142  *   @return READ ONLY null-terminated string of platform's path separator.
       
   143  */
       
   144 const char *PHYSFS_getPathSeparator(void);
       
   145 
       
   146 
       
   147 /**
       
   148  * Get an array of paths to available CD-ROM drives. This return value should
       
   149  *  be considered READ ONLY and points to an internal buffer which may change
       
   150  *  with each call to this function. This means that this function is NOT
       
   151  *  thread safe.
       
   152  *
       
   153  * The paths returned are platform-dependent ("D:\" on Win32, "/cdrom" or
       
   154  *  whatnot on Unix). Paths are only returned if there is a disc ready and
       
   155  *  accessible in the drive. So if you've got two drives (D: and E:), and only
       
   156  *  E: has a disc in it, then that's all you get. If the user inserts a disc
       
   157  *  in D: and you call this function again, you get both drives. If, on a
       
   158  *  Unix box, the user unmounts a disc and remounts it elsewhere, the next
       
   159  *  call to this function will reflect that change. Fun.
       
   160  *
       
   161  * The returned value is an array of strings, with a NULL entry to signify the
       
   162  *  end of the list:
       
   163  *
       
   164  * char **i;
       
   165  *
       
   166  * // lock thread here, if needed.
       
   167  *
       
   168  * for (i = PHYSFS__getCdRomPaths(); *i != NULL; i++)
       
   169  *     printf("cdrom path [%s] is available.\n", *i);
       
   170  *
       
   171  * // unlock thread here, if needed.
       
   172  *
       
   173  * This call may block while drives spin up. Be forewarned.
       
   174  *
       
   175  *   @return READ ONLY null-term'd array of READ ONLY null-terminated strings.
       
   176  */
       
   177 const char **PHYSFS_getCdRomPaths(void);
       
   178 
       
   179 
       
   180 /**
       
   181  * Helper function.
       
   182  *
       
   183  * Get the "base path". This is the directory where the application was run
       
   184  *  from, which is probably the installation directory.
       
   185  *
       
   186  * You should probably use the base path in your search path.
       
   187  *
       
   188  *   @param buffer pointer to buffer to fill with recommended path.
       
   189  *   @param bufsize size of buffer pointed to by (buffer).
       
   190  *  @return a copy of (buffer), for easy use as another function's parameter.
       
   191  */
       
   192 char *PHYSFS_getBasePath(char *buffer, int bufferSize);
       
   193 
       
   194 
       
   195 /**
       
   196  * Helper function.
       
   197  *
       
   198  * Get the "user path". This is meant to be a suggestion of where a specific
       
   199  *  user of the system can store files. On Unix, this is her home directory.
       
   200  *  On systems with no concept of multiple users (MacOS, win95), this will
       
   201  *  default to the "base path" returned by PHYSFS_getBasePath().
       
   202  *
       
   203  * You should probably use the user path as the basis for your write path, and
       
   204  *  also put it near the beginning of your search path.
       
   205  *
       
   206  *   @param buffer pointer to buffer to fill with recommended path.
       
   207  *   @param bufsize size of buffer pointed to by (buffer).
       
   208  *  @return a copy of (buffer), for easy use as another function's parameter.
       
   209  */
       
   210 char *PHYSFS_getUserPath(char *buffer, int bufferSize);
       
   211 
       
   212 
       
   213 /**
       
   214  * Get the current write path. The default write path is NULL.
       
   215  *
       
   216  *   @param buffer pointer to buffer to fill with recommended path.
       
   217  *   @param bufsize size of buffer pointed to by (buffer).
       
   218  *  @return a copy of (buffer), for easy use as another function's parameter,
       
   219  *           OR NULL IF NO WRITE PATH IS CURRENTLY SET.
       
   220  */
       
   221 char *PHYSFS_getWritePath(char *buffer, int bufferSize);
       
   222 
       
   223 
       
   224 /**
       
   225  * Set a new write path. This will override the previous setting. If the
       
   226  *  directory or a parent directory doesn't exist in the physical filesystem,
       
   227  *  PhysicsFS will attempt to create them as needed.
       
   228  *
       
   229  * This call will fail (and fail to change the write path) if the current path
       
   230  *  still has files open in it.
       
   231  *
       
   232  *   @param newPath The new directory to be the root of the write path,
       
   233  *                   specified in a platform-dependent manner. Setting to NULL
       
   234  *                   disables the write path, so no files can be opened for
       
   235  *                   writing via PhysicsFS.
       
   236  *  @return non-zero on success, zero on failure. All attempts to open a file
       
   237  *           for writing via PhysicsFS will fail until this call succeeds.
       
   238  *           Specifics of the error can be gleaned from PHYSFS_getLastError().
       
   239  *
       
   240  */
       
   241 int PHYSFS_setWritePath(const char *newPath);
       
   242 
       
   243 
       
   244 /**
       
   245  * Add a directory or archive to the search path. If this is a duplicate, the
       
   246  *  entry is not added again, even though the function succeeds.
       
   247  *
       
   248  *   @param newPath directory or archive to add to the path, in
       
   249  *                   platform-dependent notation.
       
   250  *   @param appendToPath nonzero to append to search path, zero to prepend.
       
   251  *  @return nonzero if added to path, zero on failure (bogus archive, path
       
   252  *                   missing, etc). Specifics of the error can be
       
   253  *                   gleaned from PHYSFS_getLastError().
       
   254  */
       
   255 int PHYSFS_addToSearchPath(const char *newPath, int appendToPath);
       
   256 
       
   257 
       
   258 /**
       
   259  * Remove a directory or archive to the search path.
       
   260  *
       
   261  * This must be a (case-sensitive) match to a dir or archive already in the
       
   262  *  search path, specified in platform-dependent notation.
       
   263  *
       
   264  * This call will fail (and fail to remove from the path) if the element still
       
   265  *  has files open in it.
       
   266  *
       
   267  *    @param oldPath dir/archive to remove.
       
   268  *   @return nonzero on success, zero on failure.
       
   269  *            Specifics of the error can be gleaned from PHYSFS_getLastError().
       
   270  */
       
   271 int PHYSFS_removeFromSearchPath(const char *oldPath);
       
   272 
       
   273 
       
   274 /**
       
   275  * Get the current search path. The default search path is an empty list.
       
   276  *
       
   277  * This return value should be considered READ ONLY and points to an internal
       
   278  *  buffer which may change with each call to this function. This means that
       
   279  *  this function is NOT thread safe.
       
   280  *
       
   281  * The returned value is an array of strings, with a NULL entry to signify the
       
   282  *  end of the list:
       
   283  *
       
   284  * char **i;
       
   285  *
       
   286  * // lock thread here, if needed.
       
   287  *
       
   288  * for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
       
   289  *     printf("[%s] is in the search path.\n", *i);
       
   290  *
       
   291  * // unlock thread here, if needed.
       
   292  *
       
   293  *   @return READ ONLY null-term'd array of READ ONLY null-terminated strings.
       
   294  */
       
   295 const char **PHYSFS_getSearchPath(void);
       
   296 
       
   297 
       
   298 /**
       
   299  * Helper function.
       
   300  *
       
   301  * Set up sane, default paths. The write path will be set to
       
   302  *  "userpath/.appName", which is created if it doesn't exist.
       
   303  *
       
   304  * The above is sufficient to make sure your program's configuration directory
       
   305  *  is separated from other clutter, and platform-independent. The period
       
   306  *  before "mygame" even hides the directory on Unix systems.
       
   307  *
       
   308  *  The search path will be:
       
   309  *
       
   310  *    - The Write Path
       
   311  *    - The Write Path/appName
       
   312  *    - The Base Path (PHYSFS_getBasePath())
       
   313  *    - The Base Path/appName
       
   314  *    - All found CD-ROM paths (optionally)
       
   315  *    - All found CD-ROM paths/appName (optionally)
       
   316  *
       
   317  * These directories are then searched for files ending with the extension
       
   318  *  (archiveExt), which, if they are valid and supported archives, will also
       
   319  *  be added to the search path. If you specified "PKG" for (archiveExt), and
       
   320  *  there's a file named data.PKG in the base dir, it'll be checked. Archives
       
   321  *  can either be appended or prepended to the search path in alphabetical
       
   322  *  order, regardless of which directories they were found in.
       
   323  *
       
   324  * All of this can be accomplished from the application, but this just does it
       
   325  *  all for you.
       
   326  *
       
   327  *    @param appName Program-specific name of your program, to separate it
       
   328  *                   from other programs using PhysicsFS.
       
   329  *
       
   330  *    @param archiveExt File extention used by your program to specify an
       
   331  *                      archive. For example, Quake 3 uses "pk3", even though
       
   332  *                      they are just zipfiles. Specify NULL to not dig out
       
   333  *                      archives automatically.
       
   334  *
       
   335  *    @param includeCdRoms Non-zero to include CD-ROMs in the search path, and
       
   336  *                         search them for archives. This may cause a
       
   337  *                         significant amount of blocking while discs are
       
   338  *                         accessed, and if there are no discs in the drive
       
   339  *                         (or even not mounted on Unix systems), then they
       
   340  *                         may not be made available anyhow. You may want to
       
   341  *                         specify zero and handle the disc setup yourself.
       
   342  *
       
   343  *    @param archivesFirst Non-zero to prepend the archives to the search path.
       
   344  *                          Zero to append them.
       
   345  */
       
   346 void PHYSFS_setSanePaths(const char *appName, const char *archiveExt,
       
   347                          int includeCdRoms, int archivesFirst);
       
   348 
       
   349 
       
   350 /**
       
   351  * Create a directory. This is specified in platform-independent notation in
       
   352  *  relation to the write path. All missing parent directories are also
       
   353  *  created if they don't exist.
       
   354  *
       
   355  * So if you've got the write path set to "C:\mygame\writepath" and call
       
   356  *  PHYSFS_mkdir("downloads/maps") then the directories
       
   357  *  "C:\mygame\writepath\downloads" and "C:\mygame\writepath\downloads\maps"
       
   358  *  will be created if possible.
       
   359  *
       
   360  *   @param dirname New path to create.
       
   361  *  @return nonzero on success, zero on error. Specifics of the error can be
       
   362  *          gleaned from PHYSFS_getLastError().
       
   363  */
       
   364 int PHYSFS_mkdir(const char *dirName);
       
   365 
       
   366 
       
   367 /**
       
   368  * Delete a file or directory. This is specified in platform-independent
       
   369  *  notation in relation to the write path.
       
   370  *
       
   371  * A directory must be empty before this call can delete it. If you need to
       
   372  *  nuke a whole directory tree, use PHYSFS_deltree()...with care.
       
   373  *
       
   374  * So if you've got the write path set to "C:\mygame\writepath" and call
       
   375  *  PHYSFS_delete("downloads/maps/level1.map") then the file
       
   376  *  "C:\mygame\writepath\downloads\maps\level1.map" is removed from the
       
   377  *  physical filesystem, if it exists and the operating system permits the
       
   378  *  deletion.
       
   379  *
       
   380  *   @param filename Filename to delete.
       
   381  *  @return nonzero on success, zero on error. Specifics of the error can be
       
   382  *          gleaned from PHYSFS_getLastError().
       
   383  */
       
   384 int PHYSFS_delete(const char *filename);
       
   385 
       
   386 
       
   387 /**
       
   388  * Delete a directory tree. This is specified in platform-independent
       
   389  *  notation in relation to the write path.
       
   390  *
       
   391  * Be CAREFUL with this function; it will take out EVERYTHING under the
       
   392  *  specified directory with extreme prejudice.
       
   393  *
       
   394  * If you specify a filename that is not a directory, PhysicsFS will attempt
       
   395  *  to delete that single file.
       
   396  *
       
   397  * So if you've got the write path set to "C:\mygame\writepath" and call
       
   398  *  PHYSFS_deltree("downloads/maps") then the directory
       
   399  *  "C:\mygame\writepath\downloads\maps" and everything in it (including child
       
   400  *  directories) is removed from the physical filesystem, if it exists and the
       
   401  *  operating system permits the deletion.
       
   402  *
       
   403  *   @param filename root of directory tree to delete.
       
   404  *  @return nonzero on success, zero on error. Specifics of the error can be
       
   405  *          gleaned from PHYSFS_getLastError().
       
   406  */
       
   407 int PHYSFS_deltree(const char *filename);
       
   408 
       
   409 
       
   410 /**
       
   411  * Enable symbolic links. Some physical filesystems and archives contain
       
   412  *  files that are just pointers to other files. On the physical filesystem,
       
   413  *  opening such a link will (transparently) open the file that is pointed to.
       
   414  *
       
   415  * By default, PhysicsFS will check if a file is really a symlink during open
       
   416  *  calls and fail if it is. Otherwise, the link could take you outside the
       
   417  *  write and search paths, and compromise security.
       
   418  *
       
   419  * If you want to take that risk, call this function with a non-zero parameter.
       
   420  *  Note that this is more for sandboxing a program's scripting language, in
       
   421  *  case untrusted scripts try to compromise the system. Generally speaking,
       
   422  *  a user could very well have a legitimate reason to set up a symlink, so
       
   423  *  unless you feel there's a specific danger in allowing them, you should
       
   424  *  permit them.
       
   425  *
       
   426  * Symbolic link permission can be enabled or disabled at any time, and is
       
   427  *  disabled by default.
       
   428  *
       
   429  *   @param allow nonzero to permit symlinks, zero to deny linking.
       
   430  */
       
   431 void PHYSFS_permitSymbolicLinks(int allow);
       
   432 
       
   433 
       
   434 /**
       
   435  * Determine if a file exists. Just because it exists does NOT mean that you
       
   436  *  will have access to read or write it.
       
   437  *
       
   438  *   @param filename a file in platform-independent notation.
       
   439  *   @param inWritePath nonzero to check write path, zero to check search path.
       
   440  *  @return nonzero if exists, zero otherwise.
       
   441  */
       
   442 int PHYSFS_exists(const char *filename, int inWritePath);
       
   443 
       
   444 
       
   445 /**
       
   446  * Figure out where in the search path a file resides. The file is specified
       
   447  *  in platform-independent notation. The returned filename will be the
       
   448  *  element of the search path where the file was found, which may be a
       
   449  *  directory, or an archive. Even if there are multiple matches in different
       
   450  *  parts of the search path, only the first one found is used, just like
       
   451  *  when opening a file.
       
   452  *
       
   453  * So, if you look for "maps/level1.map", and C:\mygame is in your search
       
   454  *  path and C:\mygame\maps\level1.map exists, then buffer will be filled in
       
   455  *  with "C:\mygame\maps\level1.map" and the function returns nonzero.
       
   456  *
       
   457  *     @param buffer pointer to buffer to fill with path.
       
   458  *     @param bufsize size of buffer pointed to by (buffer).
       
   459  *     @param filename file to look for.
       
   460  *    @return nonzero if file was found, zero otherwise. If found, (buffer)
       
   461  *             will be filled in.
       
   462  */
       
   463 int PHYSFS_getRealPath(const char *filename, char *buffer, int bufSize);
       
   464 
       
   465 
       
   466 /**
       
   467  * Open a file for writing, in platform-independent notation and in relation
       
   468  *  to the write path as the root of the writable filesystem. The specified
       
   469  *  file is created if it doesn't exist. If it does exist, it is truncated to
       
   470  *  zero bytes, and the writing offset is set to the start.
       
   471  *
       
   472  *   @param filename File to open.
       
   473  *  @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
       
   474  *           of the error can be gleaned from PHYSFS_getLastError().
       
   475  */
       
   476 void *PHYSFS_openWrite(const char *filename);
       
   477 
       
   478 
       
   479 /**
       
   480  * Open a file for writing, in platform-independent notation and in relation
       
   481  *  to the write path as the root of the writable filesystem. The specified
       
   482  *  file is created if it doesn't exist. If it does exist, the writing offset
       
   483  *  is set to the end of the file, so the first write will be the byte after
       
   484  *  the end.
       
   485  *
       
   486  *   @param filename File to open.
       
   487  *  @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
       
   488  *           of the error can be gleaned from PHYSFS_getLastError().
       
   489  */
       
   490 void *PHYSFS_openAppend(const char *filename);
       
   491 
       
   492 
       
   493 /**
       
   494  * Open a file for reading, in platform-independent notation. The search path
       
   495  *  is checked one at a time until a matching file is found, in which case an
       
   496  *  abstract filehandle is associated with it, and reading may be done.
       
   497  *  The reading offset is set to the first byte of the file.
       
   498  *
       
   499  *   @param filename File to open.
       
   500  *  @return A valid PhysicsFS filehandle on success, NULL on error. Specifics
       
   501  *           of the error can be gleaned from PHYSFS_getLastError().
       
   502  */
       
   503 void *PHYSFS_openRead(const char *filename);
       
   504 
       
   505 
       
   506 /**
       
   507  * Close a PhysicsFS filehandle. This call is capable of failing if the
       
   508  *  operating system was buffering writes to this file, and (now forced to
       
   509  *  write those changes to physical media) can not store the data for any
       
   510  *  reason. In such a case, the filehandle stays open. A well-written program
       
   511  *  should ALWAYS check the return value from the close call in addition to
       
   512  *  every writing call!
       
   513  *
       
   514  *   @param handle handle returned from PHYSFS_open*().
       
   515  *  @return nonzero on success, zero on error. Specifics of the error can be
       
   516  *          gleaned from PHYSFS_getLastError().
       
   517  */
       
   518 int PHYSFS_close(void *handle);
       
   519 
       
   520 
       
   521 /**
       
   522  * Read data from a PhysicsFS filehandle. The file must be opened for reading.
       
   523  *
       
   524  *   @param handle handle returned from PHYSFS_openRead().
       
   525  *   @param buffer buffer to store read data into.
       
   526  *   @param objSize size in bytes of objects being read from (handle).
       
   527  *   @param objCount number of (objSize) objects to read from (handle).
       
   528  *  @return number of objects read. PHYSFS_getLastError() can shed light on
       
   529  *           the reason this might be < (objCount).
       
   530  */
       
   531 int PHYSFS_read(void *handle, void *buffer, int objSize, int objCount);
       
   532 
       
   533 
       
   534 /**
       
   535  * Write data to a PhysicsFS filehandle. The file must be opened for writing.
       
   536  *
       
   537  *   @param handle retval from PHYSFS_openWrite() or PHYSFS_openAppend().
       
   538  *   @param buffer buffer to store read data into.
       
   539  *   @param objSize size in bytes of objects being read from (handle).
       
   540  *   @param objCount number of (objSize) objects to read from (handle).
       
   541  *  @return number of objects read. PHYSFS_getLastError() can shed light on
       
   542  *           the reason this might be < (objCount).
       
   543  */
       
   544 int PHYSFS_write(void *handle, void *buffer, int objSize, int objCount);
       
   545 
       
   546 
       
   547 /**
       
   548  * Determine if the end of file has been reached in a PhysicsFS filehandle.
       
   549  *
       
   550  *   @param handle handle returned from PHYSFS_openRead().
       
   551  *  @return nonzero if EOF, zero if not.
       
   552  */
       
   553 int PHYSFS_eof(void *handle);
       
   554 
       
   555 
       
   556 /**
       
   557  * Determine current position within a PhysicsFS filehandle.
       
   558  *
       
   559  *   @param handle handle returned from PHYSFS_open*().
       
   560  *  @return offset in bytes from start of file. -1 if error occurred.
       
   561  *           Specifics of the error can be gleaned from PHYSFS_getLastError().
       
   562  */
       
   563 int PHYSFS_tell(void *handle);
       
   564 
       
   565 
       
   566 /**
       
   567  * Seek to a new position within a PhysicsFS filehandle. The next read or write
       
   568  *  will occur at that place. Seeking past the beginning or end of the file is
       
   569  *  not allowed.
       
   570  *
       
   571  *   @param handle handle returned from PHYSFS_open*().
       
   572  *   @param pos number of bytes from start of file to seek to.
       
   573  *  @return nonzero on success, zero on error. Specifics of the error can be
       
   574  *          gleaned from PHYSFS_getLastError().
       
   575  */
       
   576 int PHYSFS_seek(void *handle, int pos);
       
   577 
       
   578 
       
   579 /* Byte-order reading. !!!  Need types (Int16, Int32, etc) for these...
       
   580 int PHYSFS_readLE16(void *handle, int *buffer);
       
   581 int PHYSFS_readLE32(void *handle, int *buffer);
       
   582 int PHYSFS_readBE16(void *handle, int *buffer);
       
   583 int PHYSFS_readBE32(void *handle, int *buffer);
       
   584 int PHYSFS_writeLE16(void *handle, int buffer);
       
   585 int PHYSFS_writeLE32(void *handle, int buffer);
       
   586 int PHYSFS_writeBE16(void *handle, int buffer);
       
   587 int PHYSFS_writeBE32(void *handle, int buffer);
       
   588 */
       
   589 
       
   590 #ifdef __cplusplus
       
   591 }
       
   592 #endif
       
   593 
       
   594 #endif  /* !defined _INCLUDE_PHYSFS_H_ */
       
   595 
       
   596 /* end of physfs.h ... */
       
   597