~ubuntu-branches/debian/wheezy/tea/wheezy

« back to all changes in this revision

Viewing changes to unzip.c

  • Committer: Package Import Robot
  • Author(s): Tobias Quathamer
  • Date: 2012-02-29 13:05:53 UTC
  • mfrom: (1.2.10)
  • Revision ID: package-import@ubuntu.com-20120229130553-wmwpxokaa1spmj69
Tags: 31.2.0-1
* Imported Upstream version 31.2.0
* Refresh debian/patches
* Switch to debhelper v9
* Use machine-readable format v1.0 for debian/copyright
* Update to Standards-Version 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
  version without encryption capabilities).
35
35
 */
36
36
 
 
37
//modified by Peter Semiletov
 
38
 
37
39
 
38
40
#include <stdio.h>
39
41
#include <stdlib.h>
87
89
 
88
90
 
89
91
 
90
 
 
91
92
const char unz_copyright[] =
92
93
   " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
93
94
 
94
 
/* unz_file_info_interntal contain internal info about a file in zipfile*/
 
95
// unz_file_info_interntal contain internal info about a file in zipfile
95
96
typedef struct unz_file_info_internal_s
96
97
{
97
 
    uLong offset_curfile;/* relative offset of local header 4 bytes */
 
98
  uLong offset_curfile;// relative offset of local header 4 bytes
98
99
} unz_file_info_internal;
99
100
 
100
101
 
164
165
*/
165
166
 
166
167
 
167
 
local int unzlocal_getByte OF((
168
 
    const zlib_filefunc_def* pzlib_filefunc_def,
169
 
    voidpf filestream,
170
 
    int *pi));
171
 
 
172
 
local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
173
 
    const zlib_filefunc_def* pzlib_filefunc_def;
174
 
    voidpf filestream;
175
 
    int *pi;
 
168
local int unzlocal_getByte OF ((
 
169
                                const zlib_filefunc_def* pzlib_filefunc_def,
 
170
                                voidpf filestream,
 
171
                                int *pi));
 
172
 
 
173
 
 
174
local int unzlocal_getByte (
 
175
                            const zlib_filefunc_def *pzlib_filefunc_def,
 
176
                            voidpf filestream,
 
177
                            int *pi)
176
178
{
177
 
    unsigned char c;
178
 
    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
179
 
    if (err==1)
180
 
    {
181
 
        *pi = (int)c;
182
 
        return UNZ_OK;
183
 
    }
184
 
    else
185
 
    {
186
 
        if (ZERROR(*pzlib_filefunc_def,filestream))
187
 
            return UNZ_ERRNO;
188
 
        else
189
 
            return UNZ_EOF;
190
 
    }
 
179
  unsigned char c;
 
180
 
 
181
  int err = (int) ZREAD (*pzlib_filefunc_def, filestream, &c, 1);
 
182
  if (err == 1)
 
183
     {
 
184
      *pi = (int) c;
 
185
      return UNZ_OK;
 
186
     }
 
187
  else
 
188
      {
 
189
       if (ZERROR (*pzlib_filefunc_def, filestream))
 
190
          return UNZ_ERRNO;
 
191
       else
 
192
           return UNZ_EOF;
 
193
      }
191
194
}
192
195
 
193
196
 
199
202
    voidpf filestream,
200
203
    uLong *pX));
201
204
 
202
 
local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
203
 
    const zlib_filefunc_def* pzlib_filefunc_def;
204
 
    voidpf filestream;
205
 
    uLong *pX;
 
205
 
 
206
local int unzlocal_getShort (
 
207
                             const zlib_filefunc_def* pzlib_filefunc_def,
 
208
                             voidpf filestream,
 
209
                             uLong *pX)
206
210
{
207
 
    uLong x ;
208
 
    int i;
209
 
    int err;
210
 
 
211
 
    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
212
 
    x = (uLong)i;
213
 
 
214
 
    if (err==UNZ_OK)
215
 
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
216
 
    x += ((uLong)i)<<8;
217
 
 
218
 
    if (err==UNZ_OK)
219
 
        *pX = x;
220
 
    else
221
 
        *pX = 0;
222
 
    return err;
 
211
  uLong x ;
 
212
  int i;
 
213
  int err;
 
214
 
 
215
  err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
 
216
  x = (uLong) i;
 
217
 
 
218
  if (err == UNZ_OK)
 
219
      err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
 
220
 
 
221
  x += ((uLong) i) << 8;
 
222
 
 
223
  if (err == UNZ_OK)
 
224
     *pX = x;
 
225
  else
 
226
      *pX = 0;
 
227
 
 
228
  return err;
223
229
}
224
230
 
225
 
local int unzlocal_getLong OF((
226
 
    const zlib_filefunc_def* pzlib_filefunc_def,
227
 
    voidpf filestream,
228
 
    uLong *pX));
229
 
 
230
 
local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
231
 
    const zlib_filefunc_def* pzlib_filefunc_def;
232
 
    voidpf filestream;
233
 
    uLong *pX;
 
231
 
 
232
local int unzlocal_getLong OF ((
 
233
                               const zlib_filefunc_def* pzlib_filefunc_def,
 
234
                               voidpf filestream,
 
235
                               uLong *pX));
 
236
 
 
237
 
 
238
local int unzlocal_getLong (const zlib_filefunc_def* pzlib_filefunc_def,
 
239
                            voidpf filestream,
 
240
                            uLong *pX)
234
241
{
235
 
    uLong x ;
236
 
    int i;
237
 
    int err;
238
 
 
239
 
    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
240
 
    x = (uLong)i;
241
 
 
242
 
    if (err==UNZ_OK)
243
 
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
244
 
    x += ((uLong)i)<<8;
245
 
 
246
 
    if (err==UNZ_OK)
247
 
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
248
 
    x += ((uLong)i)<<16;
249
 
 
250
 
    if (err==UNZ_OK)
251
 
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
252
 
    x += ((uLong)i)<<24;
253
 
 
254
 
    if (err==UNZ_OK)
255
 
        *pX = x;
256
 
    else
257
 
        *pX = 0;
258
 
    return err;
 
242
  uLong x ;
 
243
  int i;
 
244
  int err;
 
245
 
 
246
  err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
 
247
  x = (uLong) i;
 
248
 
 
249
  if (err == UNZ_OK)
 
250
     err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
 
251
 
 
252
  x += ((uLong)i) << 8;
 
253
 
 
254
  if (err == UNZ_OK)
 
255
     err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
 
256
 
 
257
  x += ((uLong)i) << 16;
 
258
 
 
259
  if (err == UNZ_OK)
 
260
     err = unzlocal_getByte (pzlib_filefunc_def, filestream, &i);
 
261
 
 
262
  x += ((uLong)i) << 24;
 
263
 
 
264
  if (err == UNZ_OK)
 
265
     *pX = x;
 
266
  else
 
267
      *pX = 0;
 
268
 
 
269
  return err;
259
270
}
260
271
 
261
272
 
262
273
/* My own strcmpi / strcasecmp */
263
 
local int strcmpcasenosensitive_internal (fileName1,fileName2)
264
 
    const char* fileName1;
265
 
    const char* fileName2;
 
274
local int strcmpcasenosensitive_internal (
 
275
                                          const char* fileName1,
 
276
                                          const char* fileName2)
266
277
{
267
 
    for (;;)
268
 
    {
269
 
        char c1=*(fileName1++);
270
 
        char c2=*(fileName2++);
271
 
        if ((c1>='a') && (c1<='z'))
272
 
            c1 -= 0x20;
273
 
        if ((c2>='a') && (c2<='z'))
274
 
            c2 -= 0x20;
275
 
        if (c1=='\0')
276
 
            return ((c2=='\0') ? 0 : -1);
277
 
        if (c2=='\0')
278
 
            return 1;
279
 
        if (c1<c2)
280
 
            return -1;
281
 
        if (c1>c2)
282
 
            return 1;
283
 
    }
 
278
  for (;;)
 
279
      {
 
280
       char c1 = *(fileName1++);
 
281
       char c2 = *(fileName2++);
 
282
 
 
283
       if ((c1 >= 'a') && (c1 <= 'z'))
 
284
          c1 -= 0x20;
 
285
 
 
286
       if ((c2 >= 'a') && (c2 <= 'z'))
 
287
          c2 -= 0x20;
 
288
 
 
289
       if (c1 == '\0')
 
290
          return ((c2 == '\0') ? 0 : -1);
 
291
 
 
292
       if (c2 == '\0')
 
293
          return 1;
 
294
 
 
295
       if (c1 < c2)
 
296
          return -1;
 
297
 
 
298
       if (c1 > c2)
 
299
          return 1;
 
300
      }
284
301
}
285
302
 
286
303
 
303
320
        (like 1 on Unix, 2 on Windows)
304
321
 
305
322
*/
306
 
extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
307
 
    const char* fileName1;
308
 
    const char* fileName2;
309
 
    int iCaseSensitivity;
 
323
extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
 
324
                                             const char* fileName2,
 
325
                                             int iCaseSensitivity)
310
326
{
311
 
    if (iCaseSensitivity==0)
312
 
        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
313
 
 
314
 
    if (iCaseSensitivity==1)
315
 
        return strcmp(fileName1,fileName2);
316
 
 
317
 
    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
 
327
  if (iCaseSensitivity == 0)
 
328
     iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
 
329
 
 
330
  if (iCaseSensitivity==1)
 
331
     return strcmp (fileName1, fileName2);
 
332
 
 
333
  return STRCMPCASENOSENTIVEFUNCTION (fileName1, fileName2);
318
334
}
319
335
 
320
336
#ifndef BUFREADCOMMENT
321
337
#define BUFREADCOMMENT (0x400)
322
338
#endif
323
339
 
 
340
 
324
341
/*
325
342
  Locate the Central directory of a zipfile (at the end, just before
326
343
    the global comment)
329
346
    const zlib_filefunc_def* pzlib_filefunc_def,
330
347
    voidpf filestream));
331
348
 
332
 
local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
333
 
    const zlib_filefunc_def* pzlib_filefunc_def;
334
 
    voidpf filestream;
 
349
local uLong unzlocal_SearchCentralDir (const zlib_filefunc_def* pzlib_filefunc_def,
 
350
                                       voidpf filestream)
335
351
{
336
 
    unsigned char* buf;
337
 
    uLong uSizeFile;
338
 
    uLong uBackRead;
339
 
    uLong uMaxBack=0xffff; /* maximum size of global comment */
340
 
    uLong uPosFound=0;
341
 
 
342
 
    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
343
 
        return 0;
344
 
 
345
 
 
346
 
    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
347
 
 
348
 
    if (uMaxBack>uSizeFile)
349
 
        uMaxBack = uSizeFile;
350
 
 
351
 
    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
352
 
    if (buf==NULL)
353
 
        return 0;
354
 
 
355
 
    uBackRead = 4;
356
 
    while (uBackRead<uMaxBack)
357
 
    {
 
352
  unsigned char *buf;
 
353
  uLong uSizeFile;
 
354
  uLong uBackRead;
 
355
  uLong uMaxBack = 0xffff; // maximum size of global comment
 
356
  uLong uPosFound=0;
 
357
 
 
358
  if (ZSEEK (*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0)
 
359
     return 0;
 
360
 
 
361
 
 
362
  uSizeFile = ZTELL (*pzlib_filefunc_def, filestream);
 
363
 
 
364
  if (uMaxBack > uSizeFile)
 
365
      uMaxBack = uSizeFile;
 
366
 
 
367
  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
 
368
 
 
369
  if (! buf)
 
370
     return 0;
 
371
 
 
372
  uBackRead = 4;
 
373
 
 
374
  while (uBackRead < uMaxBack)
 
375
       {
358
376
        uLong uReadSize,uReadPos ;
359
377
        int i;
360
 
        if (uBackRead+BUFREADCOMMENT>uMaxBack)
 
378
        if (uBackRead + BUFREADCOMMENT > uMaxBack)
361
379
            uBackRead = uMaxBack;
362
380
        else
363
 
            uBackRead+=BUFREADCOMMENT;
364
 
        uReadPos = uSizeFile-uBackRead ;
365
 
 
366
 
        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
367
 
                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
368
 
        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
369
 
            break;
370
 
 
371
 
        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
372
 
            break;
373
 
 
374
 
        for (i=(int)uReadSize-3; (i--)>0;)
375
 
            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
376
 
                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
 
381
            uBackRead += BUFREADCOMMENT;
 
382
        uReadPos = uSizeFile - uBackRead ;
 
383
 
 
384
        uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) ?
 
385
                     (BUFREADCOMMENT + 4) : (uSizeFile - uReadPos);
 
386
        if (ZSEEK(*pzlib_filefunc_def, filestream, uReadPos, ZLIB_FILEFUNC_SEEK_SET) != 0)
 
387
            break;
 
388
 
 
389
        if (ZREAD(*pzlib_filefunc_def, filestream, buf, uReadSize) != uReadSize)
 
390
            break;
 
391
 
 
392
        for (i = (int)uReadSize - 3; (i--) > 0;)
 
393
             if (((*(buf + i)) == 0x50) && ((*(buf + i + 1)) == 0x4b) &&
 
394
                ((*(buf + i + 2)) == 0x05) && ((*(buf + i + 3)) == 0x06))
377
395
            {
378
 
                uPosFound = uReadPos+i;
379
 
                break;
 
396
             uPosFound = uReadPos+i;
 
397
             break;
380
398
            }
381
399
 
382
 
        if (uPosFound!=0)
 
400
        if (uPosFound != 0)
383
401
            break;
384
402
    }
385
 
    TRYFREE(buf);
386
 
    return uPosFound;
 
403
 
 
404
   TRYFREE(buf);
 
405
 
 
406
   return uPosFound;
387
407
}
388
408
 
389
409
/*
395
415
     Else, the return value is a unzFile Handle, usable with other function
396
416
       of this unzip package.
397
417
*/
398
 
extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
399
 
    const char *path;
400
 
    zlib_filefunc_def* pzlib_filefunc_def;
 
418
extern unzFile ZEXPORT unzOpen2 (const char *path,
 
419
                                 zlib_filefunc_def* pzlib_filefunc_def)
401
420
{
402
 
    unz_s us;
403
 
    unz_s *s;
404
 
    uLong central_pos,uL;
 
421
  unz_s us;
 
422
  unz_s *s;
 
423
  uLong central_pos,uL;
405
424
 
406
 
    uLong number_disk;          /* number of the current dist, used for
 
425
  uLong number_disk;          /* number of the current dist, used for
407
426
                                   spaning ZIP, unsupported, always 0*/
408
 
    uLong number_disk_with_CD;  /* number the the disk with central dir, used
 
427
  uLong number_disk_with_CD;  /* number the the disk with central dir, used
409
428
                                   for spaning ZIP, unsupported, always 0*/
410
 
    uLong number_entry_CD;      /* total number of entries in
 
429
  uLong number_entry_CD;      /* total number of entries in
411
430
                                   the central dir
412
431
                                   (same than number_entry on nospan) */
413
432
 
414
 
    int err=UNZ_OK;
415
 
 
416
 
    if (unz_copyright[0]!=' ')
417
 
        return NULL;
418
 
 
419
 
    if (pzlib_filefunc_def==NULL)
420
 
        fill_fopen_filefunc(&us.z_filefunc);
 
433
  int err = UNZ_OK;
 
434
 
 
435
  if (unz_copyright[0] != ' ')
 
436
     return NULL;
 
437
 
 
438
  if (! pzlib_filefunc_def)
 
439
     fill_fopen_filefunc (&us.z_filefunc);
421
440
    else
422
441
        us.z_filefunc = *pzlib_filefunc_def;
423
442
 
424
 
    us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
425
 
                                                 path,
426
 
                                                 ZLIB_FILEFUNC_MODE_READ |
427
 
                                                 ZLIB_FILEFUNC_MODE_EXISTING);
428
 
    if (us.filestream==NULL)
429
 
        return NULL;
430
 
 
431
 
    central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
432
 
    if (central_pos==0)
433
 
        err=UNZ_ERRNO;
434
 
 
435
 
    if (ZSEEK(us.z_filefunc, us.filestream,
436
 
                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
437
 
        err=UNZ_ERRNO;
438
 
 
439
 
    /* the signature, already checked */
440
 
    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
441
 
        err=UNZ_ERRNO;
442
 
 
443
 
    /* number of this disk */
444
 
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
445
 
        err=UNZ_ERRNO;
446
 
 
447
 
    /* number of the disk with the start of the central directory */
448
 
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
449
 
        err=UNZ_ERRNO;
450
 
 
451
 
    /* total number of entries in the central dir on this disk */
452
 
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
453
 
        err=UNZ_ERRNO;
454
 
 
455
 
    /* total number of entries in the central dir */
456
 
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
457
 
        err=UNZ_ERRNO;
458
 
 
459
 
    if ((number_entry_CD!=us.gi.number_entry) ||
460
 
        (number_disk_with_CD!=0) ||
461
 
        (number_disk!=0))
462
 
        err=UNZ_BADZIPFILE;
463
 
 
464
 
    /* size of the central directory */
465
 
    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
466
 
        err=UNZ_ERRNO;
 
443
  us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
 
444
                                               path,
 
445
                                               ZLIB_FILEFUNC_MODE_READ |
 
446
                                               ZLIB_FILEFUNC_MODE_EXISTING);
 
447
  if (! us.filestream)
 
448
     return NULL;
 
449
 
 
450
  central_pos = unzlocal_SearchCentralDir (&us.z_filefunc, us.filestream);
 
451
  if (central_pos == 0)
 
452
     err = UNZ_ERRNO;
 
453
 
 
454
  if (ZSEEK(us.z_filefunc,
 
455
            us.filestream,
 
456
            central_pos,
 
457
            ZLIB_FILEFUNC_SEEK_SET) != 0)
 
458
      err=UNZ_ERRNO;
 
459
 
 
460
  // the signature, already checked
 
461
  if (unzlocal_getLong (&us.z_filefunc, us.filestream, &uL) != UNZ_OK)
 
462
     err=UNZ_ERRNO;
 
463
 
 
464
  // number of this disk
 
465
  if (unzlocal_getShort (&us.z_filefunc, us.filestream, &number_disk) != UNZ_OK)
 
466
     err = UNZ_ERRNO;
 
467
 
 
468
  // number of the disk with the start of the central directory
 
469
  if (unzlocal_getShort (&us.z_filefunc, us.filestream, &number_disk_with_CD) != UNZ_OK)
 
470
      err=UNZ_ERRNO;
 
471
 
 
472
  // total number of entries in the central dir on this disk
 
473
  if (unzlocal_getShort (&us.z_filefunc, us.filestream, &us.gi.number_entry) != UNZ_OK)
 
474
      err = UNZ_ERRNO;
 
475
 
 
476
  // total number of entries in the central dir
 
477
  if (unzlocal_getShort (&us.z_filefunc, us.filestream, &number_entry_CD) != UNZ_OK)
 
478
     err = UNZ_ERRNO;
 
479
 
 
480
  if ((number_entry_CD != us.gi.number_entry) ||
 
481
      (number_disk_with_CD != 0) ||
 
482
      (number_disk !=0 ))
 
483
      err = UNZ_BADZIPFILE;
 
484
 
 
485
   // size of the central directory
 
486
  if (unzlocal_getLong (&us.z_filefunc, us.filestream, &us.size_central_dir) != UNZ_OK)
 
487
     err = UNZ_ERRNO;
467
488
 
468
489
    /* offset of start of central directory with respect to the
469
490
          starting disk number */
470
 
    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
471
 
        err=UNZ_ERRNO;
472
 
 
473
 
    /* zipfile comment length */
474
 
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
475
 
        err=UNZ_ERRNO;
476
 
 
477
 
    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
478
 
        (err==UNZ_OK))
479
 
        err=UNZ_BADZIPFILE;
480
 
 
481
 
    if (err!=UNZ_OK)
482
 
    {
483
 
        ZCLOSE(us.z_filefunc, us.filestream);
484
 
        return NULL;
485
 
    }
486
 
 
487
 
    us.byte_before_the_zipfile = central_pos -
488
 
                            (us.offset_central_dir+us.size_central_dir);
 
491
  if (unzlocal_getLong (&us.z_filefunc, us.filestream, &us.offset_central_dir) != UNZ_OK)
 
492
    err = UNZ_ERRNO;
 
493
 
 
494
  //zipfile comment length
 
495
  if (unzlocal_getShort (&us.z_filefunc, us.filestream, &us.gi.size_comment) != UNZ_OK)
 
496
    err = UNZ_ERRNO;
 
497
 
 
498
  if ((central_pos < us.offset_central_dir+us.size_central_dir) && (err == UNZ_OK))
 
499
     err = UNZ_BADZIPFILE;
 
500
 
 
501
  if (err != UNZ_OK)
 
502
     {
 
503
      ZCLOSE (us.z_filefunc, us.filestream);
 
504
      return NULL;
 
505
     }
 
506
 
 
507
    us.byte_before_the_zipfile = central_pos - (us.offset_central_dir + us.size_central_dir);
489
508
    us.central_pos = central_pos;
490
509
    us.pfile_in_zip_read = NULL;
491
510
    us.encrypted = 0;
492
511
 
493
 
 
494
 
    s=(unz_s*)ALLOC(sizeof(unz_s));
495
 
    *s=us;
496
 
    unzGoToFirstFile((unzFile)s);
 
512
    s = (unz_s*)ALLOC (sizeof (unz_s));
 
513
    *s = us;
 
514
    unzGoToFirstFile ((unzFile)s);
497
515
    return (unzFile)s;
498
516
}
499
517
 
500
518
 
501
 
extern unzFile ZEXPORT unzOpen (path)
502
 
    const char *path;
 
519
extern unzFile ZEXPORT unzOpen (const char *path)
503
520
{
504
 
    return unzOpen2(path, NULL);
 
521
  return unzOpen2(path, NULL);
505
522
}
506
523
 
507
524
/*
509
526
  If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
510
527
    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
511
528
  return UNZ_OK if there is no problem. */
512
 
extern int ZEXPORT unzClose (file)
513
 
    unzFile file;
 
529
extern int ZEXPORT unzClose (unzFile file)
514
530
{
515
 
    unz_s* s;
516
 
    if (file==NULL)
517
 
        return UNZ_PARAMERROR;
518
 
    s=(unz_s*)file;
519
 
 
520
 
    if (s->pfile_in_zip_read!=NULL)
521
 
        unzCloseCurrentFile(file);
522
 
 
523
 
    ZCLOSE(s->z_filefunc, s->filestream);
524
 
    TRYFREE(s);
525
 
    return UNZ_OK;
 
531
  unz_s *s;
 
532
  if (! file)
 
533
      return UNZ_PARAMERROR;
 
534
 
 
535
  s = (unz_s*)file;
 
536
 
 
537
  if (s->pfile_in_zip_read)
 
538
     unzCloseCurrentFile (file);
 
539
 
 
540
  ZCLOSE (s->z_filefunc, s->filestream);
 
541
  TRYFREE(s);
 
542
 
 
543
  return UNZ_OK;
526
544
}
527
545
 
528
546
 
530
548
  Write info about the ZipFile in the *pglobal_info structure.
531
549
  No preparation of the structure is needed
532
550
  return UNZ_OK if there is no problem. */
533
 
extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
534
 
    unzFile file;
535
 
    unz_global_info *pglobal_info;
536
 
{
537
 
    unz_s* s;
538
 
    if (file==NULL)
539
 
        return UNZ_PARAMERROR;
540
 
    s=(unz_s*)file;
541
 
    *pglobal_info=s->gi;
542
 
    return UNZ_OK;
543
 
}
544
 
 
545
 
 
546
 
/*
547
 
   Translate date/time from Dos format to tm_unz (readable more easilty)
548
 
*/
549
 
local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
550
 
    uLong ulDosDate;
551
 
    tm_unz* ptm;
552
 
{
553
 
    uLong uDate;
554
 
    uDate = (uLong)(ulDosDate>>16);
555
 
    ptm->tm_mday = (uInt)(uDate&0x1f) ;
556
 
    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
557
 
    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
558
 
 
559
 
    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
560
 
    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
561
 
    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
562
 
}
563
 
 
564
 
/*
565
 
  Get Info about the current file in the zipfile, with internal only info
566
 
*/
 
551
extern int ZEXPORT unzGetGlobalInfo (unzFile file,
 
552
                                     unz_global_info *pglobal_info)
 
553
{
 
554
  unz_s *s;
 
555
  if (! file)
 
556
     return UNZ_PARAMERROR;
 
557
 
 
558
  s = (unz_s*)file;
 
559
  *pglobal_info = s->gi;
 
560
 
 
561
  return UNZ_OK;
 
562
}
 
563
 
 
564
 
 
565
//   Translate date/time from Dos format to tm_unz (readable more easilty)
 
566
local void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm)
 
567
{
 
568
  uLong uDate;
 
569
  uDate = (uLong)(ulDosDate>>16);
 
570
  ptm->tm_mday = (uInt)(uDate & 0x1f) ;
 
571
  ptm->tm_mon =  (uInt)((((uDate) & 0x1E0) / 0x20) - 1) ;
 
572
  ptm->tm_year = (uInt)(((uDate & 0x0FE00) / 0x0200) + 1980) ;
 
573
 
 
574
  ptm->tm_hour = (uInt) ((ulDosDate & 0xF800) / 0x800);
 
575
  ptm->tm_min =  (uInt) ((ulDosDate & 0x7E0) / 0x20) ;
 
576
  ptm->tm_sec =  (uInt) (2* (ulDosDate & 0x1f)) ;
 
577
}
 
578
 
 
579
 
 
580
//  Get Info about the current file in the zipfile, with internal only info
567
581
local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
568
582
                                                  unz_file_info *pfile_info,
569
583
                                                  unz_file_info_internal
575
589
                                                  char *szComment,
576
590
                                                  uLong commentBufferSize));
577
591
 
578
 
local int unzlocal_GetCurrentFileInfoInternal (file,
579
 
                                              pfile_info,
580
 
                                              pfile_info_internal,
581
 
                                              szFileName, fileNameBufferSize,
582
 
                                              extraField, extraFieldBufferSize,
583
 
                                              szComment,  commentBufferSize)
584
 
    unzFile file;
585
 
    unz_file_info *pfile_info;
586
 
    unz_file_info_internal *pfile_info_internal;
587
 
    char *szFileName;
588
 
    uLong fileNameBufferSize;
589
 
    void *extraField;
590
 
    uLong extraFieldBufferSize;
591
 
    char *szComment;
592
 
    uLong commentBufferSize;
 
592
local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
 
593
                                               unz_file_info *pfile_info,
 
594
                                               unz_file_info_internal *pfile_info_internal,
 
595
                                               char *szFileName,
 
596
                                               uLong fileNameBufferSize,
 
597
                                               void *extraField,
 
598
                                               uLong extraFieldBufferSize,
 
599
                                               char *szComment,
 
600
                                               uLong commentBufferSize)
593
601
{
594
 
    unz_s* s;
595
 
    unz_file_info file_info;
596
 
    unz_file_info_internal file_info_internal;
597
 
    int err=UNZ_OK;
598
 
    uLong uMagic;
599
 
    long lSeek=0;
600
 
 
601
 
    if (file==NULL)
602
 
        return UNZ_PARAMERROR;
603
 
    s=(unz_s*)file;
604
 
    if (ZSEEK(s->z_filefunc, s->filestream,
605
 
              s->pos_in_central_dir+s->byte_before_the_zipfile,
606
 
              ZLIB_FILEFUNC_SEEK_SET)!=0)
607
 
        err=UNZ_ERRNO;
608
 
 
609
 
 
610
 
    /* we check the magic */
611
 
    if (err==UNZ_OK) {
612
 
        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
613
 
            err=UNZ_ERRNO;
614
 
        else if (uMagic!=0x02014b50)
615
 
            err=UNZ_BADZIPFILE;
616
 
    }
617
 
 
618
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
619
 
        err=UNZ_ERRNO;
620
 
 
621
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
622
 
        err=UNZ_ERRNO;
623
 
 
624
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
625
 
        err=UNZ_ERRNO;
626
 
 
627
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
628
 
        err=UNZ_ERRNO;
629
 
 
630
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
631
 
        err=UNZ_ERRNO;
632
 
 
633
 
    unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
634
 
 
635
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
636
 
        err=UNZ_ERRNO;
637
 
 
638
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
639
 
        err=UNZ_ERRNO;
640
 
 
641
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
642
 
        err=UNZ_ERRNO;
643
 
 
644
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
645
 
        err=UNZ_ERRNO;
646
 
 
647
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
648
 
        err=UNZ_ERRNO;
649
 
 
650
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
651
 
        err=UNZ_ERRNO;
652
 
 
653
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
654
 
        err=UNZ_ERRNO;
655
 
 
656
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
657
 
        err=UNZ_ERRNO;
658
 
 
659
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
660
 
        err=UNZ_ERRNO;
661
 
 
662
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
663
 
        err=UNZ_ERRNO;
664
 
 
665
 
    lSeek+=file_info.size_filename;
666
 
    if ((err==UNZ_OK) && (szFileName!=NULL))
667
 
    {
668
 
        uLong uSizeRead ;
669
 
        if (file_info.size_filename<fileNameBufferSize)
670
 
        {
671
 
            *(szFileName+file_info.size_filename)='\0';
672
 
            uSizeRead = file_info.size_filename;
673
 
        }
674
 
        else
675
 
            uSizeRead = fileNameBufferSize;
676
 
 
677
 
        if ((file_info.size_filename>0) && (fileNameBufferSize>0))
678
 
            if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
679
 
                err=UNZ_ERRNO;
680
 
        lSeek -= uSizeRead;
681
 
    }
682
 
 
683
 
 
684
 
    if ((err==UNZ_OK) && (extraField!=NULL))
685
 
    {
686
 
        uLong uSizeRead ;
687
 
        if (file_info.size_file_extra<extraFieldBufferSize)
688
 
            uSizeRead = file_info.size_file_extra;
689
 
        else
690
 
            uSizeRead = extraFieldBufferSize;
691
 
 
692
 
        if (lSeek!=0) {
693
 
            if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
694
 
                lSeek=0;
695
 
            else
696
 
                err=UNZ_ERRNO;
697
 
        }
698
 
        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
699
 
            if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
700
 
                err=UNZ_ERRNO;
 
602
  if (! file)
 
603
     return UNZ_PARAMERROR;
 
604
 
 
605
  unz_s* s;
 
606
  unz_file_info file_info;
 
607
  unz_file_info_internal file_info_internal;
 
608
  int err = UNZ_OK;
 
609
  uLong uMagic;
 
610
  long lSeek = 0;
 
611
 
 
612
  s = (unz_s*)file;
 
613
 
 
614
  if (ZSEEK(s->z_filefunc, s->filestream,
 
615
            s->pos_in_central_dir + s->byte_before_the_zipfile,
 
616
            ZLIB_FILEFUNC_SEEK_SET) != 0)
 
617
     err = UNZ_ERRNO;
 
618
 
 
619
 
 
620
  // we check the magic
 
621
  if (err == UNZ_OK)
 
622
     {
 
623
      if (unzlocal_getLong (&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK)
 
624
         err = UNZ_ERRNO;
 
625
      else
 
626
          if (uMagic != 0x02014b50)
 
627
              err = UNZ_BADZIPFILE;
 
628
     }
 
629
 
 
630
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.version) != UNZ_OK)
 
631
      err = UNZ_ERRNO;
 
632
 
 
633
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.version_needed) != UNZ_OK)
 
634
      err = UNZ_ERRNO;
 
635
 
 
636
  if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.flag) != UNZ_OK)
 
637
      err = UNZ_ERRNO;
 
638
 
 
639
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.compression_method) != UNZ_OK)
 
640
      err = UNZ_ERRNO;
 
641
 
 
642
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.dosDate) != UNZ_OK)
 
643
      err = UNZ_ERRNO;
 
644
 
 
645
  unzlocal_DosDateToTmuDate (file_info.dosDate, &file_info.tmu_date);
 
646
 
 
647
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.crc) != UNZ_OK)
 
648
     err = UNZ_ERRNO;
 
649
 
 
650
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.compressed_size) != UNZ_OK)
 
651
      err = UNZ_ERRNO;
 
652
 
 
653
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.uncompressed_size) != UNZ_OK)
 
654
      err = UNZ_ERRNO;
 
655
 
 
656
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.size_filename) != UNZ_OK)
 
657
      err = UNZ_ERRNO;
 
658
 
 
659
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.size_file_extra) != UNZ_OK)
 
660
      err = UNZ_ERRNO;
 
661
 
 
662
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.size_file_comment) != UNZ_OK)
 
663
      err = UNZ_ERRNO;
 
664
 
 
665
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.disk_num_start) != UNZ_OK)
 
666
      err = UNZ_ERRNO;
 
667
 
 
668
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &file_info.internal_fa) != UNZ_OK)
 
669
      err = UNZ_ERRNO;
 
670
 
 
671
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info.external_fa) != UNZ_OK)
 
672
      err = UNZ_ERRNO;
 
673
 
 
674
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &file_info_internal.offset_curfile) != UNZ_OK)
 
675
      err = UNZ_ERRNO;
 
676
 
 
677
  lSeek += file_info.size_filename;
 
678
 
 
679
  if ((err == UNZ_OK) && szFileName)
 
680
     {
 
681
      uLong uSizeRead;
 
682
 
 
683
      if (file_info.size_filename < fileNameBufferSize)
 
684
         {
 
685
          *(szFileName + file_info.size_filename) = '\0';
 
686
          uSizeRead = file_info.size_filename;
 
687
         }
 
688
      else
 
689
          uSizeRead = fileNameBufferSize;
 
690
 
 
691
      if ((file_info.size_filename > 0) && (fileNameBufferSize > 0))
 
692
          if (ZREAD(s->z_filefunc, s->filestream, szFileName, uSizeRead) != uSizeRead)
 
693
             err = UNZ_ERRNO;
 
694
 
 
695
      lSeek -= uSizeRead;
 
696
     }
 
697
 
 
698
 
 
699
  if ((err == UNZ_OK) && extraField)
 
700
     {
 
701
      uLong uSizeRead;
 
702
 
 
703
      if (file_info.size_file_extra < extraFieldBufferSize)
 
704
          uSizeRead = file_info.size_file_extra;
 
705
      else
 
706
          uSizeRead = extraFieldBufferSize;
 
707
 
 
708
      if (lSeek != 0)
 
709
         {
 
710
          if (ZSEEK (s->z_filefunc, s->filestream, lSeek, ZLIB_FILEFUNC_SEEK_CUR) == 0)
 
711
             lSeek = 0;
 
712
          else
 
713
              err = UNZ_ERRNO;
 
714
         }
 
715
 
 
716
      if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0))
 
717
          if (ZREAD (s->z_filefunc, s->filestream, extraField, uSizeRead) != uSizeRead)
 
718
             err = UNZ_ERRNO;
701
719
        lSeek += file_info.size_file_extra - uSizeRead;
702
 
    }
703
 
    else
704
 
        lSeek+=file_info.size_file_extra;
705
 
 
706
 
 
707
 
    if ((err==UNZ_OK) && (szComment!=NULL))
708
 
    {
709
 
        uLong uSizeRead ;
710
 
        if (file_info.size_file_comment<commentBufferSize)
711
 
        {
712
 
            *(szComment+file_info.size_file_comment)='\0';
713
 
            uSizeRead = file_info.size_file_comment;
714
 
        }
715
 
        else
716
 
            uSizeRead = commentBufferSize;
717
 
 
718
 
        if (lSeek!=0) {
719
 
            if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
720
 
                lSeek=0;
721
 
            else
722
 
                err=UNZ_ERRNO;
723
 
        }
724
 
        if ((file_info.size_file_comment>0) && (commentBufferSize>0))
725
 
            if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
726
 
                err=UNZ_ERRNO;
727
 
        lSeek+=file_info.size_file_comment - uSizeRead;
728
 
    }
729
 
    else
730
 
        lSeek+=file_info.size_file_comment;
731
 
 
732
 
    if ((err==UNZ_OK) && (pfile_info!=NULL))
733
 
        *pfile_info=file_info;
734
 
 
735
 
    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
736
 
        *pfile_info_internal=file_info_internal;
737
 
 
738
 
    return err;
 
720
     }
 
721
  else
 
722
      lSeek += file_info.size_file_extra;
 
723
 
 
724
 
 
725
  if ((err == UNZ_OK) && szComment)
 
726
     {
 
727
      uLong uSizeRead;
 
728
      if (file_info.size_file_comment < commentBufferSize)
 
729
         {
 
730
          *(szComment + file_info.size_file_comment) = '\0';
 
731
          uSizeRead = file_info.size_file_comment;
 
732
         }
 
733
      else
 
734
          uSizeRead = commentBufferSize;
 
735
 
 
736
     if (lSeek != 0)
 
737
         {
 
738
          if (ZSEEK(s->z_filefunc, s->filestream, lSeek, ZLIB_FILEFUNC_SEEK_CUR) == 0)
 
739
             lSeek = 0;
 
740
          else
 
741
              err = UNZ_ERRNO;
 
742
         }
 
743
 
 
744
     if ((file_info.size_file_comment > 0) && (commentBufferSize > 0))
 
745
         if (ZREAD(s->z_filefunc, s->filestream, szComment, uSizeRead) != uSizeRead)
 
746
            err = UNZ_ERRNO;
 
747
 
 
748
     lSeek += file_info.size_file_comment - uSizeRead;
 
749
    }
 
