Back to index

php5  5.3.10
Classes | Defines | Enumerations | Functions | Variables
zipint.h File Reference
#include <zlib.h>
#include "zip.h"

Go to the source code of this file.

Classes

struct  zip_error
struct  zip
struct  zip_file
struct  zip_dirent
struct  zip_cdir
struct  zip_source
struct  zip_entry

Defines

#define _zip_rename   rename
#define strcmpi   strcasecmp
#define fseeko(s, o, w)   (fseek((s), (long int)(o), (w)))
#define ftello(s)   ((long)ftell((s)))
#define CENTRAL_MAGIC   "PK\1\2"
#define LOCAL_MAGIC   "PK\3\4"
#define EOCD_MAGIC   "PK\5\6"
#define DATADES_MAGIC   "PK\7\8"
#define TORRENT_SIG   "TORRENTZIPPED-"
#define TORRENT_SIG_LEN   14
#define TORRENT_CRC_LEN   8
#define TORRENT_MEM_LEVEL   8
#define CDENTRYSIZE   46u
#define LENTRYSIZE   30
#define MAXCOMLEN   65536
#define EOCDLEN   22
#define CDBUFSIZE   (MAXCOMLEN+EOCDLEN)
#define BUFSIZE   8192
#define ZIP_ZF_EOF   1 /* EOF reached */
#define ZIP_ZF_DECOMP   2 /* decompress data */
#define ZIP_ZF_CRC   4 /* compute and compare CRC */
#define ZIP_GPBF_ENCRYPTED   0x0001 /* is encrypted */
#define ZIP_GPBF_DATA_DESCRIPTOR   0x0008 /* crc/size after file data */
#define ZIP_GPBF_STRONG_ENCRYPTION   0x0040 /* uses strong encryption */
#define ZIP_ENTRY_DATA_CHANGED(x)

Enumerations

enum  zip_state {
  ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED, ZIP_ST_ADDED,
  ZIP_ST_RENAMED
}

Functions

int _zip_cdir_compute_crc (struct zip *, uLong *)
void _zip_cdir_free (struct zip_cdir *)
int _zip_cdir_grow (struct zip_cdir *, int, struct zip_error *)
struct zip_cdir_zip_cdir_new (int, struct zip_error *)
int _zip_cdir_write (struct zip_cdir *, FILE *, struct zip_error *)
void _zip_dirent_finalize (struct zip_dirent *)
void _zip_dirent_init (struct zip_dirent *)
int _zip_dirent_read (struct zip_dirent *, FILE *, unsigned char **, unsigned int *, int, struct zip_error *)
void _zip_dirent_torrent_normalize (struct zip_dirent *)
int _zip_dirent_write (struct zip_dirent *, FILE *, int, struct zip_error *)
void _zip_entry_free (struct zip_entry *)
void _zip_entry_init (struct zip *, int)
struct zip_entry_zip_entry_new (struct zip *)
void _zip_error_clear (struct zip_error *)
void _zip_error_copy (struct zip_error *, struct zip_error *)
void _zip_error_fini (struct zip_error *)
void _zip_error_get (struct zip_error *, int *, int *)
void _zip_error_init (struct zip_error *)
void _zip_error_set (struct zip_error *, int, int)
const char * _zip_error_strerror (struct zip_error *)
int _zip_file_fillbuf (void *, size_t, struct zip_file *)
unsigned int _zip_file_get_offset (struct zip *, int)
int _zip_filerange_crc (FILE *, off_t, off_t, uLong *, struct zip_error *)
struct zip_source_zip_source_file_or_p (struct zip *, const char *, FILE *, off_t, off_t)
void _zip_free (struct zip *)
const char * _zip_get_name (struct zip *, int, int, struct zip_error *)
int _zip_local_header_read (struct zip *, int)
void * _zip_memdup (const void *, size_t, struct zip_error *)
int _zip_name_locate (struct zip *, const char *, int, struct zip_error *)
struct zip_zip_new (struct zip_error *)
unsigned short _zip_read2 (unsigned char **)
unsigned int _zip_read4 (unsigned char **)
int _zip_replace (struct zip *, int, const char *, struct zip_source *)
int _zip_set_name (struct zip *, int, const char *)
int _zip_unchange (struct zip *, int, int)
void _zip_unchange_data (struct zip_entry *)

Variables

