physfs_internal.h
changeset 11 677e01f5109e
parent 9 1155788ccbe3
child 12 a4041c91d715
equal deleted inserted replaced
10:45bd486c0224 11:677e01f5109e
    13 #ifndef __PHYSICSFS_INTERNAL__
    13 #ifndef __PHYSICSFS_INTERNAL__
    14 #error Do not include this header from your applications.
    14 #error Do not include this header from your applications.
    15 #endif
    15 #endif
    16 
    16 
    17 struct __PHYSFS_DIRREADER__;
    17 struct __PHYSFS_DIRREADER__;
       
    18 struct __PHYSFS_FILEFUNCTIONS__;
    18 
    19 
    19 typedef struct __PHYSFS_FILEHANDLE__
    20 typedef struct __PHYSFS_FILEHANDLE__
    20 {
    21 {
    21         /*
    22         /*
    22          * This is reserved for the driver to store information.
    23          * This is reserved for the driver to store information.
    23          */
    24          */
    24     void *opaque;
    25     void *opaque;
    25 
    26 
    26         /*
    27         /*
    27          * This should be the DirReader that created this FileHandle.
    28          * This should be the DirHandle that created this FileHandle.
    28          */
    29          */
    29     struct __PHYSFS_DIRREADER__ *dirReader;
    30     const struct __PHYSFS_DIRREADER__ *dirReader;
    30 
    31 
       
    32         /*
       
    33          * Pointer to the file i/o functions for this filehandle.
       
    34          */
       
    35     const struct __PHYSFS_FILEFUNCTIONS__ *funcs;
       
    36 } FileHandle;
       
    37 
       
    38 
       
    39 typedef struct __PHYSFS_FILEFUNCTIONS__
       
    40 {
    31         /*
    41         /*
    32          * Read more from the file.
    42          * Read more from the file.
    33          */
    43          */
    34     int (*read)(struct __PHYSFS_FILEHANDLE__ *handle, void *buffer,
    44     int (*read)(FileHandle *handle, void *buffer,
    35                 unsigned int objSize, unsigned int objCount);
    45                 unsigned int objSize, unsigned int objCount);
    36 
    46 
    37         /*
    47         /*
    38          * Write more to the file. Archives don't have to implement this.
    48          * Write more to the file. Archives don't have to implement this.
    39          *  (Set it to NULL if not implemented).
    49          *  (Set it to NULL if not implemented).
    40          */
    50          */
    41     int (*write)(struct __PHYSFS_FILEHANDLE__ *handle, void *buffer,
    51     int (*write)(FileHandle *handle, void *buffer,
    42                  unsigned int objSize, unsigned int objCount);
    52                  unsigned int objSize, unsigned int objCount);
    43 
    53 
    44         /*
    54         /*
    45          * Returns non-zero if at end of file.
    55          * Returns non-zero if at end of file.
    46          */
    56          */
    47     int (*eof)(struct __PHYSFS_FILEHANDLE__ *handle);
    57     int (*eof)(FileHandle *handle);
    48 
    58 
    49         /*
    59         /*
    50          * Returns byte offset from start of file.
    60          * Returns byte offset from start of file.
    51          */
    61          */
    52     int (*tell)(struct __PHYSFS_FILEHANDLE__ *handle);
    62     int (*tell)(FileHandle *handle);
    53 
    63 
    54         /*
    64         /*
    55          * Move read/write pointer to byte offset from start of file.
    65          * Move read/write pointer to byte offset from start of file.
    56          *  Returns non-zero on success, zero on error.
    66          *  Returns non-zero on success, zero on error.
    57          */
    67          */
    58     int (*seek)(struct __PHYSFS_FILEHANDLE__ *handle, int offset);
    68     int (*seek)(FileHandle *handle, int offset);
    59 
    69 
    60         /*
    70         /*
    61          * Close the file, and free this structure (including "opaque").
    71          * Close the file, and free the FileHandle structure (including "opaque").
    62          */
    72          */
    63     int (*close)(void);
    73     int (*close)(FileHandle *handle);
    64 } FileHandle;
    74 } FileFunctions;
    65 
    75 
    66 
    76 
    67 typedef struct __PHYSFS_DIRREADER__
    77 typedef struct __PHYSFS_DIRREADER__
    68 {
    78 {
    69         /*
    79         /*
    70          * This is reserved for the driver to store information.
    80          * This is reserved for the driver to store information.
    71          */
    81          */
    72     void *opaque;
    82     void *opaque;
       
    83 
       
    84         /*
       
    85          * Pointer to the directory i/o functions for this reader.
       
    86          */
       
    87     const struct __PHYSFS_DIRFUNCTIONS__ *funcs;
       
    88 } DirHandle;
       
    89 
       
    90 
       
    91 /*
       
    92  * Symlinks should always be followed; PhysicsFS will use
       
    93  *  DirFunctions->isSymLink() and make a judgement on whether to
       
    94  *  continue to call other methods based on that.
       
    95  */
       
    96 typedef struct __PHYSFS_DIRFUNCTIONS__
       
    97 {
       
    98         /*
       
    99          * Returns non-zero if (filename) is a valid archive that this
       
   100          *  driver can handle. This filename is in platform-dependent
       
   101          *  notation.
       
   102          */
       
   103     int (*isArchive)(const char *filename);
       
   104 
       
   105         /*
       
   106          * Return a DirHandle for dir/archive (name).
       
   107          *  This filename is in platform-dependent notation.
       
   108          *  return (NULL) on error.
       
   109          */
       
   110     DirHandle *(*openArchive)(const char *name);
    73 
   111 
    74         /*
   112         /*
    75          * Returns a list (freeable via PHYSFS_freeList()) of
   113          * Returns a list (freeable via PHYSFS_freeList()) of
    76          *  all files in dirname.
   114          *  all files in dirname.
    77          *  Symlinks should be followed.
   115          *  This dirname is in platform-independent notation.
    78          */
   116          */
    79     char **(*enumerateFiles)(struct __PHYSFS_DIRREADER__ *r, const char *dirname);
   117     char **(*enumerateFiles)(DirHandle *r, const char *dirname);
    80 
   118 
    81         /*
   119         /*
    82          * Returns non-zero if filename is really a directory.
   120          * Returns non-zero if filename is really a directory.
    83          *  Symlinks should be followed.
   121          *  This filename is in platform-independent notation.
    84          */
   122          */
    85     int (*isDirectory)(struct __PHYSFS_DIRREADER__ *r, const char *name);
   123     int (*isDirectory)(DirHandle *r, const char *name);
    86 
   124 
    87         /*
   125         /*
    88          * Returns non-zero if filename is really a symlink.
   126          * Returns non-zero if filename is really a symlink.
    89          */
   127          *  This filename is in platform-independent notation.
    90     int (*isSymLink)(struct __PHYSFS_DIRREADER__ *r, const char *name);
   128          */
       
   129     int (*isSymLink)(DirHandle *r, const char *name);
    91 
   130 
    92         /*
   131         /*
    93          * Returns non-zero if filename can be opened for reading.
   132          * Returns non-zero if filename can be opened for reading.
    94          *  Symlinks should be followed.
   133          *  This filename is in platform-independent notation.
    95          */
   134          */
    96     int (*isOpenable)(struct __PHYSFS_DIRREADER__ *r, const char *name);
   135     int (*isOpenable)(DirHandle *r, const char *name);
    97 
   136 
    98         /*
   137         /*
    99          * Open file for reading, and return a FileHandle.
   138          * Open file for reading, and return a FileHandle.
   100          *  Symlinks should be followed.
   139          *  This filename is in platform-independent notation.
   101          */
   140          */
   102     FileHandle *(*openRead)(struct __PHYSFS_DIRREADER__ *r, const char *filename);
   141     FileHandle *(*openRead)(DirHandle *r, const char *filename);
   103 
   142 
   104         /*
   143         /*
   105          * Close directories/archives, and free this structure, including
   144          * Open file for writing, and return a FileHandle.
       
   145          *  This filename is in platform-independent notation.
       
   146          *  This method may be NULL.
       
   147          */
       
   148     FileHandle *(*openWrite)(DirHandle *r, const char *filename);
       
   149 
       
   150         /*
       
   151          * Open file for appending, and return a FileHandle.
       
   152          *  This filename is in platform-independent notation.
       
   153          *  This method may be NULL.
       
   154          */
       
   155     FileHandle *(*openAppend)(DirHandle *r, const char *filename);
       
   156 
       
   157         /*
       
   158          * Close directories/archives, and free the handle, including
   106          *  the "opaque" entry. This should assume that it won't be called if
   159          *  the "opaque" entry. This should assume that it won't be called if
   107          *  there are still files open from this DirReader.
   160          *  there are still files open from this DirHandle.
   108          */
   161          */
   109     void (*close)(struct __PHYSFS_DIRREADER__ *r);
   162     void (*close)(DirHandle *r);
   110 } DirReader;
   163 } DirFunctions;
   111 
   164 
   112 
   165 
   113 /* error messages... */
   166 /* error messages... */
   114 #define ERR_IS_INITIALIZED       "Already initialized"
   167 #define ERR_IS_INITIALIZED       "Already initialized"
   115 #define ERR_NOT_INITIALIZED      "Not initialized"
   168 #define ERR_NOT_INITIALIZED      "Not initialized"
   116 #define ERR_INVALID_ARGUMENT     "Invalid argument"
   169 #define ERR_INVALID_ARGUMENT     "Invalid argument"
       
   170 #define ERR_FILES_OPEN_READ      "Files still open for reading"
   117 #define ERR_FILES_OPEN_WRITE     "Files still open for writing"
   171 #define ERR_FILES_OPEN_WRITE     "Files still open for writing"
   118 #define ERR_NO_DIR_CREATE        "Failed to create directories"
   172 #define ERR_NO_DIR_CREATE        "Failed to create directories"
   119 #define ERR_OUT_OF_MEMORY        "Out of memory"
   173 #define ERR_OUT_OF_MEMORY        "Out of memory"
   120 #define ERR_NOT_IN_SEARCH_PATH   "No such entry in search path"
   174 #define ERR_NOT_IN_SEARCH_PATH   "No such entry in search path"
   121 #define ERR_NOT_SUPPORTED        "Operation not supported"
   175 #define ERR_NOT_SUPPORTED        "Operation not supported"
       
   176 #define ERR_UNSUPPORTED_ARCHIVE  "Archive type unsupported"
   122 
   177 
   123 
   178 
   124 /*
   179 /*
   125  * Call this to set the message returned by PHYSFS_getLastError().
   180  * Call this to set the message returned by PHYSFS_getLastError().
   126  *  Please only use the ERR_* constants above, or add new constants to the
   181  *  Please only use the ERR_* constants above, or add new constants to the
   191 /*
   246 /*
   192  * This is a pass-through to whatever stricmp() is called on your platform.
   247  * This is a pass-through to whatever stricmp() is called on your platform.
   193  */
   248  */
   194 int __PHYSFS_platformStricmp(const char *str1, const char *str2);
   249 int __PHYSFS_platformStricmp(const char *str1, const char *str2);
   195 
   250 
       
   251 /*
       
   252  * Return non-zero if filename (in platform-dependent notation) is a symlink.
       
   253  */
       
   254 int __PHYSFS_platformIsSymlink(const char *fname);
       
   255 
   196 
   256 
   197 #ifdef __cplusplus
   257 #ifdef __cplusplus
   198 extern "C" {
   258 extern "C" {
   199 #endif
   259 #endif
   200 
   260