750
  else
 
751
      lSeek += file_info.size_file_comment;
 
752
 
 
753
  if ((err == UNZ_OK) && pfile_info)
 
754
     *pfile_info = file_info;
 
755
 
 
756
  if ((err == UNZ_OK) && pfile_info_internal)
 
757
     *pfile_info_internal = file_info_internal;
 
758
 
 
759
  return err;
739
760
}
740
761
 
741
762
 
745
766
  No preparation of the structure is needed
746
767
  return UNZ_OK if there is no problem.
747
768
*/
748
 
extern int ZEXPORT unzGetCurrentFileInfo (file,
749
 
                                          pfile_info,
750
 
                                          szFileName, fileNameBufferSize,
751
 
                                          extraField, extraFieldBufferSize,
752
 
                                          szComment,  commentBufferSize)
753
 
    unzFile file;
754
 
    unz_file_info *pfile_info;
755
 
    char *szFileName;
756
 
    uLong fileNameBufferSize;
757
 
    void *extraField;
758
 
    uLong extraFieldBufferSize;
759
 
    char *szComment;
760
 
    uLong commentBufferSize;
 
769
extern int ZEXPORT unzGetCurrentFileInfo (
 
770
                                          unzFile file,
 
771
                                          unz_file_info *pfile_info,
 
772
                                          char *szFileName,
 
773
                                          uLong fileNameBufferSize,
 
774
                                          void *extraField,
 
775
                                          uLong extraFieldBufferSize,
 
776
                                          char *szComment,
 
777
                                          uLong commentBufferSize)
761
778
{
762
 
    return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
763
 
                                                szFileName,fileNameBufferSize,
764
 
                                                extraField,extraFieldBufferSize,
765
 
                                                szComment,commentBufferSize);
 
779
   return unzlocal_GetCurrentFileInfoInternal (file,
 
780
                                               pfile_info,
 
781
                                               NULL,
 
782
                                               szFileName,
 
783
                                               fileNameBufferSize,
 
784
                                               extraField,
 
785
                                               extraFieldBufferSize,
 
786
                                               szComment,
 
787
                                               commentBufferSize);
766
788
}
767
789
 
 
790
 
768
791
/*
769
792
  Set the current file of the zipfile to the first file.
770
793
  return UNZ_OK if there is no problem
771
794
*/
772
 
extern int ZEXPORT unzGoToFirstFile (file)
773
 
    unzFile file;
 
795
extern int ZEXPORT unzGoToFirstFile (unzFile file)
774
796
{
775
 
    int err=UNZ_OK;
776
 
    unz_s* s;
777
 
    if (file==NULL)
778
 
        return UNZ_PARAMERROR;
779
 
    s=(unz_s*)file;
780
 
    s->pos_in_central_dir=s->offset_central_dir;
781
 
    s->num_file=0;
782
 
    err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
 
797
  if (! file)
 
798
      return UNZ_PARAMERROR;
 
799
 
 
800
  int err = UNZ_OK;
 
801
  unz_s *s;
 
802
  s = (unz_s*)file;
 
803
  s->pos_in_central_dir = s->offset_central_dir;
 
804
  s->num_file = 0;
 
805
  err = unzlocal_GetCurrentFileInfoInternal (file, &s->cur_file_info,
783
806
                                             &s->cur_file_info_internal,
784
 
                                             NULL,0,NULL,0,NULL,0);
 
807
                                             NULL, 0, NULL, 0, NULL, 0);
785
808
    s->current_file_ok = (err == UNZ_OK);
786
809
    return err;
787
810
}
791
814
  return UNZ_OK if there is no problem
792
815
  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
793
816
*/
794
 
extern int ZEXPORT unzGoToNextFile (file)
795
 
    unzFile file;
 
817
extern int ZEXPORT unzGoToNextFile (unzFile file)
796
818
{
797
 
    unz_s* s;
798
 
    int err;
799
 
 
800
 
    if (file==NULL)
801
 
        return UNZ_PARAMERROR;
802
 
    s=(unz_s*)file;
803
 
    if (!s->current_file_ok)
804
 
        return UNZ_END_OF_LIST_OF_FILE;
805
 
    if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
806
 
      if (s->num_file+1==s->gi.number_entry)
807
 
        return UNZ_END_OF_LIST_OF_FILE;
808
 
 
809
 
    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
810
 
            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
811
 
    s->num_file++;
812
 
    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
813
 
                                               &s->cur_file_info_internal,
814
 
                                               NULL,0,NULL,0,NULL,0);
815
 
    s->current_file_ok = (err == UNZ_OK);
816
 
    return err;
 
819
  if (! file)
 
820
     return UNZ_PARAMERROR;
 
821
 
 
822
  unz_s *s;
 
823
  int err;
 
824
 
 
825
  s = (unz_s*) file;
 
826
 
 
827
  if (! s->current_file_ok)
 
828
     return UNZ_END_OF_LIST_OF_FILE;
 
829
 
 
830
  if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
 
831
     if (s->num_file + 1 == s->gi.number_entry)
 
832
        return UNZ_END_OF_LIST_OF_FILE;
 
833
 
 
834
  s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
 
835
                           s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment;
 
836
  s->num_file++;
 
837
 
 
838
  err = unzlocal_GetCurrentFileInfoInternal (file, &s->cur_file_info,
 
839
                                             &s->cur_file_info_internal,
 
840
                                             NULL, 0, NULL, 0, NULL, 0);
 
841
 
 
842
  s->current_file_ok = (err == UNZ_OK);
 
843
 
 
844
  return err;
817
845
}
818
846
 
819
847
 
825
853
  UNZ_OK if the file is found. It becomes the current file.
826
854
  UNZ_END_OF_LIST_OF_FILE if the file is not found
827
855
*/
828
 
extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
829
 
    unzFile file;
830
 
    const char *szFileName;
831
 
    int iCaseSensitivity;
 
856
extern int ZEXPORT unzLocateFile (unzFile file,
 
857
                                  const char *szFileName,
 
858
                                  int iCaseSensitivity)
832
859
{
833
 
    unz_s* s;
834
 
    int err;
 
860
  if (! file)
 
861
     return UNZ_PARAMERROR;
 
862
 
 
863
  unz_s *s;
 
864
  int err;
835
865
 
836
866
    /* We remember the 'current' position in the file so that we can jump
837
867
     * back there if we fail.
838
868
     */
839
 
    unz_file_info cur_file_infoSaved;
840
 
    unz_file_info_internal cur_file_info_internalSaved;
841
 
    uLong num_fileSaved;
842
 
    uLong pos_in_central_dirSaved;
843
 
 
844
 
 
845
 
    if (file==NULL)
846
 
        return UNZ_PARAMERROR;
847
 
 
848
 
    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
849
 
        return UNZ_PARAMERROR;
850
 
 
851
 
    s=(unz_s*)file;
852
 
    if (!s->current_file_ok)
853
 
        return UNZ_END_OF_LIST_OF_FILE;
 
869
  unz_file_info cur_file_infoSaved;
 
870
  unz_file_info_internal cur_file_info_internalSaved;
 
871
  uLong num_fileSaved;
 
872
  uLong pos_in_central_dirSaved;
 
873
 
 
874
  if (strlen (szFileName) >= UNZ_MAXFILENAMEINZIP)
 
875
      return UNZ_PARAMERROR;
 
876
 
 
877
  s = (unz_s*) file;
 
878
 
 
879
  if (! s->current_file_ok)
 
880
     return UNZ_END_OF_LIST_OF_FILE;
854
881
 
855
882
    /* Save the current state */
856
 
    num_fileSaved = s->num_file;
857
 
    pos_in_central_dirSaved = s->pos_in_central_dir;
858
 
    cur_file_infoSaved = s->cur_file_info;
859
 
    cur_file_info_internalSaved = s->cur_file_info_internal;
860
 
 
861
 
    err = unzGoToFirstFile(file);
862
 
 
863
 
    while (err == UNZ_OK)
864
 
    {
865
 
        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
866
 
        err = unzGetCurrentFileInfo(file,NULL,
867
 
                                    szCurrentFileName,sizeof(szCurrentFileName)-1,
868
 
                                    NULL,0,NULL,0);
869
 
        if (err == UNZ_OK)
 
883
  num_fileSaved = s->num_file;
 
884
  pos_in_central_dirSaved = s->pos_in_central_dir;
 
885
  cur_file_infoSaved = s->cur_file_info;
 
886
  cur_file_info_internalSaved = s->cur_file_info_internal;
 
887
 
 
888
  err = unzGoToFirstFile(file);
 
889
 
 
890
  while (err == UNZ_OK)
870
891
        {
871
 
            if (unzStringFileNameCompare(szCurrentFileName,
872
 
                                            szFileName,iCaseSensitivity)==0)
 
892
         char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1];
 
893
         err = unzGetCurrentFileInfo (file,
 
894
                                      NULL,
 
895
                                      szCurrentFileName, sizeof( szCurrentFileName) - 1,
 
896
                                      NULL, 0, NULL, 0);
 
897
 
 
898
         if (err == UNZ_OK)
 
899
           {
 
900
            if (unzStringFileNameCompare (szCurrentFileName,
 
901
                                          szFileName, iCaseSensitivity) == 0)
873
902
                return UNZ_OK;
 
903
 
874
904
            err = unzGoToNextFile(file);
 
905
           }
875
906
        }
876
 
    }
877
907
 
878
908
    /* We failed, so restore the state of the 'current file' to where we
879
909
     * were.
880
910
     */
881
 
    s->num_file = num_fileSaved ;
882
 
    s->pos_in_central_dir = pos_in_central_dirSaved ;
883
 
    s->cur_file_info = cur_file_infoSaved;
884
 
    s->cur_file_info_internal = cur_file_info_internalSaved;
885
 
    return err;
 
911
  s->num_file = num_fileSaved ;
 
912
  s->pos_in_central_dir = pos_in_central_dirSaved ;
 
913
  s->cur_file_info = cur_file_infoSaved;
 
914
  s->cur_file_info_internal = cur_file_info_internalSaved;
 
915
  return err;
886
916
}
887
917
 
888
918
 
904
934
} unz_file_pos;
905
935
*/
906
936
 
907
 
extern int ZEXPORT unzGetFilePos(file, file_pos)
908
 
    unzFile file;
909
 
    unz_file_pos* file_pos;
 
937
extern int ZEXPORT unzGetFilePos (unzFile file,
 
938
                                  unz_file_pos *file_pos)
910
939
{
911
 
    unz_s* s;
912
 
 
913
 
    if (file==NULL || file_pos==NULL)
914
 
        return UNZ_PARAMERROR;
915
 
    s=(unz_s*)file;
916
 
    if (!s->current_file_ok)
917
 
        return UNZ_END_OF_LIST_OF_FILE;
918
 
 
919
 
    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
920
 
    file_pos->num_of_file           = s->num_file;
921
 
 
922
 
    return UNZ_OK;
 
940
  if (! file || ! file_pos)
 
941
     return UNZ_PARAMERROR;
 
942
 
 
943
  unz_s* s = (unz_s*) file;
 
944
 
 
945
  if (! s->current_file_ok)
 
946
     return UNZ_END_OF_LIST_OF_FILE;
 
947
 
 
948
  file_pos->pos_in_zip_directory = s->pos_in_central_dir;
 
949
  file_pos->num_of_file = s->num_file;
 
950
 
 
951
  return UNZ_OK;
923
952
}
924
953
 
925
 
extern int ZEXPORT unzGoToFilePos(file, file_pos)
926
 
    unzFile file;
927
 
    unz_file_pos* file_pos;
 
954
 
 
955
extern int ZEXPORT unzGoToFilePos (unzFile file,
 
956
                                   unz_file_pos *file_pos)
