paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/physfs/archivers Makefile.am,1.1.1.1,1.2


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/physfs/archivers Makefile.am,1.1.1.1,1.2 dir.c,1.1.1.1,1.2 grp.c,1.1.1.1,1.2 unzip.c,1.1.1.1,1.2 zip.c,1.1.1.1,1.2
Date: Sat, 27 Apr 2002 12:06:29 -0400

Update of /cvsroot/paragui/paragui/src/physfs/archivers
In directory subversions:/tmp/cvs-serv12415/src/physfs/archivers

Modified Files:
        Makefile.am dir.c grp.c unzip.c zip.c 
Log Message:
updated physfs to version 0.1.5



Index: Makefile.am
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/Makefile.am,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** Makefile.am 15 Apr 2002 13:22:14 -0000      1.1.1.1
--- Makefile.am 27 Apr 2002 16:06:26 -0000      1.2
***************
*** 3,7 ****
  libarchivers_la_SOURCES = \
        dir.c \
-       grp.c \
        unzip.c \
        zip.c
--- 3,6 ----
***************
*** 10,12 ****
--- 9,12 ----
  
  EXTRA_DIST = \
+       grp.c \
        unzip.h

Index: dir.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/dir.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** dir.c       15 Apr 2002 13:22:14 -0000      1.1.1.1
--- dir.c       27 Apr 2002 16:06:26 -0000      1.2
***************
*** 17,28 ****
  #include "physfs_internal.h"
  
! static int DIR_read(FileHandle *handle, void *buffer,
!                     unsigned int objSize, unsigned int objCount);
! static int DIR_write(FileHandle *handle, void *buffer,
!                      unsigned int objSize, unsigned int objCount);
  static int DIR_eof(FileHandle *handle);
! static int DIR_tell(FileHandle *handle);
! static int DIR_seek(FileHandle *handle, int offset);
! static int DIR_fileLength(FileHandle *handle);
  static int DIR_fileClose(FileHandle *handle);
  static int DIR_isArchive(const char *filename, int forWriting);
--- 17,28 ----
  #include "physfs_internal.h"
  
! static PHYSFS_sint64 DIR_read(FileHandle *handle, void *buffer,
!                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
! static PHYSFS_sint64 DIR_write(FileHandle *handle, const void *buffer,
!                                PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  static int DIR_eof(FileHandle *handle);
! static PHYSFS_sint64 DIR_tell(FileHandle *handle);
! static int DIR_seek(FileHandle *handle, PHYSFS_uint64 offset);
! static PHYSFS_sint64 DIR_fileLength(FileHandle *handle);
  static int DIR_fileClose(FileHandle *handle);
  static int DIR_isArchive(const char *filename, int forWriting);
***************
*** 89,93 ****
      "DIR",
      "non-archive directory I/O",
!     "Ryan C. Gordon (address@hidden)",
      "http://www.icculus.org/physfs/";,
  };
--- 89,93 ----
      "DIR",
      "non-archive directory I/O",
!     "Ryan C. Gordon <address@hidden>",
      "http://www.icculus.org/physfs/";,
  };
***************
*** 95,126 ****
  
  
! static int DIR_read(FileHandle *handle, void *buffer,
!                     unsigned int objSize, unsigned int objCount)
  {
!     FILE *h = (FILE *) (handle->opaque);
!     size_t retval;
! 
!     errno = 0;
!     retval = fread(buffer, objSize, objCount, h);
!     BAIL_IF_MACRO((retval < (size_t) objCount) && (ferror(h)),
!                    strerror(errno), (int) retval);
! 
!     return((int) retval);
  } /* DIR_read */
  
  
! static int DIR_write(FileHandle *handle, void *buffer,
!                      unsigned int objSize, unsigned int objCount)
  {
!     FILE *h = (FILE *) (handle->opaque);
!     size_t retval;
! 
!     errno = 0;
!     retval = fwrite(buffer, (size_t) objSize, objCount, h);
!     if ( (retval < (signed int) objCount) && (ferror(h)) )
!         __PHYSFS_setError(strerror(errno));
!     fflush(h);
! 
!     return((int) retval);
  } /* DIR_write */
  
