archivers/zip.c
changeset 55 986740ba58ab
parent 53 6c3c990f006e
child 61 2f2afcbd8abd
equal deleted inserted replaced
54:2756e7c8125f 55:986740ba58ab
   514     free(d);
   514     free(d);
   515     return(-1);
   515     return(-1);
   516 } /* ZIP_exists_symcheck */
   516 } /* ZIP_exists_symcheck */
   517 
   517 
   518 
   518 
   519 static int ZIP_exists_nofollow(DirHandle *h, const char *name)
       
   520 {
       
   521     return(ZIP_exists_symcheck(h, name, 0));
       
   522 } /* ZIP_exists_nofollow */
       
   523 
       
   524 
       
   525 static int ZIP_exists(DirHandle *h, const char *name)
   519 static int ZIP_exists(DirHandle *h, const char *name)
   526 {
   520 {
   527     int retval = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT);
   521     int retval = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT);
   528     int is_sym;
   522     int is_sym;
   529 
   523 
   558 } /* ZIP_isDirectory */
   552 } /* ZIP_isDirectory */
   559 
   553 
   560 
   554 
   561 static int ZIP_isSymLink(DirHandle *h, const char *name)
   555 static int ZIP_isSymLink(DirHandle *h, const char *name)
   562 {
   556 {
   563     int retval = ZIP_exists_nofollow(h, name);
   557     int retval = ZIP_exists_symcheck(h, name, 0);
   564     if (retval == -1)
   558     if (retval == -1)
   565         return(0);
   559         return(0);
   566 
   560 
   567     retval = ( ((ZIPinfo *)(h->opaque))->entries[retval].symlink != NULL );
   561     retval = ( ((ZIPinfo *)(h->opaque))->entries[retval].symlink != NULL );
   568     return(retval);
   562     return(retval);
   572 static FileHandle *ZIP_openRead(DirHandle *h, const char *filename)
   566 static FileHandle *ZIP_openRead(DirHandle *h, const char *filename)
   573 {
   567 {
   574     FileHandle *retval = NULL;
   568     FileHandle *retval = NULL;
   575     ZIPinfo *zi = ((ZIPinfo *) (h->opaque));
   569     ZIPinfo *zi = ((ZIPinfo *) (h->opaque));
   576     ZIPfileinfo *finfo = NULL;
   570     ZIPfileinfo *finfo = NULL;
       
   571     int pos = ZIP_exists_symcheck(h, filename, SYMLINK_RECURSE_COUNT);
   577     unzFile f;
   572     unzFile f;
   578 
   573 
   579     BAIL_IF_MACRO(!ZIP_exists(h, filename), ERR_NO_SUCH_FILE, NULL);
   574     BAIL_IF_MACRO(pos == -1, ERR_NO_SUCH_FILE, NULL);
   580 
   575 
   581     f = unzOpen(zi->archiveName);
   576     f = unzOpen(zi->archiveName);
   582     BAIL_IF_MACRO(f == NULL, ERR_IO_ERROR, NULL);
   577     BAIL_IF_MACRO(f == NULL, ERR_IO_ERROR, NULL);
   583 
   578 
   584     if ( (unzLocateFile(f, filename, 2) != UNZ_OK) ||
   579     if (unzGoToFirstFile(f) != UNZ_OK)
   585          (unzOpenCurrentFile(f) != UNZ_OK) ||
   580     {
       
   581         unzClose(f);
       
   582         BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL);
       
   583     } /* if */
       
   584 
       
   585     for (; pos > 0; pos--)
       
   586     {
       
   587         if (unzGoToNextFile(f) != UNZ_OK)
       
   588         {
       
   589             unzClose(f);
       
   590             BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL);
       
   591         } /* if */
       
   592     } /* for */
       
   593 
       
   594     if ( (unzOpenCurrentFile(f) != UNZ_OK) ||
   586          ( (finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo))) == NULL ) )
   595          ( (finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo))) == NULL ) )
   587     {
   596     {
   588         unzClose(f);
   597         unzClose(f);
   589         BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL);
   598         BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL);
   590     } /* if */
   599     } /* if */