const char *const _zip_err_str []
const int _zip_nerr_str
const int _zip_err_type []

Class Documentation

struct zip_error

Definition at line 101 of file zipint.h.

Class Members
char * str
int sys_err
int zip_err
struct zip

Definition at line 109 of file zipint.h.

Collaboration diagram for zip:
Class Members
struct zip_cdir * cdir
char * ch_comment
int ch_comment_len
unsigned int ch_flags
struct zip_entry * entry
struct zip_file ** file
unsigned int flags
int nentry
int nentry_alloc
int nfile
int nfile_alloc
char * zn
FILE * zp
struct zip_file

Definition at line 131 of file zipint.h.

Collaboration diagram for zip_file:
Class Members
char * buffer
unsigned long bytes_left
unsigned long cbytes_left
unsigned long crc
unsigned long crc_orig
int flags
off_t fpos
int method
struct zip * za
z_stream * zstr
struct zip_dirent

Definition at line 150 of file zipint.h.

Class Members
unsigned short bitflags
char * comment
unsigned short comment_len
unsigned short comp_method
unsigned int comp_size
unsigned int crc
unsigned short disk_number
unsigned int ext_attrib
char * extrafield
unsigned short extrafield_len
char * filename
unsigned short filename_len
unsigned short int_attrib
time_t last_mod
unsigned int offset
unsigned int uncomp_size
unsigned short version_madeby
unsigned short version_needed
struct zip_cdir

Definition at line 173 of file zipint.h.

Collaboration diagram for zip_cdir:
Class Members
char * comment
unsigned short comment_len
struct zip_dirent * entry
int nentry
unsigned int offset
unsigned int size
struct zip_source

Definition at line 185 of file zipint.h.

Class Members
zip_source_callback f
void * ud
struct zip_entry

Definition at line 192 of file zipint.h.

Collaboration diagram for zip_entry:
Class Members
char * ch_comment
int ch_comment_len
char * ch_filename
enum zip_state struct zip_source * source

Define Documentation

#define _zip_rename   rename

Definition at line 48 of file zipint.h.

#define BUFSIZE   8192

Definition at line 78 of file zipint.h.

#define CDBUFSIZE   (MAXCOMLEN+EOCDLEN)

Definition at line 77 of file zipint.h.

#define CDENTRYSIZE   46u

Definition at line 72 of file zipint.h.

#define CENTRAL_MAGIC   "PK\1\2"

Definition at line 64 of file zipint.h.

#define DATADES_MAGIC   "PK\7\8"

Definition at line 67 of file zipint.h.

#define EOCD_MAGIC   "PK\5\6"

Definition at line 66 of file zipint.h.

#define EOCDLEN   22

Definition at line 76 of file zipint.h.

#define fseeko (   s,
  o,
 
)    (fseek((s), (long int)(o), (w)))

Definition at line 56 of file zipint.h.

#define ftello (   s)    ((long)ftell((s)))

Definition at line 59 of file zipint.h.

#define LENTRYSIZE   30

Definition at line 73 of file zipint.h.

#define LOCAL_MAGIC   "PK\3\4"

Definition at line 65 of file zipint.h.

#define MAXCOMLEN   65536

Definition at line 75 of file zipint.h.

#define strcmpi   strcasecmp

Definition at line 52 of file zipint.h.

#define TORRENT_CRC_LEN   8

Definition at line 70 of file zipint.h.

#define TORRENT_MEM_LEVEL   8

Definition at line 71 of file zipint.h.

#define TORRENT_SIG   "TORRENTZIPPED-"

Definition at line 68 of file zipint.h.

#define TORRENT_SIG_LEN   14

Definition at line 69 of file zipint.h.

#define ZIP_ENTRY_DATA_CHANGED (   x)
Value:
((x)->state == ZIP_ST_REPLACED  \
                      || (x)->state == ZIP_ST_ADDED)

Definition at line 208 of file zipint.h.

#define ZIP_GPBF_DATA_DESCRIPTOR   0x0008 /* crc/size after file data */

Definition at line 96 of file zipint.h.

#define ZIP_GPBF_ENCRYPTED   0x0001 /* is encrypted */

Definition at line 95 of file zipint.h.

#define ZIP_GPBF_STRONG_ENCRYPTION   0x0040 /* uses strong encryption */

Definition at line 97 of file zipint.h.

#define ZIP_ZF_CRC   4 /* compute and compare CRC */