--- 95,113 ----
  
  
! static PHYSFS_sint64 DIR_read(FileHandle *handle, void *buffer,
!                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  {
!     PHYSFS_sint64 retval;
!     retval = __PHYSFS_platformRead(handle->opaque, buffer, objSize, objCount);
!     return(retval);
  } /* DIR_read */
  
  
! static PHYSFS_sint64 DIR_write(FileHandle *handle, const void *buffer,
!                                PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  {
!     PHYSFS_sint64 retval;
!     retval = __PHYSFS_platformWrite(handle->opaque, buffer, objSize, 
objCount);
!     return(retval);
  } /* DIR_write */
  
***************
*** 128,150 ****
  static int DIR_eof(FileHandle *handle)
  {
!     return(feof((FILE *) (handle->opaque)));
  } /* DIR_eof */
  
  
! static int DIR_tell(FileHandle *handle)
  {
!     return(ftell((FILE *) (handle->opaque)));
  } /* DIR_tell */
  
  
! static int DIR_seek(FileHandle *handle, int offset)
  {
!     return(fseek((FILE *) (handle->opaque), offset, SEEK_SET) == 0);
  } /* DIR_seek */
  
  
! static int DIR_fileLength(FileHandle *handle)
  {
!     return(__PHYSFS_platformFileLength((FILE *) (handle->opaque)));
  } /* DIR_fileLength */
  
--- 115,137 ----
  static int DIR_eof(FileHandle *handle)
  {
!     return(__PHYSFS_platformEOF(handle->opaque));
  } /* DIR_eof */
  
  
! static PHYSFS_sint64 DIR_tell(FileHandle *handle)
  {
!     return(__PHYSFS_platformTell(handle->opaque));
  } /* DIR_tell */
  
  
! static int DIR_seek(FileHandle *handle, PHYSFS_uint64 offset)
  {
!     return(__PHYSFS_platformSeek(handle->opaque, offset));
  } /* DIR_seek */
  
  
! static PHYSFS_sint64 DIR_fileLength(FileHandle *handle)
  {
!     return(__PHYSFS_platformFileLength(handle->opaque));
  } /* DIR_fileLength */
  
***************
*** 152,178 ****
  static int DIR_fileClose(FileHandle *handle)
  {
-     FILE *h = (FILE *) (handle->opaque);
- 
- #if 0
      /*
!      * we manually fflush() the buffer, since that's the place fclose() will
       *  most likely fail, but that will leave the file handle in an undefined
!      *  state if it fails. fflush() failures we can recover from.
       */
! 
!     /* keep trying until there's success or an unrecoverable error... */
!     do {
!         __PHYSFS_platformTimeslice();
!         errno = 0;
!     } while ( (fflush(h) == EOF) && ((errno == EAGAIN) || (errno == EINTR)) );
! 
!     /* EBADF == "Not open for writing". That's fine. */
!     BAIL_IF_MACRO((errno != 0) && (errno != EBADF), strerror(errno), 0);
! #endif
! 
!     /* if fclose fails anyhow, we just have to pray that it's still usable. */
!     errno = 0;
!     BAIL_IF_MACRO(fclose(h) == EOF, strerror(errno), 0);  /* (*shrug*) */
! 
      free(handle);
      return(1);
--- 139,149 ----
  static int DIR_fileClose(FileHandle *handle)
  {
      /*
!      * we manually flush the buffer, since that's the place a close will
       *  most likely fail, but that will leave the file handle in an undefined
!      *  state if it fails. Flush failures we can recover from.
       */
!     BAIL_IF_MACRO(!__PHYSFS_platformFlush(handle->opaque), NULL, 0);
!     BAIL_IF_MACRO(!__PHYSFS_platformClose(handle->opaque), NULL, 0);
      free(handle);
      return(1);
***************
*** 197,201 ****
                      ERR_UNSUPPORTED_ARCHIVE, NULL);
  
!     retval = malloc(sizeof (DirHandle));
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
      retval->opaque = malloc(namelen + seplen + 1);
--- 168,172 ----
                      ERR_UNSUPPORTED_ARCHIVE, NULL);
  
!     retval = (DirHandle *) malloc(sizeof (DirHandle));
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
      retval->opaque = malloc(namelen + seplen + 1);
***************
*** 203,207 ****
      {
          free(retval);
!         BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
--- 174,178 ----
      {
          free(retval);
!         BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
***************
*** 212,215 ****
--- 183,187 ----
  
      retval->funcs = &__PHYSFS_DirFunctions_DIR;
+ 
      return(retval);
  } /* DIR_openArchive */
***************
*** 266,275 ****
  
  
! static FileHandle *doOpen(DirHandle *h, const char *name, const char *mode)
  {
      char *f = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, 
NULL);
!     FILE *rc;
      FileHandle *retval;
-     char *str;
  
      BAIL_IF_MACRO(f == NULL, NULL, NULL);
--- 238,248 ----
  
  
! static FileHandle *doOpen(DirHandle *h, const char *name,
!                           void *(*openFunc)(const char *filename),
!                           const FileFunctions *fileFuncs)
  {
      char *f = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, 
NULL);
!     void *rc;
      FileHandle *retval;
  
      BAIL_IF_MACRO(f == NULL, NULL, NULL);
***************
*** 279,288 ****
      {
          free(f);
!         BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
!     errno = 0;
!     rc = fopen(f, mode);
!     str = strerror(errno);
      free(f);
  
--- 252,259 ----
      {
          free(f);
!         BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
!     rc = openFunc(f);
      free(f);
  
***************
*** 290,303 ****
      {
          free(retval);
!         BAIL_IF_MACRO(1, str, NULL);
      } /* if */
  
      retval->opaque = (void *) rc;
      retval->dirHandle = h;
!     if(mode[0] == 'r') { 
!       retval->funcs = &__PHYSFS_FileFunctions_DIR;
!     } else {
!       retval->funcs = &__PHYSFS_FileFunctions_DIRW;
!     }
      return(retval);
  } /* doOpen */
--- 261,271 ----
      {
          free(retval);
!         return(NULL);
      } /* if */
  
      retval->opaque = (void *) rc;
      retval->dirHandle = h;
!     retval->funcs = fileFuncs;
! 
      return(retval);
  } /* doOpen */
***************
*** 306,310 ****
  static FileHandle *DIR_openRead(DirHandle *h, const char *filename)
  {
!     return(doOpen(h, filename, "rb"));
  } /* DIR_openRead */
  
--- 274,279 ----
  static FileHandle *DIR_openRead(DirHandle *h, const char *filename)
  {
!     return(doOpen(h, filename, __PHYSFS_platformOpenRead,
!                   &__PHYSFS_FileFunctions_DIR));
  } /* DIR_openRead */
  
***************
*** 312,316 ****
  static FileHandle *DIR_openWrite(DirHandle *h, const char *filename)
  {
!     return(doOpen(h, filename, "wb"));
  } /* DIR_openWrite */
  
--- 281,286 ----
  static FileHandle *DIR_openWrite(DirHandle *h, const char *filename)
  {
!     return(doOpen(h, filename, __PHYSFS_platformOpenWrite,
!                   &__PHYSFS_FileFunctions_DIRW));
  } /* DIR_openWrite */
  
***************
*** 318,322 ****
  static FileHandle *DIR_openAppend(DirHandle *h, const char *filename)
  {
!     return(doOpen(h, filename, "ab"));
  } /* DIR_openAppend */
  
--- 288,293 ----
  static FileHandle *DIR_openAppend(DirHandle *h, const char *filename)
  {
!     return(doOpen(h, filename, __PHYSFS_platformOpenAppend,
!                   &__PHYSFS_FileFunctions_DIRW));
  } /* DIR_openAppend */
  
***************
*** 328,337 ****
  
      BAIL_IF_MACRO(f == NULL, NULL, 0);
! 
!     errno = 0;
!     retval = (remove(f) == 0);
!     if (!retval)
!         __PHYSFS_setError(strerror(errno));
! 
      free(f);
      return(retval);
--- 299,303 ----
  
      BAIL_IF_MACRO(f == NULL, NULL, 0);
!     retval = __PHYSFS_platformDelete(f);
      free(f);
      return(retval);
***************
*** 345,354 ****
  
      BAIL_IF_MACRO(f == NULL, NULL, 0);
- 
-     errno = 0;
      retval = __PHYSFS_platformMkDir(f);
-     if (!retval)
-         __PHYSFS_setError(strerror(errno));
- 
      free(f);
      return(retval);
--- 311,315 ----

Index: grp.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/grp.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** grp.c       15 Apr 2002 13:22:14 -0000      1.1.1.1
--- grp.c       27 Apr 2002 16:06:26 -0000      1.2
***************
*** 40,70 ****
  #include "physfs_internal.h"
  
- #if 0
  #if (!defined PHYSFS_SUPPORTS_GRP)
  #error PHYSFS_SUPPORTS_GRP must be defined.
  #endif
- #endif
  
  typedef struct
  {
!     FILE *handle;
!     int totalEntries;
  } GRPinfo;
  
  typedef struct
  {
!     int startPos;
!     int curPos;
!     int size;
  } GRPfileinfo;
  
  
  static void GRP_dirClose(DirHandle *h);
! static int GRP_read(FileHandle *handle, void *buffer,
!                     unsigned int objSize, unsigned int objCount);
  static int GRP_eof(FileHandle *handle);
! static int GRP_tell(FileHandle *handle);
! static int GRP_seek(FileHandle *handle, int offset);
! static int GRP_fileLength(FileHandle *handle);
  static int GRP_fileClose(FileHandle *handle);
  static int GRP_isArchive(const char *filename, int forWriting);
--- 40,69 ----
  #include "physfs_internal.h"
  
  #if (!defined PHYSFS_SUPPORTS_GRP)
  #error PHYSFS_SUPPORTS_GRP must be defined.
  #endif
  
  typedef struct
  {
!     void *handle;
!     char *filename;
!     PHYSFS_uint32 totalEntries;
  } GRPinfo;
  
  typedef struct
  {
!     void *handle;
!     PHYSFS_uint64 startPos;
!     PHYSFS_uint64 size;
  } GRPfileinfo;
  
  
  static void GRP_dirClose(DirHandle *h);
! static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
!                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  static int GRP_eof(FileHandle *handle);
! static PHYSFS_sint64 GRP_tell(FileHandle *handle);
! static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset);
! static PHYSFS_sint64 GRP_fileLength(FileHandle *handle);
  static int GRP_fileClose(FileHandle *handle);
  static int GRP_isArchive(const char *filename, int forWriting);
***************
*** 110,114 ****
      "GRP",
      "Build engine Groupfile format",
!     "Ryan C. Gordon (address@hidden)",
      "http://www.icculus.org/physfs/";,
  };
--- 109,113 ----
      "GRP",
      "Build engine Groupfile format",
!     "Ryan C. Gordon <address@hidden>",
      "http://www.icculus.org/physfs/";,
  };
