archivers/zip.c
changeset 254 c66bbbe50f14
parent 240 052041af9001
child 335 1d4720c018c3
equal deleted inserted replaced
253:869840fedb76 254:c66bbbe50f14
    24 
    24 
    25 #include <stdio.h>
    25 #include <stdio.h>
    26 #include <stdlib.h>
    26 #include <stdlib.h>
    27 #include <string.h>
    27 #include <string.h>
    28 #include <assert.h>
    28 #include <assert.h>
       
    29 #include <time.h>
    29 #include "physfs.h"
    30 #include "physfs.h"
    30 #include "unzip.h"
    31 #include "unzip.h"
    31 
    32 
    32 
    33 
    33 #define __PHYSICSFS_INTERNAL__
    34 #define __PHYSICSFS_INTERNAL__
    73                                             const char *dirname,
    74                                             const char *dirname,
    74                                             int omitSymLinks);
    75                                             int omitSymLinks);
    75 static int ZIP_exists(DirHandle *h, const char *name);
    76 static int ZIP_exists(DirHandle *h, const char *name);
    76 static int ZIP_isDirectory(DirHandle *h, const char *name);
    77 static int ZIP_isDirectory(DirHandle *h, const char *name);
    77 static int ZIP_isSymLink(DirHandle *h, const char *name);
    78 static int ZIP_isSymLink(DirHandle *h, const char *name);
       
    79 static PHYSFS_sint64 ZIP_getLastModTime(DirHandle *h, const char *name);
    78 static FileHandle *ZIP_openRead(DirHandle *h, const char *filename);
    80 static FileHandle *ZIP_openRead(DirHandle *h, const char *filename);
    79 static void ZIP_dirClose(DirHandle *h);
    81 static void ZIP_dirClose(DirHandle *h);
    80 
    82 
    81 
    83 
    82 static const FileFunctions __PHYSFS_FileFunctions_ZIP =
    84 static const FileFunctions __PHYSFS_FileFunctions_ZIP =
    97     ZIP_openArchive,        /* openArchive() method    */
    99     ZIP_openArchive,        /* openArchive() method    */
    98     ZIP_enumerateFiles,     /* enumerateFiles() method */
   100     ZIP_enumerateFiles,     /* enumerateFiles() method */
    99     ZIP_exists,             /* exists() method         */
   101     ZIP_exists,             /* exists() method         */
   100     ZIP_isDirectory,        /* isDirectory() method    */
   102     ZIP_isDirectory,        /* isDirectory() method    */
   101     ZIP_isSymLink,          /* isSymLink() method      */
   103     ZIP_isSymLink,          /* isSymLink() method      */
   102     NULL,                   /* getLastModTime() method */  /* !!! FIXME: This can be determined in a zipfile. */
   104     ZIP_getLastModTime,     /* getLastModTime() method */
   103     ZIP_openRead,           /* openRead() method       */
   105     ZIP_openRead,           /* openRead() method       */
   104     NULL,                   /* openWrite() method      */
   106     NULL,                   /* openWrite() method      */
   105     NULL,                   /* openAppend() method     */
   107     NULL,                   /* openAppend() method     */
   106     NULL,                   /* remove() method         */
   108     NULL,                   /* remove() method         */
   107     NULL,                   /* mkdir() method          */
   109     NULL,                   /* mkdir() method          */
   579 
   581 
   580     return(1);
   582     return(1);
   581 } /* ZIP_exists */
   583 } /* ZIP_exists */
   582 
   584 
   583 
   585 
       
   586 static PHYSFS_sint64 ZIP_getLastModTime(DirHandle *h, const char *name)
       
   587 {
       
   588     ZIPinfo *zi = (ZIPinfo *) (h->opaque);
       
   589     int pos = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT);
       
   590     ZIPentry *entry;
       
   591     struct tm t;
       
   592 
       
   593     if (pos == -1)
       
   594         return(0);
       
   595 
       
   596     entry = &zi->entries[pos];
       
   597 
       
   598     /* if it's a symlink, then we ran into a possible symlink loop. */
       
   599     BAIL_IF_MACRO(entry->symlink != NULL, ERR_TOO_MANY_SYMLINKS, 0);
       
   600 
       
   601     memset(&t, '\0', sizeof (t));
       
   602     t.tm_year = entry->info.tmu_date.tm_year - 1900;
       
   603     t.tm_mon = entry->info.tmu_date.tm_mon;
       
   604     t.tm_mday = entry->info.tmu_date.tm_mday;
       
   605     t.tm_hour = entry->info.tmu_date.tm_hour;
       
   606     t.tm_min = entry->info.tmu_date.tm_min;
       
   607     t.tm_sec = entry->info.tmu_date.tm_sec;
       
   608     return((PHYSFS_sint64) mktime(&t));
       
   609 } /* ZIP_getLastModTime */
       
   610 
       
   611 
   584 static int ZIP_isDirectory(DirHandle *h, const char *name)
   612 static int ZIP_isDirectory(DirHandle *h, const char *name)
   585 {
   613 {
   586     int dlen;
   614     int dlen;
   587     int is_sym;
   615     int is_sym;
   588     int retval = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT);
   616     int retval = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT);