archivers/dir.c
changeset 21 b1ea58d70a56
parent 20 efdde0d21521
child 22 49f6101707b4
equal deleted inserted replaced
20:efdde0d21521 21:b1ea58d70a56
    17 
    17 
    18 #define __PHYSICSFS_INTERNAL__
    18 #define __PHYSICSFS_INTERNAL__
    19 #include "physfs_internal.h"
    19 #include "physfs_internal.h"
    20 
    20 
    21 extern const DirFunctions __PHYSFS_DirFunctions_DIR;
    21 extern const DirFunctions __PHYSFS_DirFunctions_DIR;
    22 static const FileFunctions __PHYSFS_FileHandle_DIR;
    22 static const FileFunctions __PHYSFS_FileFunctions_DIR;
    23 static const FileFunctions __PHYSFS_FileHandle_DIRW;
    23 static const FileFunctions __PHYSFS_FileFunctions_DIRW;
    24 
    24 
    25 static int DIR_read(FileHandle *handle, void *buffer,
    25 static int DIR_read(FileHandle *handle, void *buffer,
    26                     unsigned int objSize, unsigned int objCount)
    26                     unsigned int objSize, unsigned int objCount)
    27 {
    27 {
    28     FILE *h = (FILE *) (handle->opaque);
    28     FILE *h = (FILE *) (handle->opaque);
   110     const char *dirsep = __PHYSFS_platformDirSeparator;
   110     const char *dirsep = __PHYSFS_platformDirSeparator;
   111     DirHandle *retval = NULL;
   111     DirHandle *retval = NULL;
   112     int namelen = strlen(name);
   112     int namelen = strlen(name);
   113     int seplen = strlen(dirsep);
   113     int seplen = strlen(dirsep);
   114 
   114 
   115     BAIL_IF_MACRO(!DIR_isArchive(name, 0), ERR_UNSUPPORTED_ARCHIVE, NULL);
   115     BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
       
   116                     ERR_UNSUPPORTED_ARCHIVE, NULL);
   116 
   117 
   117     retval = malloc(sizeof (DirHandle));
   118     retval = malloc(sizeof (DirHandle));
   118     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   119     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   119     retval->opaque = malloc(namelen + seplen + 1);
   120     retval->opaque = malloc(namelen + seplen + 1);
   120     if (retval->opaque == NULL)
   121     if (retval->opaque == NULL)
   208         BAIL_IF_MACRO(0, str, NULL);
   209         BAIL_IF_MACRO(0, str, NULL);
   209     } /* if */
   210     } /* if */
   210 
   211 
   211     retval->opaque = (void *) rc;
   212     retval->opaque = (void *) rc;
   212     retval->dirHandle = h;
   213     retval->dirHandle = h;
   213     retval->funcs = &__PHYSFS_FileHandle_DIR;
   214     retval->funcs = &__PHYSFS_FileFunctions_DIR;
   214     return(retval);
   215     return(retval);
   215 } /* doOpen */
   216 } /* doOpen */
   216 
   217 
   217 
   218 
   218 static FileHandle *DIR_openRead(DirHandle *h, const char *filename)
   219 static FileHandle *DIR_openRead(DirHandle *h, const char *filename)
   273     free(h);
   274     free(h);
   274 } /* DIR_dirClose */
   275 } /* DIR_dirClose */
   275 
   276 
   276 
   277 
   277 
   278 
   278 static const FileFunctions __PHYSFS_FileHandle_DIR =
   279 static const FileFunctions __PHYSFS_FileFunctions_DIR =
   279 {
   280 {
   280     DIR_read,       /* read() method      */
   281     DIR_read,       /* read() method      */
   281     NULL,           /* write() method     */
   282     NULL,           /* write() method     */
   282     DIR_eof,        /* eof() method       */
   283     DIR_eof,        /* eof() method       */
   283     DIR_tell,       /* tell() method      */
   284     DIR_tell,       /* tell() method      */
   284     DIR_seek,       /* seek() method      */
   285     DIR_seek,       /* seek() method      */
   285     DIR_fileClose,  /* fileClose() method */
   286     DIR_fileClose,  /* fileClose() method */
   286 };
   287 };
   287 
   288 
   288 
   289 
   289 static const FileFunctions __PHYSFS_FileHandle_DIRW =
   290 static const FileFunctions __PHYSFS_FileFunctions_DIRW =
   290 {
   291 {
   291     NULL,           /* read() method      */
   292     NULL,           /* read() method      */
   292     DIR_write,      /* write() method     */
   293     DIR_write,      /* write() method     */
   293     DIR_eof,        /* eof() method       */
   294     DIR_eof,        /* eof() method       */
   294     DIR_tell,       /* tell() method      */
   295     DIR_tell,       /* tell() method      */