***************
*** 118,122 ****
  static void GRP_dirClose(DirHandle *h)
  {
!     fclose( ((GRPinfo *) h->opaque)->handle );
      free(h->opaque);
      free(h);
--- 117,122 ----
  static void GRP_dirClose(DirHandle *h)
  {
!     __PHYSFS_platformClose( ((GRPinfo *) h->opaque)->handle );
!     free(((GRPinfo *) h->opaque)->filename);
      free(h->opaque);
      free(h);
***************
*** 124,149 ****
  
  
! static int GRP_read(FileHandle *handle, void *buffer,
!                     unsigned int objSize, unsigned int objCount)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     FILE *fh = (FILE *) (((GRPinfo *) (handle->dirHandle->opaque))->handle);
!     int bytesLeft = (finfo->startPos + finfo->size) - finfo->curPos;
!     unsigned int objsLeft = bytesLeft / objSize;
!     size_t retval = 0;
  
      if (objsLeft < objCount)
!         objCount = objsLeft;
! 
!     errno = 0;
!     BAIL_IF_MACRO(fseek(fh,finfo->curPos,SEEK_SET) == -1,strerror(errno),-1);
! 
!     errno = 0;
!     retval = fread(buffer, objSize, objCount, fh);
!     finfo->curPos += (retval * objSize);
!     BAIL_IF_MACRO((retval < (size_t) objCount) && (ferror(fh)),
!                    strerror(errno), (int) retval);
  
!     return((int) retval);
  } /* GRP_read */
  
--- 124,140 ----
  
  
! static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer,
!                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     void *fh = finfo->handle;
!     PHYSFS_sint64 curPos = __PHYSFS_platformTell(fh);
!     PHYSFS_uint64 bytesLeft = (finfo->startPos + finfo->size) - curPos;
!     PHYSFS_uint64 objsLeft = (bytesLeft / objSize);
  
      if (objsLeft < objCount)
!         objCount = (PHYSFS_uint32) objsLeft;
  
!     return(__PHYSFS_platformRead(fh, buffer, objSize, objCount));
  } /* GRP_read */
  
***************
*** 152,179 ****
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     return(finfo->curPos >= finfo->startPos + finfo->size);
  } /* GRP_eof */
  
  
! static int GRP_tell(FileHandle *handle)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     return(finfo->curPos - finfo->startPos);
  } /* GRP_tell */
  
  
! static int GRP_seek(FileHandle *handle, int offset)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     int newPos = finfo->startPos + offset;
  
      BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
      BAIL_IF_MACRO(newPos > finfo->startPos + finfo->size, ERR_PAST_EOF, 0);
!     finfo->curPos = newPos;
!     return(1);
  } /* GRP_seek */
  
  
! static int GRP_fileLength(FileHandle *handle)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
--- 143,172 ----
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     void *fh = finfo->handle;
!     PHYSFS_sint64 pos = __PHYSFS_platformTell(fh);
!     BAIL_IF_MACRO(pos < 0, NULL, 1);  /* (*shrug*) */
!     return(pos >= (PHYSFS_sint64) (finfo->startPos + finfo->size));
  } /* GRP_eof */
  
  
! static PHYSFS_sint64 GRP_tell(FileHandle *handle)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     return(__PHYSFS_platformTell(finfo->handle) - finfo->startPos);
  } /* GRP_tell */
  
  
! static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
!     PHYSFS_uint64 newPos = (finfo->startPos + offset);
  
      BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
      BAIL_IF_MACRO(newPos > finfo->startPos + finfo->size, ERR_PAST_EOF, 0);
!     return(__PHYSFS_platformSeek(finfo->handle, newPos));
  } /* GRP_seek */
  
  
! static PHYSFS_sint64 GRP_fileLength(FileHandle *handle)
  {
      GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
***************
*** 184,187 ****
--- 177,183 ----
  static int GRP_fileClose(FileHandle *handle)
  {
+     GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
+     BAIL_IF_MACRO(__PHYSFS_platformClose(finfo->handle), NULL, 0);
+ 
      free(handle->opaque);
      free(handle);
***************
*** 190,217 ****
  
  
! static int openGrp(const char *filename, int forWriting, FILE **fh, int 
*count)
  {
!     char buf[12];
! 
!      /* !!! FIXME: Get me platform-independent typedefs! */
!     if (sizeof (int) != 4)
!         assert(0);
  
      *fh = NULL;
      BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
  
!     errno = 0;
!     *fh = fopen(filename, "rb");
!     BAIL_IF_MACRO(*fh == NULL, strerror(errno), 0);
      
!     errno = 0;
!     BAIL_IF_MACRO(fread(buf, 12, 1, *fh) != 1, strerror(errno), 0);
!     BAIL_IF_MACRO(strncmp(buf, "KenSilverman", 12) != 0,
!                     ERR_UNSUPPORTED_ARCHIVE, 0);
  
!     if (fread(count, 4, 1, *fh) != 1)
!         *count = 0;
  
      return(1);
  } /* openGrp */
  
--- 186,223 ----
  
  
! static int openGrp(const char *filename, int forWriting,
!                     void **fh, PHYSFS_sint32 *count)
  {
!     PHYSFS_uint8 buf[12];
  
      *fh = NULL;
      BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
  
!     *fh = __PHYSFS_platformOpenRead(filename);
!     BAIL_IF_MACRO(*fh == NULL, NULL, 0);
      
!     if (__PHYSFS_platformRead(*fh, buf, 12, 1) != 1)
!         goto openGrp_failed;
! 
!     if (memcmp(buf, "KenSilverman", 12) != 0)
!     {
!         __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
!         goto openGrp_failed;
!     } /* if */
! 
!     if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_sint32), 1) != 1)
!         goto openGrp_failed;
  