928
957
{
929
 
    unz_s* s;
930
 
    int err;
931
 
 
932
 
    if (file==NULL || file_pos==NULL)
933
 
        return UNZ_PARAMERROR;
934
 
    s=(unz_s*)file;
935
 
 
936
 
    /* jump to the right spot */
937
 
    s->pos_in_central_dir = file_pos->pos_in_zip_directory;
938
 
    s->num_file           = file_pos->num_of_file;
939
 
 
940
 
    /* set the current file */
941
 
    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
942
 
                                               &s->cur_file_info_internal,
943
 
                                               NULL,0,NULL,0,NULL,0);
944
 
    /* return results */
945
 
    s->current_file_ok = (err == UNZ_OK);
946
 
    return err;
 
958
 
 
959
  if (! file || ! file_pos)
 
960
      return UNZ_PARAMERROR;
 
961
 
 
962
  unz_s *s=(unz_s*)file;
 
963
 
 
964
  int err;
 
965
 
 
966
  // jump to the right spot
 
967
  s->pos_in_central_dir = file_pos->pos_in_zip_directory;
 
968
  s->num_file = file_pos->num_of_file;
 
969
 
 
970
  // set the current file
 
971
  err = unzlocal_GetCurrentFileInfoInternal (file, &s->cur_file_info,
 
972
                                             &s->cur_file_info_internal,
 
973
                                             NULL, 0, NULL, 0, NULL, 0);
 
974
  s->current_file_ok = (err == UNZ_OK);
 
975
  return err;
947
976
}
948
977
 
949
978
/*
958
987
  store in *piSizeVar the size of extra info in local header
959
988
        (filename and size of extra field data)
960
989
*/
961
 
local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
962
 
                                                    poffset_local_extrafield,
963
 
                                                    psize_local_extrafield)
964
 
    unz_s* s;
965
 
    uInt* piSizeVar;
966
 
    uLong *poffset_local_extrafield;
967
 
    uInt  *psize_local_extrafield;
 
990
local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s *s,
 
991
                                                    uInt *piSizeVar,
 
992
                                                    uLong *poffset_local_extrafield,
 
993
                                                    uInt *psize_local_extrafield)
968
994
{
969
 
    uLong uMagic,uData,uFlags;
970
 
    uLong size_filename;
971
 
    uLong size_extra_field;
972
 
    int err=UNZ_OK;
973
 
 
974
 
    *piSizeVar = 0;
975
 
    *poffset_local_extrafield = 0;
976
 
    *psize_local_extrafield = 0;
977
 
 
978
 
    if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
979
 
                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
980
 
        return UNZ_ERRNO;
981
 
 
982
 
 
983
 
    if (err==UNZ_OK) {
984
 
        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
985
 
            err=UNZ_ERRNO;
986
 
        else if (uMagic!=0x04034b50)
987
 
            err=UNZ_BADZIPFILE;
988
 
    }
989
 
 
990
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
991
 
        err=UNZ_ERRNO;
 
995
  uLong uMagic,uData,uFlags;
 
996
  uLong size_filename;
 
997
  uLong size_extra_field;
 
998
  int err = UNZ_OK;
 
999
 
 
1000
  *piSizeVar = 0;
 
1001
  *poffset_local_extrafield = 0;
 
1002
  *psize_local_extrafield = 0;
 
1003
 
 
1004
  if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
 
1005
                               s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
 
1006
     return UNZ_ERRNO;
 
1007
 
 
1008
 
 
1009
  if (err == UNZ_OK)
 
1010
     {
 
1011
      if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
 
1012
          err = UNZ_ERRNO;
 
1013
      else
 
1014
          if (uMagic != 0x04034b50)
 
1015
             err = UNZ_BADZIPFILE;
 
1016
     }
 
1017
 
 
1018
  if (unzlocal_getShort (&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
 
1019
      err = UNZ_ERRNO;
992
1020
/*
993
1021
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
994
1022
        err=UNZ_BADZIPFILE;
995
1023
*/
996
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
997
 
        err=UNZ_ERRNO;
998
 
 
999
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1000
 
        err=UNZ_ERRNO;
1001
 
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1002
 
        err=UNZ_BADZIPFILE;
1003
 
 
1004
 
    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1005
 
                         (s->cur_file_info.compression_method!=Z_DEFLATED))
1006
 
        err=UNZ_BADZIPFILE;
1007
 
 
1008
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1009
 
        err=UNZ_ERRNO;
1010
 
 
1011
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1012
 
        err=UNZ_ERRNO;
1013
 
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1014
 
                              ((uFlags & 8)==0))
1015
 
        err=UNZ_BADZIPFILE;
1016
 
 
1017
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1018
 
        err=UNZ_ERRNO;
1019
 
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1020
 
                              ((uFlags & 8)==0))
1021
 
        err=UNZ_BADZIPFILE;
1022
 
 
1023
 
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1024
 
        err=UNZ_ERRNO;
1025
 
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1026
 
                              ((uFlags & 8)==0))
1027
 
        err=UNZ_BADZIPFILE;
1028
 
 
1029
 
 
1030
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1031
 
        err=UNZ_ERRNO;
1032
 
    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1033
 
        err=UNZ_BADZIPFILE;
1034
 
 
1035
 
    *piSizeVar += (uInt)size_filename;
1036
 
 
1037
 
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1038
 
        err=UNZ_ERRNO;
1039
 
    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1040
 
                                    SIZEZIPLOCALHEADER + size_filename;
1041
 
    *psize_local_extrafield = (uInt)size_extra_field;
1042
 
 
1043
 
    *piSizeVar += (uInt)size_extra_field;
1044
 
 
1045
 
    return err;
 
