misc/libphysfs/physfs.h
changeset 12218 bb5522e88ab2
parent 10017 de822cd3df3a
equal deleted inserted replaced
12217:ea891871f481 12218:bb5522e88ab2
     6 
     6 
     7 /**
     7 /**
     8  * \mainpage PhysicsFS
     8  * \mainpage PhysicsFS
     9  *
     9  *
    10  * The latest version of PhysicsFS can be found at:
    10  * The latest version of PhysicsFS can be found at:
    11  *     http://icculus.org/physfs/
    11  *     https://icculus.org/physfs/
    12  *
    12  *
    13  * PhysicsFS; a portable, flexible file i/o abstraction.
    13  * PhysicsFS; a portable, flexible file i/o abstraction.
    14  *
    14  *
    15  * This API gives you access to a system file system in ways superior to the
    15  * This API gives you access to a system file system in ways superior to the
    16  *  stdio or system i/o calls. The brief benefits:
    16  *  stdio or system i/o calls. The brief benefits:
    17  *
    17  *
    18  *   - It's portable.
    18  *   - It's portable.
    19  *   - It's safe. No file access is permitted outside the specified dirs.
    19  *   - It's safe. No file access is permitted outside the specified dirs.
    20  *   - It's flexible. Archives (.ZIP files) can be used transparently as
    20  *   - It's flexible. Archives (.ZIP files) can be used transparently as
    21  *      directory structures.
    21  *      directory structures.
    22  *
       
    23  * This system is largely inspired by Quake 3's PK3 files and the related
       
    24  *  fs_* cvars. If you've ever tinkered with these, then this API will be
       
    25  *  familiar to you.
       
    26  *
    22  *
    27  * With PhysicsFS, you have a single writing directory and multiple
    23  * With PhysicsFS, you have a single writing directory and multiple
    28  *  directories (the "search path") for reading. You can think of this as a
    24  *  directories (the "search path") for reading. You can think of this as a
    29  *  filesystem within a filesystem. If (on Windows) you were to set the
    25  *  filesystem within a filesystem. If (on Windows) you were to set the
    30  *  writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
    26  *  writing directory to "C:\MyGame\MyWritingDirectory", then no PHYSFS calls
   126  *  game...keeping external content on a tight leash in this manner can be of
   122  *  game...keeping external content on a tight leash in this manner can be of
   127  *  utmost importance to some applications.
   123  *  utmost importance to some applications.
   128  *
   124  *
   129  * PhysicsFS is mostly thread safe. The error messages returned by
   125  * PhysicsFS is mostly thread safe. The error messages returned by
   130  *  PHYSFS_getLastError() are unique by thread, and library-state-setting
   126  *  PHYSFS_getLastError() are unique by thread, and library-state-setting
   131  *  functions are mutex'd. For efficiency, individual file accesses are
   127  *  functions are mutex'd. For efficiency, individual file accesses are 
   132  *  not locked, so you can not safely read/write/seek/close/etc the same
   128  *  not locked, so you can not safely read/write/seek/close/etc the same 
   133  *  file from two threads at the same time. Other race conditions are bugs
   129  *  file from two threads at the same time. Other race conditions are bugs 
   134  *  that should be reported/patched.
   130  *  that should be reported/patched.
   135  *
   131  *
   136  * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
   132  * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
   137  *  calls, doing so is not recommended, and you can not use system
   133  *  calls, doing so is not recommended, and you can not use system
   138  *  filehandles with PhysicsFS and vice versa.
   134  *  filehandles with PhysicsFS and vice versa.
   401  *          or without support for various archives. You can check with
   397  *          or without support for various archives. You can check with
   402  *          PHYSFS_supportedArchiveTypes() to see if your archive type is
   398  *          PHYSFS_supportedArchiveTypes() to see if your archive type is
   403  *          supported.
   399  *          supported.
   404  *
   400  *
   405  * \sa PHYSFS_supportedArchiveTypes
   401  * \sa PHYSFS_supportedArchiveTypes
       
   402  * \sa PHYSFS_registerArchiver
       
   403  * \sa PHYSFS_deregisterArchiver
   406  */
   404  */
   407 typedef struct PHYSFS_ArchiveInfo
   405 typedef struct PHYSFS_ArchiveInfo
   408 {
   406 {
   409     const char *extension;   /**< Archive file extension: "ZIP", for example. */
   407     const char *extension;   /**< Archive file extension: "ZIP", for example. */
   410     const char *description; /**< Human-readable archive description. */
   408     const char *description; /**< Human-readable archive description. */
   411     const char *author;      /**< Person who did support for this archive. */
   409     const char *author;      /**< Person who did support for this archive. */
   412     const char *url;         /**< URL related to this archive */
   410     const char *url;         /**< URL related to this archive */
       
   411     int supportsSymlinks;    /**< non-zero if archive offers symbolic links. */
   413 } PHYSFS_ArchiveInfo;
   412 } PHYSFS_ArchiveInfo;
   414 
   413 
   415 
   414 
   416 /**
   415 /**
   417  * \struct PHYSFS_Version
   416  * \struct PHYSFS_Version
   575  * }
   574  * }
   576  * \endcode
   575  * \endcode
   577  *
   576  *
   578  * The return values are pointers to internal memory, and should
   577  * The return values are pointers to internal memory, and should
   579  *  be considered READ ONLY, and never freed. The returned values are
   578  *  be considered READ ONLY, and never freed. The returned values are
   580  *  valid until the next call to PHYSFS_deinit().
   579  *  valid until the next call to PHYSFS_deinit(), PHYSFS_registerArchiver(),
       
   580  *  or PHYSFS_deregisterArchiver().
   581  *
   581  *
   582  *   \return READ ONLY Null-terminated array of READ ONLY structures.
   582  *   \return READ ONLY Null-terminated array of READ ONLY structures.
       
   583  *
       
   584  * \sa PHYSFS_registerArchiver
       
   585  * \sa PHYSFS_deregisterArchiver
   583  */
   586  */
   584 PHYSFS_DECL const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
   587 PHYSFS_DECL const PHYSFS_ArchiveInfo **PHYSFS_supportedArchiveTypes(void);
   585 
   588 
   586 
   589 
   587 /**
   590 /**
  1092  * We've got [x.sav].
  1095  * We've got [x.sav].
  1093  * We've got [y.sav].
  1096  * We've got [y.sav].
  1094  * We've got [z.sav].
  1097  * We've got [z.sav].
  1095  * We've got [w.sav].\endverbatim
  1098  * We've got [w.sav].\endverbatim
  1096  *
  1099  *
  1097  * Feel free to sort the list however you like. We only promise there will
  1100  * Feel free to sort the list however you like. However, the returned data
  1098  *  be no duplicates, but not what order the final list will come back in.
  1101  *  will always contain no duplicates, and will be always sorted in alphabetic
       
  1102  *  (rather: Unicode) order for you.
  1099  *
  1103  *
  1100  * Don't forget to call PHYSFS_freeList() with the return value from this
  1104  * Don't forget to call PHYSFS_freeList() with the return value from this
  1101  *  function when you are done with it.
  1105  *  function when you are done with it.
  1102  *
  1106  *
  1103  *    \param dir directory in platform-independent notation to enumerate.
  1107  *    \param dir directory in platform-independent notation to enumerate.
  1544  *  the platform's native byte order.
  1548  *  the platform's native byte order.
  1545  *
  1549  *
  1546  *    \param val value to convert
  1550  *    \param val value to convert
  1547  *   \return converted value.
  1551  *   \return converted value.
  1548  *
  1552  *
       
  1553  * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
       
  1554  *          any sort of 64-bit support.
       
  1555  */
       
  1556 PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
       
  1557 
       
  1558 
       
  1559 /**
       
  1560  * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
       
  1561  * \brief Swap littleendian unsigned 64 to platform's native byte order.
       
  1562  *
       
  1563  * Take a 64-bit unsigned value in littleendian format and convert it to
       
  1564  *  the platform's native byte order.
       
  1565  *
       
  1566  *    \param val value to convert
       
  1567  *   \return converted value.
       
  1568  *
  1549  * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1569  * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1550  *          any sort of 64-bit support.
  1570  *          any sort of 64-bit support.
  1551  */
  1571  */
  1552 PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
  1572 PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1553 
  1573 
  1554 
  1574 
  1555 /**
  1575 /**
  1556  * \fn PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val)
  1576  * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1557  * \brief Swap littleendian unsigned 64 to platform's native byte order.
  1577  * \brief Swap bigendian signed 16 to platform's native byte order.
  1558  *
  1578  *
  1559  * Take a 64-bit unsigned value in littleendian format and convert it to
  1579  * Take a 16-bit signed value in bigendian format and convert it to
  1560  *  the platform's native byte order.
  1580  *  the platform's native byte order.
  1561  *
  1581  *
  1562  *    \param val value to convert
  1582  *    \param val value to convert
  1563  *   \return converted value.
  1583  *   \return converted value.
  1564  *
  1584  */
  1565  * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  1585 PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1566  *          any sort of 64-bit support.
  1586 
  1567  */
  1587 
  1568 PHYSFS_DECL PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
  1588 /**
  1569 
  1589  * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1570 
  1590  * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1571 /**
  1591  *
  1572  * \fn PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val)
  1592  * Take a 16-bit unsigned value in bigendian format and convert it to
  1573  * \brief Swap bigendian signed 16 to platform's native byte order.
       
  1574  *
       
  1575  * Take a 16-bit signed value in bigendian format and convert it to
       
  1576  *  the platform's native byte order.
  1593  *  the platform's native byte order.
  1577  *
  1594  *
  1578  *    \param val value to convert
  1595  *    \param val value to convert
  1579  *   \return converted value.
  1596  *   \return converted value.
  1580  */
  1597  */
  1581 PHYSFS_DECL PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
  1598 PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1582 
  1599 
  1583 
  1600 /**
  1584 /**
  1601  * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1585  * \fn PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val)
  1602  * \brief Swap bigendian signed 32 to platform's native byte order.
  1586  * \brief Swap bigendian unsigned 16 to platform's native byte order.
  1603  *
  1587  *
  1604  * Take a 32-bit signed value in bigendian format and convert it to
  1588  * Take a 16-bit unsigned value in bigendian format and convert it to
       
  1589  *  the platform's native byte order.
  1605  *  the platform's native byte order.
  1590  *
  1606  *
  1591  *    \param val value to convert
  1607  *    \param val value to convert
  1592  *   \return converted value.
  1608  *   \return converted value.
  1593  */
  1609  */
  1594 PHYSFS_DECL PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
  1610 PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1595 
  1611 
  1596 /**
  1612 
  1597  * \fn PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val)
  1613 /**
  1598  * \brief Swap bigendian signed 32 to platform's native byte order.
  1614  * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1599  *
  1615  * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1600  * Take a 32-bit signed value in bigendian format and convert it to
  1616  *
       
  1617  * Take a 32-bit unsigned value in bigendian format and convert it to
  1601  *  the platform's native byte order.
  1618  *  the platform's native byte order.
  1602  *
  1619  *
  1603  *    \param val value to convert
  1620  *    \param val value to convert
  1604  *   \return converted value.
  1621  *   \return converted value.
  1605  */
  1622  */
  1606 PHYSFS_DECL PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
  1623 PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1607 
  1624 
  1608 
  1625 
  1609 /**
  1626 /**
  1610  * \fn PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val)
  1627  * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
  1611  * \brief Swap bigendian unsigned 32 to platform's native byte order.
  1628  * \brief Swap bigendian signed 64 to platform's native byte order.
  1612  *
  1629  *
  1613  * Take a 32-bit unsigned value in bigendian format and convert it to
  1630  * Take a 64-bit signed value in bigendian format and convert it to
  1614  *  the platform's native byte order.
  1631  *  the platform's native byte order.
  1615  *
  1632  *
  1616  *    \param val value to convert
  1633  *    \param val value to convert
  1617  *   \return converted value.
  1634  *   \return converted value.
  1618  */
  1635  *
  1619 PHYSFS_DECL PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
  1636  * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1620 
       
  1621 
       
  1622 /**
       
  1623  * \fn PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val)
       
  1624  * \brief Swap bigendian signed 64 to platform's native byte order.
       
  1625  *
       
  1626  * Take a 64-bit signed value in bigendian format and convert it to
       
  1627  *  the platform's native byte order.
       
  1628  *
       
  1629  *    \param val value to convert
       
  1630  *   \return converted value.
       
  1631  *
       
  1632  * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
       
  1633  *          any sort of 64-bit support.
  1637  *          any sort of 64-bit support.
  1634  */
  1638  */
  1635 PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1639 PHYSFS_DECL PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
  1636 
  1640 
  1637 
  1641 
  1991  *    \param file PhysicsFS file handle to which to write.
  1995  *    \param file PhysicsFS file handle to which to write.
  1992  *    \param val Value to convert and write.
  1996  *    \param val Value to convert and write.
  1993  *   \return zero on failure, non-zero on success. On failure, you can
  1997  *   \return zero on failure, non-zero on success. On failure, you can
  1994  *           find out what went wrong from PHYSFS_getLastError().
  1998  *           find out what went wrong from PHYSFS_getLastError().
  1995  *
  1999  *
  1996  * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  2000  * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  1997  *          any sort of 64-bit support.
  2001  *          any sort of 64-bit support.
  1998  */
  2002  */
  1999 PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  2003 PHYSFS_DECL int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val);
  2000 
  2004 
  2001 
  2005 
  2027  *    \param file PhysicsFS file handle to which to write.
  2031  *    \param file PhysicsFS file handle to which to write.
  2028  *    \param val Value to convert and write.
  2032  *    \param val Value to convert and write.
  2029  *   \return zero on failure, non-zero on success. On failure, you can
  2033  *   \return zero on failure, non-zero on success. On failure, you can
  2030  *           find out what went wrong from PHYSFS_getLastError().
  2034  *           find out what went wrong from PHYSFS_getLastError().
  2031  *
  2035  *
  2032  * \warning Remember, PHYSFS_uint64 is only 32 bits on platforms without
  2036  * \warning Remember, PHYSFS_sint64 is only 32 bits on platforms without
  2033  *          any sort of 64-bit support.
  2037  *          any sort of 64-bit support.
  2034  */
  2038  */
  2035 PHYSFS_DECL int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  2039 PHYSFS_DECL int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val);
  2036 
  2040 
  2037 
  2041 
  2602  *
  2606  *
  2603  * \sa PHYSFS_stat
  2607  * \sa PHYSFS_stat
  2604  */
  2608  */
  2605 typedef enum PHYSFS_FileType
  2609 typedef enum PHYSFS_FileType
  2606 {
  2610 {
  2607     PHYSFS_FILETYPE_REGULAR, /**< a normal file */
  2611 	PHYSFS_FILETYPE_REGULAR, /**< a normal file */
  2608     PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
  2612 	PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
  2609     PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
  2613 	PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
  2610     PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
  2614 	PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
  2611 } PHYSFS_FileType;
  2615 } PHYSFS_FileType;
  2612 
  2616 
  2613 /**
  2617 /**
  2614  * \struct PHYSFS_Stat
  2618  * \struct PHYSFS_Stat
  2615  * \brief Meta data for a file or directory
  2619  * \brief Meta data for a file or directory
  2626  * \sa PHYSFS_stat
  2630  * \sa PHYSFS_stat
  2627  * \sa PHYSFS_FileType
  2631  * \sa PHYSFS_FileType
  2628  */
  2632  */
  2629 typedef struct PHYSFS_Stat
  2633 typedef struct PHYSFS_Stat
  2630 {
  2634 {
  2631     PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
  2635 	PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
  2632     PHYSFS_sint64 modtime;  /**< last modification time */
  2636 	PHYSFS_sint64 modtime;  /**< last modification time */
  2633     PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
  2637 	PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
  2634     PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
  2638 	PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
  2635     PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
  2639 	PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
  2636     int readonly; /**< non-zero if read only, zero if writable. */
  2640 	int readonly; /**< non-zero if read only, zero if writable. */
  2637 } PHYSFS_Stat;
  2641 } PHYSFS_Stat;
  2638 
  2642 
  2639 /**
  2643 /**
  2640  * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
  2644  * \fn int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat)
  2641  * \brief Get various information about a directory or a file.
  2645  * \brief Get various information about a directory or a file.
  3131     PHYSFS_ERR_UNSUPPORTED,      /**< Operation or feature unsupported.     */
  3135     PHYSFS_ERR_UNSUPPORTED,      /**< Operation or feature unsupported.     */
  3132     PHYSFS_ERR_PAST_EOF,         /**< Attempted to access past end of file. */
  3136     PHYSFS_ERR_PAST_EOF,         /**< Attempted to access past end of file. */
  3133     PHYSFS_ERR_FILES_STILL_OPEN, /**< Files still open.                     */
  3137     PHYSFS_ERR_FILES_STILL_OPEN, /**< Files still open.                     */
  3134     PHYSFS_ERR_INVALID_ARGUMENT, /**< Bad parameter passed to an function.  */
  3138     PHYSFS_ERR_INVALID_ARGUMENT, /**< Bad parameter passed to an function.  */
  3135     PHYSFS_ERR_NOT_MOUNTED,      /**< Requested archive/dir not mounted.    */
  3139     PHYSFS_ERR_NOT_MOUNTED,      /**< Requested archive/dir not mounted.    */
  3136     PHYSFS_ERR_NO_SUCH_PATH,     /**< No such file, directory, or parent.   */
  3140     PHYSFS_ERR_NOT_FOUND,        /**< File (or whatever) not found.         */
  3137     PHYSFS_ERR_SYMLINK_FORBIDDEN,/**< Symlink seen when not permitted.      */
  3141     PHYSFS_ERR_SYMLINK_FORBIDDEN,/**< Symlink seen when not permitted.      */
  3138     PHYSFS_ERR_NO_WRITE_DIR,     /**< No write dir has been specified.      */
  3142     PHYSFS_ERR_NO_WRITE_DIR,     /**< No write dir has been specified.      */
  3139     PHYSFS_ERR_OPEN_FOR_READING, /**< Wrote to a file opened for reading.   */
  3143     PHYSFS_ERR_OPEN_FOR_READING, /**< Wrote to a file opened for reading.   */
  3140     PHYSFS_ERR_OPEN_FOR_WRITING, /**< Read from a file opened for writing.  */
  3144     PHYSFS_ERR_OPEN_FOR_WRITING, /**< Read from a file opened for writing.  */
  3141     PHYSFS_ERR_NOT_A_FILE,       /**< Needed a file, got a directory (etc). */
  3145     PHYSFS_ERR_NOT_A_FILE,       /**< Needed a file, got a directory (etc). */
  3146     PHYSFS_ERR_PERMISSION,       /**< Permission denied.                    */
  3150     PHYSFS_ERR_PERMISSION,       /**< Permission denied.                    */
  3147     PHYSFS_ERR_NO_SPACE,         /**< No space (disk full, over quota, etc) */
  3151     PHYSFS_ERR_NO_SPACE,         /**< No space (disk full, over quota, etc) */
  3148     PHYSFS_ERR_BAD_FILENAME,     /**< Filename is bogus/insecure.           */
  3152     PHYSFS_ERR_BAD_FILENAME,     /**< Filename is bogus/insecure.           */
  3149     PHYSFS_ERR_BUSY,             /**< Tried to modify a file the OS needs.  */
  3153     PHYSFS_ERR_BUSY,             /**< Tried to modify a file the OS needs.  */
  3150     PHYSFS_ERR_DIR_NOT_EMPTY,    /**< Tried to delete dir with files in it. */
  3154     PHYSFS_ERR_DIR_NOT_EMPTY,    /**< Tried to delete dir with files in it. */
  3151     PHYSFS_ERR_OS_ERROR          /**< Unspecified OS-level error.           */
  3155     PHYSFS_ERR_OS_ERROR,         /**< Unspecified OS-level error.           */
       
  3156     PHYSFS_ERR_DUPLICATE,        /**< Duplicate entry.                      */
       
  3157     PHYSFS_ERR_BAD_PASSWORD      /**< Bad password.                         */
  3152 } PHYSFS_ErrorCode;
  3158 } PHYSFS_ErrorCode;
  3153 
  3159 
  3154 
  3160 
  3155 /**
  3161 /**
  3156  * \fn PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
  3162  * \fn PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
  3309  * \sa PHYSFS_getUserDir
  3315  * \sa PHYSFS_getUserDir
  3310  */
  3316  */
  3311 PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app);
  3317 PHYSFS_DECL const char *PHYSFS_getPrefDir(const char *org, const char *app);
  3312 
  3318 
  3313 
  3319 
       
  3320 /**
       
  3321  * \struct PHYSFS_Archiver
       
  3322  * \brief Abstract interface to provide support for user-defined archives.
       
  3323  *
       
  3324  * \warning This is advanced, hardcore stuff. You don't need this unless you
       
  3325  *          really know what you're doing. Most apps will not need this.
       
  3326  *
       
  3327  * Historically, PhysicsFS provided a means to mount various archive file
       
  3328  *  formats, and physical directories in the native filesystem. However,
       
  3329  *  applications have been limited to the file formats provided by the
       
  3330  *  library. This interface allows an application to provide their own
       
  3331  *  archive file types.
       
  3332  *
       
  3333  * Conceptually, a PHYSFS_Archiver provides directory entries, while
       
  3334  *  PHYSFS_Io provides data streams for those directory entries. The most
       
  3335  *  obvious use of PHYSFS_Archiver is to provide support for an archive
       
  3336  *  file type that isn't provided by PhysicsFS directly: perhaps some
       
  3337  *  proprietary format that only your application needs to understand.
       
  3338  *
       
  3339  * Internally, all the built-in archive support uses this interface, so the
       
  3340  *  best examples for building a PHYSFS_Archiver is the source code to
       
  3341  *  PhysicsFS itself.
       
  3342  *
       
  3343  * An archiver is added to the system with PHYSFS_registerArchiver(), and then
       
  3344  *  it will be available for use automatically with PHYSFS_mount(); if a
       
  3345  *  given archive can be handled with your archiver, it will be given control
       
  3346  *  as appropriate.
       
  3347  *
       
  3348  * These methods deal with dir handles. You have one instance of your
       
  3349  *  archiver, and it generates a unique, opaque handle for each opened
       
  3350  *  archive in its openArchive() method. Since the lifetime of an Archiver
       
  3351  *  (not an archive) is generally the entire lifetime of the process, and it's
       
  3352  *  assumed to be a singleton, we do not provide any instance data for the
       
  3353  *  archiver itself; the app can just use some static variables if necessary.
       
  3354  *
       
  3355  * Symlinks should always be followed (except in stat()); PhysicsFS will
       
  3356  *  use the stat() method to check for symlinks and make a judgement on
       
  3357  *  whether to continue to call other methods based on that.
       
  3358  *
       
  3359  * Archivers, when necessary, should set the PhysicsFS error state with
       
  3360  *  PHYSFS_setErrorCode() before returning. PhysicsFS will pass these errors
       
  3361  *  back to the application unmolested in most cases.
       
  3362  *
       
  3363  * Thread safety: TO BE DECIDED.  !!! FIXME
       
  3364  *
       
  3365  * \sa PHYSFS_registerArchiver
       
  3366  * \sa PHYSFS_deregisterArchiver
       
  3367  * \sa PHYSFS_supportedArchiveTypes
       
  3368  */
       
  3369 typedef struct PHYSFS_Archiver
       
  3370 {
       
  3371 
       
  3372 // !!! FIXME: split read/write interfaces?
       
  3373 
       
  3374     /**
       
  3375      * \brief Binary compatibility information.
       
  3376      *
       
  3377      * This must be set to zero at this time. Future versions of this
       
  3378      *  struct will increment this field, so we know what a given
       
  3379      *  implementation supports. We'll presumably keep supporting older
       
  3380      *  versions as we offer new features, though.
       
  3381      */
       
  3382     PHYSFS_uint32 version;
       
  3383 
       
  3384     /**
       
  3385      * \brief Basic info about this archiver.
       
  3386      *
       
  3387      * This is used to identify your archive, and is returned in
       
  3388      *  PHYSFS_supportedArchiveTypes().
       
  3389      */
       
  3390     PHYSFS_ArchiveInfo info;
       
  3391 
       
  3392 // !!! FIXME: documentation: \brief?
       
  3393     /**
       
  3394      * \brief
       
  3395      *
       
  3396      * Open an archive provided by (io).
       
  3397      *  (name) is a filename associated with (io), but doesn't necessarily
       
  3398      *  map to anything, let alone a real filename. This possibly-
       
  3399      *  meaningless name is in platform-dependent notation.
       
  3400      * (forWrite) is non-zero if this is to be used for
       
  3401      *  the write directory, and zero if this is to be used for an
       
  3402      *  element of the search path.
       
  3403      * Return NULL on failure. We ignore any error code you set here;
       
  3404      *  when PHYSFS_mount() returns, the error will be PHYSFS_ERR_UNSUPPORTED
       
  3405      *  (no Archivers could handle this data).  // !!! FIXME: yeah?
       
  3406      *  Returns non-NULL on success. The pointer returned will be
       
  3407      *  passed as the "opaque" parameter for later calls.
       
  3408      */
       
  3409     void *(*openArchive)(PHYSFS_Io *io, const char *name, int forWrite);
       
  3410 
       
  3411     /**
       
  3412      * List all files in (dirname). Each file is passed to (cb),
       
  3413      *  where a copy is made if appropriate, so you should dispose of
       
  3414      *  it properly upon return from the callback.
       
  3415      * If you have a failure, report as much as you can.
       
  3416      *  (dirname) is in platform-independent notation.
       
  3417      */
       
  3418     void (*enumerateFiles)(void *opaque, const char *dirname,
       
  3419                            PHYSFS_EnumFilesCallback cb,
       
  3420                            const char *origdir, void *callbackdata);
       
  3421 
       
  3422     /**
       
  3423      * Open file for reading.
       
  3424      *  This filename, (fnm), is in platform-independent notation.
       
  3425      * If you can't handle multiple opens of the same file,
       
  3426      *  you can opt to fail for the second call.
       
  3427      * Fail if the file does not exist.
       
  3428      * Returns NULL on failure, and calls PHYSFS_setErrorCode().
       
  3429      *  Returns non-NULL on success. The pointer returned will be
       
  3430      *  passed as the "opaque" parameter for later file calls.
       
  3431      */
       
  3432     PHYSFS_Io *(*openRead)(void *opaque, const char *fnm);
       
  3433 
       
  3434     /**
       
  3435      * Open file for writing.
       
  3436      * If the file does not exist, it should be created. If it exists,
       
  3437      *  it should be truncated to zero bytes. The writing
       
  3438      *  offset should be the start of the file.
       
  3439      * This filename is in platform-independent notation.
       
  3440      * If you can't handle multiple opens of the same file,
       
  3441      *  you can opt to fail for the second call.
       
  3442      * Returns NULL on failure, and calls PHYSFS_setErrorCode().
       
  3443      *  Returns non-NULL on success. The pointer returned will be
       
  3444      *  passed as the "opaque" parameter for later file calls.
       
  3445      */
       
  3446     PHYSFS_Io *(*openWrite)(void *opaque, const char *filename);
       
  3447 
       
  3448     /**
       
  3449      * Open file for appending.
       
  3450      * If the file does not exist, it should be created. The writing
       
  3451      *  offset should be the end of the file.
       
  3452      * This filename is in platform-independent notation.
       
  3453      * If you can't handle multiple opens of the same file,
       
  3454      *  you can opt to fail for the second call.
       
  3455      * Returns NULL on failure, and calls PHYSFS_setErrorCode().
       
  3456      *  Returns non-NULL on success. The pointer returned will be
       
  3457      *  passed as the "opaque" parameter for later file calls.
       
  3458      */
       
  3459     PHYSFS_Io *(*openAppend)(void *opaque, const char *filename);
       
  3460 
       
  3461     /**
       
  3462      * Delete a file in the archive/directory.
       
  3463      *  Return non-zero on success, zero on failure.
       
  3464      *  This filename is in platform-independent notation.
       
  3465      *  This method may be NULL.
       
  3466      * On failure, call PHYSFS_setErrorCode().
       
  3467      */
       
  3468     int (*remove)(void *opaque, const char *filename);
       
  3469 
       
  3470     /**
       
  3471      * Create a directory in the archive/directory.
       
  3472      *  If the application is trying to make multiple dirs, PhysicsFS
       
  3473      *  will split them up into multiple calls before passing them to
       
  3474      *  your driver.
       
  3475      *  Return non-zero on success, zero on failure.
       
  3476      *  This filename is in platform-independent notation.
       
  3477      *  This method may be NULL.
       
  3478      * On failure, call PHYSFS_setErrorCode().
       
  3479      */
       
  3480     int (*mkdir)(void *opaque, const char *filename);
       
  3481 
       
  3482     /**
       
  3483      * Obtain basic file metadata.
       
  3484      *  Returns non-zero on success, zero on failure.
       
  3485      *  On failure, call PHYSFS_setErrorCode().
       
  3486      */
       
  3487     int (*stat)(void *opaque, const char *fn, PHYSFS_Stat *stat);
       
  3488 
       
  3489     /**
       
  3490      * Close directories/archives, and free any associated memory,
       
  3491      *  including the original PHYSFS_Io and (opaque) itself, if
       
  3492      *  applicable. Implementation can assume that it won't be called if
       
  3493      *  there are still files open from this archive.
       
  3494      */
       
  3495     void (*closeArchive)(void *opaque);
       
  3496 } PHYSFS_Archiver;
       
  3497 
       
  3498 /**
       
  3499  * \fn int PHYSFS_registerArchiver(const PHYSFS_Archiver *archiver)
       
  3500  * \brief Add a new archiver to the system.
       
  3501  *
       
  3502  * !!! FIXME: write me.
       
  3503  *
       
  3504  * You may not have two archivers that handle the same extension. If you are
       
  3505  *  going to have a clash, you can deregister the other archiver (including
       
  3506  *  built-in ones) with PHYSFS_deregisterArchiver().
       
  3507  *
       
  3508  * The data in (archiver) is copied; you may free this pointer when this
       
  3509  *  function returns.
       
  3510  *
       
  3511  *   \param archiver The archiver to register.
       
  3512  *  \return Zero on error, non-zero on success.
       
  3513  *
       
  3514  * \sa PHYSFS_Archiver
       
  3515  * \sa PHYSFS_deregisterArchiver
       
  3516  */
       
  3517 PHYSFS_DECL int PHYSFS_registerArchiver(const PHYSFS_Archiver *archiver);
       
  3518 
       
  3519 /**
       
  3520  * \fn int PHYSFS_deregisterArchiver(const char *ext)
       
  3521  * \brief Remove an archiver from the system.
       
  3522  *
       
  3523  * !!! FIXME: write me.
       
  3524  *
       
  3525  * This fails if there are any archives still open that use this archiver.
       
  3526  *
       
  3527  *   \param ext Filename extension that the archiver handles.
       
  3528  *  \return Zero on error, non-zero on success.
       
  3529  *
       
  3530  * \sa PHYSFS_Archiver
       
  3531  * \sa PHYSFS_registerArchiver
       
  3532  */
       
  3533 PHYSFS_DECL int PHYSFS_deregisterArchiver(const char *ext);
       
  3534 
       
  3535 
  3314 /* Everything above this line is part of the PhysicsFS 2.1 API. */
  3536 /* Everything above this line is part of the PhysicsFS 2.1 API. */
  3315 
       
  3316 
  3537 
  3317 #ifdef __cplusplus
  3538 #ifdef __cplusplus
  3318 }
  3539 }
  3319 #endif
  3540 #endif
  3320 
  3541