misc/quazip/zip.c
author Xeli
Fri, 28 Oct 2011 17:41:39 +0200
branchhedgeroid
changeset 6055 88cfcd9161d3
parent 5752 ea95ee97c805
permissions -rw-r--r--
Enabled landhash check again
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5752
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     1
/* zip.c -- IO on .zip files using zlib
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     2
   Version 1.01e, February 12th, 2005
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     3
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     4
   27 Dec 2004 Rolf Kalbermatter
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     5
   Modification to zipOpen2 to support globalComment retrieval.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     6
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     7
   Copyright (C) 1998-2005 Gilles Vollant
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     8
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     9
   Read zip.h for more info
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    10
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    11
   Modified by Sergey A. Tachenov to integrate with Qt.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    12
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    13
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    14
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    15
#include <stdio.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    16
#include <stdlib.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    17
#include <string.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    18
#include <time.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    19
#include "zlib.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    20
#include "zip.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    21
#include "quazip_global.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    22
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    23
#ifdef STDC
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    24
#  include <stddef.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    25
#  include <string.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    26
#  include <stdlib.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    27
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    28
#ifdef NO_ERRNO_H
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    29
    extern int errno;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    30
#else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    31
#   include <errno.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    32
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    33
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    34
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    35
#ifndef local
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    36
#  define local static
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    37
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    38
/* compile with -Dlocal if your debugger can't find static symbols */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    39
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    40
#ifndef VERSIONMADEBY
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    41
# define VERSIONMADEBY   (0x031e) /* best for standard pkware crypt */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    42
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    43
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    44
#ifndef Z_BUFSIZE
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    45
#define Z_BUFSIZE (16384)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    46
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    47
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    48
#ifndef Z_MAXFILENAMEINZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    49
#define Z_MAXFILENAMEINZIP (256)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    50
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    51
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    52
#ifndef ALLOC
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    53
# define ALLOC(size) (malloc(size))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    54
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    55
#ifndef TRYFREE
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    56
# define TRYFREE(p) {if (p) free(p);}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    57
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    58
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    59
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    60
#define SIZECENTRALDIRITEM (0x2e)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    61
#define SIZEZIPLOCALHEADER (0x1e)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    62
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    63
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    64
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    65
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    66
#ifndef SEEK_CUR
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    67
#define SEEK_CUR    1
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    68
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    69
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    70
#ifndef SEEK_END
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    71
#define SEEK_END    2
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    72
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    73
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    74
#ifndef SEEK_SET
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    75
#define SEEK_SET    0
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    76
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    77
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    78
#ifndef DEF_MEM_LEVEL
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    79
#if MAX_MEM_LEVEL >= 8
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    80
#  define DEF_MEM_LEVEL 8
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    81
#else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    82
#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    83
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    84
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    85
const char zip_copyright[] =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    86
   " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    87
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    88
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    89
#define SIZEDATA_INDATABLOCK (4096-(4*4))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    90
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    91
#define LOCALHEADERMAGIC    (0x04034b50)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    92
#define DESCRIPTORHEADERMAGIC    (0x08074b50)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    93
#define CENTRALHEADERMAGIC  (0x02014b50)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    94
#define ENDHEADERMAGIC      (0x06054b50)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    95
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    96
#define FLAG_LOCALHEADER_OFFSET (0x06)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    97
#define CRC_LOCALHEADER_OFFSET  (0x0e)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    98
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    99
#define SIZECENTRALHEADER (0x2e) /* 46 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   100
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   101
typedef struct linkedlist_datablock_internal_s
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   102
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   103
  struct linkedlist_datablock_internal_s* next_datablock;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   104
  uLong  avail_in_this_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   105
  uLong  filled_in_this_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   106
  uLong  unused; /* for future use and alignement */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   107
  unsigned char data[SIZEDATA_INDATABLOCK];
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   108
} linkedlist_datablock_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   109
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   110
typedef struct linkedlist_data_s
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   111
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   112
    linkedlist_datablock_internal* first_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   113
    linkedlist_datablock_internal* last_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   114
} linkedlist_data;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   115
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   116
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   117
typedef struct
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   118
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   119
    z_stream stream;            /* zLib stream structure for inflate */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   120
    int  stream_initialised;    /* 1 is stream is initialised */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   121
    uInt pos_in_buffered_data;  /* last written byte in buffered_data */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   122
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   123
    uLong pos_local_header;     /* offset of the local header of the file
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   124
                                     currenty writing */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   125
    char* central_header;       /* central header data for the current file */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   126
    uLong size_centralheader;   /* size of the central header for cur file */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   127
    uLong flag;                 /* flag of the file currently writing */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   128
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   129
    int  method;                /* compression method of file currenty wr.*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   130
    int  raw;                   /* 1 for directly writing raw data */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   131
    Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   132
    uLong dosDate;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   133
    uLong crc32;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   134
    int  encrypt;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   135