Definition at line 91 of file zipint.h.

#define ZIP_ZF_DECOMP   2 /* decompress data */

Definition at line 90 of file zipint.h.

#define ZIP_ZF_EOF   1 /* EOF reached */

Definition at line 89 of file zipint.h.


Enumeration Type Documentation

enum zip_state
Enumerator:
ZIP_ST_UNCHANGED 
ZIP_ST_DELETED 
ZIP_ST_REPLACED 
ZIP_ST_ADDED 
ZIP_ST_RENAMED 

Definition at line 84 of file zipint.h.


Function Documentation

int _zip_cdir_compute_crc ( struct zip ,
uLong *   
)
void _zip_cdir_free ( struct zip_cdir )

Definition at line 55 of file zip_dirent.c.

{
    int i;

    if (!cd)
       return;

    for (i=0; i<cd->nentry; i++)
       _zip_dirent_finalize(cd->entry+i);
    free(cd->comment);
    free(cd->entry);
    free(cd);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_cdir_grow ( struct zip_cdir ,
int  ,
struct zip_error  
)

Definition at line 72 of file zip_dirent.c.

{
    struct zip_dirent *entry;

    if (nentry < cd->nentry) {
       _zip_error_set(error, ZIP_ER_INTERNAL, 0);
       return -1;
    }

    if ((entry=((struct zip_dirent *)
              realloc(cd->entry, sizeof(*(cd->entry))*nentry))) == NULL) {
       _zip_error_set(error, ZIP_ER_MEMORY, 0);
       return -1;
    }

    cd->nentry = nentry;
    cd->entry = entry;

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct zip_cdir* _zip_cdir_new ( int  ,
struct zip_error  
) [read]

Definition at line 96 of file zip_dirent.c.

{
    struct zip_cdir *cd;
    
    if ((cd=(struct zip_cdir *)malloc(sizeof(*cd))) == NULL) {
       _zip_error_set(error, ZIP_ER_MEMORY, 0);
       return NULL;
    }

    if ((cd->entry=(struct zip_dirent *)malloc(sizeof(*(cd->entry))*nentry))
       == NULL) {
       _zip_error_set(error, ZIP_ER_MEMORY, 0);
       free(cd);
       return NULL;
    }

    /* entries must be initialized by caller */

    cd->nentry = nentry;
    cd->size = cd->offset = 0;
    cd->comment = NULL;
    cd->comment_len = 0;

    return cd;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_cdir_write ( struct zip_cdir ,
FILE *  ,
struct zip_error  
)

Definition at line 125 of file zip_dirent.c.

{
    int i;

    cd->offset = ftello(fp);

    for (i=0; i<cd->nentry; i++) {
       if (_zip_dirent_write(cd->entry+i, fp, 0, error) != 0)
           return -1;
    }

    cd->size = ftello(fp) - cd->offset;
    
    /* clearerr(fp); */
    fwrite(EOCD_MAGIC, 1, 4, fp);
    _zip_write4(0, fp);
    _zip_write2((unsigned short)cd->nentry, fp);
    _zip_write2((unsigned short)cd->nentry, fp);
    _zip_write4(cd->size, fp);
    _zip_write4(cd->offset, fp);
    _zip_write2(cd->comment_len, fp);
    fwrite(cd->comment, 1, cd->comment_len, fp);

    if (ferror(fp)) {
       _zip_error_set(error, ZIP_ER_WRITE, errno);
       return -1;
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_dirent_finalize ( struct zip_dirent )

Definition at line 159 of file zip_dirent.c.

{
    free(zde->filename);
    zde->filename = NULL;
    free(zde->extrafield);
    zde->extrafield = NULL;
    free(zde->comment);
    zde->comment = NULL;
}

Here is the caller graph for this function:

void _zip_dirent_init ( struct zip_dirent )

Definition at line 172 of file zip_dirent.c.

{
    de->version_madeby = 0;
    de->version_needed = 20; /* 2.0 */
    de->bitflags = 0;
    de->comp_method = 0;
    de->last_mod = 0;
    de->crc = 0;
    de->comp_size = 0;
    de->uncomp_size = 0;
    de->filename = NULL;
    de->filename_len = 0;
    de->extrafield = NULL;
    de->extrafield_len = 0;
    de->comment = NULL;
    de->comment_len = 0;
    de->disk_number = 0;
    de->int_attrib = 0;
    de->ext_attrib = 0;
    de->offset = 0;
}

Here is the caller graph for this function:

int _zip_dirent_read ( struct zip_dirent ,
FILE *  ,
unsigned char **  ,
unsigned int ,
int  ,
struct zip_error  
)

Definition at line 215 of file zip_dirent.c.

{
    unsigned char buf[CDENTRYSIZE];
    unsigned char *cur;
    unsigned short dostime, dosdate;
    unsigned int size;

    if (local)
       size = LENTRYSIZE;
    else
       size = CDENTRYSIZE;

    if (leftp && (*leftp < size)) {
       _zip_error_set(error, ZIP_ER_NOZIP, 0);
       return -1;
    }

    if (bufp) {
       /* use data from buffer */
       cur = *bufp;
    }
    else {
       /* read entry from disk */
       if ((fread(buf, 1, size, fp)<size)) {
           _zip_error_set(error, ZIP_ER_READ, errno);
           return -1;
       }
       cur = buf;
    }

    if (memcmp(cur, (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
       _zip_error_set(error, ZIP_ER_NOZIP, 0);
       return -1;
    }
    cur += 4;

    
    /* convert buffercontents to zip_dirent */
    
    if (!local)
       zde->version_madeby = _zip_read2(&cur);
    else
       zde->version_madeby = 0;
    zde->version_needed = _zip_read2(&cur);
    zde->bitflags = _zip_read2(&cur);
    zde->comp_method = _zip_read2(&cur);
    
    /* convert to time_t */
    dostime = _zip_read2(&cur);
    dosdate = _zip_read2(&cur);
    zde->last_mod = _zip_d2u_time(dostime, dosdate);
    
    zde->crc = _zip_read4(&cur);
    zde->comp_size = _zip_read4(&cur);
    zde->uncomp_size = _zip_read4(&cur);
    
    zde->filename_len = _zip_read2(&cur);
    zde->extrafield_len = _zip_read2(&cur);
    
    if (local) {
       zde->comment_len = 0;
       zde->disk_number = 0;
       zde->int_attrib = 0;
       zde->ext_attrib = 0;
       zde->offset = 0;
    } else {
       zde->comment_len = _zip_read2(&cur);
       zde->disk_number = _zip_read2(&cur);
       zde->int_attrib = _zip_read2(&cur);
       zde->ext_attrib = _zip_read4(&cur);
       zde->offset = _zip_read4(&cur);
    }

    zde->filename = NULL;
    zde->extrafield = NULL;
    zde->comment = NULL;

    size += zde->filename_len+zde->extrafield_len+zde->comment_len;

    if (leftp && (*leftp < size)) {
       _zip_error_set(error, ZIP_ER_NOZIP, 0);
       return -1;
    }

    if (bufp) {
       if (zde->filename_len) {
           zde->filename = _zip_readstr(&cur, zde->filename_len, 1, error);
           if (!zde->filename)
                  return -1;
       }

       if (zde->extrafield_len) {
           zde->extrafield = _zip_readstr(&cur, zde->extrafield_len, 0,
                                      error);
           if (!zde->extrafield)
              return -1;
       }

       if (zde->comment_len) {
           zde->comment = _zip_readstr(&cur, zde->comment_len, 0, error);
           if (!zde->comment)
              return -1;
       }
    }
    else {
       if (zde->filename_len) {
           zde->filename = _zip_readfpstr(fp, zde->filename_len, 1, error);
           if (!zde->filename)
                  return -1;
       }

       if (zde->extrafield_len) {
           zde->extrafield = _zip_readfpstr(fp, zde->extrafield_len, 0,
                                        error);
           if (!zde->extrafield)
              return -1;
       }

       if (zde->comment_len) {
           zde->comment = _zip_readfpstr(fp, zde->comment_len, 0, error);
           if (!zde->comment)
              return -1;
       }
    }

    if (bufp)
      *bufp = cur;
    if (leftp)
       *leftp -= size;

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 357 of file zip_dirent.c.

{
    static struct tm torrenttime;
    static time_t last_mod = 0;

    if (last_mod == 0) {
#ifdef HAVE_STRUCT_TM_TM_ZONE
       time_t now;
       struct tm *l;
#endif

       torrenttime.tm_sec = 0;
       torrenttime.tm_min = 32;
       torrenttime.tm_hour = 23;
       torrenttime.tm_mday = 24;
       torrenttime.tm_mon = 11;
       torrenttime.tm_year = 96;
       torrenttime.tm_wday = 0;
       torrenttime.tm_yday = 0;
       torrenttime.tm_isdst = 0;

#ifdef HAVE_STRUCT_TM_TM_ZONE
       time(&now);
       l = localtime(&now);
       torrenttime.tm_gmtoff = l->tm_gmtoff;
       torrenttime.tm_zone = l->tm_zone;
#endif

       last_mod = mktime(&torrenttime);
    }
    
    de->version_madeby = 0;
    de->version_needed = 20; /* 2.0 */
    de->bitflags = 2; /* maximum compression */
    de->comp_method = ZIP_CM_DEFLATE;
    de->last_mod = last_mod;

    de->disk_number = 0;
    de->int_attrib = 0;
    de->ext_attrib = 0;
    de->offset = 0;

    free(de->extrafield);
    de->extrafield = NULL;
    de->extrafield_len = 0;
    free(de->comment);
    de->comment = NULL;
    de->comment_len = 0;
}

Here is the caller graph for this function:

int _zip_dirent_write ( struct zip_dirent ,
FILE *  ,
int  ,
struct zip_error  
)

Definition at line 420 of file zip_dirent.c.

{
    unsigned short dostime, dosdate;

    fwrite(localp ? LOCAL_MAGIC : CENTRAL_MAGIC, 1, 4, fp);

    if (!localp)
       _zip_write2(zde->version_madeby, fp);
    _zip_write2(zde->version_needed, fp);
    _zip_write2(zde->bitflags, fp);
    _zip_write2(zde->comp_method, fp);

    _zip_u2d_time(zde->last_mod, &dostime, &dosdate);
    _zip_write2(dostime, fp);
    _zip_write2(dosdate, fp);
    
    _zip_write4(zde->crc, fp);
    _zip_write4(zde->comp_size, fp);
    _zip_write4(zde->uncomp_size, fp);
    
    _zip_write2(zde->filename_len, fp);
    _zip_write2(zde->extrafield_len, fp);
    
    if (!localp) {
       _zip_write2(zde->comment_len, fp);
       _zip_write2(zde->disk_number, fp);
       _zip_write2(zde->int_attrib, fp);
       _zip_write4(zde->ext_attrib, fp);
       _zip_write4(zde->offset, fp);
    }

    if (zde->filename_len)
       fwrite(zde->filename, 1, zde->filename_len, fp);

    if (zde->extrafield_len)
       fwrite(zde->extrafield, 1, zde->extrafield_len, fp);

    if (!localp) {
       if (zde->comment_len)
           fwrite(zde->comment, 1, zde->comment_len, fp);
    }

    if (ferror(fp)) {
       _zip_error_set(error, ZIP_ER_WRITE, errno);
       return -1;
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_entry_free ( struct zip_entry )

Definition at line 43 of file zip_entry_free.c.

{
    free(ze->ch_filename);
    ze->ch_filename = NULL;
    free(ze->ch_comment);
    ze->ch_comment = NULL;
    ze->ch_comment_len = -1;

    _zip_unchange_data(ze);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_entry_init ( struct zip ,
int   
)
struct zip_entry* _zip_entry_new ( struct zip ) [read]

Definition at line 43 of file zip_entry_new.c.

{
    struct zip_entry *ze;
    if (!za) {
       ze = (struct zip_entry *)malloc(sizeof(struct zip_entry));
       if (!ze) {
           _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
           return NULL;
       }
    }
    else {
       if (za->nentry >= za->nentry_alloc-1) {
           za->nentry_alloc += 16;
           za->entry = (struct zip_entry *)realloc(za->entry,
                                              sizeof(struct zip_entry)
                                              * za->nentry_alloc);
           if (!za->entry) {
              _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
              return NULL;
           }
       }
       ze = za->entry+za->nentry;
    }

    ze->state = ZIP_ST_UNCHANGED;

    ze->ch_filename = NULL;
    ze->ch_comment = NULL;
    ze->ch_comment_len = -1;
    ze->source = NULL;

    if (za)
       za->nentry++;

    return ze;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_error_clear ( struct zip_error )

Definition at line 43 of file zip_error.c.

{
    err->zip_err = ZIP_ER_OK;
    err->sys_err = 0;
}

Here is the caller graph for this function:

void _zip_error_copy ( struct zip_error ,
struct zip_error  
)

Definition at line 52 of file zip_error.c.

{
    dst->zip_err = src->zip_err;
    dst->sys_err = src->sys_err;
}

Here is the caller graph for this function:

void _zip_error_fini ( struct zip_error )

Definition at line 61 of file zip_error.c.

{
    free(err->str);
    err->str = NULL;
}

Here is the caller graph for this function:

void _zip_error_get ( struct zip_error ,
int ,
int  
)

Definition at line 70 of file zip_error.c.

{
    if (zep)
       *zep = err->zip_err;
    if (sep) {
       if (zip_error_get_sys_type(err->zip_err) != ZIP_ET_NONE)
           *sep = err->sys_err;
       else
           *sep = 0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_error_init ( struct zip_error )

Definition at line 85 of file zip_error.c.

{
    err->zip_err = ZIP_ER_OK;
    err->sys_err = 0;
    err->str = NULL;
}

Here is the caller graph for this function:

void _zip_error_set ( struct zip_error ,
int  ,
int   
)

Definition at line 95 of file zip_error.c.

{
    if (err) {
       err->zip_err = ze;
       err->sys_err = se;
    }
}
const char* _zip_error_strerror ( struct zip_error )

Definition at line 46 of file zip_error_strerror.c.

{
    const char *zs, *ss;
    char buf[128], *s;

    _zip_error_fini(err);

    if (err->zip_err < 0 || err->zip_err >= _zip_nerr_str) {
       sprintf(buf, "Unknown error %d", err->zip_err);
       zs = NULL;
       ss = buf;
    }
    else {
       zs = _zip_err_str[err->zip_err];
       
       switch (_zip_err_type[err->zip_err]) {
       case ZIP_ET_SYS:
           ss = strerror(err->sys_err);
           break;

       case ZIP_ET_ZLIB:
           ss = zError(err->sys_err);
           break;

       default:
           ss = NULL;
       }
    }

    if (ss == NULL)
       return zs;
    else {
       if ((s=(char *)malloc(strlen(ss)
                           + (zs ? strlen(zs)+2 : 0) + 1)) == NULL)
           return _zip_err_str[ZIP_ER_MEMORY];
       
       sprintf(s, "%s%s%s",
              (zs ? zs : ""),
              (zs ? ": " : ""),
              ss);
       err->str = s;

       return s;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_file_fillbuf ( void *  ,
size_t  ,
struct zip_file  
)

Definition at line 142 of file zip_fopen_index.c.

{
    int i, j;

    if (zf->error.zip_err != ZIP_ER_OK)
       return -1;

    if ((zf->flags & ZIP_ZF_EOF) || zf->cbytes_left <= 0 || buflen <= 0)
       return 0;
    
    if (fseeko(zf->za->zp, zf->fpos, SEEK_SET) < 0) {
       _zip_error_set(&zf->error, ZIP_ER_SEEK, errno);
       return -1;
    }
    if (buflen < zf->cbytes_left)
       i = buflen;
    else
       i = zf->cbytes_left;

    j = fread(buf, 1, i, zf->za->zp);
    if (j == 0) {
       _zip_error_set(&zf->error, ZIP_ER_EOF, 0);
       j = -1;
    }
    else if (j < 0)
       _zip_error_set(&zf->error, ZIP_ER_READ, errno);
    else {
       zf->fpos += j;
       zf->cbytes_left -= j;
    }

    return j; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int _zip_file_get_offset ( struct zip ,
int   
)

Definition at line 54 of file zip_file_get_offset.c.

{
    struct zip_dirent de;
    unsigned int offset;

    offset = za->cdir->entry[idx].offset;

    if (fseeko(za->zp, offset, SEEK_SET) != 0) {
       _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
       return 0;
    }

    if (_zip_dirent_read(&de, za->zp, NULL, NULL, 1, &za->error) != 0)
       return 0;

    offset += LENTRYSIZE + de.filename_len + de.extrafield_len;

    _zip_dirent_finalize(&de);

    return offset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_filerange_crc ( FILE *  ,
off_t  ,
off_t  ,
uLong *  ,
struct zip_error  
)

Definition at line 45 of file zip_filerange_crc.c.

{
    Bytef buf[BUFSIZE];
    size_t n;

    *crcp = crc32(0L, Z_NULL, 0);

    if (fseeko(fp, start, SEEK_SET) != 0) {
       _zip_error_set(errp, ZIP_ER_SEEK, errno);
       return -1;
    }
    
    while (len > 0) {
       n = len > BUFSIZE ? BUFSIZE : len;
       if ((n=fread(buf, 1, n, fp)) <= 0) {
           _zip_error_set(errp, ZIP_ER_READ, errno);
           return -1;
       }

       *crcp = crc32(*crcp, buf, n);

       len-= n;
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_free ( struct zip )

Definition at line 47 of file zip_free.c.

{
    int i;

    if (za == NULL)
       return;

    if (za->zn)
       free(za->zn);

    if (za->zp)
       fclose(za->zp);

    _zip_cdir_free(za->cdir);

    if (za->entry) {
       for (i=0; i<za->nentry; i++) {
           _zip_entry_free(za->entry+i);
       }
       free(za->entry);
    }

    for (i=0; i<za->nfile; i++) {
       if (za->file[i]->error.zip_err == ZIP_ER_OK) {
           _zip_error_set(&za->file[i]->error, ZIP_ER_ZIPCLOSED, 0);
           za->file[i]->za = NULL;
       }
    }

    free(za->file);
    
    free(za);

    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* _zip_get_name ( struct zip ,
int  ,
int  ,
struct zip_error  
)

Definition at line 49 of file zip_get_name.c.

{
    if (idx < 0 || idx >= za->nentry) {
       _zip_error_set(error, ZIP_ER_INVAL, 0);
       return NULL;
    }

    if ((flags & ZIP_FL_UNCHANGED) == 0) {
       if (za->entry[idx].state == ZIP_ST_DELETED) {
           _zip_error_set(error, ZIP_ER_DELETED, 0);
           return NULL;
       }
       if (za->entry[idx].ch_filename)
           return za->entry[idx].ch_filename;
    }

    if (za->cdir == NULL || idx >= za->cdir->nentry) {
       _zip_error_set(error, ZIP_ER_INVAL, 0);
       return NULL;
    }
    
    return za->cdir->entry[idx].filename;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_local_header_read ( struct zip ,
int   
)
void* _zip_memdup ( const void *  ,
size_t  ,
struct zip_error  
)

Definition at line 42 of file zip_memdup.c.

{
    void *ret;

    ret = malloc(len);
    if (!ret) {
       _zip_error_set(error, ZIP_ER_MEMORY, 0);
       return NULL;
    }

    memcpy(ret, mem, len);

    return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_name_locate ( struct zip ,
const char *  ,
int  ,
struct zip_error  
)

Definition at line 51 of file zip_name_locate.c.

{
    int (*cmp)(const char *, const char *);
    const char *fn, *p;
    int i, n;

    if (fname == NULL) {
       _zip_error_set(error, ZIP_ER_INVAL, 0);
       return -1;
    }

    if((flags & ZIP_FL_UNCHANGED)  && !za->cdir) {
       return -1;
    }

    cmp = (flags & ZIP_FL_NOCASE) ? strcmpi : strcmp;

    n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry;
    for (i=0; i<n; i++) {
       if (flags & ZIP_FL_UNCHANGED)
           fn = za->cdir->entry[i].filename;
       else
           fn = _zip_get_name(za, i, flags, error);

       /* newly added (partially filled) entry */
       if (fn == NULL)
           continue;

       if (flags & ZIP_FL_NODIR) {
           p = strrchr(fn, '/');
           if (p)
              fn = p+1;
       }

       if (cmp(fname, fn) == 0)
           return i;
    }

/* Look for an entry should not raise an error  */
/*    _zip_error_set(error, ZIP_ER_NOENT, 0);*/
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct zip* _zip_new ( struct zip_error ) [read]

Definition at line 47 of file zip_new.c.

{
    struct zip *za;

    za = (struct zip *)malloc(sizeof(struct zip));
    if (!za) {
       _zip_error_set(error, ZIP_ER_MEMORY, 0);
       return NULL;
    }

    za->zn = NULL;
    za->zp = NULL;
    _zip_error_init(&za->error);
    za->cdir = NULL;
    za->ch_comment = NULL;
    za->ch_comment_len = -1;
    za->nentry = za->nentry_alloc = 0;
    za->entry = NULL;
    za->nfile = za->nfile_alloc = 0;
    za->file = NULL;
    za->flags = za->ch_flags = 0;
    
    return za;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned short _zip_read2 ( unsigned char **  )

Definition at line 495 of file zip_dirent.c.

{
    unsigned short ret;

    ret = (*a)[0]+((*a)[1]<<8);
    *a += 2;

    return ret;
}

Here is the caller graph for this function:

unsigned int _zip_read4 ( unsigned char **  )

Definition at line 508 of file zip_dirent.c.

{
    unsigned int ret;

    ret = ((((((*a)[3]<<8)+(*a)[2])<<8)+(*a)[1])<<8)+(*a)[0];
    *a += 4;

    return ret;
}

Here is the caller graph for this function:

int _zip_replace ( struct zip ,
int  ,
const char *  ,
struct zip_source  
)

Definition at line 58 of file zip_replace.c.

{
    if (idx == -1) {
       if (_zip_entry_new(za) == NULL)
           return -1;

       idx = za->nentry - 1;
    }
    
    _zip_unchange_data(za->entry+idx);

    if (name && _zip_set_name(za, idx, name) != 0)
       return -1;
    
    za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry)
                         ? ZIP_ST_ADDED : ZIP_ST_REPLACED);
    za->entry[idx].source = source;

    return idx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_set_name ( struct zip ,
int  ,
const char *   
)

Definition at line 44 of file zip_set_name.c.

{
    char *s;
    int i;
    
    if (idx < 0 || idx >= za->nentry || name == NULL) {
       _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
       return -1;
    }

    if ((i=_zip_name_locate(za, name, 0, NULL)) != -1 && i != idx) {
       _zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
       return -1;
    }

    /* no effective name change */
    if (i == idx)
       return 0;
    
    if ((s=strdup(name)) == NULL) {
       _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
       return -1;
    }
    
    if (za->entry[idx].state == ZIP_ST_UNCHANGED) 
       za->entry[idx].state = ZIP_ST_RENAMED;

    free(za->entry[idx].ch_filename);
    za->entry[idx].ch_filename = s;

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct zip_source* _zip_source_file_or_p ( struct zip ,
const char *  ,
FILE *  ,
off_t  ,
off_t   
) [read]

Definition at line 75 of file zip_source_filep.c.

{
    struct read_file *f;
    struct zip_source *zs;

    if (file == NULL && fname == NULL) {
       _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
       return NULL;
    }

    if ((f=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) {
       _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
       return NULL;
    }

    f->fname = NULL;
    if (fname) {
       if ((f->fname=strdup(fname)) == NULL) {
           _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
           free(f);
           return NULL;
       }
    }
    f->f = file;
    f->off = start;
    f->len = (len ? len : -1);
    
    if ((zs=zip_source_function(za, read_file, f)) == NULL) {
       free(f);
       return NULL;
    }

    return zs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _zip_unchange ( struct zip ,
int  ,
int   
)

Definition at line 51 of file zip_unchange.c.

{
    int i;
    
    if (idx < 0 || idx >= za->nentry) {
       _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
       return -1;
    }

    if (za->entry[idx].ch_filename) {
       if (!allow_duplicates) {
           i = _zip_name_locate(za,
                      _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL),
                             0, NULL);
           if (i != -1 && i != idx) {
              _zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
              return -1;
           }
       }

       free(za->entry[idx].ch_filename);
       za->entry[idx].ch_filename = NULL;
    }

    free(za->entry[idx].ch_comment);
    za->entry[idx].ch_comment = NULL;
    za->entry[idx].ch_comment_len = -1;

    _zip_unchange_data(za->entry+idx);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _zip_unchange_data ( struct zip_entry )

Definition at line 43 of file zip_unchange_data.c.

{
    if (ze->source) {
       (void)ze->source->f(ze->source->ud, NULL, 0, ZIP_SOURCE_FREE);
       free(ze->source);
       ze->source = NULL;
    }
    
    ze->state = ze->ch_filename ? ZIP_ST_RENAMED : ZIP_ST_UNCHANGED;
}

Here is the caller graph for this function:


Variable Documentation

const char* const _zip_err_str[]

Definition at line 10 of file zip_err_str.c.

const int _zip_err_type[]

Definition at line 43 of file zip_err_str.c.

Definition at line 37 of file zip_err_str.c.