!     *count = PHYSFS_swapSLE32(*count);
  
      return(1);
+ 
+ openGrp_failed:
+     if (*fh != NULL)
+         __PHYSFS_platformClose(*fh);
+ 
+     *count = -1;
+     *fh = NULL;
+     return(0);
  } /* openGrp */
  
***************
*** 219,228 ****
  static int GRP_isArchive(const char *filename, int forWriting)
  {
!     FILE *fh;
      int fileCount;
      int retval = openGrp(filename, forWriting, &fh, &fileCount);
  
      if (fh != NULL)
!         fclose(fh);
  
      return(retval);
--- 225,234 ----
  static int GRP_isArchive(const char *filename, int forWriting)
  {
!     void *fh;
      int fileCount;
      int retval = openGrp(filename, forWriting, &fh, &fileCount);
  
      if (fh != NULL)
!         __PHYSFS_platformClose(fh);
  
      return(retval);
***************
*** 232,236 ****
  static DirHandle *GRP_openArchive(const char *name, int forWriting)
  {
!     FILE *fh;
      int fileCount;
      DirHandle *retval = malloc(sizeof (DirHandle));
--- 238,242 ----
  static DirHandle *GRP_openArchive(const char *name, int forWriting)
  {
!     void *fh = NULL;
      int fileCount;
      DirHandle *retval = malloc(sizeof (DirHandle));
***************
*** 240,259 ****
      if (retval->opaque == NULL)
      {
!         free(retval);
!         BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
      } /* if */
  
!     if (!openGrp(name, forWriting, &fh, &fileCount))
      {
!         if (fh != NULL)
!             fclose(fh);
!         free(retval->opaque);
!         free(retval);
      } /* if */
  
      ((GRPinfo *) retval->opaque)->handle = fh;
      ((GRPinfo *) retval->opaque)->totalEntries = fileCount;
      retval->funcs = &__PHYSFS_DirFunctions_GRP;
      return(retval);
  } /* GRP_openArchive */
  
--- 246,285 ----
      if (retval->opaque == NULL)
      {
!         __PHYSFS_setError(ERR_OUT_OF_MEMORY);
!         goto GRP_openArchive_failed;
      } /* if */
  
!     ((GRPinfo *) retval->opaque)->filename = (char *) malloc(strlen(name) + 
1);
!     if (((GRPinfo *) retval->opaque)->filename == NULL)
      {
!         __PHYSFS_setError(ERR_OUT_OF_MEMORY);
!         goto GRP_openArchive_failed;
      } /* if */
  
+     if (!openGrp(name, forWriting, &fh, &fileCount))
+         goto GRP_openArchive_failed;
+ 
+     strcpy(((GRPinfo *) retval->opaque)->filename, name);
      ((GRPinfo *) retval->opaque)->handle = fh;
      ((GRPinfo *) retval->opaque)->totalEntries = fileCount;
      retval->funcs = &__PHYSFS_DirFunctions_GRP;
      return(retval);
+ 
+ GRP_openArchive_failed:
+     if (retval != NULL)
+     {
+         if (retval->opaque != NULL)
+         {
+             if ( ((GRPinfo *) retval->opaque)->filename != NULL )
+                 free( ((GRPinfo *) retval->opaque)->filename );
+             free(retval->opaque);
+         } /* if */
+         free(retval);
+     } /* if */
+ 
+     if (fh != NULL)
+         __PHYSFS_platformClose(fh);
+ 
+     return(NULL);
  } /* GRP_openArchive */
  
***************
*** 263,285 ****
                                              int omitSymLinks)
  {
!     char buf[16];
      GRPinfo *g = (GRPinfo *) (h->opaque);
!     FILE *fh = g->handle;
!     int i;
      LinkedStringList *retval = NULL;
      LinkedStringList *l = NULL;
      LinkedStringList *prev = NULL;
  
      if (*dirname != '\0')   /* no directories in GRP files. */
          return(NULL);
  
          /* jump to first file entry... */
!     errno = 0;
!     BAIL_IF_MACRO(fseek(fh, 16, SEEK_SET) == -1, strerror(errno), NULL);
  
      for (i = 0; i < g->totalEntries; i++)
      {
!         errno = 0;
!         BAIL_IF_MACRO(fread(buf, 16, 1, fh) != 1, strerror(errno), retval);
  
          buf[12] = '\0';  /* FILENAME.EXT is all you get. */
--- 289,310 ----
                                              int omitSymLinks)
  {
!     PHYSFS_uint8 buf[16];
      GRPinfo *g = (GRPinfo *) (h->opaque);
!     void *fh = g->handle;
!     PHYSFS_uint32 i;
      LinkedStringList *retval = NULL;
      LinkedStringList *l = NULL;
      LinkedStringList *prev = NULL;
  
+     /* !!! FIXME: Does this consider "/" ? */
      if (*dirname != '\0')   /* no directories in GRP files. */
          return(NULL);
  
          /* jump to first file entry... */
!     BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, NULL);
  
      for (i = 0; i < g->totalEntries; i++)
      {
!         BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 16, 1) != 1, NULL, 
retval);
  
          buf[12] = '\0';  /* FILENAME.EXT is all you get. */
***************
*** 289,293 ****
              break;
  
!         l->str = (char *) malloc(strlen(buf) + 1);
          if (l->str == NULL)
          {
--- 314,318 ----
              break;
  
!         l->str = (char *) malloc(strlen((const char *) buf) + 1);
          if (l->str == NULL)
          {
***************
*** 296,300 ****
          } /* if */
  
!         strcpy(l->str, buf);
  
          if (retval == NULL)
--- 321,325 ----
          } /* if */
  
!         strcpy(l->str, (const char *) buf);
  
          if (retval == NULL)
***************
*** 311,320 ****
  
  
! static int getFileEntry(DirHandle *h, const char *name, int *size)
  {
!     char buf[16];
      GRPinfo *g = (GRPinfo *) (h->opaque);
!     FILE *fh = g->handle;
!     int i;
      char *ptr;
      int retval = (g->totalEntries + 1) * 16; /* offset of raw file data */
--- 336,346 ----
  
  
! static PHYSFS_sint32 getFileEntry(DirHandle *h, const char *name,
!                                   PHYSFS_uint32 *size)
  {
!     PHYSFS_uint8 buf[16];
      GRPinfo *g = (GRPinfo *) (h->opaque);
!     void *fh = g->handle;
!     PHYSFS_uint32 i;
      char *ptr;
      int retval = (g->totalEntries + 1) * 16; /* offset of raw file data */
***************
*** 331,357 ****
          return(-1);
  
!         /* jump to first file entry... */
!     errno = 0;
!     BAIL_IF_MACRO(fseek(fh, 16, SEEK_SET) == -1, strerror(errno), -1);
  
      for (i = 0; i < g->totalEntries; i++)
      {
!         int fsize;
  
!         errno = 0;
!         BAIL_IF_MACRO(fread(buf, 16, 1, fh) != 1, strerror(errno), -1);
! 
!         fsize = *((int *) (buf + 12));
  
          buf[12] = '\0';  /* FILENAME.EXT is all you get. */
  
!         if (__PHYSFS_platformStricmp(buf, name) == 0)
          {
              if (size != NULL)
!                 *size = fsize;
              return(retval);
          } /* if */
  
!         retval += fsize;
      } /* for */
  
--- 357,381 ----
          return(-1);
  
!     /* jump to first file entry... */
!     BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, -1);
  
      for (i = 0; i < g->totalEntries; i++)
      {
!         PHYSFS_sint32 l = 0;
  
!         BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 12, 1) != 1, NULL, -1);
!         BAIL_IF_MACRO(__PHYSFS_platformRead(fh, &l, sizeof (l), 1) != 1, 
NULL, -1);
!         l = PHYSFS_swapSLE32(l);
  
          buf[12] = '\0';  /* FILENAME.EXT is all you get. */
  
!         if (__PHYSFS_platformStricmp((const char *) buf, name) == 0)
          {
              if (size != NULL)
!                 *size = l;
              return(retval);
          } /* if */
  
!         retval += l;
      } /* for */
  