#ifndef NOCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   136
    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   137
    const unsigned long* pcrc_32_tab;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   138
    int crypt_header_size;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   139
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   140
} curfile_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   141
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   142
typedef struct
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   143
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   144
    zlib_filefunc_def z_filefunc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   145
    voidpf filestream;        /* io structore of the zipfile */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   146
    linkedlist_data central_dir;/* datablock with central dir in construction*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   147
    int  in_opened_file_inzip;  /* 1 if a file in the zip is currently writ.*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   148
    curfile_info ci;            /* info on the file curretly writing */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   149
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   150
    uLong begin_pos;            /* position of the beginning of the zipfile */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   151
    uLong add_position_when_writting_offset;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   152
    uLong number_entry;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   153
#ifndef NO_ADDFILEINEXISTINGZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   154
    char *globalcomment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   155
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   156
} zip_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   157
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   158
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   159
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   160
#ifndef NOCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   161
#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   162
#include "crypt.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   163
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   164
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   165
local linkedlist_datablock_internal* allocate_new_datablock()
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   166
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   167
    linkedlist_datablock_internal* ldi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   168
    ldi = (linkedlist_datablock_internal*)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   169
                 ALLOC(sizeof(linkedlist_datablock_internal));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   170
    if (ldi!=NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   171
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   172
        ldi->next_datablock = NULL ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   173
        ldi->filled_in_this_block = 0 ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   174
        ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   175
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   176
    return ldi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   177
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   178
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   179
local void free_datablock(ldi)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   180
    linkedlist_datablock_internal* ldi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   181
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   182
    while (ldi!=NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   183
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   184
        linkedlist_datablock_internal* ldinext = ldi->next_datablock;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   185
        TRYFREE(ldi);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   186
        ldi = ldinext;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   187
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   188
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   189
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   190
local void init_linkedlist(ll)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   191
    linkedlist_data* ll;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   192
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   193
    ll->first_block = ll->last_block = NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   194
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   195
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   196
#if 0 // unused
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   197
local void free_linkedlist(ll)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   198
    linkedlist_data* ll;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   199
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   200
    free_datablock(ll->first_block);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   201
    ll->first_block = ll->last_block = NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   202
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   203
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   204
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   205
local int add_data_in_datablock(ll,buf,len)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   206
    linkedlist_data* ll;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   207
    const void* buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   208
    uLong len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   209
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   210
    linkedlist_datablock_internal* ldi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   211
    const unsigned char* from_copy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   212
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   213
    if (ll==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   214
        return ZIP_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   215
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   216
    if (ll->last_block == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   217
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   218
        ll->first_block = ll->last_block = allocate_new_datablock();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   219
        if (ll->first_block == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   220
            return ZIP_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   221
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   222
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   223
    ldi = ll->last_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   224
    from_copy = (unsigned char*)buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   225
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   226
    while (len>0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   227
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   228
        uInt copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   229
        uInt i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   230
        unsigned char* to_copy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   231
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   232
        if (ldi->avail_in_this_block==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   233
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   234
            ldi->next_datablock = allocate_new_datablock();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   235
            if (ldi->next_datablock == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   236
                return ZIP_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   237
            ldi = ldi->next_datablock ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   238
            ll->last_block = ldi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   239
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   240
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   241
        if (ldi->avail_in_this_block < len)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   242
            copy_this = (uInt)ldi->avail_in_this_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   243
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   244
            copy_this = (uInt)len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   245
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   246
        to_copy = &(ldi->data[ldi->filled_in_this_block]);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   247
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   248
        for (i=0;i<copy_this;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   249
            *(to_copy+i)=*(from_copy+i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   250
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   251
        ldi->filled_in_this_block += copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   252
        ldi->avail_in_this_block -= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   253
        from_copy += copy_this ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   254
        len -= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   255
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   256
    return ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   257
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   258
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   259
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   260
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   261
/****************************************************************************/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   262
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   263
#ifndef NO_ADDFILEINEXISTINGZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   264
/* ===========================================================================
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   265
   Inputs a long in LSB order to the given file
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   266
   nbByte == 1, 2 or 4 (byte, short or long)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   267
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   268
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   269
local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   270
                                voidpf filestream, uLong x, int nbByte));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   271
local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   272
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   273
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   274
    uLong x;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   275
    int nbByte;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   276
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   277
    unsigned char buf[4];
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   278
    int n;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   279
    for (n = 0; n < nbByte; n++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   280
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   281
        buf[n] = (unsigned char)(x & 0xff);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   282
        x >>= 8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   283
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   284
    if (x != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   285
      {     /* data overflow - hack for ZIP64 (X Roche) */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   286
      for (n = 0; n < nbByte; n++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   287
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   288
          buf[n] = 0xff;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   289
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   290
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   291
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   292
    if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   293
        return ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   294
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   295
        return ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   296
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   297
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   298
local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   299
local void ziplocal_putValue_inmemory (dest, x, nbByte)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   300
    void* dest;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   301
    uLong x;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   302
    int nbByte;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   303
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   304
    unsigned char* buf=(unsigned char*)dest;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   305
    int n;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   306
    for (n = 0; n < nbByte; n++) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   307
        buf[n] = (unsigned char)(x & 0xff);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   308
        x >>= 8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   309
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   310
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   311
    if (x != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   312
    {     /* data overflow - hack for ZIP64 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   313
       for (n = 0; n < nbByte; n++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   314
       {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   315
          buf[n] = 0xff;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   316
       }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   317
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   318
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   319
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   320
/****************************************************************************/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   321
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   322
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   323
local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   324
    const tm_zip* ptm;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   325
    uLong dosDate UNUSED;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   326
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   327
    uLong year = (uLong)ptm->tm_year;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   328
    if (year>1980)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   329
        year-=1980;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   330
    else if (year>80)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   331
        year-=80;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   332
    return
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   333
      (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   334
        ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   335
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   336
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   337
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   338
/****************************************************************************/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   339
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   340
local int ziplocal_getByte OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   341
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   342
    voidpf filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   343
    int *pi));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   344
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   345
local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   346
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   347
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   348
    int *pi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   349
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   350
    unsigned char c;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   351
    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   352
    if (err==1)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   353
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   354
        *pi = (int)c;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   355
        return ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   356
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   357
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   358
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   359
        if (ZERROR(*pzlib_filefunc_def,filestream))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   360
            return ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   361
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   362
            return ZIP_EOF;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   363
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   364
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   365
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   366
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   367
/* ===========================================================================
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   368
   Reads a long in LSB order from the given gz_stream. Sets
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   369
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   370
local int ziplocal_getShort OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   371
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   372
    voidpf filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   373
    uLong *pX));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   374
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   375
local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   376
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   377
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   378
    uLong *pX;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   379
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   380
    uLong x ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   381
    int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   382
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   383
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   384
    err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   385
    x = (uLong)i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   386
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   387
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   388
        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   389
    x += ((uLong)i)<<8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   390
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   391
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   392
        *pX = x;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   393
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   394
        *pX = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   395
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   396
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   397
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   398
local int ziplocal_getLong OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   399
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   400
    voidpf filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   401
    uLong *pX));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   402
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   403
local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   404
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   405
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   406
    uLong *pX;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   407
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   408
    uLong x ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   409
    int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   410
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   411
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   412
    err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   413
    x = (uLong)i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   414
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   415
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   416
        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   417
    x += ((uLong)i)<<8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   418
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   419
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   420
        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   421
    x += ((uLong)i)<<16;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   422
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   423
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   424
        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   425
    x += ((uLong)i)<<24;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   426
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   427
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   428
        *pX = x;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   429
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   430
        *pX = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   431
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   432
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   433
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   434
#ifndef BUFREADCOMMENT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   435
#define BUFREADCOMMENT (0x400)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   436
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   437
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   438
  Locate the Central directory of a zipfile (at the end, just before
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   439
    the global comment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   440
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   441
local uLong ziplocal_SearchCentralDir OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   442
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   443
    voidpf filestream));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   444
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   445
local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   446
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   447
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   448
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   449
    unsigned char* buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   450
    uLong uSizeFile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   451
    uLong uBackRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   452
    uLong uMaxBack=0xffff; /* maximum size of global comment */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   453
    uLong uPosFound=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   454
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   455
    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   456
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   457
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   458
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   459
    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   460
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   461
    if (uMaxBack>uSizeFile)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   462
        uMaxBack = uSizeFile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   463
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   464
    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   465
    if (buf==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   466
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   467
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   468
    uBackRead = 4;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   469
    while (uBackRead<uMaxBack)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   470
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   471
        uLong uReadSize,uReadPos ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   472
        int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   473
        if (uBackRead+BUFREADCOMMENT>uMaxBack)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   474
            uBackRead = uMaxBack;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   475
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   476
            uBackRead+=BUFREADCOMMENT;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   477
        uReadPos = uSizeFile-uBackRead ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   478
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   479
        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   480
                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   481
        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   482
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   483
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   484
        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   485
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   486
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   487
        for (i=(int)uReadSize-3; (i--)>0;)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   488
            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   489
                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   490
            {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   491
                uPosFound = uReadPos+i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   492
                break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   493
            }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   494
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   495
        if (uPosFound!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   496
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   497
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   498
    TRYFREE(buf);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   499
    return uPosFound;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   500
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   501
#endif /* !NO_ADDFILEINEXISTINGZIP*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   502
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   503
/************************************************************/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   504
extern zipFile ZEXPORT zipOpen2 (file, append, globalcomment, pzlib_filefunc_def)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   505
    voidpf file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   506
    int append;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   507
    zipcharpc* globalcomment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   508
    zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   509
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   510
    zip_internal ziinit;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   511
    zip_internal* zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   512
    int err=ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   513
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   514
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   515
    if (pzlib_filefunc_def==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   516
        fill_qiodevice_filefunc(&ziinit.z_filefunc);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   517
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   518
        ziinit.z_filefunc = *pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   519
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   520
    ziinit.filestream = (*(ziinit.z_filefunc.zopen_file))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   521
                 (ziinit.z_filefunc.opaque,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   522
                  file,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   523
                  (append == APPEND_STATUS_CREATE) ?
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   524
                  (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   525
                    (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   526
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   527
    if (ziinit.filestream == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   528
        return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   529
    ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   530
    ziinit.in_opened_file_inzip = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   531
    ziinit.ci.stream_initialised = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   532
    ziinit.number_entry = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   533
    ziinit.add_position_when_writting_offset = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   534
    init_linkedlist(&(ziinit.central_dir));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   535
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   536
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   537
    zi = (zip_internal*)ALLOC(sizeof(zip_internal));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   538
    if (zi==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   539
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   540
        ZCLOSE(ziinit.z_filefunc,ziinit.filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   541
        return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   542
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   543
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   544
    /* now we add file in a zipfile */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   545
#    ifndef NO_ADDFILEINEXISTINGZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   546
    ziinit.globalcomment = NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   547
    if (append == APPEND_STATUS_ADDINZIP)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   548
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   549
        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   550
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   551
        uLong size_central_dir;     /* size of the central directory  */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   552
        uLong offset_central_dir;   /* offset of start of central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   553
        uLong central_pos,uL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   554
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   555
        uLong number_disk;          /* number of the current dist, used for
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   556
                                    spaning ZIP, unsupported, always 0*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   557
        uLong number_disk_with_CD;  /* number the the disk with central dir, used
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   558
                                    for spaning ZIP, unsupported, always 0*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   559
        uLong number_entry;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   560
        uLong number_entry_CD;      /* total number of entries in
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   561
                                    the central dir
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   562
                                    (same than number_entry on nospan) */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   563
        uLong size_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   564
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   565
        central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   566
        if (central_pos==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   567
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   568
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   569
        if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   570
                                        central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   571
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   572
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   573
        /* the signature, already checked */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   574
        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   575
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   576
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   577
        /* number of this disk */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   578
        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   579
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   580
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   581
        /* number of the disk with the start of the central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   582
        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   583
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   584
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   585
        /* total number of entries in the central dir on this disk */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   586
        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   587
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   588
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   589
        /* total number of entries in the central dir */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   590
        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   591
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   592
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   593
        if ((number_entry_CD!=number_entry) ||
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   594
            (number_disk_with_CD!=0) ||
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   595
            (number_disk!=0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   596
            err=ZIP_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   597
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   598
        /* size of the central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   599
        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   600
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   601
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   602
        /* offset of start of central directory with respect to the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   603
            starting disk number */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   604
        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   605
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   606
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   607
        /* zipfile global comment length */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   608
        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   609
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   610
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   611
        if ((central_pos<offset_central_dir+size_central_dir) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   612
            (err==ZIP_OK))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   613
            err=ZIP_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   614
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   615
        if (err!=ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   616
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   617
            ZCLOSE(ziinit.z_filefunc, ziinit.filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   618
            return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   619
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   620
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   621
        if (size_comment>0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   622
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   623
            ziinit.globalcomment = ALLOC(size_comment+1);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   624
            if (ziinit.globalcomment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   625
            {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   626
               size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   627
               ziinit.globalcomment[size_comment]=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   628
            }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   629
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   630
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   631
        byte_before_the_zipfile = central_pos -
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   632
                                (offset_central_dir+size_central_dir);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   633
        ziinit.add_position_when_writting_offset = byte_before_the_zipfile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   634
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   635
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   636
            uLong size_central_dir_to_read = size_central_dir;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   637
            size_t buf_size = SIZEDATA_INDATABLOCK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   638
            void* buf_read = (void*)ALLOC(buf_size);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   639
            if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   640
                  offset_central_dir + byte_before_the_zipfile,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   641
                  ZLIB_FILEFUNC_SEEK_SET) != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   642
                  err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   643
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   644
            while ((size_central_dir_to_read>0) && (err==ZIP_OK))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   645
            {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   646
                uLong read_this = SIZEDATA_INDATABLOCK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   647
                if (read_this > size_central_dir_to_read)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   648
                    read_this = size_central_dir_to_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   649
                if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   650
                    err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   651
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   652
                if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   653
                    err = add_data_in_datablock(&ziinit.central_dir,buf_read,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   654
                                                (uLong)read_this);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   655
                size_central_dir_to_read-=read_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   656
            }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   657
            TRYFREE(buf_read);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   658
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   659
        ziinit.begin_pos = byte_before_the_zipfile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   660
        ziinit.number_entry = number_entry_CD;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   661
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   662
        if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   663
                  offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   664
            err=ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   665
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   666
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   667
    if (globalcomment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   668
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   669
      *globalcomment = ziinit.globalcomment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   670
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   671
#    endif /* !NO_ADDFILEINEXISTINGZIP*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   672
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   673
    if (err != ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   674
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   675
#    ifndef NO_ADDFILEINEXISTINGZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   676
        TRYFREE(ziinit.globalcomment);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   677
#    endif /* !NO_ADDFILEINEXISTINGZIP*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   678
        TRYFREE(zi);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   679
        return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   680
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   681
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   682
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   683
        *zi = ziinit;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   684
        return (zipFile)zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   685
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   686
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   687
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   688
extern zipFile ZEXPORT zipOpen (file, append)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   689
    voidpf file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   690
    int append;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   691
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   692
    return zipOpen2(file,append,NULL,NULL);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   693
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   694
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   695
extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   696
                                         extrafield_local, size_extrafield_local,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   697
                                         extrafield_global, size_extrafield_global,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   698
                                         comment, method, level, raw,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   699
                                         windowBits, memLevel, strategy,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   700
                                         password, crcForCrypting)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   701
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   702
    const char* filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   703
    const zip_fileinfo* zipfi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   704
    const void* extrafield_local;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   705
    uInt size_extrafield_local;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   706
    const void* extrafield_global;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   707
    uInt size_extrafield_global;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   708
    const char* comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   709
    int method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   710
    int level;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   711
    int raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   712
    int windowBits;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   713
    int memLevel;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   714
    int strategy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   715
    const char* password;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   716
    uLong crcForCrypting;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   717
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   718
    zip_internal* zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   719
    uInt size_filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   720
    uInt size_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   721
    uInt i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   722
    int err = ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   723
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   724
#    ifdef NOCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   725
    if (password != NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   726
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   727
#    endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   728
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   729
    if (file == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   730
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   731
    if ((method!=0) && (method!=Z_DEFLATED))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   732
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   733
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   734
    zi = (zip_internal*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   735
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   736
    if (zi->in_opened_file_inzip == 1)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   737
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   738
        err = zipCloseFileInZip (file);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   739
        if (err != ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   740
            return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   741
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   742
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   743
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   744
    if (filename==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   745
        filename="-";
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   746
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   747
    if (comment==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   748
        size_comment = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   749
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   750
        size_comment = (uInt)strlen(comment);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   751
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   752
    size_filename = (uInt)strlen(filename);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   753
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   754
    if (zipfi == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   755
        zi->ci.dosDate = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   756
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   757
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   758
        if (zipfi->dosDate != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   759
            zi->ci.dosDate = zipfi->dosDate;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   760
        else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   761
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   762
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   763
    zi->ci.flag = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   764
    if ((level==8) || (level==9))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   765
      zi->ci.flag |= 2;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   766
    if ((level==2))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   767
      zi->ci.flag |= 4;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   768
    if ((level==1))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   769
      zi->ci.flag |= 6;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   770
    if (password != NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   771
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   772
      zi->ci.flag |= 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   773
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   774
    zi->ci.flag |= 8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   775
    zi->ci.crc32 = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   776
    zi->ci.method = method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   777
    zi->ci.encrypt = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   778
    zi->ci.stream_initialised = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   779
    zi->ci.pos_in_buffered_data = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   780
    zi->ci.raw = raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   781
    zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   782
    zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   783
                                      size_extrafield_global + size_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   784
    zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   785
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   786
    ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   787
    /* version info */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   788
    ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   789
    ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   790
    ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   791
    ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   792
    ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   793
    ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   794
    ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   795
    ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   796
    ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   797
    ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   798
    ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   799
    ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   800
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   801
    if (zipfi==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   802
        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   803
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   804
        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   805
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   806
    if (zipfi==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   807
        ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   808
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   809
        ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   810
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   811
    ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   812
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   813
    for (i=0;i<size_filename;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   814
        *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   815
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   816
    for (i=0;i<size_extrafield_global;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   817
        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   818
              *(((const char*)extrafield_global)+i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   819
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   820
    for (i=0;i<size_comment;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   821
        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   822
              size_extrafield_global+i) = *(comment+i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   823
    if (zi->ci.central_header == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   824
        return ZIP_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   825
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   826
    /* write the local header */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   827
    err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   828
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   829
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   830
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   831
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   832
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   833
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   834
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   835
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   836
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   837
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   838
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   839
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   840
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   841
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   842
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   843
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   844
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   845
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   846
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   847
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   848
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   849
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   850
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   851
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   852
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   853
    if ((err==ZIP_OK) && (size_filename>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   854
        if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   855
                err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   856
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   857
    if ((err==ZIP_OK) && (size_extrafield_local>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   858
        if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   859
                                                                           !=size_extrafield_local)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   860
                err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   861
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   862
    zi->ci.stream.avail_in = (uInt)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   863
    zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   864
    zi->ci.stream.next_out = zi->ci.buffered_data;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   865
    zi->ci.stream.total_in = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   866
    zi->ci.stream.total_out = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   867
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   868
    if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   869
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   870
        zi->ci.stream.zalloc = (alloc_func)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   871
        zi->ci.stream.zfree = (free_func)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   872
        zi->ci.stream.opaque = (voidpf)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   873
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   874
        if (windowBits>0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   875
            windowBits = -windowBits;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   876
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   877
        err = deflateInit2(&zi->ci.stream, level,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   878
               Z_DEFLATED, windowBits, memLevel, strategy);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   879
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   880
        if (err==Z_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   881
            zi->ci.stream_initialised = 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   882
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   883
#    ifndef NOCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   884
    zi->ci.crypt_header_size = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   885
    if ((err==Z_OK) && (password != NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   886
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   887
        unsigned char bufHead[RAND_HEAD_LEN];
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   888
        unsigned int sizeHead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   889
        zi->ci.encrypt = 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   890
        zi->ci.pcrc_32_tab = get_crc_table();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   891
        /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   892
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   893
        crcForCrypting = (uLong)zi->ci.dosDate << 16; // ATTANTION! Without this row, you don't unpack your password protected archive in other app.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   894
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   895
        sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   896
        zi->ci.crypt_header_size = sizeHead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   897
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   898
        if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   899
                err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   900
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   901
#    endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   902
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   903
    if (err==Z_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   904
        zi->in_opened_file_inzip = 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   905
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   906
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   907
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   908
extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   909
                                        extrafield_local, size_extrafield_local,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   910
                                        extrafield_global, size_extrafield_global,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   911
                                        comment, method, level, raw)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   912
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   913
    const char* filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   914
    const zip_fileinfo* zipfi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   915
    const void* extrafield_local;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   916
    uInt size_extrafield_local;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   917
    const void* extrafield_global;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   918
    uInt size_extrafield_global;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   919
    const char* comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   920
    int method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   921
    int level;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   922
    int raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   923
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   924
    return zipOpenNewFileInZip3 (file, filename, zipfi,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   925
                                 extrafield_local, size_extrafield_local,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   926
                                 extrafield_global, size_extrafield_global,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   927
                                 comment, method, level, raw,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   928
                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   929
                                 NULL, 0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   930
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   931
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   932
extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   933
                                        extrafield_local, size_extrafield_local,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   934
                                        extrafield_global, size_extrafield_global,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   935
                                        comment, method, level)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   936
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   937
    const char* filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   938
    const zip_fileinfo* zipfi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   939
    const void* extrafield_local;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   940
    uInt size_extrafield_local;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   941
    const void* extrafield_global;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   942
    uInt size_extrafield_global;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   943
    const char* comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   944
    int method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   945
    int level;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   946
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   947
    return zipOpenNewFileInZip2 (file, filename, zipfi,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   948
                                 extrafield_local, size_extrafield_local,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   949
                                 extrafield_global, size_extrafield_global,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   950
                                 comment, method, level, 0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   951
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   952
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   953
local int zipFlushWriteBuffer(zi)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   954
  zip_internal* zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   955
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   956
    int err=ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   957
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   958
    if (zi->ci.encrypt != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   959
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   960
#ifndef NOCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   961
        uInt i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   962
        int t;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   963
        for (i=0;i<zi->ci.pos_in_buffered_data;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   964
            zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   965
                                       zi->ci.buffered_data[i],t);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   966
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   967
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   968
    if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   969
                                                                    !=zi->ci.pos_in_buffered_data)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   970
      err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   971
    zi->ci.pos_in_buffered_data = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   972
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   973
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   974
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   975
extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   976
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   977
    const void* buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   978
    unsigned len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   979
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   980
    zip_internal* zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   981
    int err=ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   982
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   983
    if (file == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   984
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   985
    zi = (zip_internal*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   986
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   987
    if (zi->in_opened_file_inzip == 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   988
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   989
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   990
    zi->ci.stream.next_in = (void*)buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   991
    zi->ci.stream.avail_in = len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   992
    zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   993
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   994
    while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   995
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   996
        if (zi->ci.stream.avail_out == 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   997
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   998
            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   999
                err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1000
            zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1001
            zi->ci.stream.next_out = zi->ci.buffered_data;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1002
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1003
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1004
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1005
        if(err != ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1006
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1007
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1008
        if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1009
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1010
            uLong uTotalOutBefore = zi->ci.stream.total_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1011
            err=deflate(&zi->ci.stream,  Z_NO_FLUSH);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1012
            zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1013
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1014
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1015
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1016
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1017
            uInt copy_this,i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1018
            if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1019
                copy_this = zi->ci.stream.avail_in;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1020
            else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1021
                copy_this = zi->ci.stream.avail_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1022
            for (i=0;i<copy_this;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1023
                *(((char*)zi->ci.stream.next_out)+i) =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1024
                    *(((const char*)zi->ci.stream.next_in)+i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1025
            {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1026
                zi->ci.stream.avail_in -= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1027
                zi->ci.stream.avail_out-= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1028
                zi->ci.stream.next_in+= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1029
                zi->ci.stream.next_out+= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1030
                zi->ci.stream.total_in+= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1031
                zi->ci.stream.total_out+= copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1032
                zi->ci.pos_in_buffered_data += copy_this;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1033
            }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1034
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1035
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1036
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1037
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1038
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1039
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1040
extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1041
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1042
    uLong uncompressed_size;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1043
    uLong crc32;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1044
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1045
    zip_internal* zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1046
    uLong compressed_size;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1047
    int err=ZIP_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1048
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1049
    if (file == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1050
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1051
    zi = (zip_internal*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1052
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1053
    if (zi->in_opened_file_inzip == 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1054
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1055
    zi->ci.stream.avail_in = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1056
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1057
    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1058
        while (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1059
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1060
        uLong uTotalOutBefore;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1061
        if (zi->ci.stream.avail_out == 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1062
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1063
            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1064
                err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1065
            zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1066
            zi->ci.stream.next_out = zi->ci.buffered_data;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1067
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1068
        uTotalOutBefore = zi->ci.stream.total_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1069
        err=deflate(&zi->ci.stream,  Z_FINISH);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1070
        zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1071
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1072
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1073
    if (err==Z_STREAM_END)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1074
        err=ZIP_OK; /* this is normal */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1075
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1076
    if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1077
        if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1078
            err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1079
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1080
    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1081
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1082
        err=deflateEnd(&zi->ci.stream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1083
        zi->ci.stream_initialised = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1084
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1085
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1086
    if (!zi->ci.raw)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1087
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1088
        crc32 = (uLong)zi->ci.crc32;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1089
        uncompressed_size = (uLong)zi->ci.stream.total_in;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1090
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1091
    compressed_size = (uLong)zi->ci.stream.total_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1092
#    ifndef NOCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1093
    compressed_size += zi->ci.crypt_header_size;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1094
#    endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1095
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1096
    ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1097
    ziplocal_putValue_inmemory(zi->ci.central_header+20,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1098
                                compressed_size,4); /*compr size*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1099
    if (zi->ci.stream.data_type == Z_ASCII)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1100
        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1101
    ziplocal_putValue_inmemory(zi->ci.central_header+24,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1102
                                uncompressed_size,4); /*uncompr size*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1103
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1104
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1105
        err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1106
                                       (uLong)zi->ci.size_centralheader);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1107
    free(zi->ci.central_header);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1108
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1109
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1110
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1111
        uLong cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1112
        if (ZSEEK(zi->z_filefunc,zi->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1113
                  zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1114
            err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1115
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1116
        if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1117
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1118
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1119
        if (err==ZIP_OK) /* compressed size, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1120
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1121
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1122
        if (err==ZIP_OK) /* uncompressed size, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1123
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1124
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1125
        if (ZSEEK(zi->z_filefunc,zi->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1126
                  cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1127
            err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1128
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1129
        /* Write local Descriptor after file data */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1130
        if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1131
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)DESCRIPTORHEADERMAGIC,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1132
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1133
        if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1134
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1135
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1136
        if (err==ZIP_OK) /* compressed size, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1137
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1138
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1139
        if (err==ZIP_OK) /* uncompressed size, unknown */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1140
            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1141
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1142
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1143
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1144
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1145
    zi->number_entry ++;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1146
    zi->in_opened_file_inzip = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1147
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1148
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1149
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1150
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1151
extern int ZEXPORT zipCloseFileInZip (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1152
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1153
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1154
    return zipCloseFileInZipRaw (file,0,0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1155
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1156
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1157
extern int ZEXPORT zipClose (file, global_comment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1158
    zipFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1159
    const char* global_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1160
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1161
    zip_internal* zi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1162
    int err = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1163
    uLong size_centraldir = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1164
    uLong centraldir_pos_inzip;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1165
    uInt size_global_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1166
    if (file == NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1167
        return ZIP_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1168
    zi = (zip_internal*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1169
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1170
    if (zi->in_opened_file_inzip == 1)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1171
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1172
        err = zipCloseFileInZip (file);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1173
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1174
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1175
#ifndef NO_ADDFILEINEXISTINGZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1176
    if (global_comment==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1177
        global_comment = zi->globalcomment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1178
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1179
    if (global_comment==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1180
        size_global_comment = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1181
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1182
        size_global_comment = (uInt)strlen(global_comment);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1183
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1184
    centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1185
    if (err==ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1186
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1187
        linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1188
        while (ldi!=NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1189
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1190
            if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1191
                if (ZWRITE(zi->z_filefunc,zi->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1192
                           ldi->data,ldi->filled_in_this_block)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1193
                              !=ldi->filled_in_this_block )
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1194
                    err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1195
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1196
            size_centraldir += ldi->filled_in_this_block;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1197
            ldi = ldi->next_datablock;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1198
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1199
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1200
    free_datablock(zi->central_dir.first_block);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1201
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1202
    if (err==ZIP_OK) /* Magic End */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1203
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1204
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1205
    if (err==ZIP_OK) /* number of this disk */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1206
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1207
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1208
    if (err==ZIP_OK) /* number of the disk with the start of the central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1209
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1210
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1211
    if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1212
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1213
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1214
    if (err==ZIP_OK) /* total number of entries in the central dir */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1215
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1216
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1217
    if (err==ZIP_OK) /* size of the central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1218
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1219
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1220
    if (err==ZIP_OK) /* offset of start of central directory with respect to the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1221
                            starting disk number */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1222
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1223
                                (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1224
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1225
    if (err==ZIP_OK) /* zipfile comment length */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1226
        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1227
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1228
    if ((err==ZIP_OK) && (size_global_comment>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1229
        if (ZWRITE(zi->z_filefunc,zi->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1230
                   global_comment,size_global_comment) != size_global_comment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1231
                err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1232
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1233
    if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1234
        if (err == ZIP_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1235
            err = ZIP_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1236
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1237
#ifndef NO_ADDFILEINEXISTINGZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1238
    TRYFREE(zi->globalcomment);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1239
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1240
    TRYFREE(zi);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1241
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1242
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1243
}