archivers/grp.c
changeset 480 2cf0b6edd200
parent 467 99664d9842cb
child 504 3420d82f9b01
equal deleted inserted replaced
479:5990d6efd4f8 480:2cf0b6edd200
    42 #include "physfs_internal.h"
    42 #include "physfs_internal.h"
    43 
    43 
    44 typedef struct
    44 typedef struct
    45 {
    45 {
    46     char name[13];
    46     char name[13];
    47     PHYSFS_uint64 startPos;
    47     PHYSFS_uint32 startPos;
    48     PHYSFS_uint64 size;
    48     PHYSFS_uint32 size;
    49 } GRPentry;
    49 } GRPentry;
    50 
    50 
    51 typedef struct
    51 typedef struct
    52 {
    52 {
    53     char *filename;
    53     char *filename;
    58 
    58 
    59 typedef struct
    59 typedef struct
    60 {
    60 {
    61     void *handle;
    61     void *handle;
    62     GRPentry *entry;
    62     GRPentry *entry;
    63     PHYSFS_sint64 curPos;
    63     PHYSFS_uint32 curPos;
    64 } GRPfileinfo;
    64 } GRPfileinfo;
    65 
    65 
    66 
    66 
    67 static void GRP_dirClose(DirHandle *h);
    67 static void GRP_dirClose(DirHandle *h);
    68 static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
    68 static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
   143 static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
   143 static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
   144                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
   144                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
   145 {
   145 {
   146     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
   146     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
   147     GRPentry *entry = finfo->entry;
   147     GRPentry *entry = finfo->entry;
   148     PHYSFS_uint64 bytesLeft = entry->size - finfo->curPos;
   148     PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
   149     PHYSFS_uint64 objsLeft = (bytesLeft / objSize);
   149     PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
   150     PHYSFS_sint64 rc;
   150     PHYSFS_sint64 rc;
   151 
   151 
   152     if (objsLeft < objCount)
   152     if (objsLeft < objCount)
   153         objCount = (PHYSFS_uint32) objsLeft;
   153         objCount = objsLeft;
   154 
   154 
   155     rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount);
   155     rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount);
   156     if (rc > 0)
   156     if (rc > 0)
   157         finfo->curPos += (rc * objSize);
   157         finfo->curPos += (PHYSFS_uint32) (rc * objSize);
   158 
   158 
   159     return(rc);
   159     return(rc);
   160 } /* GRP_read */
   160 } /* GRP_read */
   161 
   161 
   162 
   162 
   169 
   169 
   170 static int GRP_eof(FileHandle *handle)
   170 static int GRP_eof(FileHandle *handle)
   171 {
   171 {
   172     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
   172     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
   173     GRPentry *entry = finfo->entry;
   173     GRPentry *entry = finfo->entry;
   174     return(finfo->curPos >= (PHYSFS_sint64) entry->size);
   174     return(finfo->curPos >= entry->size);
   175 } /* GRP_eof */
   175 } /* GRP_eof */
   176 
   176 
   177 
   177 
   178 static PHYSFS_sint64 GRP_tell(FileHandle *handle)
   178 static PHYSFS_sint64 GRP_tell(FileHandle *handle)
   179 {
   179 {
   183 
   183 
   184 static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset)
   184 static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset)
   185 {
   185 {
   186     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
   186     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
   187     GRPentry *entry = finfo->entry;
   187     GRPentry *entry = finfo->entry;
   188     PHYSFS_uint64 newPos = (entry->startPos + offset);
       
   189     int rc;
   188     int rc;
   190 
   189 
   191     BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
   190     BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
   192     BAIL_IF_MACRO(newPos > entry->startPos + entry->size, ERR_PAST_EOF, 0);
   191     BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
   193     rc = __PHYSFS_platformSeek(finfo->handle, newPos);
   192     rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset);
   194     if (rc)
   193     if (rc)
   195         finfo->curPos = offset;
   194         finfo->curPos = (PHYSFS_uint32) offset;
   196 
   195 
   197     return(rc);
   196     return(rc);
   198 } /* GRP_seek */
   197 } /* GRP_seek */
   199 
   198 
   200 
   199 
   201 static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
   200 static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
   202 {
   201 {
   203     return(((GRPfileinfo *) handle->opaque)->entry->size);
   202     GRPfileinfo *finfo = ((GRPfileinfo *) handle->opaque);
       
   203     return((PHYSFS_sint64) finfo->entry->size);
   204 } /* GRP_fileLength */
   204 } /* GRP_fileLength */
   205 
   205 
   206 
   206 
   207 static int GRP_fileClose(FileHandle *handle)
   207 static int GRP_fileClose(FileHandle *handle)
   208 {
   208 {