***************
*** 380,386 ****
  static FileHandle *GRP_openRead(DirHandle *h, const char *name)
  {
      FileHandle *retval;
      GRPfileinfo *finfo;
!     int size, offset;
  
      offset = getFileEntry(h, name, &size);
--- 404,412 ----
  static FileHandle *GRP_openRead(DirHandle *h, const char *name)
  {
+     const char *filename = ((GRPinfo *) h->opaque)->filename;
      FileHandle *retval;
      GRPfileinfo *finfo;
!     PHYSFS_uint32 size;
!     PHYSFS_sint32 offset;
  
      offset = getFileEntry(h, name, &size);
***************
*** 396,401 ****
      } /* if */
  
      finfo->startPos = offset;
-     finfo->curPos = offset;
      finfo->size = size;
      retval->opaque = (void *) finfo;
--- 422,435 ----
      } /* if */
  
+     finfo->handle = __PHYSFS_platformOpenRead(filename);
+     if ( (finfo->handle == NULL) ||
+          (!__PHYSFS_platformSeek(finfo->handle, offset)) )
+     {
+         free(finfo);
+         free(retval);
+         return(NULL);
+     } /* if */
+ 
      finfo->startPos = offset;
      finfo->size = size;
      retval->opaque = (void *) finfo;

Index: unzip.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/unzip.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** unzip.c     15 Apr 2002 13:22:14 -0000      1.1.1.1
--- unzip.c     27 Apr 2002 16:06:26 -0000      1.2
***************
*** 12,15 ****
--- 12,22 ----
  #include "unzip.h"
  
+ #define __PHYSICSFS_INTERNAL__
+ #include "physfs_internal.h"
+ 
+ #if (!defined PHYSFS_SUPPORTS_ZIP)
+ #error PHYSFS_SUPPORTS_ZIP must be defined.
+ #endif
+ 
  #ifdef STDC
  #  include <stddef.h>
***************
*** 87,91 ****
        z_stream stream;            /* zLib stream structure for inflate */
  
!       uLong pos_in_zipfile;       /* position in byte on the zipfile, for 
fseek*/
        uLong stream_initialised;   /* flag set if stream structure is 
initialised*/
  
--- 94,98 ----
        z_stream stream;            /* zLib stream structure for inflate */
  
!       uLong pos_in_zipfile;       /* position in byte on the zipfile, for 
seek*/
        uLong stream_initialised;   /* flag set if stream structure is 
initialised*/
  
***************
*** 98,102 ****
        uLong rest_read_compressed; /* number of byte to be decompressed */
        uLong rest_read_uncompressed;/*number of byte to be obtained after 
decomp*/
!       FILE* file;                 /* io structore of the zipfile */
        uLong compression_method;   /* compression method (0==store) */
        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
--- 105,109 ----
        uLong rest_read_compressed; /* number of byte to be decompressed */
        uLong rest_read_uncompressed;/*number of byte to be obtained after 
decomp*/
!       void* file;                 /* io structore of the zipfile */
        uLong compression_method;   /* compression method (0==store) */
        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