1024
  if (unzlocal_getShort (&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
 
1025
      err = UNZ_ERRNO;
 
1026
 
 
1027
  if (unzlocal_getShort (&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
 
1028
      err = UNZ_ERRNO;
 
1029
  else
 
1030
      if ((err == UNZ_OK) && (uData != s->cur_file_info.compression_method))
 
1031
          err = UNZ_BADZIPFILE;
 
1032
 
 
1033
  if ((err == UNZ_OK) && (s->cur_file_info.compression_method != 0) &&
 
1034
                         (s->cur_file_info.compression_method != Z_DEFLATED))
 
1035
      err = UNZ_BADZIPFILE;
 
1036
 
 
1037
  if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
 
1038
      err = UNZ_ERRNO;
 
1039
 
 
1040
  if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
 
1041
      err = UNZ_ERRNO;
 
1042
  else
 
1043
      if ((err == UNZ_OK) && (uData != s->cur_file_info.crc) &&
 
1044
                             ((uFlags & 8) == 0))
 
1045
         err = UNZ_BADZIPFILE;
 
1046
 
 
1047
  if (unzlocal_getLong (&s->z_filefunc, s->filestream, &uData) != UNZ_OK) // size compr
 
1048
     err = UNZ_ERRNO;
 
1049
  else
 
1050
      if ((err == UNZ_OK) && (uData != s->cur_file_info.compressed_size) &&
 
1051
                             ((uFlags & 8) == 0))
 
1052
         err = UNZ_BADZIPFILE;
 
1053
 
 
1054
  if (unzlocal_getLong (&s->z_filefunc, s->filestream,&uData) != UNZ_OK) // size uncompr
 
1055
      err = UNZ_ERRNO;
 
1056
  else
 
1057
      if ((err == UNZ_OK) && (uData != s->cur_file_info.uncompressed_size) &&
 
1058
                             ((uFlags & 8) == 0))
 
1059
         err = UNZ_BADZIPFILE;
 
1060
 
 
1061
 
 
1062
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &size_filename) != UNZ_OK)
 
1063
      err = UNZ_ERRNO;
 
1064
  else
 
1065
      if ((err == UNZ_OK) && (size_filename != s->cur_file_info.size_filename))
 
1066
          err = UNZ_BADZIPFILE;
 
1067
 
 
1068
  *piSizeVar += (uInt)size_filename;
 
1069
 
 
1070
  if (unzlocal_getShort (&s->z_filefunc, s->filestream, &size_extra_field) != UNZ_OK)
 
1071
      err = UNZ_ERRNO;
 
1072
 
 
1073
  *poffset_local_extrafield = s->cur_file_info_internal.offset_curfile +
 
1074
                              SIZEZIPLOCALHEADER + size_filename;
 
1075
  *psize_local_extrafield = (uInt)size_extra_field;
 
1076
 
 
1077
  *piSizeVar += (uInt)size_extra_field;
 
1078
 
 
1079
  return err;
1046
1080
}
1047
1081
 
1048
1082
/*
1049
1083
  Open for reading data the current file in the zipfile.
1050
1084
  If there is no error and the file is opened, the return value is UNZ_OK.
1051
1085
*/
1052
 
extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1053
 
    unzFile file;
1054
 
    int* method;
1055
 
    int* level;
1056
 
    int raw;
1057
 
    const char* password;
 
1086
extern int ZEXPORT unzOpenCurrentFile3 (unzFile file,
 
1087
                                        int *method,
 
1088
                                        int *level,
 
1089
                                        int raw,
 
1090
                                        const char *password)
1058
1091
{
1059
 
    int err=UNZ_OK;
1060
 
    uInt iSizeVar;
1061
 
    unz_s* s;
1062
 
    file_in_zip_read_info_s* pfile_in_zip_read_info;
1063
 
    uLong offset_local_extrafield;  /* offset of the local extra field */
1064
 
    uInt  size_local_extrafield;    /* size of the local extra field */
1065
 
#    ifndef NOUNCRYPT
1066
 
    char source[12];
1067
 
#    else
1068
 
    if (password != NULL)
1069
 
        return UNZ_PARAMERROR;
1070
 
#    endif
1071
 
 
1072
 
    if (file==NULL)
1073
 
        return UNZ_PARAMERROR;
1074
 
    s=(unz_s*)file;
1075
 
    if (!s->current_file_ok)
1076
 
        return UNZ_PARAMERROR;
1077
 
 
1078
 
    if (s->pfile_in_zip_read != NULL)
1079
 
        unzCloseCurrentFile(file);
1080
 
 
1081
 
    if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1082
 
                &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1083
 
        return UNZ_BADZIPFILE;
1084
 
 
1085
 
    pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1086
 
                                        ALLOC(sizeof(file_in_zip_read_info_s));
1087
 
    if (pfile_in_zip_read_info==NULL)
1088
 
        return UNZ_INTERNALERROR;
1089
 
 
1090
 
    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1091
 
    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1092
 
    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1093
 
    pfile_in_zip_read_info->pos_local_extrafield=0;
1094
 
    pfile_in_zip_read_info->raw=raw;
1095
 
 
1096
 
    if (pfile_in_zip_read_info->read_buffer==NULL)
1097
 
    {
1098
 
        TRYFREE(pfile_in_zip_read_info);
1099
 
        return UNZ_INTERNALERROR;
1100
 
    }
1101
 
 
1102
 
    pfile_in_zip_read_info->stream_initialised=0;
1103
 
 
1104
 
    if (method!=NULL)
1105
 
        *method = (int)s->cur_file_info.compression_method;
1106
 
 
1107
 
    if (level!=NULL)
1108
 
    {
1109
 
        *level = 6;
1110
 
        switch (s->cur_file_info.flag & 0x06)
1111
 
        {
1112
 
          case 6 : *level = 1; break;
1113
 
          case 4 : *level = 2; break;
1114
 
          case 2 : *level = 9; break;
1115
 
        }
1116
 
    }
1117
 
 
1118
 
    if ((s->cur_file_info.compression_method!=0) &&
1119
 
        (s->cur_file_info.compression_method!=Z_DEFLATED))
1120
 
        err=UNZ_BADZIPFILE;
1121
 
 
1122
 
    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1123
 
    pfile_in_zip_read_info->crc32=0;
1124
 
    pfile_in_zip_read_info->compression_method =
1125
 
            s->cur_file_info.compression_method;
1126
 
    pfile_in_zip_read_info->filestream=s->filestream;
1127
 
    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1128
 
    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1129
 
 
1130
 
    pfile_in_zip_read_info->stream.total_out = 0;
1131
 
 
1132
 
    if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1133
 
        (!raw))
1134
 
    {
 
1092
  if (! file)
 
1093
      return UNZ_PARAMERROR;
 
1094
 
 
1095
  int err = UNZ_OK;
 
1096
  uInt iSizeVar;
 
1097
  unz_s *s;
 
1098
  file_in_zip_read_info_s *pfile_in_zip_read_info;
 
1099
  uLong offset_local_extrafield;  /* offset of the local extra field */
 
1100
  uInt size_local_extrafield;    /* size of the local extra field */
 
1101
 
 
1102
#ifndef NOUNCRYPT
 
1103
  char source[12];
 
1104
#else
 
1105
  if (password)
 
1106
     return UNZ_PARAMERROR;
 
1107
#endif
 
1108
 
 
1109
  s = (unz_s*)file;
 
1110
  if (! s->current_file_ok)
 
1111
     return UNZ_PARAMERROR;
 
1112
 
 
1113
  if (s->pfile_in_zip_read)
 
1114
     unzCloseCurrentFile(file);
 
1115
 
 
1116
  if (unzlocal_CheckCurrentFileCoherencyHeader (s, &iSizeVar,
 
1117
                                                &offset_local_extrafield, &size_local_extrafield) != UNZ_OK)
 
1118
     return UNZ_BADZIPFILE;
 
1119
 
 
1120
  pfile_in_zip_read_info = (file_in_zip_read_info_s*) ALLOC(sizeof (file_in_zip_read_info_s));
 
1121
 
 
1122
  if (! pfile_in_zip_read_info)
 
1123
      return UNZ_INTERNALERROR;
 
1124
 
 
1125
  pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
 
1126
  pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
 
1127
  pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
 
1128
  pfile_in_zip_read_info->pos_local_extrafield = 0;
 
1129
  pfile_in_zip_read_info->raw = raw;
 
1130
 
 
1131
  if (! pfile_in_zip_read_info->read_buffer)
 
1132
     {
 
1133
      TRYFREE (pfile_in_zip_read_info);
 
1134
      return UNZ_INTERNALERROR;
 
1135
     }
 
1136
 
 
1137
  pfile_in_zip_read_info->stream_initialised=0;
 
1138
 
 
1139
  if (method)
 
1140
      *method = (int)s->cur_file_info.compression_method;
 
1141
 
 
1142
  if (level)
 
1143
     {
 
1144
      *level = 6;
 
1145
      switch (s->cur_file_info.flag & 0x06)
 
1146
             {
 
1147
              case 6: *level = 1; break;
 
1148
              case 4: *level = 2; break;
 
1149
              case 2: *level = 9; break;
 
1150
             }
 
1151
      }
 
1152
 
 
1153
  if ((s->cur_file_info.compression_method != 0) &&
 
1154
      (s->cur_file_info.compression_method != Z_DEFLATED))
 
1155
       err=UNZ_BADZIPFILE;
 
1156
 
 
1157
  pfile_in_zip_read_info->crc32_wait = s->cur_file_info.crc;
 
1158
  pfile_in_zip_read_info->crc32 = 0;
 
1159
  pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
 
1160
  pfile_in_zip_read_info->filestream = s->filestream;
 
1161
  pfile_in_zip_read_info->z_filefunc = s->z_filefunc;
 
1162
  pfile_in_zip_read_info->byte_before_the_zipfile = s->byte_before_the_zipfile;
 
1163
 
 
1164
  pfile_in_zip_read_info->stream.total_out = 0;
 
1165
 
 
1166
  if ((s->cur_file_info.compression_method == Z_DEFLATED) &&
 
1167
     (!raw))
 
1168
     {
1135
1169
      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1136
1170
      pfile_in_zip_read_info->stream.zfree = (free_func)0;
1137
1171
      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1138
1172
      pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1139
1173
      pfile_in_zip_read_info->stream.avail_in = 0;
1140
1174
 
1141
 
      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
 
1175
      err = inflateInit2 (&pfile_in_zip_read_info->stream, -MAX_WBITS);
 
1176
 
1142
1177
      if (err == Z_OK)
1143
 
        pfile_in_zip_read_info->stream_initialised=1;
 
1178
          pfile_in_zip_read_info->stream_initialised = 1;
1144
1179
      else
1145
 
      {
1146
 
        TRYFREE(pfile_in_zip_read_info);
1147
 
        return err;
1148
 
      }
 
1180
          {
 
1181
           TRYFREE (pfile_in_zip_read_info);
 
1182
           return err;
 
1183
          }
1149
1184
        /* windowBits is passed < 0 to tell that there is no zlib header.
1150
1185
         * Note that in this case inflate *requires* an extra "dummy" byte
1151
1186
         * after the compressed stream in order to complete decompression and
1153
1188
         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1154
1189
         * size of both compressed and uncompressed data
1155
1190
         */
1156
 
    }
1157
 
    pfile_in_zip_read_info->rest_read_compressed =
1158
 
            s->cur_file_info.compressed_size ;
1159
 
    pfile_in_zip_read_info->rest_read_uncompressed =
1160
 
            s->cur_file_info.uncompressed_size ;
1161
 
 
1162
 
 
1163
 
    pfile_in_zip_read_info->pos_in_zipfile =
1164
 
            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1165
 
              iSizeVar;
1166
 
 
1167
 
    pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1168
 
 
1169
 
    s->pfile_in_zip_read = pfile_in_zip_read_info;
1170
 
 
1171
 
#    ifndef NOUNCRYPT
1172
 
    if (password != NULL)
1173
 
    {
1174
 
        int i;
1175
 
        s->pcrc_32_tab = get_crc_table();
1176
 
        init_keys(password,s->keys,s->pcrc_32_tab);
1177
 
        if (ZSEEK(s->z_filefunc, s->filestream,
1178
 
                  s->pfile_in_zip_read->pos_in_zipfile +
1179
 
                     s->pfile_in_zip_read->byte_before_the_zipfile,
1180
 
                  SEEK_SET)!=0)
1181
 
            return UNZ_INTERNALERROR;
1182
 
        if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1183
 
            return UNZ_INTERNALERROR;
1184
 
 
1185
 
        for (i = 0; i<12; i++)
1186
 
            zdecode(s->keys,s->pcrc_32_tab,source[i]);
1187
 
 
1188
 
        s->pfile_in_zip_read->pos_in_zipfile+=12;
1189
 
        s->encrypted=1;
1190
 
    }
1191
 
#    endif
1192
 
 
1193
 
 
1194
 
    return UNZ_OK;
1195
 
}
1196
 
 
1197
 
extern int ZEXPORT unzOpenCurrentFile (file)
1198
 
    unzFile file;
1199
 
{
1200
 
    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1201
 
}
1202
 
 
1203
 
extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1204
 
    unzFile file;
1205
 
    const char* password;
1206
 
{
1207
 
    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1208
 
}
1209
 
 
1210
 
extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1211
 
    unzFile file;
1212
 
    int* method;
1213
 
    int* level;
1214
 
    int raw;
1215
 
{
1216
 
    return unzOpenCurrentFile3(file, method, level, raw, NULL);
 
1191
      }
 
1192
 
 
1193
  pfile_in_zip_read_info->rest_read_compressed = s->cur_file_info.compressed_size;
 
1194
  pfile_in_zip_read_info->rest_read_uncompressed = s->cur_file_info.uncompressed_size;
 
1195
 
 
1196
  pfile_in_zip_read_info->pos_in_zipfile = s->cur_file_info_internal.offset_curfile +
 
1197
                                           SIZEZIPLOCALHEADER +
 
1198
                                           iSizeVar;
 
1199
 
 
1200
  pfile_in_zip_read_info->stream.avail_in = (uInt)0;
 
1201
 
 
1202
  s->pfile_in_zip_read = pfile_in_zip_read_info;
 
1203
 
 
1204
#ifndef NOUNCRYPT
 
1205
 
 
1206
  if (password)
 
1207
     {
 
1208
      int i;
 
1209
      s->pcrc_32_tab = get_crc_table();
 
1210
      init_keys (password, s->keys, s->pcrc_32_tab);
 
1211
 
 
1212
      if (ZSEEK(s->z_filefunc, s->filestream,
 
1213
                s->pfile_in_zip_read->pos_in_zipfile +
 
1214
                s->pfile_in_zip_read->byte_before_the_zipfile,
 
1215
                SEEK_SET) != 0)
 
1216
         return UNZ_INTERNALERROR;
 
1217
 
 
1218
      if (ZREAD(s->z_filefunc, s->filestream,source, 12) < 12)
 
1219
         return UNZ_INTERNALERROR;
 
1220
 
 
1221
      for (i = 0; i < 12; i++)
 
1222
          zdecode (s->keys, s->pcrc_32_tab, source[i]);
 
1223
 
 
1224
      s->pfile_in_zip_read->pos_in_zipfile += 12;
 
1225
      s->encrypted = 1;
 
1226
    }
 
1227
 
 
1228
#endif
 
1229
 
 
1230
 
 
1231
  return UNZ_OK;
 
1232
}
 
1233
 
 
1234
 
 
1235
extern int ZEXPORT unzOpenCurrentFile (unzFile file)
 
1236
{
 
1237
  return unzOpenCurrentFile3 (file, NULL, NULL, 0, NULL);
 
1238
}
 
1239
 
 
1240
 
 
1241
extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file,
 
1242
                                               const char *password)
 
1243
{
 
1244
  return unzOpenCurrentFile3 (file, NULL, NULL, 0, password);
 
1245
}
 
1246
 
 
1247
 
 
1248
extern int ZEXPORT unzOpenCurrentFile2 (unzFile file,
 
1249
                                        int *method,
 
1250
                                        int *level,
 
1251
                                        int raw)
 
1252
{
 
1253
  return unzOpenCurrentFile3 (file, method, level, raw, NULL);
1217
1254
}
1218
1255
 
1219
1256
/*
1226
1263
  return <0 with error code if there is an error
1227
1264
    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1228
1265
*/
1229
 
extern int ZEXPORT unzReadCurrentFile  (file, buf, len)
1230
 
    unzFile file;
1231
 
    voidp buf;
1232
 
    unsigned len;
 
1266
extern int ZEXPORT unzReadCurrentFile (unzFile file,
 
1267
                                       voidp buf,
 
1268
                                       unsigned len)
1233
1269
{
1234
 
    int err=UNZ_OK;
1235
 
    uInt iRead = 0;
1236
 
    unz_s* s;
1237
 
    file_in_zip_read_info_s* pfile_in_zip_read_info;
1238
 
    if (file==NULL)
1239
 
        return UNZ_PARAMERROR;
1240
 
    s=(unz_s*)file;
1241
 
    pfile_in_zip_read_info=s->pfile_in_zip_read;
1242
 
 
1243
 
    if (pfile_in_zip_read_info==NULL)
1244
 
        return UNZ_PARAMERROR;
1245
 
 
1246
 
 
1247
 
    if ((pfile_in_zip_read_info->read_buffer == NULL))
1248
 
        return UNZ_END_OF_LIST_OF_FILE;
1249
 
    if (len==0)
1250
 
        return 0;
1251
 
 
1252
 
    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1253
 
 
1254
 
    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1255
 
 
1256
 
    if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1257
 
        (!(pfile_in_zip_read_info->raw)))
1258
 
        pfile_in_zip_read_info->stream.avail_out =
1259
 
            (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1260
 
 
1261
 
    if ((len>pfile_in_zip_read_info->rest_read_compressed+
1262
 
           pfile_in_zip_read_info->stream.avail_in) &&
1263
 
         (pfile_in_zip_read_info->raw))
1264
 
        pfile_in_zip_read_info->stream.avail_out =
1265
 
            (uInt)pfile_in_zip_read_info->rest_read_compressed+
1266
 
            pfile_in_zip_read_info->stream.avail_in;
1267
 
 
1268
 
    while (pfile_in_zip_read_info->stream.avail_out>0)
1269
 
    {
1270
 
        if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1271
 
            (pfile_in_zip_read_info->rest_read_compressed>0))
1272
 
        {
1273
 
            uInt uReadThis = UNZ_BUFSIZE;
1274
 
            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1275
 
                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1276
 
            if (uReadThis == 0)
1277
 
                return UNZ_EOF;
1278
 
            if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1279
 
                      pfile_in_zip_read_info->filestream,
1280
 
                      pfile_in_zip_read_info->pos_in_zipfile +
1281
 
                         pfile_in_zip_read_info->byte_before_the_zipfile,
1282
 
                         ZLIB_FILEFUNC_SEEK_SET)!=0)
1283
 
                return UNZ_ERRNO;
1284
 
            if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1285
 
                      pfile_in_zip_read_info->filestream,
1286
 
                      pfile_in_zip_read_info->read_buffer,
1287
 
                      uReadThis)!=uReadThis)
1288
 
                return UNZ_ERRNO;
1289
 
 
1290
 
 
1291
 
#            ifndef NOUNCRYPT
1292
 
            if(s->encrypted)
 
1270
  if (! file)
 
1271
      return UNZ_PARAMERROR;
 
1272
 
 
1273
  int err = UNZ_OK;
 
1274
  uInt iRead = 0;
 
1275
 
 
1276
  file_in_zip_read_info_s *pfile_in_zip_read_info;
 
1277
 
 
1278
  unz_s *s = (unz_s*)file;
 
1279
  pfile_in_zip_read_info = s->pfile_in_zip_read;
 
1280
 
 
1281
  if (! pfile_in_zip_read_info)
 
1282
     return UNZ_PARAMERROR;
 
1283
 
 
1284
  if (! pfile_in_zip_read_info->read_buffer)
 
1285
     return UNZ_END_OF_LIST_OF_FILE;
 
1286
 
 
1287
  if (len == 0)
 
1288
      return 0;
 
1289
 
 
1290
  pfile_in_zip_read_info->stream.next_out = (Bytef*) buf;
 
1291
  pfile_in_zip_read_info->stream.avail_out = (uInt) len;
 
1292
 
 
1293
  if ((len > pfile_in_zip_read_info->rest_read_uncompressed) && ! pfile_in_zip_read_info->raw)
 
1294
      pfile_in_zip_read_info->stream.avail_out = (uInt) pfile_in_zip_read_info->rest_read_uncompressed;
 
1295
 
 
1296
  if ((len > pfile_in_zip_read_info->rest_read_compressed +
 
1297
       pfile_in_zip_read_info->stream.avail_in) && pfile_in_zip_read_info->raw)
 
1298
       pfile_in_zip_read_info->stream.avail_out = (uInt) pfile_in_zip_read_info->rest_read_compressed +
 
1299
                                                   pfile_in_zip_read_info->stream.avail_in;
 
1300
 
 
1301
  while (pfile_in_zip_read_info->stream.avail_out > 0)
 
1302
       {
 
1303
        if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
 
1304
            (pfile_in_zip_read_info->rest_read_compressed > 0))
1293
1305
            {
1294
 
                uInt i;
1295
 
                for(i=0;i<uReadThis;i++)
1296
 
                  pfile_in_zip_read_info->read_buffer[i] =
1297
 
                      zdecode(s->keys,s->pcrc_32_tab,
1298
 
                              pfile_in_zip_read_info->read_buffer[i]);
 
1306
             uInt uReadThis = UNZ_BUFSIZE;
 
1307
 
 
1308
             if (pfile_in_zip_read_info->rest_read_compressed < uReadThis)
 
1309
                 uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed;
 
1310
 
 
1311
             if (uReadThis == 0)
 
1312
                  return UNZ_EOF;
 
1313
 
 
1314
             if (ZSEEK (pfile_in_zip_read_info->z_filefunc,
 
1315
                        pfile_in_zip_read_info->filestream,
 
1316
                        pfile_in_zip_read_info->pos_in_zipfile +
 
1317
                        pfile_in_zip_read_info->byte_before_the_zipfile,
 
1318
                        ZLIB_FILEFUNC_SEEK_SET) != 0)
 
1319
                return UNZ_ERRNO;
 
1320
 
 
1321
            if (ZREAD (pfile_in_zip_read_info->z_filefunc,
 
1322
                       pfile_in_zip_read_info->filestream,
 
1323
                       pfile_in_zip_read_info->read_buffer,
 
1324
                       uReadThis) != uReadThis)
 
1325
                return UNZ_ERRNO;
 
1326
 
 
1327
 
 
1328
#ifndef NOUNCRYPT
 
1329
 
 
1330
             if (s->encrypted)
 
1331
                {
 
1332
                 uInt i;
 
1333
                 for (i = 0; i < uReadThis; i++)
 
1334
                      pfile_in_zip_read_info->read_buffer[i] = zdecode (s->keys,
 
1335
                                                                        s->pcrc_32_tab,
 
1336
                                                                        pfile_in_zip_read_info->read_buffer[i]);
 
1337
                  }
 
1338
#endif
 
1339
 
 
1340
 
 
1341
             pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
 
1342
             pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
 
1343
             pfile_in_zip_read_info->stream.next_in = (Bytef*) pfile_in_zip_read_info->read_buffer;
 
1344
             pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1299
1345
            }
1300
 
#            endif
1301
 
 
1302
 
 
1303
 
            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1304
 
 
1305
 
            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1306
 
 
1307
 
            pfile_in_zip_read_info->stream.next_in =
1308
 
                (Bytef*)pfile_in_zip_read_info->read_buffer;
1309
 
            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1310
 
        }
1311
 
 
1312
 
        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1313
 
        {
1314
 
            uInt uDoCopy,i ;
 
1346
 
 
1347
        if ((pfile_in_zip_read_info->compression_method == 0) || (pfile_in_zip_read_info->raw))
 
1348
           {
 
1349
            uInt uDoCopy, i;
1315
1350
 
1316
1351
            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1317
 
                (pfile_in_zip_read_info->rest_read_compressed == 0))
1318
 
                return (iRead==0) ? UNZ_EOF : iRead;
 
1352
                 (pfile_in_zip_read_info->rest_read_compressed == 0))
 
1353
                 return (iRead==0) ? UNZ_EOF : iRead;
1319
1354
 
1320
 
            if (pfile_in_zip_read_info->stream.avail_out <
1321
 
                            pfile_in_zip_read_info->stream.avail_in)
1322
 
                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
 
1355
            if (pfile_in_zip_read_info->stream.avail_out < pfile_in_zip_read_info->stream.avail_in)
 
1356
                 uDoCopy = pfile_in_zip_read_info->stream.avail_out;
1323
1357
            else
1324
 
                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1325
 
 
1326
 
            for (i=0;i<uDoCopy;i++)
1327
 
                *(pfile_in_zip_read_info->stream.next_out+i) =
1328
 
                        *(pfile_in_zip_read_info->stream.next_in+i);
1329
 
 
1330
 
            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1331
 
                                pfile_in_zip_read_info->stream.next_out,
1332
 
                                uDoCopy);
1333
 
            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1334
 
            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1335
 
            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1336
 
            pfile_in_zip_read_info->stream.next_out += uDoCopy;
1337
 
            pfile_in_zip_read_info->stream.next_in += uDoCopy;
1338
 
            pfile_in_zip_read_info->stream.total_out += uDoCopy;
1339
 
            iRead += uDoCopy;
1340
 
        }
 
1358
                uDoCopy = pfile_in_zip_read_info->stream.avail_in;
 
1359
 
 
1360
                for (i = 0; i < uDoCopy; i++)
 
1361
                    {
 
1362
                     *(pfile_in_zip_read_info->stream.next_out+i) = *(pfile_in_zip_read_info->stream.next_in + i);
 
1363
                    }
 
1364
 
 
1365
                pfile_in_zip_read_info->crc32 = crc32 (pfile_in_zip_read_info->crc32,
 
1366
                                                       pfile_in_zip_read_info->stream.next_out,
 
1367
                                                       uDoCopy);
 
1368
                pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
 
1369
                pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
 
1370
                pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
 
1371
                pfile_in_zip_read_info->stream.next_out += uDoCopy;
 
1372
                pfile_in_zip_read_info->stream.next_in += uDoCopy;
 
1373
                pfile_in_zip_read_info->stream.total_out += uDoCopy;
 
1374
                iRead += uDoCopy;
 
1375
             }
1341
1376
        else
1342
 
        {
1343
 
            uLong uTotalOutBefore,uTotalOutAfter;
1344
 
            const Bytef *bufBefore;
1345
 
            uLong uOutThis;
1346
 
            int flush=Z_SYNC_FLUSH;
1347
 
 
1348
 
            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1349
 
            bufBefore = pfile_in_zip_read_info->stream.next_out;
1350
 
 
1351
 
            /*
1352
 
            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1353
 
                     pfile_in_zip_read_info->stream.avail_out) &&
1354
 
                (pfile_in_zip_read_info->rest_read_compressed == 0))
1355
 
                flush = Z_FINISH;
1356
 
            */
1357
 
            err=inflate(&pfile_in_zip_read_info->stream,flush);
1358
 
 
1359
 
            if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
1360
 
              err = Z_DATA_ERROR;
1361
 
 
1362
 
            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1363
 
            uOutThis = uTotalOutAfter-uTotalOutBefore;
1364
 
 
1365
 
            pfile_in_zip_read_info->crc32 =
1366
 
                crc32(pfile_in_zip_read_info->crc32,bufBefore,
1367
 
                        (uInt)(uOutThis));
1368
 
 
1369
 
            pfile_in_zip_read_info->rest_read_uncompressed -=
1370
 
                uOutThis;
1371
 
 
1372
 
            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1373
 
 
1374
 
            if (err==Z_STREAM_END)
 
1377
            {
 
1378
             uLong uTotalOutBefore, uTotalOutAfter;
 
1379
             const Bytef *bufBefore;
 
1380
             uLong uOutThis;
 
1381
             int flush = Z_SYNC_FLUSH;
 
1382
 
 
1383
             uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
 
1384
             bufBefore = pfile_in_zip_read_info->stream.next_out;
 
1385
 
 
1386
                  /*
 
1387
                  if ((pfile_in_zip_read_info->rest_read_uncompressed ==
 
1388
                           pfile_in_zip_read_info->stream.avail_out) &&
 
1389
                      (pfile_in_zip_read_info->rest_read_compressed == 0))
 
1390
                      flush = Z_FINISH;
 
1391
                  */
 
1392
             err = inflate (&pfile_in_zip_read_info->stream,flush);
 
1393
 
 
1394
             if ((err >= 0) && pfile_in_zip_read_info->stream.msg)
 
1395
                 err = Z_DATA_ERROR;
 
1396
 
 
1397
             uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
 
1398
             uOutThis = uTotalOutAfter - uTotalOutBefore;
 
1399
 
 
1400
             pfile_in_zip_read_info->crc32 = crc32 (pfile_in_zip_read_info->crc32, bufBefore,
 
1401
                                                   (uInt)(uOutThis));
 
1402
 
 
1403
             pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
 
1404
 
 
1405
             iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
 
1406
 
 
1407
             if (err == Z_STREAM_END)
1375
1408
                return (iRead==0) ? UNZ_EOF : iRead;
1376
 
            if (err!=Z_OK)
1377
 
                break;
1378
 
        }
1379
 
    }
1380
 
 
1381
 
    if (err==Z_OK)
1382
 
        return iRead;
 
1409
 
 
1410
             if (err != Z_OK)
 
1411
                 break;
 
1412
            }
 
1413
         }
 
1414
 
 
1415
   if (err == Z_OK)
 
1416
       return iRead;
 
1417
 
1383
1418
    return err;
1384
1419
}
1385
1420
 
1386
1421
 
1387
 
/*
1388
 
  Give the current position in uncompressed data
1389
 
*/
1390
 
extern z_off_t ZEXPORT unztell (file)
1391
 
    unzFile file;
 
1422
//  Give the current position in uncompressed data
 
1423
 
 
1424
extern z_off_t ZEXPORT unztell (unzFile file)
1392
1425
{
1393
 
    unz_s* s;
1394
 
    file_in_zip_read_info_s* pfile_in_zip_read_info;
1395
 
    if (file==NULL)
1396
 
        return UNZ_PARAMERROR;
1397
 
    s=(unz_s*)file;
1398
 
    pfile_in_zip_read_info=s->pfile_in_zip_read;
1399
 
 
1400
 
    if (pfile_in_zip_read_info==NULL)
1401
 
        return UNZ_PARAMERROR;
1402
 
 
1403
 
    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
 
1426
  if (! file)
 
1427
      return UNZ_PARAMERROR;
 
1428
 
 
1429
  file_in_zip_read_info_s *pfile_in_zip_read_info;
 
1430
 
 
1431
  unz_s *s = (unz_s*)file;
 
1432
  pfile_in_zip_read_info = s->pfile_in_zip_read;
 
1433
 
 
1434
  if (! pfile_in_zip_read_info)
 
1435
     return UNZ_PARAMERROR;
 
1436
 
 
1437
  return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1404
1438
}
1405
1439
 
1406
1440
 
1407
 
/*
1408
 
  return 1 if the end of file was reached, 0 elsewhere
1409
 
*/
1410
 
extern int ZEXPORT unzeof (file)
1411
 
    unzFile file;
 
1441
//return 1 if the end of file was reached, 0 elsewhere
 