***************
*** 108,112 ****
  typedef struct
  {
!       FILE* file;                 /* io structore of the zipfile */
        unz_global_info gi;       /* public global information */
        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
--- 115,119 ----
  typedef struct
  {
!       void* file;                 /* io structore of the zipfile */
        unz_global_info gi;       /* public global information */
        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
***************
*** 134,143 ****
  
  
  local int unzlocal_getByte(fin,pi)
!       FILE *fin;
        int *pi;
  {
!     unsigned char c;
!       int err = fread(&c, 1, 1, fin);
      if (err==1)
      {
--- 141,151 ----
  
  
+ #if 0  /* not actually used anymore, at this point. */
  local int unzlocal_getByte(fin,pi)
!       void *fin;
        int *pi;
  {
!     PHYSFS_uint8 c;
!       PHYSFS_sint64 err = __PHYSFS_platformRead(fin, &c, sizeof (c), 1);
      if (err==1)
      {
***************
*** 147,157 ****
      else
      {
!         if (ferror(fin)) 
!             return UNZ_ERRNO;
!         else
              return UNZ_EOF;
      }
  }
! 
  
  /* ===========================================================================
--- 155,165 ----
      else
      {
!         if (__PHYSFS_platformEOF(fin)) 
              return UNZ_EOF;
+         else
+             return UNZ_ERRNO;
      }
  }
! #endif
  
  /* ===========================================================================
***************
*** 159,215 ****
  */
  local int unzlocal_getShort (fin,pX)
!       FILE* fin;
      uLong *pX;
  {
!     uLong x ;
!     int i;
!     int err;
! 
!     err = unzlocal_getByte(fin,&i);
!     x = (uLong)i;
!     
!     if (err==UNZ_OK)
!         err = unzlocal_getByte(fin,&i);
!     x += ((uLong)i)<<8;
!    
!     if (err==UNZ_OK)
!         *pX = x;
      else
          *pX = 0;
!     return err;
  }
  
  local int unzlocal_getLong (fin,pX)
!       FILE* fin;
      uLong *pX;
  {
!     uLong x ;
!     int i;
!     int err;
! 
!     err = unzlocal_getByte(fin,&i);
!     x = (uLong)i;
!     
!     if (err==UNZ_OK)
!         err = unzlocal_getByte(fin,&i);
!     x += ((uLong)i)<<8;
! 
!     if (err==UNZ_OK)
!         err = unzlocal_getByte(fin,&i);
!     x += ((uLong)i)<<16;
! 
!     if (err==UNZ_OK)
!         err = unzlocal_getByte(fin,&i);
!     x += ((uLong)i)<<24;
!    
!     if (err==UNZ_OK)
!         *pX = x;
      else
          *pX = 0;
!     return err;
  }
  
  
  /* My own strcmpi / strcasecmp */
  local int strcmpcasenosensitive_internal (fileName1,fileName2)
        const char* fileName1;
--- 167,222 ----
  */
  local int unzlocal_getShort (fin,pX)
!       void* fin;
      uLong *pX;
  {
!     PHYSFS_uint16 val;
!       PHYSFS_sint64 err = __PHYSFS_platformRead(fin, &val, sizeof (val), 1);
!     if (err==1)
!     {
!         *pX = (uLong) PHYSFS_swapULE16(val);
!         return UNZ_OK;
!     }
      else
+     {
          *pX = 0;
!         if (__PHYSFS_platformEOF(fin)) 
!             return UNZ_EOF;
!         else
!             return UNZ_ERRNO;
!     }
! 
!     return(UNZ_ERRNO);  /* shouldn't ever hit this. */
  }
  
  local int unzlocal_getLong (fin,pX)
!       void* fin;
      uLong *pX;
  {
!     PHYSFS_uint32 val;
!       PHYSFS_sint64 err = __PHYSFS_platformRead(fin, &val, sizeof (val), 1);
!     if (err==1)
!     {
!         *pX = (uLong) PHYSFS_swapULE32(val);
!         return UNZ_OK;
!     }
      else
+     {
          *pX = 0;
!         if (__PHYSFS_platformEOF(fin)) 
!             return UNZ_EOF;
!         else
!             return UNZ_ERRNO;
!     }
! 
!     return(UNZ_ERRNO);  /* shouldn't ever hit this. */
  }
  
  
  /* My own strcmpi / strcasecmp */
+ #if 1
+ 
+ #define strcmpcasenosensitive_internal(x,y) __PHYSFS_platformStricmp(x,y)
+ 
+ #else
  local int strcmpcasenosensitive_internal (fileName1,fileName2)
        const char* fileName1;
***************
*** 234,238 ****
        }
  }
! 
  
  #ifdef  CASESENSITIVITYDEFAULT_NO
--- 241,245 ----
        }
  }
! #endif
  
  #ifdef  CASESENSITIVITYDEFAULT_NO
***************
*** 276,280 ****
  */
  local uLong unzlocal_SearchCentralDir(fin)
!       FILE *fin;
  {
        unsigned char* buf;
--- 283,287 ----
  */
  local uLong unzlocal_SearchCentralDir(fin)
!       void *fin;
  {
        unsigned char* buf;
***************
*** 283,293 ****
        uLong uMaxBack=0xffff; /* maximum size of global comment */
        uLong uPosFound=0;
-       
-       if (fseek(fin,0,SEEK_END) != 0)
-               return 0;
  
  
-       uSizeFile = ftell( fin );
-       
        if (uMaxBack>uSizeFile)
                uMaxBack = uSizeFile;
--- 290,296 ----
        uLong uMaxBack=0xffff; /* maximum size of global comment */
        uLong uPosFound=0;
  
+       uSizeFile = (uLong) __PHYSFS_platformFileLength( fin );
  
        if (uMaxBack>uSizeFile)
                uMaxBack = uSizeFile;
***************
*** 310,321 ****
                uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 
                       (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
!               if (fseek(fin,uReadPos,SEEK_SET)!=0)
                        break;
  
!               if (fread(buf,(uInt)uReadSize,1,fin)!=1)
                        break;
  
!                 for (i=(int)uReadSize-3; (i--)>0;)
!                       if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 
                                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
                        {
--- 313,325 ----
                uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 
                       (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
!               if (!__PHYSFS_platformSeek(fin,uReadPos))
                        break;
  
!               if (__PHYSFS_platformRead(fin,buf,(uInt)uReadSize,1)!=1)
                        break;
  
!               for (i=(int)uReadSize-3; (i--)>0;)
!               {
!                       if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
                                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
                        {
***************
*** 323,326 ****
--- 327,331 ----
                                break;
                        }
+               }
  
                if (uPosFound!=0)
***************
*** 346,350 ****
        unz_s *s;
        uLong central_pos,uL;
!       FILE * fin ;
  
        uLong number_disk;          /* number of the current dist, used for 
--- 351,355 ----
        unz_s *s;
        uLong central_pos,uL;
!       void* fin ;
  
        uLong number_disk;          /* number of the current dist, used for 
***************
*** 361,365 ****
          return NULL;
  
!     fin=fopen(path,"rb");
        if (fin==NULL)
                return NULL;
--- 366,370 ----
          return NULL;
  
!     fin=__PHYSFS_platformOpenRead(path);
        if (fin==NULL)
                return NULL;
***************
*** 369,373 ****
                err=UNZ_ERRNO;
  
!       if (fseek(fin,central_pos,SEEK_SET)!=0)
                err=UNZ_ERRNO;
  
--- 374,378 ----
                err=UNZ_ERRNO;
  
!       if (!__PHYSFS_platformSeek(fin,central_pos))
                err=UNZ_ERRNO;
  
***************
*** 416,420 ****
        if (err!=UNZ_OK)
        {
!               fclose(fin);
                return NULL;
        }
--- 421,425 ----
        if (err!=UNZ_OK)
        {
!               __PHYSFS_platformClose(fin);
                return NULL;
        }
***************
*** 450,454 ****
          unzCloseCurrentFile(file);
  
!       fclose(s->file);
        TRYFREE(s);
        return UNZ_OK;
--- 455,459 ----
          unzCloseCurrentFile(file);
  
!       __PHYSFS_platformClose(s->file);
        TRYFREE(s);
        return UNZ_OK;
***************
*** 531,535 ****
                return UNZ_PARAMERROR;
        s=(unz_s*)file;
!       if 
(fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
                err=UNZ_ERRNO;
  
--- 536,540 ----
                return UNZ_PARAMERROR;
        s=(unz_s*)file;
!       if 
(!__PHYSFS_platformSeek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile))
                err=UNZ_ERRNO;
  
***************
*** 604,609 ****
  
                if ((file_info.size_filename>0) && (fileNameBufferSize>0))
!                       if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
                                err=UNZ_ERRNO;
                lSeek -= uSizeRead;
        }
--- 609,616 ----
  
                if ((file_info.size_filename>0) && (fileNameBufferSize>0))
!         {
!                       if 
(__PHYSFS_platformRead(s->file,szFileName,(uInt)uSizeRead,1)!=1)
                                err=UNZ_ERRNO;
+         }
                lSeek -= uSizeRead;
        }
***************
*** 620,624 ****
                if (lSeek!=0)
                {
!                       if (fseek(s->file,lSeek,SEEK_CUR)==0)
                                lSeek=0;
                        else
--- 627,632 ----
                if (lSeek!=0)
                {
!             PHYSFS_sint64 curpos = __PHYSFS_platformTell(s->file);
!                       if ((curpos >= 0) && 
(__PHYSFS_platformSeek(s->file,lSeek+curpos)))
                                lSeek=0;
                        else
***************
*** 627,631 ****
                if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
                {
!                       if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
                                err=UNZ_ERRNO;
                }
--- 635,639 ----
                if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
                {
!                       if 
(__PHYSFS_platformRead(s->file,extraField,(uInt)uSizeRead,1)!=1)
                                err=UNZ_ERRNO;
                }
***************
*** 649,653 ****
                if (lSeek!=0)
          {
!                       if (fseek(s->file,lSeek,SEEK_CUR)==0)
                                lSeek=0;
                        else
--- 657,662 ----
                if (lSeek!=0)
          {
!             PHYSFS_sint64 curpos = __PHYSFS_platformTell(s->file);
!                       if (__PHYSFS_platformSeek(s->file,lSeek+curpos))
                                lSeek=0;
                        else
***************
*** 656,660 ****
                if ((file_info.size_file_comment>0) && (commentBufferSize>0))
                {
!                       if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
                                err=UNZ_ERRNO;
                }
--- 665,669 ----
                if ((file_info.size_file_comment>0) && (commentBufferSize>0))
                {
!                       if 
(__PHYSFS_platformRead(s->file,szComment,(uInt)uSizeRead,1)!=1)
                                err=UNZ_ERRNO;
                }
***************
*** 830,835 ****
        *psize_local_extrafield = 0;
  
!       if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
!                                                               
s->byte_before_the_zipfile,SEEK_SET)!=0)
        {
                return UNZ_ERRNO;
--- 839,845 ----
        *psize_local_extrafield = 0;
  
!       if (!__PHYSFS_platformSeek(s->file,
!                                                               
s->cur_file_info_internal.offset_curfile +
!                                                               
s->byte_before_the_zipfile))
        {
                return UNZ_ERRNO;
***************
*** 1048,1057 ****
                        if (uReadThis == 0)
                                return UNZ_EOF;
!                       if (fseek(pfile_in_zip_read_info->file,
                        pfile_in_zip_read_info->pos_in_zipfile + 
!                          
pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
                                return UNZ_ERRNO;
!                       if 
(fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
!                          pfile_in_zip_read_info->file)!=1)
                                return UNZ_ERRNO;
                        pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
--- 1058,1068 ----
                        if (uReadThis == 0)
                                return UNZ_EOF;
!                       if (!__PHYSFS_platformSeek(pfile_in_zip_read_info->file,
                        pfile_in_zip_read_info->pos_in_zipfile + 
!                          pfile_in_zip_read_info->byte_before_the_zipfile))
                                return UNZ_ERRNO;
!                       if (__PHYSFS_platformRead(pfile_in_zip_read_info->file,
!                                       pfile_in_zip_read_info->read_buffer,
!                                       uReadThis,1)!=1)
                                return UNZ_ERRNO;
                        pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
***************
*** 1219,1228 ****
                return 0;
        
!       if (fseek(pfile_in_zip_read_info->file,
                pfile_in_zip_read_info->offset_local_extrafield + 
!                         
pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
                return UNZ_ERRNO;
  
!       if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
                return UNZ_ERRNO;
  
--- 1230,1239 ----
                return 0;
        
!       if (!__PHYSFS_platformSeek(pfile_in_zip_read_info->file,
                pfile_in_zip_read_info->offset_local_extrafield + 
!                         pfile_in_zip_read_info->pos_local_extrafield))
                return UNZ_ERRNO;
  
!       if 
(__PHYSFS_platformRead(pfile_in_zip_read_info->file,buf,(uInt)size_to_read,1)!=1)
                return UNZ_ERRNO;
  
***************
*** 1292,1296 ****
                uReadThis = s->gi.size_comment;
  
!       if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
                return UNZ_ERRNO;
  
--- 1303,1307 ----
                uReadThis = s->gi.size_comment;
  
!       if (!__PHYSFS_platformSeek(s->file,s->central_pos+22))
                return UNZ_ERRNO;
  
***************
*** 1298,1302 ****
      {
        *szComment='\0';
!         if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
                return UNZ_ERRNO;
      }
--- 1309,1313 ----
      {
        *szComment='\0';
!         if (__PHYSFS_platformRead(s->file,szComment,(uInt)uReadThis,1)!=1)
                return UNZ_ERRNO;
      }
***************
*** 1306,1307 ****
--- 1317,1319 ----
        return (int)uReadThis;
  }
+ 

Index: zip.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/archivers/zip.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** zip.c       15 Apr 2002 13:22:14 -0000      1.1.1.1
--- zip.c       27 Apr 2002 16:06:26 -0000      1.2
***************
*** 10,19 ****
   * !!! FIXME: overall design bugs.
   *
-  *  Make unz_file_info.version into two fields of unsigned char. That's what
-  *   they are in the zipfile; heavens knows why unzip.c casts it...this causes
-  *   a byte ordering headache for me in entry_is_symlink().
-  *
   *  Maybe add a seekToStartOfCurrentFile() in unzip.c if complete seek
   *   semantics are impossible.
   */
  
--- 10,18 ----
   * !!! FIXME: overall design bugs.
   *
   *  Maybe add a seekToStartOfCurrentFile() in unzip.c if complete seek
   *   semantics are impossible.
+  *
+  *  Could be more i/o efficient if we combined unzip.c and this file.
+  *   (and thus lose all the unzGoToNextFile() dummy loops.
   */
  
***************
*** 21,25 ****
  #include <stdlib.h>
  #include <string.h>
! #include <errno.h>
  #include "physfs.h"
  #include "unzip.h"
--- 20,24 ----
  #include <stdlib.h>
  #include <string.h>
! #include <assert.h>
  #include "physfs.h"
  #include "unzip.h"
***************
*** 59,71 ****
  
  
! static int ZIP_read(FileHandle *handle, void *buffer,
!                     unsigned int objSize, unsigned int objCount);
  static int ZIP_eof(FileHandle *handle);
! static int ZIP_tell(FileHandle *handle);
! static int ZIP_seek(FileHandle *handle, int offset);
! static int ZIP_fileLength(FileHandle *handle);
  static int ZIP_fileClose(FileHandle *handle);
  static int ZIP_isArchive(const char *filename, int forWriting);
! static char *ZIP_realpath(unzFile fh, unz_file_info *info);
  static DirHandle *ZIP_openArchive(const char *name, int forWriting);
  static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
--- 58,70 ----
  
  
! static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buffer,
!                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  static int ZIP_eof(FileHandle *handle);
! static PHYSFS_sint64 ZIP_tell(FileHandle *handle);
! static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset);
! static PHYSFS_sint64 ZIP_fileLength(FileHandle *handle);
  static int ZIP_fileClose(FileHandle *handle);
  static int ZIP_isArchive(const char *filename, int forWriting);
! static char *ZIP_realpath(unzFile fh, unz_file_info *info, ZIPentry *entry);
  static DirHandle *ZIP_openArchive(const char *name, int forWriting);
  static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
***************
*** 111,115 ****
      "ZIP",
      "PkZip/WinZip/Info-Zip compatible",
!     "Ryan C. Gordon (address@hidden)",
      "http://www.icculus.org/physfs/";,
  };
--- 110,114 ----
      "ZIP",
      "PkZip/WinZip/Info-Zip compatible",
!     "Ryan C. Gordon <address@hidden>",
      "http://www.icculus.org/physfs/";,
  };
***************
*** 117,126 ****
  
  
! static int ZIP_read(FileHandle *handle, void *buffer,
!                     unsigned int objSize, unsigned int objCount)
  {
      unzFile fh = ((ZIPfileinfo *) (handle->opaque))->handle;
!     int bytes = objSize * objCount;
!     int rc = unzReadCurrentFile(fh, buffer, bytes);
  
      if (rc < bytes)
--- 116,125 ----
  
  
! static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buffer,
!                               PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  {
      unzFile fh = ((ZIPfileinfo *) (handle->opaque))->handle;
!     int bytes = (int) (objSize * objCount); /* !!! FIXME: overflow? */
!     PHYSFS_sint32 rc = unzReadCurrentFile(fh, buffer, bytes);
  
      if (rc < bytes)
***************
*** 141,145 ****
  
  
! static int ZIP_tell(FileHandle *handle)
  {
      return(unztell(((ZIPfileinfo *) (handle->opaque))->handle));
--- 140,144 ----
  
  
! static PHYSFS_sint64 ZIP_tell(FileHandle *handle)
  {
      return(unztell(((ZIPfileinfo *) (handle->opaque))->handle));
***************
*** 147,159 ****
  
  
! static int ZIP_seek(FileHandle *handle, int offset)
  {
!     /* this blows. */
      unzFile fh = ((ZIPfileinfo *) (handle->opaque))->handle;
      char *buf = NULL;
!     int bufsize = 4096 * 2;
  
      BAIL_IF_MACRO(unztell(fh) == offset, NULL, 1);
!     BAIL_IF_MACRO(ZIP_fileLength(handle) <= offset, ERR_PAST_EOF, 0);
  
          /* reset to the start of the zipfile. */
--- 146,158 ----
  
  
! static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset)
  {
!     /* !!! FIXME : this blows. */
      unzFile fh = ((ZIPfileinfo *) (handle->opaque))->handle;
      char *buf = NULL;
!     PHYSFS_uint32 bufsize = 4096 * 2;
  
      BAIL_IF_MACRO(unztell(fh) == offset, NULL, 1);
!     BAIL_IF_MACRO(ZIP_fileLength(handle) <= (PHYSFS_sint64) offset, 
ERR_PAST_EOF, 0);
  
          /* reset to the start of the zipfile. */
***************
*** 170,175 ****
      while (offset > 0)
      {
!         int chunk = (offset > bufsize) ? bufsize : offset;
!         int rc = unzReadCurrentFile(fh, buf, chunk);
          BAIL_IF_MACRO(rc == 0, ERR_IO_ERROR, 0);  /* shouldn't happen. */
          BAIL_IF_MACRO(rc == UNZ_ERRNO, ERR_IO_ERROR, 0);
--- 169,174 ----
      while (offset > 0)
      {
!         PHYSFS_uint32 chunk = (offset > bufsize) ? bufsize : 
(PHYSFS_uint32)offset;
!         PHYSFS_sint32 rc = unzReadCurrentFile(fh, buf, chunk);
          BAIL_IF_MACRO(rc == 0, ERR_IO_ERROR, 0);  /* shouldn't happen. */
          BAIL_IF_MACRO(rc == UNZ_ERRNO, ERR_IO_ERROR, 0);
***************
*** 183,187 ****
  
  
! static int ZIP_fileLength(FileHandle *handle)
  {
      ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque);
--- 182,186 ----
  
  
! static PHYSFS_sint64 ZIP_fileLength(FileHandle *handle)
  {
      ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque);
***************
*** 238,269 ****
  
  
! static char *ZIP_realpath(unzFile fh, unz_file_info *info)
  {
!     char *retval = NULL;
!     int size;
! 
!     BAIL_IF_MACRO(unzOpenCurrentFile(fh) != UNZ_OK, ERR_IO_ERROR, NULL);
!     size = info->uncompressed_size;
!     retval = (char *) malloc(size + 1);
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
!     if (unzReadCurrentFile(fh, retval, size) != size)
!     {
!         free(retval);
!         __PHYSFS_setError(ERR_IO_ERROR);
!         retval = NULL;
!     } /* if */
!     retval[size] = '\0';
!     unzCloseCurrentFile(fh);
! 
      return(retval);
! } /* ZIP_realpath */
  
  
! /* "uLong" is defined by zlib and/or unzip.h ... */
! typedef union
  {
!     unsigned char uchar4[4];
!     uLong ul;
! } uchar4_uLong;
  
  
--- 237,270 ----
  
  
! /*
!  * !!! FIXME: Really implement this.
!  * !!! FIXME:  symlinks in zipfiles can be relative paths, including
!  * !!! FIXME:  "." and ".." entries. These need to be parsed out.
!  * !!! FIXME:  For now, though, we're just copying the relative path. Oh well.
!  */
! static char *expand_symlink_path(const char *path, ZIPentry *entry)
  {
!     char *retval = (char *) malloc(strlen(path) + 1);
      BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
!     strcpy(retval, path);
      return(retval);
! } /* expand_symlink_path */
  
  
! static char *ZIP_realpath(unzFile fh, unz_file_info *info, ZIPentry *entry)
  {
!     char path[MAXZIPENTRYSIZE];
!     int size = info->uncompressed_size;
!     int rc;
! 
!     BAIL_IF_MACRO(size >= sizeof (path), ERR_IO_ERROR, NULL);
!     BAIL_IF_MACRO(unzOpenCurrentFile(fh) != UNZ_OK, ERR_IO_ERROR, NULL);
!     rc = unzReadCurrentFile(fh, path, size);
!     unzCloseCurrentFile(fh);
!     BAIL_IF_MACRO(rc != size, ERR_IO_ERROR, NULL);
!     path[size] = '\0'; /* null terminate it. */
! 
!     return(expand_symlink_path(path, entry));  /* retval is malloc()'d. */
! } /* ZIP_realpath */
  
  
***************
*** 271,280 ****
  {
      int retval = 0;
!     unsigned char hosttype;
!     uchar4_uLong converter;
! 
!     converter.ul = version;
!     hosttype = converter.uchar4[1]; /* !!! BYTE ORDERING ALERT! */
! 
  
      /*
--- 272,276 ----
  {
      int retval = 0;
!     PHYSFS_uint8 hosttype = (PHYSFS_uint8) ((version >> 8) & 0xFF);
  
      /*
***************
*** 345,349 ****
          if (entry_is_symlink(d))
          {
!             info->entries[i].symlink = ZIP_realpath(unz, d);
              if (info->entries[i].symlink == NULL)
              {
--- 341,345 ----
          if (entry_is_symlink(d))
          {
!             info->entries[i].symlink = ZIP_realpath(unz, d, 
&info->entries[i]);
              if (info->entries[i].symlink == NULL)
              {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]