1442
 
 
1443
extern int ZEXPORT unzeof (unzFile file)
1412
1444
{
1413
 
    unz_s* s;
1414
 
    file_in_zip_read_info_s* pfile_in_zip_read_info;
1415
 
    if (file==NULL)
1416
 
        return UNZ_PARAMERROR;
1417
 
    s=(unz_s*)file;
1418
 
    pfile_in_zip_read_info=s->pfile_in_zip_read;
1419
 
 
1420
 
    if (pfile_in_zip_read_info==NULL)
1421
 
        return UNZ_PARAMERROR;
1422
 
 
1423
 
    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1424
 
        return 1;
1425
 
    else
1426
 
        return 0;
 
1445
  if (! file)
 
1446
     return UNZ_PARAMERROR;
 
1447
 
 
1448
  file_in_zip_read_info_s* pfile_in_zip_read_info;
 
1449
  unz_s *s = (unz_s*)file;
 
1450
  pfile_in_zip_read_info = s->pfile_in_zip_read;
 
1451
 
 
1452
  if (! pfile_in_zip_read_info)
 
1453
     return UNZ_PARAMERROR;
 
1454
 
 
1455
  if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
 
1456
     return 1;
 
1457
  else
 
1458
      return 0;
1427
1459
}
1428
1460
 
1429
1461
 
1440
1472
  the return value is the number of bytes copied in buf, or (if <0)
1441
1473
    the error code
1442
1474
*/
1443
 
extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1444
 
    unzFile file;
1445
 
    voidp buf;
1446
 
    unsigned len;
 
1475
extern int ZEXPORT unzGetLocalExtrafield (unzFile file,
 
1476
                                          voidp buf,
 
1477
                                          unsigned len)
1447
1478
{
1448
 
    unz_s* s;
1449
 
    file_in_zip_read_info_s* pfile_in_zip_read_info;
1450
 
    uInt read_now;
1451
 
    uLong size_to_read;
1452
 
 
1453
 
    if (file==NULL)
1454
 
        return UNZ_PARAMERROR;
1455
 
    s=(unz_s*)file;
1456
 
    pfile_in_zip_read_info=s->pfile_in_zip_read;
1457
 
 
1458
 
    if (pfile_in_zip_read_info==NULL)
1459
 
        return UNZ_PARAMERROR;
1460
 
 
1461
 
    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1462
 
                pfile_in_zip_read_info->pos_local_extrafield);
1463
 
 
1464
 
    if (buf==NULL)
1465
 
        return (int)size_to_read;
1466
 
 
1467
 
    if (len>size_to_read)
1468
 
        read_now = (uInt)size_to_read;
1469
 
    else
1470
 
        read_now = (uInt)len ;
1471
 
 
1472
 
    if (read_now==0)
1473
 
        return 0;
1474
 
 
1475
 
    if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1476
 
              pfile_in_zip_read_info->filestream,
1477
 
              pfile_in_zip_read_info->offset_local_extrafield +
1478
 
              pfile_in_zip_read_info->pos_local_extrafield,
1479
 
              ZLIB_FILEFUNC_SEEK_SET)!=0)
1480
 
        return UNZ_ERRNO;
1481
 
 
1482
 
    if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1483
 
              pfile_in_zip_read_info->filestream,
1484
 
              buf,read_now)!=read_now)
1485
 
        return UNZ_ERRNO;
1486
 
 
1487
 
    return (int)read_now;
 
1479
  if (! file)
 
1480
     return UNZ_PARAMERROR;
 
1481
 
 
1482
  file_in_zip_read_info_s* pfile_in_zip_read_info;
 
1483
  uInt read_now;
 
1484
  uLong size_to_read;
 
1485
 
 
1486
  unz_s* s = (unz_s*)file;
 
1487
  pfile_in_zip_read_info = s->pfile_in_zip_read;
 
1488
 
 
1489
  if (! pfile_in_zip_read_info)
 
1490
     return UNZ_PARAMERROR;
 
1491
 
 
1492
  size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
 
1493
                  pfile_in_zip_read_info->pos_local_extrafield);
 
1494
 
 
1495
  if (! buf)
 
1496
     return (int) size_to_read;
 
1497
 
 
1498
  if (len > size_to_read)
 
1499
     read_now = (uInt) size_to_read;
 
1500
  else
 
1501
      read_now = (uInt) len ;
 
1502
 
 
1503
  if (read_now == 0)
 
1504
     return 0;
 
1505
 
 
1506
  if (ZSEEK (pfile_in_zip_read_info->z_filefunc,
 
1507
             pfile_in_zip_read_info->filestream,
 
1508
             pfile_in_zip_read_info->offset_local_extrafield +
 
1509
             pfile_in_zip_read_info->pos_local_extrafield,
 
1510
             ZLIB_FILEFUNC_SEEK_SET) != 0)
 
1511
     return UNZ_ERRNO;
 
1512
 
 
1513
  if (ZREAD (pfile_in_zip_read_info->z_filefunc,
 
1514
             pfile_in_zip_read_info->filestream,
 
1515
             buf,
 
1516
             read_now) != read_now)
 
1517
      return UNZ_ERRNO;
 
1518
 
 
1519
  return (int)read_now;
1488
1520
}
1489
1521
 
1490
1522
/*
1491
1523
  Close the file in zip opened with unzipOpenCurrentFile
1492
1524
  Return UNZ_CRCERROR if all the file was read but the CRC is not good
1493
1525
*/
1494
 
extern int ZEXPORT unzCloseCurrentFile (file)
1495
 
    unzFile file;
 
1526
extern int ZEXPORT unzCloseCurrentFile (unzFile file)
1496
1527
{
1497
 
    int err=UNZ_OK;
1498
 
 
1499
 
    unz_s* s;
1500
 
    file_in_zip_read_info_s* pfile_in_zip_read_info;
1501
 
    if (file==NULL)
1502
 
        return UNZ_PARAMERROR;
1503
 
    s=(unz_s*)file;
1504
 
    pfile_in_zip_read_info=s->pfile_in_zip_read;
1505
 
 
1506
 
    if (pfile_in_zip_read_info==NULL)
1507
 
        return UNZ_PARAMERROR;
1508
 
 
1509
 
 
1510
 
    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
1511
 
        (!pfile_in_zip_read_info->raw))
1512
 
    {
1513
 
        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1514
 
            err=UNZ_CRCERROR;
1515
 
    }
1516
 
 
1517
 
 
1518
 
    TRYFREE(pfile_in_zip_read_info->read_buffer);
1519
 
    pfile_in_zip_read_info->read_buffer = NULL;
1520
 
    if (pfile_in_zip_read_info->stream_initialised)
1521
 
        inflateEnd(&pfile_in_zip_read_info->stream);
1522
 
 
1523
 
    pfile_in_zip_read_info->stream_initialised = 0;
1524
 
    TRYFREE(pfile_in_zip_read_info);
1525
 
 
1526
 
    s->pfile_in_zip_read=NULL;
1527
 
 
1528
 
    return err;
 
1528
  if (! file)
 
1529
     return UNZ_PARAMERROR;
 
1530
 
 
1531
  int err = UNZ_OK;
 
1532
 
 
1533
  file_in_zip_read_info_s *pfile_in_zip_read_info;
 
1534
  unz_s *s = (unz_s*) file;
 
1535
  pfile_in_zip_read_info = s->pfile_in_zip_read;
 
1536
 
 
1537
  if (! pfile_in_zip_read_info)
 
1538
     return UNZ_PARAMERROR;
 
1539
 
 
1540
 
 
1541
  if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && ! pfile_in_zip_read_info->raw)
 
1542
      if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
 
1543
         err = UNZ_CRCERROR;
 
1544
 
 
1545
 
 
1546
  TRYFREE (pfile_in_zip_read_info->read_buffer);
 
1547
  pfile_in_zip_read_info->read_buffer = NULL;
 
1548
 
 
1549
  if (pfile_in_zip_read_info->stream_initialised)
 
1550
      inflateEnd (&pfile_in_zip_read_info->stream);
 
1551
 
 
1552
  pfile_in_zip_read_info->stream_initialised = 0;
 
1553
  TRYFREE (pfile_in_zip_read_info);
 
1554
 
 
1555
  s->pfile_in_zip_read = NULL;
 
1556
 
 
1557
  return err;
1529
1558
}
1530
1559
 
1531
1560
 
1534
1563
  uSizeBuf is the size of the szComment buffer.
1535
1564
  return the number of byte copied or an error code <0
1536
1565
*/
1537
 
extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1538
 
    unzFile file;
1539
 
    char *szComment;
1540
 
    uLong uSizeBuf;
 
1566
extern int ZEXPORT unzGetGlobalComment (unzFile file,
 
1567
                                        char *szComment,
 
1568
                                        uLong uSizeBuf)
1541
1569
{
1542
 
    unz_s* s;
1543
 
    uLong uReadThis ;
1544
 
    if (file==NULL)
1545
 
        return UNZ_PARAMERROR;
1546
 
    s=(unz_s*)file;
1547
 
 
1548
 
    uReadThis = uSizeBuf;
1549
 
    if (uReadThis>s->gi.size_comment)
1550
 
        uReadThis = s->gi.size_comment;
1551
 
 
1552
 
    if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1553
 
        return UNZ_ERRNO;
1554
 
 
1555
 
    if (uReadThis>0)
1556
 
    {
1557
 
      *szComment='\0';
1558
 
      if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1559
 
        return UNZ_ERRNO;
1560
 
    }
1561
 
 
1562
 
    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
1563
 
        *(szComment+s->gi.size_comment)='\0';
1564
 
    return (int)uReadThis;
 
1570
  if (! file)
 
1571
     return UNZ_PARAMERROR;
 
1572
 
 
1573
  uLong uReadThis;
 
1574
  unz_s *s = (unz_s*)file;
 
1575
 
 
1576
  uReadThis = uSizeBuf;
 
1577
  if (uReadThis>s->gi.size_comment)
 
1578
     uReadThis = s->gi.size_comment;
 
1579
 
 
1580
  if (ZSEEK (s->z_filefunc, s->filestream, s->central_pos + 22, ZLIB_FILEFUNC_SEEK_SET) !=0 )
 
1581
     return UNZ_ERRNO;
 
1582
 
 
1583
  if (uReadThis > 0)
 
1584
     {
 
1585
      *szComment = '\0';
 
1586
      if (ZREAD (s->z_filefunc, s->filestream, szComment, uReadThis) != uReadThis)
 
1587
         return UNZ_ERRNO;
 
1588
     }
 
1589
 
 
1590
  if (szComment && (uSizeBuf > s->gi.size_comment))
 
1591
     *(szComment + s->gi.size_comment) = '\0';
 
1592
 
 
1593
  return (int)uReadThis;
1565
1594
}
1566
1595
 
1567
 
/* Additions by RX '2004 */
1568
 
extern uLong ZEXPORT unzGetOffset (file)
1569
 
    unzFile file;
 
1596
 
 
1597
// Additions by RX '2004
 
1598
extern uLong ZEXPORT unzGetOffset (unzFile file)
1570
1599
{
1571
1600
    unz_s* s;
1572
1601
 
1581
1610
    return s->pos_in_central_dir;
1582
1611
}
1583
1612
 
1584
 
extern int ZEXPORT unzSetOffset (file, pos)
1585
 
        unzFile file;
1586
 
        uLong pos;
 
1613
 
 
1614
extern int ZEXPORT unzSetOffset (unzFile file,
 
1615
                                 uLong pos)
1587
1616
{
1588
 
    unz_s* s;
1589
 
    int err;
1590
 
 
1591
 
    if (file==NULL)
1592
 
        return UNZ_PARAMERROR;
1593
 
    s=(unz_s*)file;
1594
 
 
1595
 
    s->pos_in_central_dir = pos;
1596
 
    s->num_file = s->gi.number_entry;      /* hack */
1597
 
    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1598
 
                                              &s->cur_file_info_internal,
1599
 
                                              NULL,0,NULL,0,NULL,0);
1600
 
    s->current_file_ok = (err == UNZ_OK);
1601
 
    return err;
 
1617
  if (! file)
 
1618
     return UNZ_PARAMERROR;
 
1619
 
 
1620
  int err;
 
1621
  unz_s *s = (unz_s*)file;
 
1622
 
 
1623
  s->pos_in_central_dir = pos;
 
1624
  s->num_file = s->gi.number_entry; //hack
 
1625
  err = unzlocal_GetCurrentFileInfoInternal (file, &s->cur_file_info,
 
1626
                                             &s->cur_file_info_internal,
 
1627
                                             NULL, 0, NULL, 0, NULL, 0);
 
1628
  s->current_file_ok = (err == UNZ_OK);
 
1629
  return err;
1602
1630
}