~ubuntu-branches/ubuntu/trusty/unzip/trusty

« back to all changes in this revision

Viewing changes to unzpriv.h.orig

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-06-25 15:57:03 UTC
  • Revision ID: james.westby@ubuntu.com-20080625155703-rea6vbrcb62yry5m
Tags: 5.52-11ubuntu1
* Merge with Debian; remaining changes:
  - debian/rules: Configure with large file support.
  - unzip.c: Change banner to indicate Ubuntu modification.
  - support UTF-8 file names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Copyright (c) 1990-2005 Info-ZIP.  All rights reserved.
3
 
 
4
 
  See the accompanying file LICENSE, version 2000-Apr-09 or later
5
 
  (the contents of which are also included in unzip.h) for terms of use.
6
 
  If, for some reason, all these files are missing, the Info-ZIP license
7
 
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
8
 
*/
9
 
/*---------------------------------------------------------------------------
10
 
 
11
 
  unzpriv.h
12
 
 
13
 
  This header file contains private (internal) macros, typedefs, prototypes
14
 
  and global-variable declarations used by all of the UnZip source files.
15
 
  In a prior life it was part of the main unzip.h header, but now it is only
16
 
  included by that header if UNZIP_INTERNAL is defined.
17
 
 
18
 
  ---------------------------------------------------------------------------*/
19
 
 
20
 
 
21
 
 
22
 
#ifndef __unzpriv_h   /* prevent multiple inclusions */
23
 
#define __unzpriv_h
24
 
 
25
 
/* First thing: Signal all following code that we compile UnZip utilities! */
26
 
#ifndef UNZIP
27
 
#  define UNZIP
28
 
#endif
29
 
 
30
 
/* GRR 960204:  MORE defined here in preparation for removal altogether */
31
 
#ifndef MORE
32
 
# ifndef RISCOS
33
 
#  define MORE
34
 
# endif
35
 
#endif
36
 
 
37
 
/* fUnZip should never need to be reentrant */
38
 
#ifdef FUNZIP
39
 
#  ifdef REENTRANT
40
 
#    undef REENTRANT
41
 
#  endif
42
 
#  ifdef DLL
43
 
#    undef DLL
44
 
#  endif
45
 
#  ifdef SFX    /* fUnZip is NOT the sfx stub! */
46
 
#    undef SFX
47
 
#  endif
48
 
#endif
49
 
 
50
 
#if (defined(USE_ZLIB) && !defined(NO_DEFLATE64))
51
 
   /* zlib does not (yet?) provide Deflate64(tm) support */
52
 
#  define NO_DEFLATE64
53
 
#endif
54
 
 
55
 
#ifdef NO_DEFLATE64
56
 
   /* disable support for Deflate64(tm) */
57
 
#  ifdef USE_DEFLATE64
58
 
#    undef USE_DEFLATE64
59
 
#  endif
60
 
#else
61
 
   /* enable Deflate64(tm) support unless compiling for SFX stub */
62
 
#  if (!defined(USE_DEFLATE64) && !defined(SFX))
63
 
#    define USE_DEFLATE64
64
 
#  endif
65
 
#endif
66
 
 
67
 
#if (defined(NO_VMS_TEXT_CONV) || defined(VMS))
68
 
#  ifdef VMS_TEXT_CONV
69
 
#    undef VMS_TEXT_CONV
70
 
#  endif
71
 
#else
72
 
#  if (!defined(VMS_TEXT_CONV) && !defined(SFX))
73
 
#    define VMS_TEXT_CONV
74
 
#  endif
75
 
#endif
76
 
 
77
 
#if (defined(DLL) && !defined(REENTRANT))
78
 
#  define REENTRANT
79
 
#endif
80
 
 
81
 
#if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
82
 
#  define DYNAMIC_CRC_TABLE
83
 
#endif
84
 
 
85
 
#if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
86
 
#  ifndef DYNALLOC_CRCTAB
87
 
#    define DYNALLOC_CRCTAB
88
 
#  endif
89
 
#endif
90
 
 
91
 
/*---------------------------------------------------------------------------
92
 
    OS-dependent configuration for UnZip internals
93
 
  ---------------------------------------------------------------------------*/
94
 
 
95
 
/* Some compiler distributions for Win32/i386 systems try to emulate
96
 
 * a Unix (POSIX-compatible) environment.
97
 
 */
98
 
#if (defined(WIN32) && defined(UNIX))
99
 
   /* UnZip does not support merging both ports in a single executable. */
100
 
#  if (defined(FORCE_WIN32_OVER_UNIX) && defined(FORCE_UNIX_OVER_WIN32))
101
 
     /* conflicting choice requests -> we prefer the Win32 environment */
102
 
#    undef FORCE_UNIX_OVER_WIN32
103
 
#  endif
104
 
#  ifdef FORCE_WIN32_OVER_UNIX
105
 
     /* native Win32 support was explicitely requested... */
106
 
#    undef UNIX
107
 
#  else
108
 
     /* use the POSIX (Unix) emulation features by default... */
109
 
#    undef WIN32
110
 
#  endif
111
 
#endif
112
 
 
113
 
/* bad or (occasionally?) missing stddef.h: */
114
 
#if (defined(M_XENIX) || defined(DNIX))
115
 
#  define NO_STDDEF_H
116
 
#endif
117
 
 
118
 
#if (defined(M_XENIX) && !defined(M_UNIX))   /* SCO Xenix only, not SCO Unix */
119
 
#  define SCO_XENIX
120
 
#  define NO_LIMITS_H        /* no limits.h, but MODERN defined */
121
 
#  define NO_UID_GID         /* no uid_t/gid_t */
122
 
#  define size_t int
123
 
#endif
124
 
 
125
 
#ifdef realix   /* Modcomp Real/IX, real-time SysV.3 variant */
126
 
#  define SYSV
127
 
#  define NO_UID_GID         /* no uid_t/gid_t */
128
 
#endif
129
 
 
130
 
#if (defined(_AIX) && !defined(_ALL_SOURCE))
131
 
#  define _ALL_SOURCE
132
 
#endif
133
 
 
134
 
#if defined(apollo)          /* defines __STDC__ */
135
 
#    define NO_STDLIB_H
136
 
#endif
137
 
 
138
 
#ifdef DNIX
139
 
#  define SYSV
140
 
#  define SHORT_NAMES         /* 14-char limitation on path components */
141
 
/* #  define FILENAME_MAX  14 */
142
 
#  define FILENAME_MAX  NAME_MAX    /* GRR:  experiment */
143
 
#endif
144
 
 
145
 
#if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
146
 
#  ifndef SYSV
147
 
#    define SYSV
148
 
#  endif
149
 
#endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
150
 
#if (defined(M_SYSV) || defined(M_SYS5))
151
 
#  ifndef SYSV
152
 
#    define SYSV
153
 
#  endif
154
 
#endif /* M_SYSV || M_SYS5 */
155
 
/* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
156
 
#if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
157
 
#  ifndef SYSV
158
 
#    define SYSV
159
 
#  endif
160
 
#endif /* __SVR4 || __svr4__ || sgi || __hpux */
161
 
#if (defined(LINUX) || defined(__QNX__))
162
 
#  ifndef SYSV
163
 
#    define SYSV
164
 
#  endif
165
 
#endif /* LINUX || __QNX__ */
166
 
 
167
 
#if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
168
 
#  if (!defined(BSD) && !defined(SYSV))
169
 
#    define BSD
170
 
#  endif
171
 
#endif /* ultrix || __ultrix || bsd4_2 */
172
 
#if (defined(sun) || defined(pyr) || defined(CONVEX))
173
 
#  if (!defined(BSD) && !defined(SYSV))
174
 
#    define BSD
175
 
#  endif
176
 
#endif /* sun || pyr || CONVEX */
177
 
 
178
 
#ifdef pyr  /* Pyramid:  has BSD and AT&T "universes" */
179
 
#  ifdef BSD
180
 
#    define pyr_bsd
181
 
#    define USE_STRINGS_H  /* instead of more common string.h */
182
 
#    define ZMEM           /* ZMEM now uses bcopy/bzero: not in AT&T universe */
183
 
#  endif                   /* (AT&T memcpy claimed to be very slow, though) */
184
 
#  define DECLARE_ERRNO
185
 
#endif /* pyr */
186
 
 
187
 
/* stat() bug for Borland, VAX C RTL, and Atari ST MiNT on TOS
188
 
 * filesystems:  returns 0 for wildcards!  (returns 0xffffffff on Minix
189
 
 * filesystem or `U:' drive under Atari MiNT.)  Watcom C was previously
190
 
 * included on this list; it would be good to know what version the problem
191
 
 * was fixed at, if it did exist.  */
192
 
#if (defined(__TURBOC__) && !defined(WIN32))
193
 
/*#  define WILD_STAT_BUG*/
194
 
#endif
195
 
#if (defined(VMS) || defined(__MINT__))
196
 
#  define WILD_STAT_BUG
197
 
#endif
198
 
 
199
 
/*---------------------------------------------------------------------------
200
 
    OS-dependent includes
201
 
  ---------------------------------------------------------------------------*/
202
 
 
203
 
#ifdef EFT
204
 
#  define Z_OFF_T off_t  /* Amdahl UTS nonsense ("extended file types") */
205
 
#else
206
 
#if (defined(UNIX) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
207
 
#  define Z_OFF_T off_t /* 64bit offsets to support 2GB < zipfile size < 4GB */
208
 
#else
209
 
#  define Z_OFF_T long
210
 
#endif
211
 
#endif
212
 
 
213
 
#ifdef MODERN
214
 
#  ifndef NO_STDDEF_H
215
 
#    include <stddef.h>
216
 
#  endif
217
 
#  ifndef NO_STDLIB_H
218
 
#    include <stdlib.h>  /* standard library prototypes, malloc(), etc. */
219
 
#  endif
220
 
   typedef size_t extent;
221
 
#else /* !MODERN */
222
 
#  ifndef AOS_VS         /* mostly modern? */
223
 
     Z_OFF_T lseek();
224
 
#    ifdef VAXC          /* not fully modern, but has stdlib.h and void */
225
 
#      include <stdlib.h>
226
 
#    else
227
 
       char *malloc();
228
 
#    endif /* ?VAXC */
229
 
#  endif /* !AOS_VS */
230
 
   typedef unsigned int extent;
231
 
#endif /* ?MODERN */
232
 
 
233
 
 
234
 
#ifndef MINIX            /* Minix needs it after all the other includes (?) */
235
 
#  include <stdio.h>
236
 
#endif
237
 
#include <ctype.h>       /* skip for VMS, to use tolower() function? */
238
 
#include <errno.h>       /* used in mapname() */
239
 
#ifdef USE_STRINGS_H
240
 
#  include <strings.h>   /* strcpy, strcmp, memcpy, index/rindex, etc. */
241
 
#else
242
 
#  include <string.h>    /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
243
 
#endif
244
 
#if (defined(MODERN) && !defined(NO_LIMITS_H))
245
 
#  include <limits.h>    /* GRR:  EXPERIMENTAL!  (can be deleted) */
246
 
#endif
247
 
 
248
 
/* this include must be down here for SysV.4, for some reason... */
249
 
#include <signal.h>      /* used in unzip.c, fileio.c */
250
 
 
251
 
 
252
 
/*---------------------------------------------------------------------------
253
 
    API (DLL) section:
254
 
  ---------------------------------------------------------------------------*/
255
 
 
256
 
#ifdef DLL
257
 
#  define MAIN   UZ_EXP UzpMain   /* was UzpUnzip */
258
 
#  ifdef OS2DLL
259
 
#    undef Info
260
 
#    define REDIRECTC(c)             varputchar(__G__ c)
261
 
#    define REDIRECTPRINT(buf,size)  varmessage(__G__ buf, size)
262
 
#    define FINISH_REDIRECT()        finish_REXX_redirect(__G)
263
 
#  else
264
 
#    define REDIRECTC(c)
265
 
#    define REDIRECTPRINT(buf,size)  0
266
 
#    define FINISH_REDIRECT()        close_redirect(__G)
267
 
#  endif
268
 
#endif
269
 
 
270
 
/*---------------------------------------------------------------------------
271
 
    Acorn RISCOS section:
272
 
  ---------------------------------------------------------------------------*/
273
 
 
274
 
#ifdef RISCOS
275
 
#  include "acorn/riscos.h"
276
 
#endif
277
 
 
278
 
/*---------------------------------------------------------------------------
279
 
    Amiga section:
280
 
  ---------------------------------------------------------------------------*/
281
 
 
282
 
#ifdef AMIGA
283
 
#  include "amiga/amiga.h"
284
 
#endif
285
 
 
286
 
/*---------------------------------------------------------------------------
287
 
    AOS/VS section (somewhat similar to Unix, apparently):
288
 
  ---------------------------------------------------------------------------*/
289
 
 
290
 
#ifdef AOS_VS
291
 
#  ifdef __FILEIO_C
292
 
#    include "aosvs/aosvs.h"
293
 
#  endif
294
 
#endif
295
 
 
296
 
/*---------------------------------------------------------------------------
297
 
    Atari ST section:
298
 
  ---------------------------------------------------------------------------*/
299
 
 
300
 
#ifdef ATARI
301
 
#  include <time.h>
302
 
#  include <stat.h>
303
 
#  include <fcntl.h>
304
 
#  include <limits.h>
305
 
#  define SYMLINKS
306
 
#  define EXE_EXTENSION  ".tos"
307
 
#  ifndef DATE_FORMAT
308
 
#    define DATE_FORMAT  DF_DMY
309
 
#  endif
310
 
#  define DIR_END        '/'
311
 
#  define INT_SPRINTF
312
 
#  define timezone      _timezone
313
 
#  define lenEOL        2
314
 
#  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
315
 
#  undef SHORT_NAMES
316
 
#  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
317
 
#    define TIMESTAMP
318
 
#  endif
319
 
#endif
320
 
 
321
 
/*---------------------------------------------------------------------------
322
 
    AtheOS section:
323
 
  ---------------------------------------------------------------------------*/
324
 
 
325
 
#ifdef __ATHEOS__
326
 
#  include "atheos/athcfg.h"
327
 
#endif
328
 
 
329
 
/*---------------------------------------------------------------------------
330
 
    BeOS section:
331
 
  ---------------------------------------------------------------------------*/
332
 
 
333
 
#ifdef __BEOS__
334
 
#  include "beos/beocfg.h"
335
 
#endif
336
 
 
337
 
/*---------------------------------------------------------------------------
338
 
    Human68k/X680x0 section:
339
 
  ---------------------------------------------------------------------------*/
340
 
 
341
 
#ifdef __human68k__
342
 
   /* DO NOT DEFINE DOS_OS2 HERE!  If Human68k is so much */
343
 
   /*  like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
344
 
#  ifndef _MBCS
345
 
#    define _MBCS
346
 
#  endif
347
 
#  include <time.h>
348
 
#  include <fcntl.h>
349
 
#  include <io.h>
350
 
#  include <conio.h>
351
 
#  include <sys/stat.h>
352
 
#  ifdef HAVE_MBSTRING_H
353
 
#    include <mbstring.h>
354
 
#  endif
355
 
#  ifdef HAVE_MBCTYPE_H
356
 
#    include <mbctype.h>
357
 
#  else
358
 
#    ifndef _ismbblead
359
 
#      define _ismbblead(c) (0x80 <= (c) && ((c) < 0xa0 || 0xe0 <= (c)))
360
 
#    endif
361
 
#  endif
362
 
#  ifndef DATE_FORMAT
363
 
#    define DATE_FORMAT DF_YMD   /* Japanese standard */
364
 
#  endif
365
 
#  define lenEOL        1
366
 
#  define PutNativeEOL  *q++ = native(LF);
367
 
#  define INT_SPRINTF
368
 
#  define SYMLINKS
369
 
#  ifdef SFX
370
 
#    define MAIN main_sfx
371
 
#  endif
372
 
#endif
373
 
 
374
 
/*---------------------------------------------------------------------------
375
 
    Mac section:
376
 
  ---------------------------------------------------------------------------*/
377
 
 
378
 
#ifdef MACOS
379
 
#  include "maccfg.h"
380
 
#endif /* MACOS */
381
 
 
382
 
/*---------------------------------------------------------------------------
383
 
    MS-DOS, OS/2, FLEXOS section:
384
 
  ---------------------------------------------------------------------------*/
385
 
 
386
 
#ifdef WINDLL
387
 
#  ifdef MORE
388
 
#    undef MORE
389
 
#  endif
390
 
#  ifdef OS2_EAS
391
 
#    undef OS2_EAS
392
 
#  endif
393
 
#endif
394
 
 
395
 
#if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
396
 
#  ifndef MSC
397
 
#    define MSC               /* This should work for older MSC, too!  */
398
 
#  endif
399
 
#endif
400
 
 
401
 
#if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
402
 
#  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
403
 
#  include <sys/stat.h>
404
 
#  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
405
 
#  include <time.h>           /* localtime() */
406
 
#  include <fcntl.h>          /* O_BINARY for open() w/o CR/LF translation */
407
 
 
408
 
#  ifdef OS2                  /* defined for all OS/2 compilers */
409
 
#    include "os2/os2cfg.h"
410
 
#  else
411
 
#    ifdef FLEXOS
412
 
#      include "flexos/flxcfg.h"
413
 
#    else
414
 
#      include "msdos/doscfg.h"
415
 
#    endif
416
 
#  endif
417
 
 
418
 
#  if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
419
 
    /*
420
 
     * ARGH.  MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
421
 
     *  1970 Jan 1 00:00.  So we have to diddle time_t's appropriately:  add or
422
 
     *  subtract 70 years' worth of seconds; i.e., number of days times 86400;
423
 
     *  i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
424
 
     *  (25550 + 17 + 1) * 86400 == 2209075200 seconds.  We know time_t is an
425
 
     *  unsigned long (ulg) on the only system with this bug.
426
 
     */
427
 
#    define TIMET_TO_NATIVE(x)  (x) += (ulg)2209075200L;
428
 
#    define NATIVE_TO_TIMET(x)  (x) -= (ulg)2209075200L;
429
 
#  endif
430
 
#  if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
431
 
#    define timezone      _timezone
432
 
#  endif
433
 
#  if (defined(__GO32__) || defined(FLEXOS))
434
 
#    define DIR_END       '/'
435
 
#  else
436
 
#    define DIR_END       '\\'  /* OS uses '\\' as directory separator */
437
 
#    define DIR_END2      '/'   /* also check for '/' (RTL may convert) */
438
 
#  endif
439
 
#  ifdef DATE_FORMAT
440
 
#    undef DATE_FORMAT
441
 
#  endif
442
 
#  define DATE_FORMAT     dateformat()
443
 
#  define lenEOL          2
444
 
#  define PutNativeEOL    {*q++ = native(CR); *q++ = native(LF);}
445
 
#  if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
446
 
#    define USE_EF_UT_TIME
447
 
#  endif
448
 
#endif /* MSDOS || OS2 || FLEXOS */
449
 
 
450
 
/*---------------------------------------------------------------------------
451
 
    MTS section (piggybacks UNIX, I think):
452
 
  ---------------------------------------------------------------------------*/
453
 
 
454
 
#ifdef MTS
455
 
#  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
456
 
#  include <sys/stat.h>
457
 
#  include <sys/file.h>       /* MTS uses this instead of fcntl.h */
458
 
#  include <timeb.h>
459
 
#  include <time.h>
460
 
#  include <unix.h>           /* some important non-ANSI routines */
461
 
#  define mkdir(s,n) (-1)     /* no "make directory" capability */
462
 
#  define EBCDIC              /* set EBCDIC conversion on */
463
 
#  define NO_STRNICMP         /* unzip's is as good the one in MTS */
464
 
#  define USE_FWRITE
465
 
#  define close_outfile()  fclose(G.outfile)   /* can't set time on files */
466
 
#  define umask(n)            /* don't have umask() on MTS */
467
 
#  define FOPWT         "w"   /* open file for writing in TEXT mode */
468
 
#  ifndef DATE_FORMAT
469
 
#    define DATE_FORMAT DF_MDY
470
 
#  endif
471
 
#  define lenEOL        1
472
 
#  define PutNativeEOL  *q++ = native(LF);
473
 
#endif /* MTS */
474
 
 
475
 
 /*---------------------------------------------------------------------------
476
 
    Novell NLM section
477
 
  ---------------------------------------------------------------------------*/
478
 
 
479
 
#ifdef NLM
480
 
#  include "novell/nlmcfg.h"
481
 
#endif
482
 
 
483
 
 /*---------------------------------------------------------------------------
484
 
    QDOS section
485
 
  ---------------------------------------------------------------------------*/
486
 
 
487
 
#ifdef QDOS
488
 
#  define DIRENT
489
 
#  include <fcntl.h>
490
 
#  include <unistd.h>
491
 
#  include <sys/stat.h>
492
 
#  include <time.h>
493
 
#  include "qdos/izqdos.h"
494
 
#  ifndef DATE_FORMAT
495
 
#    define DATE_FORMAT DF_MDY
496
 
#  endif
497
 
#  define lenEOL        1
498
 
#  define PutNativeEOL  *q++ = native(LF);
499
 
#  define DIR_END       '_'
500
 
#  define RETURN        QReturn
501
 
#  undef PATH_MAX
502
 
#  define PATH_MAX      36
503
 
#  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
504
 
#    define TIMESTAMP
505
 
#  endif
506
 
#  define SCREENSIZE(ttrows, ttcols)  screensize(ttrows, ttcols)
507
 
#  define SCREENWIDTH 80
508
 
#endif
509
 
 
510
 
/*---------------------------------------------------------------------------
511
 
    Tandem NSK section:
512
 
  ---------------------------------------------------------------------------*/
513
 
 
514
 
#ifdef TANDEM
515
 
#  include "tandem.h"
516
 
#  include <fcntl.h>
517
 
#  ifndef __INT32
518
 
     /* We are compiling with non-WIDE memory model, int = 16 bits */
519
 
#    ifndef INT_16BIT
520
 
#      define INT_16BIT   /* report "int" size is 16-bit to inflate setup */
521
 
#    endif
522
 
#    ifdef USE_DEFLATE64
523
 
       /* Following required for 64k WSIZE of Deflate64 support */
524
 
#      define MED_MEM     /* else OUTBUFSIZ is 64K and fails in do_string */
525
 
#      define INBUFSIZ  8192  /* but larger buffer for real OSes */
526
 
#    endif
527
 
#  endif
528
 
   /* use a single LF delimiter so that writes to 101 text files work */
529
 
#  define PutNativeEOL  *q++ = native(LF);
530
 
#  define lenEOL        1
531
 
#  ifndef DATE_FORMAT
532
 
#    define DATE_FORMAT  DF_DMY
533
 
#  endif
534
 
#  define SCREENLINES   25
535
 
   /* USE_EF_UT_TIME is set in tandem.h */
536
 
#  define RESTORE_UIDGID
537
 
#  define NO_STRNICMP
538
 
#endif
539
 
 
540
 
/*---------------------------------------------------------------------------
541
 
    THEOS section:
542
 
  ---------------------------------------------------------------------------*/
543
 
 
544
 
#ifdef THEOS
545
 
#  include "theos/thscfg.h"
546
 
#endif
547
 
 
548
 
/*---------------------------------------------------------------------------
549
 
    TOPS-20 section:
550
 
  ---------------------------------------------------------------------------*/
551
 
 
552
 
#ifdef TOPS20
553
 
#  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
554
 
#  include <sys/stat.h>
555
 
#  include <sys/param.h>
556
 
#  include <sys/time.h>
557
 
#  include <sys/timeb.h>
558
 
#  include <sys/file.h>
559
 
#  include <timex.h>
560
 
#  include <monsym.h>           /* get amazing monsym() macro */
561
 
   extern int open(), close(), read();
562
 
   extern int stat(), unlink(), jsys(), fcntl();
563
 
   extern long lseek(), dup(), creat();
564
 
#  define strchr    index       /* GRR: necessary? */
565
 
#  define strrchr   rindex
566
 
#  define REALLY_SHORT_SYMS
567
 
#  define NO_MKDIR
568
 
#  ifndef HAVE_STRNICMP
569
 
#    define NO_STRNICMP           /* probably not provided by TOPS20 C RTL  */
570
 
#  endif
571
 
#  define DIR_BEG       '<'
572
 
#  define DIR_END       '>'
573
 
#  define DIR_EXT       ".directory"
574
 
#  ifndef DATE_FORMAT
575
 
#    define DATE_FORMAT DF_MDY
576
 
#  endif
577
 
#  define EXE_EXTENSION ".exe"  /* just a guess... */
578
 
#endif /* TOPS20 */
579
 
 
580
 
/*---------------------------------------------------------------------------
581
 
    Unix section:
582
 
  ---------------------------------------------------------------------------*/
583
 
 
584
 
#ifdef UNIX
585
 
#  include "unix/unxcfg.h"
586
 
#endif /* UNIX */
587
 
 
588
 
/*---------------------------------------------------------------------------
589
 
    VM/CMS and MVS section:
590
 
  ---------------------------------------------------------------------------*/
591
 
 
592
 
#ifdef CMS_MVS
593
 
#  include "vmmvs.h"
594
 
#  define CLOSE_INFILE()  close_infile(__G)
595
 
#endif
596
 
 
597
 
/*---------------------------------------------------------------------------
598
 
    VMS section:
599
 
  ---------------------------------------------------------------------------*/
600
 
 
601
 
#ifdef VMS
602
 
#  include <types.h>                    /* GRR:  experimenting... */
603
 
#  include <stat.h>
604
 
#  include <time.h>                     /* the usual non-BSD time functions */
605
 
#  include <file.h>                     /* same things as fcntl.h has */
606
 
#  include <unixio.h>
607
 
#  include <rms.h>
608
 
#  define _MAX_PATH (NAM$C_MAXRSS+1)    /* to define FILNAMSIZ below */
609
 
#  ifndef HAVE_STRNICMP                 /* use our private zstrnicmp() */
610
 
#    define NO_STRNICMP                 /*  unless explicitely overridden */
611
 
#  endif
612
 
#  ifdef RETURN_CODES  /* VMS interprets standard PK return codes incorrectly */
613
 
#    define RETURN(ret) return_VMS(__G__ (ret))   /* verbose version */
614
 
#    define EXIT(ret)   return_VMS(__G__ (ret))
615
 
#  else
616
 
#    define RETURN      return_VMS                /* quiet version */
617
 
#    define EXIT        return_VMS
618
 
#  endif
619
 
#  ifdef VMSCLI
620
 
#    define USAGE(ret)  VMSCLI_usage(__G__ (ret))
621
 
#  endif
622
 
#  define DIR_BEG       '['
623
 
#  define DIR_END       ']'
624
 
#  define DIR_EXT       ".dir"
625
 
#  ifndef DATE_FORMAT
626
 
#    define DATE_FORMAT DF_MDY
627
 
#  endif
628
 
#  define lenEOL        1
629
 
#  define PutNativeEOL  *q++ = native(LF);
630
 
#  define SCREENSIZE(ttrows, ttcols)  screensize(ttrows, ttcols)
631
 
#  define SCREENWIDTH   80
632
 
#  define SCREENLWRAP   screenlinewrap()
633
 
#  if (defined(__VMS_VERSION) && !defined(VMS_VERSION))
634
 
#    define VMS_VERSION __VMS_VERSION
635
 
#  endif
636
 
#  if (defined(__VMS_VER) && !defined(__CRTL_VER))
637
 
#    define __CRTL_VER __VMS_VER
638
 
#  endif
639
 
#  if ((!defined(__CRTL_VER)) || (__CRTL_VER < 70000000))
640
 
#    define NO_GMTIME           /* gmtime() of earlier VMS C RTLs is broken */
641
 
#  else
642
 
#    if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
643
 
#      define USE_EF_UT_TIME
644
 
#    endif
645
 
#  endif
646
 
#  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
647
 
#    define TIMESTAMP
648
 
#  endif
649
 
#  define RESTORE_UIDGID
650
 
#  ifdef __DECC
651
 
     /* File open callback ID values. */
652
 
#    define OPENR_ID 1
653
 
     /* File open callback ID storage. */
654
 
     extern int openr_id;
655
 
     /* File open callback function. */
656
 
     extern int acc_cb();
657
 
     /* Option macros for open().
658
 
      * General: Stream access
659
 
      *
660
 
      * Callback function (DEC C only) sets deq, mbc, mbf, rah, wbh, ...
661
 
      */
662
 
#    define OPNZIP_RMS_ARGS "ctx=stm", "acc", acc_cb, &openr_id
663
 
#  else /* !__DECC */ /* (So, GNU C, VAX C, ...)*/
664
 
#    define OPNZIP_RMS_ARGS "ctx=stm"
665
 
#  endif /* ?__DECC */
666
 
#endif /* VMS */
667
 
 
668
 
/*---------------------------------------------------------------------------
669
 
    Win32 (Windows 95/NT) section:
670
 
  ---------------------------------------------------------------------------*/
671
 
 
672
 
#if (defined(WIN32) && !defined(POCKET_UNZIP) && !defined(_WIN32_WCE))
673
 
#  include "win32/w32cfg.h"
674
 
#endif
675
 
 
676
 
/*---------------------------------------------------------------------------
677
 
    Win32 Windows CE section (when not using POCKET_UNZIP)
678
 
  ---------------------------------------------------------------------------*/
679
 
 
680
 
#if (defined(_WIN32_WCE) || defined(POCKET_UNZIP))
681
 
#  include "wince/wcecfg.h"
682
 
#endif
683
 
 
684
 
 
685
 
 
686
 
 
687
 
 
688
 
/*************/
689
 
/*  Defines  */
690
 
/*************/
691
 
 
692
 
#ifdef USE_DEFLATE64
693
 
#  define UNZIP_VERSION   21   /* compatible with PKUNZIP 4.0 */
694
 
#else
695
 
#  define UNZIP_VERSION   20   /* compatible with PKUNZIP 2.0 */
696
 
#endif
697
 
#define VMS_UNZIP_VERSION 42   /* if OS-needed-to-extract is VMS:  can do */
698
 
 
699
 
#if (defined(MSDOS) || defined(OS2))
700
 
#  define DOS_OS2
701
 
#endif
702
 
 
703
 
#if (defined(OS2) || defined(WIN32))
704
 
#  define OS2_W32
705
 
#endif
706
 
 
707
 
#if (defined(DOS_OS2) || defined(WIN32))
708
 
#  define DOS_OS2_W32
709
 
#  define DOS_W32_OS2          /* historical:  don't use */
710
 
#endif
711
 
 
712
 
#if (defined(DOS_OS2_W32) || defined(__human68k__))
713
 
#  define DOS_H68_OS2_W32
714
 
#endif
715
 
 
716
 
#if (defined(DOS_OS2) || defined(FLEXOS))
717
 
#  define DOS_FLX_OS2
718
 
#endif
719
 
 
720
 
#if (defined(DOS_OS2_W32) || defined(FLEXOS))
721
 
#  define DOS_FLX_OS2_W32
722
 
#endif
723
 
 
724
 
#if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
725
 
#  define DOS_FLX_H68_OS2_W32
726
 
#endif
727
 
 
728
 
#if (defined(DOS_FLX_OS2) || defined(NLM))
729
 
#  define DOS_FLX_NLM_OS2
730
 
#endif
731
 
 
732
 
#if (defined(DOS_FLX_OS2_W32) || defined(NLM))
733
 
#  define DOS_FLX_NLM_OS2_W32
734
 
#endif
735
 
 
736
 
#if (defined(DOS_FLX_H68_OS2_W32) || defined(NLM))
737
 
#  define DOS_FLX_H68_NLM_OS2_W32
738
 
#endif
739
 
 
740
 
#if (defined(TOPS20) || defined(VMS))
741
 
#  define T20_VMS
742
 
#endif
743
 
 
744
 
#if (defined(MSDOS) || defined(T20_VMS))
745
 
#  define DOS_T20_VMS
746
 
#endif
747
 
 
748
 
#if (defined(__ATHEOS__) || defined(__BEOS__))
749
 
#  define ATH_BEO
750
 
#endif
751
 
 
752
 
#if (defined(ATH_BEO) || defined(UNIX))
753
 
#  define ATH_BEO_UNX
754
 
#endif
755
 
 
756
 
#if (defined(ATH_BEO_UNX) || defined(THEOS))
757
 
#  define ATH_BEO_THS_UNX
758
 
#endif
759
 
 
760
 
/* clean up with a few defaults */
761
 
#ifndef DIR_END
762
 
#  define DIR_END       '/'     /* last char before program name or filename */
763
 
#endif
764
 
#ifndef DATE_FORMAT
765
 
#  define DATE_FORMAT   DF_MDY  /* defaults to US convention */
766
 
#endif
767
 
#ifndef DATE_SEPCHAR
768
 
#  define DATE_SEPCHAR  '-'
769
 
#endif
770
 
#ifndef CLOSE_INFILE
771
 
#  define CLOSE_INFILE()  close(G.zipfd)
772
 
#endif
773
 
#ifndef RETURN
774
 
#  define RETURN        return  /* only used in main() */
775
 
#endif
776
 
#ifndef EXIT
777
 
#  define EXIT          exit
778
 
#endif
779
 
#ifndef USAGE
780
 
#  define USAGE(ret)    usage(__G__ (ret))    /* used in unzip.c, zipinfo.c */
781
 
#endif
782
 
#ifndef TIMET_TO_NATIVE         /* everybody but MSC 7.0 and Macintosh */
783
 
#  define TIMET_TO_NATIVE(x)
784
 
#  define NATIVE_TO_TIMET(x)
785
 
#endif
786
 
#ifndef SSTAT
787
 
#  ifdef WILD_STAT_BUG
788
 
#    define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
789
 
#  else
790
 
#    define SSTAT stat
791
 
#  endif
792
 
#endif
793
 
#ifndef STRNICMP
794
 
#  ifdef NO_STRNICMP
795
 
#    define STRNICMP zstrnicmp
796
 
#  else
797
 
#    define STRNICMP strnicmp
798
 
#  endif
799
 
#endif
800
 
 
801
 
 
802
 
#if (defined(DOS_FLX_NLM_OS2_W32) || defined(ATH_BEO_UNX) || defined(RISCOS))
803
 
#  ifndef HAVE_UNLINK
804
 
#    define HAVE_UNLINK
805
 
#  endif
806
 
#endif
807
 
#if (defined(AOS_VS) || defined(ATARI)) /* GRR: others? */
808
 
#  ifndef HAVE_UNLINK
809
 
#    define HAVE_UNLINK
810
 
#  endif
811
 
#endif
812
 
 
813
 
/* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
814
 
 
815
 
#if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
816
 
#  if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
817
 
#    define INT_SPRINTF      /* sprintf() returns int:  SysVish/Posix */
818
 
#  endif
819
 
#  if (defined(DOS_FLX_NLM_OS2_W32) || defined(VMS) || defined(AMIGA))
820
 
#    define INT_SPRINTF      /* sprintf() returns int:  ANSI */
821
 
#  endif
822
 
#  if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
823
 
#    if (defined(POSIX) || defined(__POSIX))
824
 
#      define INT_SPRINTF    /* sprintf() returns int:  ANSI/Posix */
825
 
#    endif
826
 
#    ifdef __GNUC__
827
 
#      define PCHAR_SPRINTF  /* undetermined actual return value */
828
 
#    endif
829
 
#  endif
830
 
#  if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS) || defined(THEOS))
831
 
#    define INT_SPRINTF      /* sprintf() returns int:  ANSI/Posix */
832
 
#  endif
833
 
#  if defined(sun)
834
 
#    define PCHAR_SPRINTF    /* sprintf() returns char *:  SunOS cc *and* gcc */
835
 
#  endif
836
 
#endif
837
 
 
838
 
/* defaults that we hope will take care of most machines in the future */
839
 
 
840
 
#if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
841
 
#  ifdef __STDC__
842
 
#    define INT_SPRINTF      /* sprintf() returns int:  ANSI */
843
 
#  endif
844
 
#  ifndef INT_SPRINTF
845
 
#    define PCHAR_SPRINTF    /* sprintf() returns char *:  BSDish */
846
 
#  endif
847
 
#endif
848
 
 
849
 
#define MSG_STDERR(f)  (f & 1)        /* bit 0:  0 = stdout, 1 = stderr */
850
 
#define MSG_INFO(f)    ((f & 6) == 0) /* bits 1 and 2:  0 = info */
851
 
#define MSG_WARN(f)    ((f & 6) == 2) /* bits 1 and 2:  1 = warning */
852
 
#define MSG_ERROR(f)   ((f & 6) == 4) /* bits 1 and 2:  2 = error */
853
 
#define MSG_FATAL(f)   ((f & 6) == 6) /* bits 1 and 2:  (3 = fatal error) */
854
 
#define MSG_ZFN(f)     (f & 0x0008)   /* bit 3:  1 = print zipfile name */
855
 
#define MSG_FN(f)      (f & 0x0010)   /* bit 4:  1 = print filename */
856
 
#define MSG_LNEWLN(f)  (f & 0x0020)   /* bit 5:  1 = leading newline if !SOL */
857
 
#define MSG_TNEWLN(f)  (f & 0x0040)   /* bit 6:  1 = trailing newline if !SOL */
858
 
#define MSG_MNEWLN(f)  (f & 0x0080)   /* bit 7:  1 = trailing NL for prompts */
859
 
/* the following are subject to change */
860
 
#define MSG_NO_WGUI(f) (f & 0x0100)   /* bit 8:  1 = skip if Windows GUI */
861
 
#define MSG_NO_AGUI(f) (f & 0x0200)   /* bit 9:  1 = skip if Acorn GUI */
862
 
#define MSG_NO_DLL2(f) (f & 0x0400)   /* bit 10:  1 = skip if OS/2 DLL */
863
 
#define MSG_NO_NDLL(f) (f & 0x0800)   /* bit 11:  1 = skip if WIN32 DLL */
864
 
#define MSG_NO_WDLL(f) (f & 0x1000)   /* bit 12:  1 = skip if Windows DLL */
865
 
 
866
 
#if (defined(MORE) && !defined(SCREENLINES))
867
 
#  ifdef DOS_FLX_NLM_OS2_W32
868
 
#    define SCREENLINES 25  /* can be (should be) a function instead */
869
 
#  else
870
 
#    define SCREENLINES 24  /* VT-100s are assumed to be minimal hardware */
871
 
#  endif
872
 
#endif
873
 
#if (defined(MORE) && !defined(SCREENSIZE))
874
 
#  ifndef SCREENWIDTH
875
 
#    define SCREENSIZE(scrrows, scrcols) { \
876
 
          if ((scrrows) != NULL) *(scrrows) = SCREENLINES; }
877
 
#  else
878
 
#    define SCREENSIZE(scrrows, scrcols) { \
879
 
          if ((scrrows) != NULL) *(scrrows) = SCREENLINES; \
880
 
          if ((scrcols) != NULL) *(scrcols) = SCREENWIDTH; }
881
 
#  endif
882
 
#endif
883
 
 
884
 
#define DIR_BLKSIZ  64      /* number of directory entries per block
885
 
                             *  (should fit in 4096 bytes, usually) */
886
 
#ifndef WSIZE
887
 
#  ifdef USE_DEFLATE64
888
 
#    define WSIZE   65536L  /* window size--must be a power of two, and */
889
 
#  else                     /*  at least 64K for PKZip's deflate64 method */
890
 
#    define WSIZE   0x8000  /* window size--must be a power of two, and */
891
 
#  endif                    /*  at least 32K for zip's deflate method */
892
 
#endif
893
 
 
894
 
#ifdef __16BIT__
895
 
#  ifndef INT_16BIT
896
 
#    define INT_16BIT       /* on 16-bit systems int size is 16 bits */
897
 
#  endif
898
 
#else
899
 
#  define nearmalloc  malloc
900
 
#  define nearfree    free
901
 
#  if (!defined(__IBMC__) || !defined(OS2))
902
 
#    ifndef near
903
 
#      define near
904
 
#    endif
905
 
#    ifndef far
906
 
#      define far
907
 
#    endif
908
 
#  endif
909
 
#endif
910
 
 
911
 
#if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
912
 
#  undef DYNALLOC_CRCTAB
913
 
#endif
914
 
 
915
 
#if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
916
 
#  undef DYNALLOC_CRCTAB   /* not safe with reentrant code */
917
 
#endif
918
 
 
919
 
#if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
920
 
#  ifdef DYNALLOC_CRCTAB
921
 
#    undef DYNALLOC_CRCTAB
922
 
#  endif
923
 
#endif
924
 
 
925
 
#if (defined(USE_ZLIB) && defined(ASM_CRC))
926
 
#  undef ASM_CRC
927
 
#endif
928
 
 
929
 
#ifndef INBUFSIZ
930
 
#  if (defined(MED_MEM) || defined(SMALL_MEM))
931
 
#    define INBUFSIZ  2048  /* works for MS-DOS small model */
932
 
#  else
933
 
#    define INBUFSIZ  8192  /* larger buffers for real OSes */
934
 
#  endif
935
 
#endif
936
 
 
937
 
#if (defined(INT_16BIT) && (defined(USE_DEFLATE64) || lenEOL > 1))
938
 
   /* For environments using 16-bit integers OUTBUFSIZ must be limited to
939
 
    * less than 64k (do_string() uses "unsigned" in calculations involving
940
 
    * OUTBUFSIZ).  This is achieved by defining MED_MEM when WSIZE = 64k (aka
941
 
    * Deflate64 support enabled) or EOL markers consist multiple characters.
942
 
    * (The rule gets applied AFTER the default rule for INBUFSIZ because it
943
 
    * is not neccessary to reduce INBUFSIZE in this case.)
944
 
    */
945
 
#  if (!defined(SMALL_MEM) && !defined(MED_MEM))
946
 
#    define MED_MEM
947
 
#  endif
948
 
#endif
949
 
 
950
 
/* Logic for case of small memory, length of EOL > 1:  if OUTBUFSIZ == 2048,
951
 
 * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
952
 
 * and transbuf 1040 bytes.  Have room for 32 extra EOL chars; 1008/32 == 31.5
953
 
 * chars/line, smaller than estimated 35-70 characters per line for C source
954
 
 * and normal text.  Hence difference is sufficient for most "average" files.
955
 
 * (Argument scales for larger OUTBUFSIZ.)
956
 
 */
957
 
#ifdef SMALL_MEM          /* i.e., 16-bit OSes:  MS-DOS, OS/2 1.x, etc. */
958
 
#  define LoadFarString(x)       fLoadFarString(__G__ (x))
959
 
#  define LoadFarStringSmall(x)  fLoadFarStringSmall(__G__ (x))
960
 
#  define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
961
 
#  if (defined(_MSC_VER) && (_MSC_VER >= 600))
962
 
#    define zfstrcpy(dest, src)  _fstrcpy((dest), (src))
963
 
#    define zfstrcmp(s1, s2)     _fstrcmp((s1), (s2))
964
 
#  endif
965
 
#  if !(defined(SFX) || defined(FUNZIP))
966
 
#    if (defined(_MSC_VER))
967
 
#      define zfmalloc(sz)       _fmalloc((sz))
968
 
#      define zffree(x)          _ffree(x)
969
 
#    endif
970
 
#    if (defined(__TURBOC__))
971
 
#      include <alloc.h>
972
 
#      define zfmalloc(sz)       farmalloc((unsigned long)(sz))
973
 
#      define zffree(x)          farfree(x)
974
 
#    endif
975
 
#  endif /* !(SFX || FUNZIP) */
976
 
#  ifndef Far
977
 
#    define Far far  /* __far only works for MSC 6.00, not 6.0a or Borland */
978
 
#  endif
979
 
#  define OUTBUFSIZ INBUFSIZ
980
 
#  if (lenEOL == 1)
981
 
#    define RAWBUFSIZ (OUTBUFSIZ>>1)
982
 
#  else
983
 
#    define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
984
 
#  endif
985
 
#  define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
986
 
   typedef short  shrint;            /* short/int or "shrink int" (unshrink) */
987
 
#else
988
 
#  define zfstrcpy(dest, src)       strcpy((dest), (src))
989
 
#  define zfstrcmp(s1, s2)          strcmp((s1), (s2))
990
 
#  define zfmalloc                  malloc
991
 
#  define zffree(x)                 free(x)
992
 
#  ifdef QDOS
993
 
#    define LoadFarString(x)        Qstrfix(x)   /* fix up _ for '.' */
994
 
#    define LoadFarStringSmall(x)   Qstrfix(x)
995
 
#    define LoadFarStringSmall2(x)  Qstrfix(x)
996
 
#  else
997
 
#    define LoadFarString(x)        (char *)(x)
998
 
#    define LoadFarStringSmall(x)   (char *)(x)
999
 
#    define LoadFarStringSmall2(x)  (char *)(x)
1000
 
#  endif
1001
 
#  ifdef MED_MEM
1002
 
#    define OUTBUFSIZ 0xFF80         /* can't malloc arrays of 0xFFE8 or more */
1003
 
#    define TRANSBUFSIZ 0xFF80
1004
 
     typedef short  shrint;
1005
 
#  else
1006
 
#    define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
1007
 
#    define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
1008
 
#    ifdef AMIGA
1009
 
       typedef short shrint;
1010
 
#    else
1011
 
       typedef int  shrint;          /* for efficiency/speed, we hope... */
1012
 
#    endif
1013
 
#  endif /* ?MED_MEM */
1014
 
#  define RAWBUFSIZ OUTBUFSIZ
1015
 
#endif /* ?SMALL_MEM */
1016
 
 
1017
 
#ifndef Far
1018
 
#  define Far
1019
 
#endif
1020
 
 
1021
 
#ifndef Cdecl
1022
 
#  define Cdecl
1023
 
#endif
1024
 
 
1025
 
#ifndef MAIN
1026
 
#  define MAIN  main
1027
 
#endif
1028
 
 
1029
 
#ifdef SFX      /* disable some unused features for SFX executables */
1030
 
#  ifndef NO_ZIPINFO
1031
 
#    define NO_ZIPINFO
1032
 
#  endif
1033
 
#  ifdef TIMESTAMP
1034
 
#    undef TIMESTAMP
1035
 
#  endif
1036
 
#endif
1037
 
 
1038
 
#ifdef SFX
1039
 
#  ifdef CHEAP_SFX_AUTORUN
1040
 
#    ifndef NO_SFX_EXDIR
1041
 
#      define NO_SFX_EXDIR
1042
 
#    endif
1043
 
#  endif
1044
 
#  ifndef NO_SFX_EXDIR
1045
 
#    ifndef SFX_EXDIR
1046
 
#      define SFX_EXDIR
1047
 
#    endif
1048
 
#  else
1049
 
#    ifdef SFX_EXDIR
1050
 
#      undef SFX_EXDIR
1051
 
#    endif
1052
 
#  endif
1053
 
#endif
1054
 
 
1055
 
/* user may have defined both by accident...  NOTIMESTAMP takes precedence */
1056
 
#if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
1057
 
#  undef TIMESTAMP
1058
 
#endif
1059
 
 
1060
 
#if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
1061
 
#  define COPYRIGHT_CLEAN
1062
 
#endif
1063
 
 
1064
 
/* The LZW patent is expired worldwide since 2004-Jul-07, so USE_UNSHRINK
1065
 
 * is now enabled by default.  See unshrink.c.
1066
 
 */
1067
 
#if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
1068
 
#  define USE_UNSHRINK
1069
 
#endif
1070
 
 
1071
 
#ifndef O_BINARY
1072
 
#  define O_BINARY  0
1073
 
#endif
1074
 
 
1075
 
#ifndef PIPE_ERROR
1076
 
#  define PIPE_ERROR (errno == EPIPE)
1077
 
#endif
1078
 
 
1079
 
/* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
1080
 
#ifdef VMS
1081
 
#  define FOPR  "r","ctx=stm"
1082
 
#  define FOPM  "r+","ctx=stm","rfm=fix","mrs=512"
1083
 
#  define FOPW  "w","ctx=stm","rfm=fix","mrs=512"
1084
 
#  define FOPWR "w+","ctx=stm","rfm=fix","mrs=512"
1085
 
#endif /* VMS */
1086
 
 
1087
 
#ifdef CMS_MVS
1088
 
/* Binary files must be RECFM=F,LRECL=1 for ftell() to get correct pos */
1089
 
/* ...unless byteseek is used.  Let's try that for a while.            */
1090
 
#  define FOPR "rb,byteseek"
1091
 
#  define FOPM "r+b,byteseek"
1092
 
#  ifdef MVS
1093
 
#    define FOPW "wb,recfm=u,lrecl=32760,byteseek" /* New binary files */
1094
 
#    define FOPWE "wb"                             /* Existing binary files */
1095
 
#    define FOPWT "w,lrecl=133"                    /* New text files */
1096
 
#    define FOPWTE "w"                             /* Existing text files */
1097
 
#  else
1098
 
#    define FOPW "wb,recfm=v,lrecl=32760"
1099
 
#    define FOPWT "w"
1100
 
#  endif
1101
 
#endif /* CMS_MVS */
1102
 
 
1103
 
#ifdef TOPS20          /* TOPS-20 MODERN?  You kidding? */
1104
 
#  define FOPW "w8"
1105
 
#endif /* TOPS20 */
1106
 
 
1107
 
/* Defaults when nothing special has been defined previously. */
1108
 
#ifdef MODERN
1109
 
#  ifndef FOPR
1110
 
#    define FOPR "rb"
1111
 
#  endif
1112
 
#  ifndef FOPM
1113
 
#    define FOPM "r+b"
1114
 
#  endif
1115
 
#  ifndef FOPW
1116
 
#    define FOPW "wb"
1117
 
#  endif
1118
 
#  ifndef FOPWT
1119
 
#    define FOPWT "wt"
1120
 
#  endif
1121
 
#  ifndef FOPWR
1122
 
#    define FOPWR "w+b"
1123
 
#  endif
1124
 
#else /* !MODERN */
1125
 
#  ifndef FOPR
1126
 
#    define FOPR "r"
1127
 
#  endif
1128
 
#  ifndef FOPM
1129
 
#    define FOPM "r+"
1130
 
#  endif
1131
 
#  ifndef FOPW
1132
 
#    define FOPW "w"
1133
 
#  endif
1134
 
#  ifndef FOPWT
1135
 
#    define FOPWT "w"
1136
 
#  endif
1137
 
#  ifndef FOPWR
1138
 
#    define FOPWR "w+b"
1139
 
#  endif
1140
 
#endif /* ?MODERN */
1141
 
 
1142
 
/*
1143
 
 * If <limits.h> exists on most systems, should include that, since it may
1144
 
 * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
1145
 
 * _POSIX_PATH_MAX.
1146
 
 */
1147
 
#ifdef DOS_FLX_NLM_OS2_W32
1148
 
#  include <limits.h>
1149
 
#endif
1150
 
 
1151
 
#ifndef PATH_MAX
1152
 
#  ifdef MAXPATHLEN
1153
 
#    define PATH_MAX      MAXPATHLEN    /* in <sys/param.h> on some systems */
1154
 
#  else
1155
 
#    ifdef _MAX_PATH
1156
 
#      define PATH_MAX    _MAX_PATH
1157
 
#    else
1158
 
#      if FILENAME_MAX > 255
1159
 
#        define PATH_MAX  FILENAME_MAX  /* used like PATH_MAX on some systems */
1160
 
#      else
1161
 
#        define PATH_MAX  1024
1162
 
#      endif
1163
 
#    endif /* ?_MAX_PATH */
1164
 
#  endif /* ?MAXPATHLEN */
1165
 
#endif /* !PATH_MAX */
1166
 
 
1167
 
#define FILNAMSIZ  PATH_MAX
1168
 
 
1169
 
/* DBCS support for Info-ZIP  (mainly for japanese (-: )
1170
 
 * by Yoshioka Tsuneo (QWF00133@nifty.ne.jp,tsuneo-y@is.aist-nara.ac.jp)
1171
 
 */
1172
 
#ifdef _MBCS
1173
 
#  include <locale.h>
1174
 
   /* Multi Byte Character Set */
1175
 
#  define ___MBS_TMP_DEF  char *___tmp_ptr;
1176
 
#  define ___TMP_PTR      ___tmp_ptr
1177
 
#  define CLEN(ptr) mblen((ZCONST char *)(ptr), MB_CUR_MAX)
1178
 
#  ifndef PREINCSTR
1179
 
#    define PREINCSTR(ptr) (ptr += CLEN(ptr))
1180
 
#  endif
1181
 
#  define POSTINCSTR(ptr) (___TMP_PTR=(char *)(ptr), PREINCSTR(ptr),___TMP_PTR)
1182
 
   char *plastchar OF((ZCONST char *ptr, extent len));
1183
 
#  define lastchar(ptr, len) ((int)(unsigned)*plastchar(ptr, len))
1184
 
#  ifndef MBSCHR
1185
 
#    define NEED_UZMBSCHR
1186
 
#    define MBSCHR(str,c) (char *)uzmbschr((ZCONST unsigned char *)(str), c)
1187
 
#  endif
1188
 
#  ifndef MBSRCHR
1189
 
#    define NEED_UZMBSRCHR
1190
 
#    define MBSRCHR(str,c) (char *)uzmbsrchr((ZCONST unsigned char *)(str), c)
1191
 
#  endif
1192
 
#  define SETLOCALE(category, locale) setlocale(category, locale)
1193
 
#else /* !_MBCS */
1194
 
#  define ___MBS_TMP_DEF
1195
 
#  define ___TMP_PTR
1196
 
#  define CLEN(ptr) 1
1197
 
#  define PREINCSTR(ptr) (++(ptr))
1198
 
#  define POSTINCSTR(ptr) ((ptr)++)
1199
 
#  define plastchar(ptr, len) (&ptr[(len)-1])
1200
 
#  define lastchar(ptr, len) (ptr[(len)-1])
1201
 
#  define MBSCHR(str, c) strchr(str, c)
1202
 
#  define MBSRCHR(str, c) strrchr(str, c)
1203
 
#  define SETLOCALE(category, locale)
1204
 
#endif /* ?_MBCS */
1205
 
#define INCSTR(ptr) PREINCSTR(ptr)
1206
 
 
1207
 
 
1208
 
#if (defined(MALLOC_WORK) && !defined(MY_ZCALLOC))
1209
 
   /* Any system without a special calloc function */
1210
 
# ifndef zcalloc
1211
 
#  define zcalloc(items, size) \
1212
 
          (zvoid far *)calloc((unsigned)(items), (unsigned)(size))
1213
 
# endif
1214
 
# ifndef zcfree
1215
 
#  define zcfree    free
1216
 
# endif
1217
 
#endif /* MALLOC_WORK && !MY_ZCALLOC */
1218
 
 
1219
 
#ifdef REGULUS  /* returns the inode number on success(!)...argh argh argh */
1220
 
#  define stat(p,s) zstat((p),(s))
1221
 
#endif
1222
 
 
1223
 
#if (defined(CRAY) && defined(ZMEM))
1224
 
#  undef ZMEM
1225
 
#endif
1226
 
 
1227
 
#ifdef ZMEM
1228
 
#  undef ZMEM
1229
 
#  define memcmp(b1,b2,len)      bcmp(b2,b1,len)
1230
 
#  define memcpy(dest,src,len)   bcopy(src,dest,len)
1231
 
#  define memzero                bzero
1232
 
#else
1233
 
#  define memzero(dest,len)      memset(dest,0,len)
1234
 
#endif
1235
 
 
1236
 
#ifndef TRUE
1237
 
#  define TRUE      1   /* sort of obvious */
1238
 
#endif
1239
 
#ifndef FALSE
1240
 
#  define FALSE     0
1241
 
#endif
1242
 
 
1243
 
#ifndef SEEK_SET
1244
 
#  define SEEK_SET  0
1245
 
#  define SEEK_CUR  1
1246
 
#  define SEEK_END  2
1247
 
#endif
1248
 
 
1249
 
#if (!defined(S_IEXEC) && defined(S_IXUSR))
1250
 
#  define S_IEXEC   S_IXUSR
1251
 
#endif
1252
 
 
1253
 
#if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
1254
 
#  define SYMLINKS
1255
 
#  ifndef S_ISLNK
1256
 
#    define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK)
1257
 
#  endif
1258
 
#endif /* UNIX && S_IFLNK && !MTS */
1259
 
 
1260
 
#ifndef S_ISDIR
1261
 
#  ifdef CMS_MVS
1262
 
#    define S_ISDIR(m)  (FALSE)
1263
 
#  else
1264
 
#    define S_ISDIR(m)  (((m) & S_IFMT) == S_IFDIR)
1265
 
# endif
1266
 
#endif
1267
 
 
1268
 
#ifndef IS_VOLID
1269
 
#  define IS_VOLID(m)  ((m) & 0x08)
1270
 
#endif
1271
 
 
1272
 
 
1273
 
#ifdef SHORT_SYMS                   /* Mark Williams C, ...? */
1274
 
#  define extract_or_test_files     xtr_or_tst_files
1275
 
#  define extract_or_test_member    xtr_or_tst_member
1276
 
#endif
1277
 
 
1278
 
#ifdef REALLY_SHORT_SYMS            /* TOPS-20 linker:  first 6 chars */
1279
 
#  define process_cdir_file_hdr     XXpcdfh
1280
 
#  define process_local_file_hdr    XXplfh
1281
 
#  define extract_or_test_files     XXxotf  /* necessary? */
1282
 
#  define extract_or_test_member    XXxotm  /* necessary? */
1283
 
#  define check_for_newer           XXcfn
1284
 
#  define overwrite_all             XXoa
1285
 
#  define process_all_files         XXpaf
1286
 
#  define extra_field               XXef
1287
 
#  define explode_lit8              XXel8
1288
 
#  define explode_lit4              XXel4
1289
 
#  define explode_nolit8            XXnl8
1290
 
#  define explode_nolit4            XXnl4
1291
 
#  define cpdist8                   XXcpdist8
1292
 
#  define inflate_codes             XXic
1293
 
#  define inflate_stored            XXis
1294
 
#  define inflate_fixed             XXif
1295
 
#  define inflate_dynamic           XXid
1296
 
#  define inflate_block             XXib
1297
 
#  define maxcodemax                XXmax
1298
 
#endif
1299
 
 
1300
 
#ifndef S_TIME_T_MAX            /* max value of signed (>= 32-bit) time_t */
1301
 
#  define S_TIME_T_MAX  ((time_t)(ulg)0x7fffffffL)
1302
 
#endif
1303
 
#ifndef U_TIME_T_MAX            /* max value of unsigned (>= 32-bit) time_t */
1304
 
#  define U_TIME_T_MAX  ((time_t)(ulg)0xffffffffL)
1305
 
#endif
1306
 
#ifdef DOSTIME_MINIMUM          /* min DOSTIME value (1980-01-01) */
1307
 
#  undef DOSTIME_MINIMUM
1308
 
#endif
1309
 
#define DOSTIME_MINIMUM ((ulg)0x00210000L)
1310
 
#ifdef DOSTIME_2038_01_18       /* approximate DOSTIME equivalent of */
1311
 
#  undef DOSTIME_2038_01_18     /*  the signed-32-bit time_t limit */
1312
 
#endif
1313
 
#define DOSTIME_2038_01_18 ((ulg)0x74320000L)
1314
 
 
1315
 
#ifdef QDOS
1316
 
#  define ZSUFX         "_zip"
1317
 
#  define ALT_ZSUFX     ".zip"
1318
 
#else
1319
 
#  ifdef RISCOS
1320
 
#    define ZSUFX       "/zip"
1321
 
#  else
1322
 
#    define ZSUFX       ".zip"
1323
 
#  endif
1324
 
#  define ALT_ZSUFX     ".ZIP"   /* Unix-only so far (only case-sensitive fs) */
1325
 
#endif
1326
 
 
1327
 
#define CENTRAL_HDR_SIG   "\001\002"   /* the infamous "PK" signature bytes, */
1328
 
#define LOCAL_HDR_SIG     "\003\004"   /*  w/o "PK" (so unzip executable not */
1329
 
#define END_CENTRAL_SIG   "\005\006"   /*  mistaken for zipfile itself) */
1330
 
#define EXTD_LOCAL_SIG    "\007\010"   /* [ASCII "\113" == EBCDIC "\080" ??] */
1331
 
 
1332
 
/** internal-only return codes **/
1333
 
#define IZ_DIR            76   /* potential zipfile is a directory */
1334
 
/* special return codes for mapname() */
1335
 
#define MPN_OK            0      /* mapname successful */
1336
 
#define MPN_INF_TRUNC    (1<<8)  /* caution - filename truncated */
1337
 
#define MPN_INF_SKIP     (2<<8)  /* info  - skipped because nothing to do */
1338
 
#define MPN_ERR_SKIP     (3<<8)  /* error - entry skipped */
1339
 
#define MPN_ERR_TOOLONG  (4<<8)  /* error - path too long */
1340
 
#define MPN_NOMEM        (10<<8) /* error - out of memory, file skipped */
1341
 
#define MPN_CREATED_DIR  (16<<8) /* directory created: set time & permission */
1342
 
#define MPN_VOL_LABEL    (17<<8) /* volume label, but can't set on hard disk */
1343
 
#define MPN_INVALID      (99<<8) /* internal logic error, should never reach */
1344
 
/* mask for internal mapname&checkdir return codes */
1345
 
#define MPN_MASK          0x7F00
1346
 
/* error code for extracting/testing extra field blocks */
1347
 
#define IZ_EF_TRUNC       79   /* local extra field truncated (PKZIP'd) */
1348
 
 
1349
 
/* choice of activities for do_string() */
1350
 
#define SKIP              0             /* skip header block */
1351
 
#define DISPLAY           1             /* display archive comment (ASCII) */
1352
 
#define DISPL_8           5             /* display file comment (ext. ASCII) */
1353
 
#define DS_FN             2             /* read filename (ext. ASCII, chead) */
1354
 
#define DS_FN_C           2             /* read filename from central header */
1355
 
#define DS_FN_L           6             /* read filename from local header */
1356
 
#define EXTRA_FIELD       3             /* copy extra field into buffer */
1357
 
#define DS_EF             3
1358
 
#ifdef AMIGA
1359
 
#  define FILENOTE        4             /* convert file comment to filenote */
1360
 
#endif
1361
 
#if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
1362
 
#  define CHECK_AUTORUN   7             /* copy command, display remainder */
1363
 
#  define CHECK_AUTORUN_Q 8             /* copy command, skip remainder */
1364
 
#endif
1365
 
 
1366
 
#define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
1367
 
#define EXISTS_AND_OLDER  0
1368
 
#define EXISTS_AND_NEWER  1
1369
 
 
1370
 
#define OVERWRT_QUERY     0    /* status values for G.overwrite_mode */
1371
 
#define OVERWRT_ALWAYS    1
1372
 
#define OVERWRT_NEVER     2
1373
 
 
1374
 
#define IS_OVERWRT_ALL    (G.overwrite_mode == OVERWRT_ALWAYS)
1375
 
#define IS_OVERWRT_NONE   (G.overwrite_mode == OVERWRT_NEVER)
1376
 
 
1377
 
#define ROOT              0    /* checkdir() extract-to path:  called once */
1378
 
#define INIT              1    /* allocate buildpath:  called once per member */
1379
 
#define APPEND_DIR        2    /* append a dir comp.:  many times per member */
1380
 
#define APPEND_NAME       3    /* append actual filename:  once per member */
1381
 
#define GETPATH           4    /* retrieve the complete path and free it */
1382
 
#define END               5    /* free root path prior to exiting program */
1383
 
 
1384
 
/* version_made_by codes (central dir):  make sure these */
1385
 
/*  are not defined on their respective systems!! */
1386
 
#define FS_FAT_           0    /* filesystem used by MS-DOS, OS/2, Win32 */
1387
 
#define AMIGA_            1
1388
 
#define VMS_              2
1389
 
#define UNIX_             3
1390
 
#define VM_CMS_           4
1391
 
#define ATARI_            5    /* what if it's a minix filesystem? [cjh] */
1392
 
#define FS_HPFS_          6    /* filesystem used by OS/2 (and NT 3.x) */
1393
 
#define MAC_              7    /* HFS filesystem used by MacOS */
1394
 
#define Z_SYSTEM_         8
1395
 
#define CPM_              9
1396
 
#define TOPS20_           10
1397
 
#define FS_NTFS_          11   /* filesystem used by Windows NT */
1398
 
#define QDOS_             12
1399
 
#define ACORN_            13   /* Archimedes Acorn RISC OS */
1400
 
#define FS_VFAT_          14   /* filesystem used by Windows 95, NT */
1401
 
#define MVS_              15
1402
 
#define BEOS_             16   /* hybrid POSIX/database filesystem */
1403
 
#define TANDEM_           17   /* Tandem NSK */
1404
 
#define THEOS_            18   /* THEOS */
1405
 
#define MAC_OSX_          19   /* Mac OS/X (Darwin) */
1406
 
#define ATHEOS_           30   /* AtheOS */
1407
 
#define NUM_HOSTS         31   /* index of last system + 1 */
1408
 
/* don't forget to update zipinfo.c appropiately if NUM_HOSTS changes! */
1409
 
 
1410
 
#define STORED            0    /* compression methods */
1411
 
#define SHRUNK            1
1412
 
#define REDUCED1          2
1413
 
#define REDUCED2          3
1414
 
#define REDUCED3          4
1415
 
#define REDUCED4          5
1416
 
#define IMPLODED          6
1417
 
#define TOKENIZED         7
1418
 
#define DEFLATED          8
1419
 
#define ENHDEFLATED       9
1420
 
#define DCLIMPLODED      10
1421
 
#define PKRESMOD11       11
1422
 
#define BZIP2ED          12
1423
 
#define NUM_METHODS      13    /* index of last method + 1 */
1424
 
/* don't forget to update list_files(), extract.c and zipinfo.c appropriately
1425
 
 * if NUM_METHODS changes */
1426
 
 
1427
 
/* (the PK-class error codes are public and have been moved into unzip.h) */
1428
 
 
1429
 
#define DF_MDY            0    /* date format 10/26/91 (USA only) */
1430
 
#define DF_DMY            1    /* date format 26/10/91 (most of the world) */
1431
 
#define DF_YMD            2    /* date format 91/10/26 (a few countries) */
1432
 
 
1433
 
/*---------------------------------------------------------------------------
1434
 
    Extra-field block ID values and offset info.
1435
 
  ---------------------------------------------------------------------------*/
1436
 
/* extra-field ID values, all little-endian: */
1437
 
#define EF_PKSZ64    0x0001    /* PKWARE's 64-bit filesize extensions */
1438
 
#define EF_AV        0x0007    /* PKWARE's authenticity verification */
1439
 
#define EF_OS2       0x0009    /* OS/2 extended attributes */
1440
 
#define EF_PKW32     0x000a    /* PKWARE's Win95/98/WinNT filetimes */
1441
 
#define EF_PKVMS     0x000c    /* PKWARE's VMS */
1442
 
#define EF_PKUNIX    0x000d    /* PKWARE's Unix */
1443
 
#define EF_IZVMS     0x4d49    /* Info-ZIP's VMS ("IM") */
1444
 
#define EF_IZUNIX    0x5855    /* Info-ZIP's old Unix[1] ("UX") */
1445
 
#define EF_IZUNIX2   0x7855    /* Info-ZIP's new Unix[2] ("Ux") */
1446
 
#define EF_TIME      0x5455    /* universal timestamp ("UT") */
1447
 
#define EF_MAC3      0x334d    /* Info-ZIP's new Macintosh (= "M3") */
1448
 
#define EF_JLMAC     0x07c8    /* Johnny Lee's old Macintosh (= 1992) */
1449
 
#define EF_ZIPIT     0x2605    /* Thomas Brown's Macintosh (ZipIt) */
1450
 
#define EF_ZIPIT2    0x2705    /* T. Brown's Mac (ZipIt) v 1.3.8 and newer ? */
1451
 
#define EF_SMARTZIP  0x4d63    /* Mac SmartZip by Marco Bambini */
1452
 
#define EF_VMCMS     0x4704    /* Info-ZIP's VM/CMS ("\004G") */
1453
 
#define EF_MVS       0x470f    /* Info-ZIP's MVS ("\017G") */
1454
 
#define EF_ACL       0x4c41    /* (OS/2) access control list ("AL") */
1455
 
#define EF_NTSD      0x4453    /* NT security descriptor ("SD") */
1456
 
#define EF_ATHEOS    0x7441    /* AtheOS ("At") */
1457
 
#define EF_BEOS      0x6542    /* BeOS ("Be") */
1458
 
#define EF_QDOS      0xfb4a    /* SMS/QDOS ("J\373") */
1459
 
#define EF_AOSVS     0x5356    /* AOS/VS ("VS") */
1460
 
#define EF_SPARK     0x4341    /* David Pilling's Acorn/SparkFS ("AC") */
1461
 
#define EF_TANDEM    0x4154    /* Tandem NSK ("TA") */
1462
 
#define EF_THEOS     0x6854    /* Jean-Michel Dubois' Theos "Th" */
1463
 
#define EF_THEOSO    0x4854    /* old Theos port */
1464
 
#define EF_MD5       0x4b46    /* Fred Kantor's MD5 ("FK") */
1465
 
#define EF_ASIUNIX   0x756e    /* ASi's Unix ("nu") */
1466
 
 
1467
 
#define EB_HEADSIZE       4    /* length of extra field block header */
1468
 
#define EB_ID             0    /* offset of block ID in header */
1469
 
#define EB_LEN            2    /* offset of data length field in header */
1470
 
#define EB_UCSIZE_P       0    /* offset of ucsize field in compr. data */
1471
 
#define EB_CMPRHEADLEN    6    /* lenght of compression header */
1472
 
 
1473
 
#define EB_UX_MINLEN      8    /* minimal "UX" field contains atime, mtime */
1474
 
#define EB_UX_FULLSIZE    12   /* full "UX" field (atime, mtime, uid, gid) */
1475
 
#define EB_UX_ATIME       0    /* offset of atime in "UX" extra field data */
1476
 
#define EB_UX_MTIME       4    /* offset of mtime in "UX" extra field data */
1477
 
#define EB_UX_UID         8    /* byte offset of UID in "UX" field data */
1478
 
#define EB_UX_GID         10   /* byte offset of GID in "UX" field data */
1479
 
 
1480
 
#define EB_UX2_MINLEN     4    /* minimal "Ux" field contains UID/GID */
1481
 
#define EB_UX2_UID        0    /* byte offset of UID in "Ux" field data */
1482
 
#define EB_UX2_GID        2    /* byte offset of GID in "Ux" field data */
1483
 
#define EB_UX2_VALID      (1 << 8)      /* UID/GID present */
1484
 
 
1485
 
#define EB_UT_MINLEN      1    /* minimal UT field contains Flags byte */
1486
 
#define EB_UT_FLAGS       0    /* byte offset of Flags field */
1487
 
#define EB_UT_TIME1       1    /* byte offset of 1st time value */
1488
 
#define EB_UT_FL_MTIME    (1 << 0)      /* mtime present */
1489
 
#define EB_UT_FL_ATIME    (1 << 1)      /* atime present */
1490
 
#define EB_UT_FL_CTIME    (1 << 2)      /* ctime present */
1491
 
 
1492
 
#define EB_FLGS_OFFS      4    /* offset of flags area in generic compressed
1493
 
                                  extra field blocks (BEOS, MAC, and others) */
1494
 
#define EB_OS2_HLEN       4    /* size of OS2/ACL compressed data header */
1495
 
#define EB_BEOS_HLEN      5    /* length of BeOS&AtheOS e.f attribute header */
1496
 
#define EB_BE_FL_UNCMPR   0x01 /* "BeOS&AtheOS attribs uncompr." bit flag */
1497
 
#define EB_MAC3_HLEN      14   /* length of Mac3 attribute block header */
1498
 
#define EB_SMARTZIP_HLEN  64   /* fixed length of the SmartZip extra field */
1499
 
#define EB_M3_FL_DATFRK   0x01 /* "this entry is data fork" flag */
1500
 
#define EB_M3_FL_UNCMPR   0x04 /* "Mac3 attributes uncompressed" bit flag */
1501
 
#define EB_M3_FL_TIME64   0x08 /* "Mac3 time fields are 64 bit wide" flag */
1502
 
#define EB_M3_FL_NOUTC    0x10 /* "Mac3 timezone offset fields missing" flag */
1503
 
 
1504
 
#define EB_NTSD_C_LEN     4    /* length of central NT security data */
1505
 
#define EB_NTSD_L_LEN     5    /* length of minimal local NT security data */
1506
 
#define EB_NTSD_VERSION   4    /* offset of NTSD version byte */
1507
 
#define EB_NTSD_MAX_VER   (0)  /* maximum version # we know how to handle */
1508
 
 
1509
 
#define EB_ASI_CRC32      0    /* offset of ASI Unix field's crc32 checksum */
1510
 
#define EB_ASI_MODE       4    /* offset of ASI Unix permission mode field */
1511
 
 
1512
 
#define EB_IZVMS_HLEN     12   /* length of IZVMS attribute block header */
1513
 
#define EB_IZVMS_FLGS     4    /* offset of compression type flag */
1514
 
#define EB_IZVMS_UCSIZ    6    /* offset of ucsize field in IZVMS header */
1515
 
#define EB_IZVMS_BCMASK   07   /* 3 bits for compression type */
1516
 
#define EB_IZVMS_BCSTOR   0    /*  Stored */
1517
 
#define EB_IZVMS_BC00     1    /*  0byte -> 0bit compression */
1518
 
#define EB_IZVMS_BCDEFL   2    /*  Deflated */
1519
 
 
1520
 
 
1521
 
/*---------------------------------------------------------------------------
1522
 
    True sizes of the various headers, as defined by PKWARE--so it is not
1523
 
    likely that these will ever change.  But if they do, make sure both these
1524
 
    defines AND the typedefs below get updated accordingly.
1525
 
  ---------------------------------------------------------------------------*/
1526
 
#define LREC_SIZE   26   /* lengths of local file headers, central */
1527
 
#define CREC_SIZE   42   /*  directory headers, and the end-of-    */
1528
 
#define ECREC_SIZE  18   /*  central-dir record, respectively      */
1529
 
 
1530
 
#define MAX_BITS    13                 /* used in unshrink() */
1531
 
#define HSIZE       (1 << MAX_BITS)    /* size of global work area */
1532
 
 
1533
 
#define LF     10        /* '\n' on ASCII machines; must be 10 due to EBCDIC */
1534
 
#define CR     13        /* '\r' on ASCII machines; must be 13 due to EBCDIC */
1535
 
#define CTRLZ  26        /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
1536
 
 
1537
 
#ifdef EBCDIC
1538
 
#  define foreign(c)    ascii[(uch)(c)]
1539
 
#  define native(c)     ebcdic[(uch)(c)]
1540
 
#  define NATIVE        "EBCDIC"
1541
 
#  define NOANSIFILT
1542
 
#endif
1543
 
 
1544
 
#ifdef VMS
1545
 
#  define ENV_UNZIP       "UNZIP_OPTS"     /* names of environment variables */
1546
 
#  define ENV_ZIPINFO     "ZIPINFO_OPTS"
1547
 
#endif /* VMS */
1548
 
#ifdef RISCOS
1549
 
#  define ENV_UNZIP       "Unzip$Options"
1550
 
#  define ENV_ZIPINFO     "Zipinfo$Options"
1551
 
#  define ENV_UNZIPEXTS   "Unzip$Exts"
1552
 
#endif /* RISCOS */
1553
 
#ifndef ENV_UNZIP
1554
 
#  define ENV_UNZIP       "UNZIP"          /* the standard names */
1555
 
#  define ENV_ZIPINFO     "ZIPINFO"
1556
 
#endif
1557
 
#define ENV_UNZIP2        "UNZIPOPT"     /* alternate names, for zip compat. */
1558
 
#define ENV_ZIPINFO2      "ZIPINFOOPT"
1559
 
 
1560
 
#if (!defined(QQ) && !defined(NOQQ))
1561
 
#  define QQ
1562
 
#endif
1563
 
 
1564
 
#ifdef QQ                         /* Newtware version:  no file */
1565
 
#  define QCOND     (!uO.qflag)   /*  comments with -vq or -vqq */
1566
 
#else                             /* Bill Davidsen version:  no way to */
1567
 
#  define QCOND     (longhdr)     /*  kill file comments when listing */
1568
 
#endif
1569
 
 
1570
 
#ifdef OLD_QQ
1571
 
#  define QCOND2    (uO.qflag < 2)
1572
 
#else
1573
 
#  define QCOND2    (!uO.qflag)
1574
 
#endif
1575
 
 
1576
 
#ifdef WILD_STOP_AT_DIR
1577
 
#  define __WDLPRO  , int sepc
1578
 
#  define __WDL     , sepc
1579
 
#  define __WDLDEF  int sepc;
1580
 
#  define WISEP     , (uO.W_flag ? '/' : '\0')
1581
 
#else
1582
 
#  define __WDLPRO
1583
 
#  define __WDL
1584
 
#  define __WDLDEF
1585
 
#  define WISEP
1586
 
#endif
1587
 
 
1588
 
 
1589
 
 
1590
 
 
1591
 
/**************/
1592
 
/*  Typedefs  */
1593
 
/**************/
1594
 
 
1595
 
#ifdef NO_UID_GID
1596
 
#  ifdef UID_USHORT
1597
 
     typedef unsigned short  uid_t;    /* TI SysV.3 */
1598
 
     typedef unsigned short  gid_t;
1599
 
#  else
1600
 
     typedef unsigned int    uid_t;    /* SCO Xenix */
1601
 
     typedef unsigned int    gid_t;
1602
 
#  endif
1603
 
#endif
1604
 
 
1605
 
#if (defined(GOT_UTIMBUF) || defined(sgi) || defined(ATARI))
1606
 
   typedef struct utimbuf ztimbuf;
1607
 
#else
1608
 
   typedef struct ztimbuf {
1609
 
       time_t actime;        /* new access time */
1610
 
       time_t modtime;       /* new modification time */
1611
 
   } ztimbuf;
1612
 
#endif
1613
 
 
1614
 
typedef struct iztimes {
1615
 
   time_t atime;             /* new access time */
1616
 
   time_t mtime;             /* new modification time */
1617
 
   time_t ctime;             /* used for creation time; NOT same as st_ctime */
1618
 
} iztimes;
1619
 
 
1620
 
#ifdef SET_DIR_ATTRIB
1621
 
   typedef struct direntry {    /* head of system-specific struct holding */
1622
 
       struct direntry *next;   /*  defered directory attributes info */
1623
 
       char *fn;                /* filename of directory */
1624
 
       char buf[1];             /* start of system-specific internal data */
1625
 
   } direntry;
1626
 
#endif /* SET_DIR_ATTRIB */
1627
 
 
1628
 
#ifdef SYMLINKS
1629
 
   typedef struct slinkentry {  /* info for deferred symlink creation */
1630
 
       struct slinkentry *next; /* pointer to next entry in chain */
1631
 
       extent targetlen;        /* length of target filespec */
1632
 
       extent attriblen;        /* length of system-specific attrib data */
1633
 
       char *target;            /* pointer to target filespec */
1634
 
       char *fname;             /* pointer to name of link */
1635
 
       char buf[2];             /* name of link, allocs space for 2 '\0's */
1636
 
   } slinkentry;
1637
 
#endif /* SYMLINKS */
1638
 
 
1639
 
typedef struct min_info {
1640
 
    Z_OFF_T offset;
1641
 
    ulg compr_size;          /* compressed size (needed if extended header) */
1642
 
    ulg uncompr_size;        /* uncompressed size (needed if extended header) */
1643
 
    ulg crc;                 /* crc (needed if extended header) */
1644
 
    ush diskstart;           /* no of volume where this entry starts */
1645
 
    uch hostver;
1646
 
    uch hostnum;
1647
 
    unsigned file_attr;      /* local flavor, as used by creat(), chmod()... */
1648
 
    unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
1649
 
    unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
1650
 
    unsigned textfile : 1;   /* file is text (according to zip) */
1651
 
    unsigned textmode : 1;   /* file is to be extracted as text */
1652
 
    unsigned lcflag : 1;     /* convert filename to lowercase */
1653
 
    unsigned vollabel : 1;   /* "file" is an MS-DOS volume (disk) label */
1654
 
    unsigned HasUxAtt : 1;   /* crec ext_file_attr has Unix style mode bits */
1655
 
#ifndef SFX
1656
 
    char Far *cfilname;      /* central header version of filename */
1657
 
#endif
1658
 
} min_info;
1659
 
 
1660
 
typedef struct VMStimbuf {
1661
 
    char *revdate;    /* (both roughly correspond to Unix modtime/st_mtime) */
1662
 
    char *credate;
1663
 
} VMStimbuf;
1664
 
 
1665
 
/*---------------------------------------------------------------------------
1666
 
    Zipfile work area declarations.
1667
 
  ---------------------------------------------------------------------------*/
1668
 
 
1669
 
#ifdef MALLOC_WORK
1670
 
   union work {
1671
 
     struct {                 /* unshrink(): */
1672
 
       shrint *Parent;          /* pointer to (8192 * sizeof(shrint)) */
1673
 
       uch *value;              /* pointer to 8KB char buffer */
1674
 
       uch *Stack;              /* pointer to another 8KB char buffer */
1675
 
     } shrink;
1676
 
     uch *Slide;              /* explode(), inflate(), unreduce() */
1677
 
   };
1678
 
#else /* !MALLOC_WORK */
1679
 
   union work {
1680
 
     struct {                 /* unshrink(): */
1681
 
       shrint Parent[HSIZE];    /* (8192 * sizeof(shrint)) == 16KB minimum */
1682
 
       uch value[HSIZE];        /* 8KB */
1683
 
       uch Stack[HSIZE];        /* 8KB */
1684
 
     } shrink;                  /* total = 32KB minimum; 80KB on Cray/Alpha */
1685
 
     uch Slide[WSIZE];        /* explode(), inflate(), unreduce() */
1686
 
   };
1687
 
#endif /* ?MALLOC_WORK */
1688
 
 
1689
 
#define slide  G.area.Slide
1690
 
 
1691
 
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
1692
 
#  define redirSlide G.redirect_sldptr
1693
 
#else
1694
 
#  define redirSlide G.area.Slide
1695
 
#endif
1696
 
 
1697
 
/*---------------------------------------------------------------------------
1698
 
    Zipfile layout declarations.  If these headers ever change, make sure the
1699
 
    xxREC_SIZE defines (above) change with them!
1700
 
  ---------------------------------------------------------------------------*/
1701
 
 
1702
 
   typedef uch   local_byte_hdr[ LREC_SIZE ];
1703
 
#      define L_VERSION_NEEDED_TO_EXTRACT_0     0
1704
 
#      define L_VERSION_NEEDED_TO_EXTRACT_1     1
1705
 
#      define L_GENERAL_PURPOSE_BIT_FLAG        2
1706
 
#      define L_COMPRESSION_METHOD              4
1707
 
#      define L_LAST_MOD_DOS_DATETIME           6
1708
 
#      define L_CRC32                           10
1709
 
#      define L_COMPRESSED_SIZE                 14
1710
 
#      define L_UNCOMPRESSED_SIZE               18
1711
 
#      define L_FILENAME_LENGTH                 22
1712
 
#      define L_EXTRA_FIELD_LENGTH              24
1713
 
 
1714
 
   typedef uch   cdir_byte_hdr[ CREC_SIZE ];
1715
 
#      define C_VERSION_MADE_BY_0               0
1716
 
#      define C_VERSION_MADE_BY_1               1
1717
 
#      define C_VERSION_NEEDED_TO_EXTRACT_0     2
1718
 
#      define C_VERSION_NEEDED_TO_EXTRACT_1     3
1719
 
#      define C_GENERAL_PURPOSE_BIT_FLAG        4
1720
 
#      define C_COMPRESSION_METHOD              6
1721
 
#      define C_LAST_MOD_DOS_DATETIME           8
1722
 
#      define C_CRC32                           12
1723
 
#      define C_COMPRESSED_SIZE                 16
1724
 
#      define C_UNCOMPRESSED_SIZE               20
1725
 
#      define C_FILENAME_LENGTH                 24
1726
 
#      define C_EXTRA_FIELD_LENGTH              26
1727
 
#      define C_FILE_COMMENT_LENGTH             28
1728
 
#      define C_DISK_NUMBER_START               30
1729
 
#      define C_INTERNAL_FILE_ATTRIBUTES        32
1730
 
#      define C_EXTERNAL_FILE_ATTRIBUTES        34
1731
 
#      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
1732
 
 
1733
 
   typedef uch   ec_byte_rec[ ECREC_SIZE+4 ];
1734
 
/*     define SIGNATURE                         0   space-holder only */
1735
 
#      define NUMBER_THIS_DISK                  4
1736
 
#      define NUM_DISK_WITH_START_CENTRAL_DIR   6
1737
 
#      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
1738
 
#      define TOTAL_ENTRIES_CENTRAL_DIR         10
1739
 
#      define SIZE_CENTRAL_DIRECTORY            12
1740
 
#      define OFFSET_START_CENTRAL_DIRECTORY    16
1741
 
#      define ZIPFILE_COMMENT_LENGTH            20
1742
 
 
1743
 
 
1744
 
/* The following structs are used to hold all header data of a zip entry.
1745
 
   Traditionally, the structs' layouts followed the data layout of the
1746
 
   corresponding zipfile header structures.  However, the zipfile header
1747
 
   layouts were designed in the old ages of 16-bit CPUs, they are subject
1748
 
   to structure padding and/or alignment issues on newer systems with a
1749
 
   "natural word width" of more than 2 bytes.
1750
 
   Please note that the structure members are now reordered by size
1751
 
   (top-down), to prevent internal padding and optimize memory usage!
1752
 
 */
1753
 
   typedef struct local_file_header {                 /* LOCAL */
1754
 
       ulg csize;
1755
 
       ulg ucsize;
1756
 
       ulg last_mod_dos_datetime;
1757
 
       ulg crc32;
1758
 
       uch version_needed_to_extract[2];
1759
 
       ush general_purpose_bit_flag;
1760
 
       ush compression_method;
1761
 
       ush filename_length;
1762
 
       ush extra_field_length;
1763
 
   } local_file_hdr;
1764
 
 
1765
 
#if 0
1766
 
   typedef struct central_directory_file_header {     /* CENTRAL */
1767
 
       uch version_made_by[2];
1768
 
       uch version_needed_to_extract[2];
1769
 
       ush general_purpose_bit_flag;
1770
 
       ush compression_method;
1771
 
       ulg last_mod_dos_datetime;
1772
 
       ulg crc32;
1773
 
       ulg csize;
1774
 
       ulg ucsize;
1775
 
       ush filename_length;
1776
 
       ush extra_field_length;
1777
 
       ush file_comment_length;
1778
 
       ush disk_number_start;
1779
 
       ush internal_file_attributes;
1780
 
       ulg external_file_attributes;
1781
 
       ulg relative_offset_local_header;
1782
 
   } cdir_file_hdr;
1783
 
#endif /* 0 */
1784
 
 
1785
 
   typedef struct end_central_dir_record {            /* END CENTRAL */
1786
 
       ush number_this_disk;
1787
 
       ush num_disk_start_cdir;
1788
 
       ush num_entries_centrl_dir_ths_disk;
1789
 
       ush total_entries_central_dir;
1790
 
       ulg size_central_directory;
1791
 
       ulg offset_start_central_directory;
1792
 
       ush zipfile_comment_length;
1793
 
   } ecdir_rec;
1794
 
 
1795
 
 
1796
 
/* Huffman code lookup table entry--this entry is four bytes for machines
1797
 
   that have 16-bit pointers (e.g. PC's in the small or medium model).
1798
 
   Valid extra bits are 0..16.  e == 31 is EOB (end of block), e == 32
1799
 
   means that v is a literal, 32 < e < 64 means that v is a pointer to
1800
 
   the next table, which codes (e & 31)  bits, and lastly e == 99 indicates
1801
 
   an unused code.  If a code with e == 99 is looked up, this implies an
1802
 
   error in the data. */
1803
 
 
1804
 
struct huft {
1805
 
    uch e;                /* number of extra bits or operation */
1806
 
    uch b;                /* number of bits in this code or subcode */
1807
 
    union {
1808
 
        ush n;            /* literal, length base, or distance base */
1809
 
        struct huft *t;   /* pointer to next level of table */
1810
 
    } v;
1811
 
};
1812
 
 
1813
 
 
1814
 
typedef struct _APIDocStruct {
1815
 
    char *compare;
1816
 
    char *function;
1817
 
    char *syntax;
1818
 
    char *purpose;
1819
 
} APIDocStruct;
1820
 
 
1821
 
 
1822
 
 
1823
 
 
1824
 
/*************/
1825
 
/*  Globals  */
1826
 
/*************/
1827
 
 
1828
 
#if (defined(OS2) && !defined(FUNZIP))
1829
 
#  include "os2/os2data.h"
1830
 
#endif
1831
 
 
1832
 
#include "globals.h"
1833
 
 
1834
 
 
1835
 
 
1836
 
/*************************/
1837
 
/*  Function Prototypes  */
1838
 
/*************************/
1839
 
 
1840
 
/*---------------------------------------------------------------------------
1841
 
    Functions in unzip.c (initialization routines):
1842
 
  ---------------------------------------------------------------------------*/
1843
 
 
1844
 
#ifndef WINDLL
1845
 
   int    MAIN                   OF((int argc, char **argv));
1846
 
   int    unzip                  OF((__GPRO__ int argc, char **argv));
1847
 
   int    uz_opts                OF((__GPRO__ int *pargc, char ***pargv));
1848
 
   int    usage                  OF((__GPRO__ int error));
1849
 
#endif /* !WINDLL */
1850
 
 
1851
 
/*---------------------------------------------------------------------------
1852
 
    Functions in process.c (main driver routines):
1853
 
  ---------------------------------------------------------------------------*/
1854
 
 
1855
 
int      process_zipfiles        OF((__GPRO));
1856
 
void     free_G_buffers          OF((__GPRO));
1857
 
/* static int    do_seekable     OF((__GPRO__ int lastchance)); */
1858
 
/* static int    find_ecrec      OF((__GPRO__ long searchlen)); */
1859
 
int      uz_end_central          OF((__GPRO));
1860
 
int      process_cdir_file_hdr   OF((__GPRO));
1861
 
int      get_cdir_ent            OF((__GPRO));
1862
 
int      process_local_file_hdr  OF((__GPRO));
1863
 
unsigned ef_scan_for_izux        OF((ZCONST uch *ef_buf, unsigned ef_len,
1864
 
                                     int ef_is_c, ulg dos_mdatetime,
1865
 
                                     iztimes *z_utim, ush *z_uidgid));
1866
 
#if (defined(RISCOS) || defined(ACORN_FTYPE_NFS))
1867
 
   zvoid *getRISCOSexfield       OF((ZCONST uch *ef_buf, unsigned ef_len));
1868
 
#endif
1869
 
 
1870
 
#ifndef SFX
1871
 
 
1872
 
/*---------------------------------------------------------------------------
1873
 
    Functions in zipinfo.c (`zipinfo-style' listing routines):
1874
 
  ---------------------------------------------------------------------------*/
1875
 
 
1876
 
#ifndef NO_ZIPINFO
1877
 
#ifndef WINDLL
1878
 
   int   zi_opts                 OF((__GPRO__ int *pargc, char ***pargv));
1879
 
#endif
1880
 
int      zi_end_central          OF((__GPRO));
1881
 
int      zipinfo                 OF((__GPRO));
1882
 
/* static int      zi_long       OF((__GPRO__ ulg *pEndprev)); */
1883
 
/* static int      zi_short      OF((__GPRO)); */
1884
 
/* static char    *zi_time       OF((__GPRO__ ZCONST ulg *datetimez,
1885
 
                                     ZCONST time_t *modtimez, char *d_t_str));*/
1886
 
#endif /* !NO_ZIPINFO */
1887
 
 
1888
 
/*---------------------------------------------------------------------------
1889
 
    Functions in list.c (generic zipfile-listing routines):
1890
 
  ---------------------------------------------------------------------------*/
1891
 
 
1892
 
int      list_files              OF((__GPRO));
1893
 
#ifdef TIMESTAMP
1894
 
   int   get_time_stamp          OF((__GPRO__  time_t *last_modtime,
1895
 
                                     ulg *nmember));
1896
 
#endif
1897
 
int      ratio                   OF((ulg uc, ulg c));
1898
 
void     fnprint                 OF((__GPRO));
1899
 
 
1900
 
#endif /* !SFX */
1901
 
 
1902
 
/*---------------------------------------------------------------------------
1903
 
    Functions in fileio.c:
1904
 
  ---------------------------------------------------------------------------*/
1905
 
 
1906
 
int      open_input_file      OF((__GPRO));
1907
 
int      open_outfile         OF((__GPRO));                    /* also vms.c */
1908
 
void     undefer_input        OF((__GPRO));
1909
 
void     defer_leftover_input OF((__GPRO));
1910
 
unsigned readbuf              OF((__GPRO__ char *buf, register unsigned len));
1911
 
int      readbyte             OF((__GPRO));
1912
 
int      fillinbuf            OF((__GPRO));
1913
 
int      seek_zipf            OF((__GPRO__ Z_OFF_T abs_offset));
1914
 
#ifdef FUNZIP
1915
 
   int   flush                OF((__GPRO__ ulg size));  /* actually funzip.c */
1916
 
#else
1917
 
   int   flush                OF((__GPRO__ uch *buf, ulg size, int unshrink));
1918
 
#endif
1919
 
/* static int  disk_error     OF((__GPRO)); */
1920
 
void     handler              OF((int signal));
1921
 
time_t   dos_to_unix_time     OF((ulg dos_datetime));
1922
 
int      check_for_newer      OF((__GPRO__ char *filename)); /* os2,vmcms,vms */
1923
 
int      do_string            OF((__GPRO__ unsigned int length, int option));
1924
 
ush      makeword             OF((ZCONST uch *b));
1925
 
ulg      makelong             OF((ZCONST uch *sig));
1926
 
#if (!defined(STR_TO_ISO) || defined(NEED_STR2ISO))
1927
 
   char *str2iso              OF((char *dst, ZCONST char *src));
1928
 
#endif
1929
 
#if (!defined(STR_TO_OEM) || defined(NEED_STR2OEM))
1930
 
   char *str2oem              OF((char *dst, ZCONST char *src));
1931
 
#endif
1932
 
#ifdef NO_STRNICMP
1933
 
   int   zstrnicmp            OF((register ZCONST char *s1,
1934
 
                                  register ZCONST char *s2,
1935
 
                                  register unsigned n));
1936
 
#endif
1937
 
#ifdef REGULUS
1938
 
   int   zstat                OF((ZCONST char *p, struct stat *s));
1939
 
#endif
1940
 
#ifdef ZMEM   /* MUST be ifdef'd because of conflicts with the standard def. */
1941
 
   zvoid *memset OF((register zvoid *, register int, register unsigned int));
1942
 
   int    memcmp OF((register ZCONST zvoid*, register ZCONST zvoid *,
1943
 
                     register unsigned int));
1944
 
   zvoid *memcpy OF((register zvoid *, register ZCONST zvoid *,
1945
 
                     register unsigned int));
1946
 
#endif
1947
 
#ifdef NEED_UZMBSCHR
1948
 
   unsigned char *uzmbschr  OF((ZCONST unsigned char *str, unsigned int c));
1949
 
#endif
1950
 
#ifdef NEED_UZMBSRCHR
1951
 
   unsigned char *uzmbsrchr OF((ZCONST unsigned char *str, unsigned int c));
1952
 
#endif
1953
 
#ifdef SMALL_MEM
1954
 
   char *fLoadFarString       OF((__GPRO__ const char Far *sz));
1955
 
   char *fLoadFarStringSmall  OF((__GPRO__ const char Far *sz));
1956
 
   char *fLoadFarStringSmall2 OF((__GPRO__ const char Far *sz));
1957
 
   #ifndef zfstrcpy
1958
 
     char Far * Far zfstrcpy  OF((char Far *s1, const char Far *s2));
1959
 
   #endif
1960
 
   #if (!defined(SFX) && !defined(zfstrcmp))
1961
 
     int Far zfstrcmp         OF((const char Far *s1, const char Far *s2));
1962
 
   #endif
1963
 
#endif
1964
 
 
1965
 
 
1966
 
/*---------------------------------------------------------------------------
1967
 
    Functions in extract.c:
1968
 
  ---------------------------------------------------------------------------*/
1969
 
 
1970
 
int    extract_or_test_files     OF((__GPRO));
1971
 
/* static int   store_info          OF((void)); */
1972
 
/* static int   extract_or_test_member   OF((__GPRO)); */
1973
 
/* static int   TestExtraField   OF((__GPRO__ uch *ef, unsigned ef_len)); */
1974
 
/* static int   test_OS2         OF((__GPRO__ uch *eb, unsigned eb_size)); */
1975
 
/* static int   test_NT          OF((__GPRO__ uch *eb, unsigned eb_size)); */
1976
 
int    memextract                OF((__GPRO__ uch *tgt, ulg tgtsize,
1977
 
                                     ZCONST uch *src, ulg srcsize));
1978
 
int    memflush                  OF((__GPRO__ ZCONST uch *rawbuf, ulg size));
1979
 
#if (defined(VMS) || defined(VMS_TEXT_CONV))
1980
 
   uch   *extract_izvms_block    OF((__GPRO__ ZCONST uch *ebdata,
1981
 
                                     unsigned size, unsigned *retlen,
1982
 
                                     ZCONST uch *init, unsigned needlen));
1983
 
#endif
1984
 
char  *fnfilter                  OF((ZCONST char *raw, uch *space));
1985
 
 
1986
 
/*---------------------------------------------------------------------------
1987
 
    Decompression functions:
1988
 
  ---------------------------------------------------------------------------*/
1989
 
 
1990
 
#if (!defined(SFX) && !defined(FUNZIP))
1991
 
int    explode                   OF((__GPRO));                  /* explode.c */
1992
 
#endif
1993
 
int    huft_free                 OF((struct huft *t));          /* inflate.c */
1994
 
int    huft_build                OF((__GPRO__ ZCONST unsigned *b, unsigned n,
1995
 
                                     unsigned s, ZCONST ush *d, ZCONST uch *e,
1996
 
                                     struct huft **t, unsigned *m));
1997
 
#ifdef USE_ZLIB
1998
 
   int    UZinflate              OF((__GPRO__ int is_defl64));  /* inflate.c */
1999
 
#  define inflate_free(x)        inflateEnd(&((Uz_Globs *)(&G))->dstrm)
2000
 
#else
2001
 
   int    inflate                OF((__GPRO__ int is_defl64));  /* inflate.c */
2002
 
   int    inflate_free           OF((__GPRO));                  /* inflate.c */
2003
 
#endif /* ?USE_ZLIB */
2004
 
#if (!defined(SFX) && !defined(FUNZIP))
2005
 
#ifndef COPYRIGHT_CLEAN
2006
 
   int    unreduce               OF((__GPRO));                 /* unreduce.c */
2007
 
/* static void  LoadFollowers    OF((__GPRO__ f_array *follower, uch *Slen));
2008
 
                                                                * unreduce.c */
2009
 
#endif /* !COPYRIGHT_CLEAN */
2010
 
#ifndef LZW_CLEAN
2011
 
   int    unshrink               OF((__GPRO));                 /* unshrink.c */
2012
 
/* static void  partial_clear    OF((__GPRO));                  * unshrink.c */
2013
 
#endif /* !LZW_CLEAN */
2014
 
#endif /* !SFX && !FUNZIP */
2015
 
 
2016
 
/*---------------------------------------------------------------------------
2017
 
    Internal API functions (only included in DLL versions):
2018
 
  ---------------------------------------------------------------------------*/
2019
 
 
2020
 
#ifdef DLL
2021
 
   void     setFileNotFound       OF((__GPRO));                     /* api.c */
2022
 
   int      unzipToMemory         OF((__GPRO__ char *zip, char *file,
2023
 
                                      UzpBuffer *retstr));          /* api.c */
2024
 
   int      redirect_outfile      OF((__GPRO));                     /* api.c */
2025
 
   int      writeToMemory         OF((__GPRO__ ZCONST uch *rawbuf,
2026
 
                                      extent size));                /* api.c */
2027
 
   int      close_redirect        OF((__GPRO));                     /* api.c */
2028
 
   /* this obsolescent entry point kept for compatibility: */
2029
 
   int      UzpUnzip              OF((int argc, char **argv));/* use UzpMain */
2030
 
#ifdef OS2DLL
2031
 
   int      varmessage            OF((__GPRO__ ZCONST uch *buf, ulg size));
2032
 
   int      varputchar            OF((__GPRO__ int c));         /* rexxapi.c */
2033
 
   int      finish_REXX_redirect  OF((__GPRO));                 /* rexxapi.c */
2034
 
#endif
2035
 
#ifdef API_DOC
2036
 
   void     APIhelp               OF((__GPRO__ int argc, char **argv));
2037
 
#endif                                                          /* apihelp.c */
2038
 
#endif /* DLL */
2039
 
 
2040
 
/*---------------------------------------------------------------------------
2041
 
    MSDOS-only functions:
2042
 
  ---------------------------------------------------------------------------*/
2043
 
 
2044
 
#if (defined(MSDOS) && (defined(__GO32__) || defined(__EMX__)))
2045
 
   unsigned _dos_getcountryinfo(void *);                          /* msdos.c */
2046
 
#if (!defined(__DJGPP__) || (__DJGPP__ < 2))
2047
 
   unsigned _dos_setftime(int, unsigned, unsigned);               /* msdos.c */
2048
 
   unsigned _dos_setfileattr(const char *, unsigned);             /* msdos.c */
2049
 
   unsigned _dos_creat(const char *, unsigned, int *);            /* msdos.c */
2050
 
   void _dos_getdrive(unsigned *);                                /* msdos.c */
2051
 
   unsigned _dos_close(int);                                      /* msdos.c */
2052
 
#endif /* !__DJGPP__ || (__DJGPP__ < 2) */
2053
 
#endif
2054
 
 
2055
 
/*---------------------------------------------------------------------------
2056
 
    OS/2-only functions:
2057
 
  ---------------------------------------------------------------------------*/
2058
 
 
2059
 
#ifdef OS2   /* GetFileTime conflicts with something in Win32 header files */
2060
 
#if (defined(REENTRANT) && defined(USETHREADID))
2061
 
   ulg   GetThreadId          OF((void));
2062
 
#endif
2063
 
   int   GetCountryInfo       OF((void));                           /* os2.c */
2064
 
   long  GetFileTime          OF((ZCONST char *name));              /* os2.c */
2065
 
/* static void  SetPathAttrTimes OF((__GPRO__ int flags, int dir));    os2.c */
2066
 
/* static int   SetEAs        OF((__GPRO__ const char *path,
2067
 
                                  void *eablock));                     os2.c */
2068
 
/* static int   SetACL        OF((__GPRO__ const char *path,
2069
 
                                  void *eablock));                     os2.c */
2070
 
/* static int   IsFileNameValid OF((const char *name));                os2.c */
2071
 
/* static void  map2fat       OF((char *pathcomp, char **pEndFAT));    os2.c */
2072
 
/* static int   SetLongNameEA OF((char *name, char *longname));        os2.c */
2073
 
/* static void  InitNLS       OF((void));                              os2.c */
2074
 
   int   IsUpperNLS           OF((int nChr));                       /* os2.c */
2075
 
   int   ToLowerNLS           OF((int nChr));                       /* os2.c */
2076
 
   void  DebugMalloc          OF((void));                           /* os2.c */
2077
 
#endif
2078
 
 
2079
 
/*---------------------------------------------------------------------------
2080
 
    QDOS-only functions:
2081
 
  ---------------------------------------------------------------------------*/
2082
 
 
2083
 
#ifdef QDOS
2084
 
   int    QMatch              (uch, uch);
2085
 
   void   QFilename           (__GPRO__ char *);
2086
 
   char  *Qstrfix             (char *);
2087
 
   int    QReturn             (int zip_error);
2088
 
#endif
2089
 
 
2090
 
/*---------------------------------------------------------------------------
2091
 
    TOPS20-only functions:
2092
 
  ---------------------------------------------------------------------------*/
2093
 
 
2094
 
#ifdef TOPS20
2095
 
   int    upper               OF((char *s));                     /* tops20.c */
2096
 
   int    enquote             OF((char *s));                     /* tops20.c */
2097
 
   int    dequote             OF((char *s));                     /* tops20.c */
2098
 
   int    fnlegal             OF(()); /* error if prototyped? */ /* tops20.c */
2099
 
#endif
2100
 
 
2101
 
/*---------------------------------------------------------------------------
2102
 
    VM/CMS- and MVS-only functions:
2103
 
  ---------------------------------------------------------------------------*/
2104
 
 
2105
 
#ifdef CMS_MVS
2106
 
   extent getVMMVSexfield     OF((char *type, uch *ef_block, unsigned datalen));
2107
 
   FILE  *vmmvs_open_infile   OF((__GPRO));                       /* vmmvs.c */
2108
 
   void   close_infile        OF((__GPRO));                       /* vmmvs.c */
2109
 
#endif
2110
 
 
2111
 
/*---------------------------------------------------------------------------
2112
 
    VMS-only functions:
2113
 
  ---------------------------------------------------------------------------*/
2114
 
 
2115
 
#ifdef VMS
2116
 
   int    check_format        OF((__GPRO));                         /* vms.c */
2117
 
/* int    open_outfile        OF((__GPRO));           * (see fileio.c) vms.c */
2118
 
/* int    flush               OF((__GPRO__ uch *rawbuf, unsigned size,
2119
 
                                  int final_flag));   * (see fileio.c) vms.c */
2120
 
#ifdef RETURN_CODES
2121
 
   void   return_VMS          OF((__GPRO__ int zip_error));         /* vms.c */
2122
 
#else
2123
 
   void   return_VMS          OF((int zip_error));                  /* vms.c */
2124
 
#endif
2125
 
#ifdef VMSCLI
2126
 
   ulg    vms_unzip_cmdline   OF((int *, char ***));            /* cmdline.c */
2127
 
   int    VMSCLI_usage        OF((__GPRO__ int error));         /* cmdline.c */
2128
 
#endif
2129
 
#endif
2130
 
 
2131
 
/*---------------------------------------------------------------------------
2132
 
    WIN32-only functions:
2133
 
  ---------------------------------------------------------------------------*/
2134
 
 
2135
 
#ifdef WIN32
2136
 
   int   IsWinNT        OF((void));                               /* win32.c */
2137
 
#ifdef NTSD_EAS
2138
 
   void  process_defer_NT     OF((__GPRO));                       /* win32.c */
2139
 
   int   test_NTSD      OF((__GPRO__ uch *eb, unsigned eb_size,
2140
 
                            uch *eb_ucptr, ulg eb_ucsize));       /* win32.c */
2141
 
#  define TEST_NTSD     test_NTSD
2142
 
#endif
2143
 
#ifdef W32_STAT_BANDAID
2144
 
   int   zstat_win32    OF((__W32STAT_GLOBALS__
2145
 
                            const char *path, struct stat *buf)); /* win32.c */
2146
 
#endif
2147
 
#endif
2148
 
 
2149
 
/*---------------------------------------------------------------------------
2150
 
    Miscellaneous/shared functions:
2151
 
  ---------------------------------------------------------------------------*/
2152
 
 
2153
 
Uz_Globs *globalsCtor    OF((void));                            /* globals.c */
2154
 
 
2155
 
int      envargs         OF((int *Pargc, char ***Pargv,
2156
 
                             ZCONST char *envstr, ZCONST char *envstr2));
2157
 
                                                                /* envargs.c */
2158
 
void     mksargs         OF((int *argcp, char ***argvp));       /* envargs.c */
2159
 
 
2160
 
int      match           OF((ZCONST char *s, ZCONST char *p,
2161
 
                             int ic __WDLPRO));                   /* match.c */
2162
 
int      iswild          OF((ZCONST char *p));                    /* match.c */
2163
 
 
2164
 
#ifdef DYNALLOC_CRCTAB
2165
 
   void     free_crc_table  OF((void));                          /* crctab.c */
2166
 
#endif
2167
 
#ifndef USE_ZLIB
2168
 
   ZCONST ulg near *get_crc_table  OF((void));         /* funzip.c, crctab.c */
2169
 
   ulg      crc32           OF((ulg crc, ZCONST uch *buf, extent len));
2170
 
#endif /* !USE_ZLIB */                        /* assembler source or crc32.c */
2171
 
 
2172
 
int      dateformat      OF((void));                                /* local */
2173
 
char     dateseparator   OF((void));                                /* local */
2174
 
#ifndef WINDLL
2175
 
   void  version         OF((__GPRO));                              /* local */
2176
 
#endif
2177
 
int      mapattr         OF((__GPRO));                              /* local */
2178
 
int      mapname         OF((__GPRO__ int renamed));                /* local */
2179
 
int      checkdir        OF((__GPRO__ char *pathcomp, int flag));   /* local */
2180
 
char    *do_wild         OF((__GPRO__ ZCONST char *wildzipfn));     /* local */
2181
 
char    *GetLoadPath     OF((__GPRO));                              /* local */
2182
 
#if (defined(MORE) && (defined(ATH_BEO_UNX) || defined(QDOS) || defined(VMS)))
2183
 
   int screensize        OF((int *tt_rows, int *tt_cols));          /* local */
2184
 
# if defined(VMS)
2185
 
   int screenlinewrap    OF((void));                                /* local */
2186
 
# endif
2187
 
#endif /* MORE && (ATH_BEO_UNX || QDOS || VMS) */
2188
 
#ifdef OS2_W32
2189
 
   int   SetFileSize     OF((FILE *file, ulg filesize));            /* local */
2190
 
#endif
2191
 
#ifndef MTS /* macro in MTS */
2192
 
   void  close_outfile   OF((__GPRO));                              /* local */
2193
 
#endif
2194
 
#ifdef SET_SYMLINK_ATTRIBS
2195
 
   int  set_symlnk_attribs  OF((__GPRO__ slinkentry *slnk_entry));  /* local */
2196
 
#endif
2197
 
#ifdef SET_DIR_ATTRIB
2198
 
   int   defer_dir_attribs  OF((__GPRO__ direntry **pd));           /* local */
2199
 
   int   set_direc_attribs  OF((__GPRO__ direntry *d));             /* local */
2200
 
#endif
2201
 
#ifdef TIMESTAMP
2202
 
# ifdef WIN32
2203
 
   int   stamp_file      OF((__GPRO__
2204
 
                             ZCONST char *fname, time_t modtime));  /* local */
2205
 
# else
2206
 
   int   stamp_file      OF((ZCONST char *fname, time_t modtime));  /* local */
2207
 
# endif
2208
 
#endif
2209
 
#if (defined(MALLOC_WORK) && defined(MY_ZCALLOC))
2210
 
   zvoid far *zcalloc    OF((unsigned int, unsigned int));
2211
 
   zvoid zcfree          OF((zvoid far *));
2212
 
#endif /* MALLOC_WORK && MY_ZCALLOC */
2213
 
#ifdef SYSTEM_SPECIFIC_CTOR
2214
 
   void  SYSTEM_SPECIFIC_CTOR   OF((__GPRO));                       /* local */
2215
 
#endif
2216
 
#ifdef SYSTEM_SPECIFIC_DTOR
2217
 
   void  SYSTEM_SPECIFIC_DTOR   OF((__GPRO));                       /* local */
2218
 
#endif
2219
 
 
2220
 
 
2221
 
 
2222
 
 
2223
 
 
2224
 
/************/
2225
 
/*  Macros  */
2226
 
/************/
2227
 
 
2228
 
#ifndef MAX
2229
 
#  define MAX(a,b)   ((a) > (b) ? (a) : (b))
2230
 
#endif
2231
 
#ifndef MIN
2232
 
#  define MIN(a,b)   ((a) < (b) ? (a) : (b))
2233
 
#endif
2234
 
 
2235
 
#ifdef DEBUG
2236
 
#  if (defined(THEOS) && defined(NO_BOGUS_SPC))
2237
 
#    define NO_DEBUG_IN_MACROS
2238
 
#    define Trace(x)   _fprintf x
2239
 
#  else
2240
 
#    define Trace(x)   fprintf x
2241
 
#  endif
2242
 
#else
2243
 
#  define Trace(x)
2244
 
#endif
2245
 
 
2246
 
#ifdef DEBUG_TIME
2247
 
#  define TTrace(x)  fprintf x
2248
 
#else
2249
 
#  define TTrace(x)
2250
 
#endif
2251
 
 
2252
 
#ifdef NO_DEBUG_IN_MACROS
2253
 
#  define MTrace(x)
2254
 
#else
2255
 
#  define MTrace(x)  Trace(x)
2256
 
#endif
2257
 
 
2258
 
#if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
2259
 
#  define ToLower(x)   ((char)(isupper((int)x)? tolower((int)x) : x))
2260
 
#else
2261
 
#  define ToLower      tolower          /* assumed "smart"; used in match() */
2262
 
#endif
2263
 
 
2264
 
#ifdef USE_STRM_INPUT
2265
 
   /* ``Replace'' the unbuffered UNIX style I/O function with similar
2266
 
    * standard C functions from <stdio.h>.
2267
 
    */
2268
 
#  define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
2269
 
#  define lseek(fd,o,w) fseek((FILE *)(fd),(o),(w))
2270
 
#  define close(fd) fclose((FILE *)(fd))
2271
 
#endif /* USE_STRM_INPUT */
2272
 
 
2273
 
/* The return value of the Info() "macro function" is never checked in
2274
 
 * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
2275
 
 * Info() definition for "FUNZIP" would have to be corrected:
2276
 
 * #define Info(buf,flag,sprf_arg) \
2277
 
 *      (fprintf((flag)&1? stderr : stdout, \
2278
 
 *               (char *)(sprintf sprf_arg, (buf))) == EOF)
2279
 
 */
2280
 
#ifndef Info   /* may already have been defined for redirection */
2281
 
#  ifdef FUNZIP
2282
 
#    define Info(buf,flag,sprf_arg) \
2283
 
     fprintf((flag)&1? stderr : stdout, (char *)(sprintf sprf_arg, (buf)))
2284
 
#  else
2285
 
#    ifdef INT_SPRINTF  /* optimized version for "int sprintf()" flavour */
2286
 
#      define Info(buf,flag,sprf_arg) \
2287
 
       (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
2288
 
#    else          /* generic version, does not use sprintf() return value */
2289
 
#      define Info(buf,flag,sprf_arg) \
2290
 
       (*G.message)((zvoid *)&G, (uch *)(buf), \
2291
 
                     (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
2292
 
#    endif
2293
 
#  endif
2294
 
#endif /* !Info */
2295
 
 
2296
 
/*  The following macro wrappers around the fnfilter function are used many
2297
 
 *  times to prepare archive entry names or name components for displaying
2298
 
 *  listings and (warning/error) messages. They use sections in the upper half
2299
 
 *  of 'slide' as buffer, since their output is normally fed through the
2300
 
 *  Info() macro with 'slide' (the start of this area) as message buffer.
2301
 
 */
2302
 
#define FnFilter1(fname)  fnfilter((fname), slide + (WSIZE>>1))
2303
 
#define FnFilter2(fname)  fnfilter((fname), slide + ((WSIZE>>1) + (WSIZE>>2)))
2304
 
 
2305
 
#ifndef FUNZIP   /* used only in inflate.c */
2306
 
#  define MESSAGE(str,len,flag)  (*G.message)((zvoid *)&G,(str),(len),(flag))
2307
 
#endif
2308
 
 
2309
 
#if 0            /* Optimization: use the (const) result of crc32(0L,NULL,0) */
2310
 
#  define CRCVAL_INITIAL  crc32(0L, NULL, 0)
2311
 
#else
2312
 
#  define CRCVAL_INITIAL  0L
2313
 
#endif
2314
 
 
2315
 
#ifndef TEST_NTSD               /* "NTSD valid?" checking function */
2316
 
#  define TEST_NTSD     NULL    /*   ... is not available */
2317
 
#endif
2318
 
 
2319
 
#define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
2320
 
  {error_in_archive=error; if(error>1) return error;}
2321
 
 
2322
 
/*
2323
 
 *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
2324
 
 *  and unzip.c in several functions.
2325
 
 *
2326
 
 *  macro SKIP_(length)
2327
 
 *      ush length;
2328
 
 *  {
2329
 
 *      if (length && ((error = do_string(length, SKIP)) != 0)) {
2330
 
 *          error_in_archive = error;   /-* might be warning *-/
2331
 
 *          if (error > 1)              /-* fatal *-/
2332
 
 *              return (error);
2333
 
 *      }
2334
 
 *  }
2335
 
 *
2336
 
 */
2337
 
 
2338
 
 
2339
 
#ifdef FUNZIP
2340
 
#  define FLUSH(w)  flush(__G__ (ulg)(w))
2341
 
#  define NEXTBYTE  getc(G.in)   /* redefined in crypt.h if full version */
2342
 
#else
2343
 
#  define FLUSH(w)  ((G.mem_mode) ? memflush(__G__ redirSlide,(ulg)(w)) \
2344
 
                                  : flush(__G__ redirSlide,(ulg)(w),0))
2345
 
#  define NEXTBYTE  (G.incnt-- > 0 ? (int)(*G.inptr++) : readbyte(__G))
2346
 
#endif
2347
 
 
2348
 
 
2349
 
#define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
2350
 
  while (G.bits_left<=8*(int)(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
2351
 
  G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
2352
 
  zdest=(shrint)((unsigned)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
2353
 
  G.bits_left-=nbits;}
2354
 
 
2355
 
/*
2356
 
 * macro READBITS(nbits,zdest)    * only used by unreduce and unshrink *
2357
 
 *  {
2358
 
 *      if (nbits > G.bits_left) {  * fill G.bitbuf, 8*sizeof(ulg) bits *
2359
 
 *          int temp;
2360
 
 *
2361
 
 *          G.zipeof = 1;
2362
 
 *          while (G.bits_left <= 8*(int)(sizeof(G.bitbuf)-1) &&
2363
 
 *                 (temp = NEXTBYTE) != EOF) {
2364
 
 *              G.bitbuf |= (ulg)temp << G.bits_left;
2365
 
 *              G.bits_left += 8;
2366
 
 *              G.zipeof = 0;
2367
 
 *          }
2368
 
 *      }
2369
 
 *      zdest = (shrint)((unsigned)G.bitbuf & mask_bits[nbits]);
2370
 
 *      G.bitbuf >>= nbits;
2371
 
 *      G.bits_left -= nbits;
2372
 
 *  }
2373
 
 *
2374
 
 */
2375
 
 
2376
 
 
2377
 
/* GRR:  should use StringLower for STRLOWER macro if possible */
2378
 
 
2379
 
/*
2380
 
 *  Copy the zero-terminated string in str1 into str2, converting any
2381
 
 *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
2382
 
 *  as well, of course.  str1 and str2 may be the same character array.
2383
 
 */
2384
 
#ifdef _MBCS
2385
 
#  define STRLOWER(str1, str2) \
2386
 
   { \
2387
 
       char  *p, *q, c; unsigned i; \
2388
 
       p = (char *)(str1); \
2389
 
       q = (char *)(str2); \
2390
 
       while ((c = *p) != '\0') { \
2391
 
           if ((i = CLEN(p)) > 1) { \
2392
 
               while (i--) *q++ = *p++; \
2393
 
           } else { \
2394
 
               *q++ = (char)(isupper((int)(c))? tolower((int)(c)) : c); \
2395
 
               p++; \
2396
 
           } \
2397
 
       } \
2398
 
       *q = '\0'; \
2399
 
   }
2400
 
#else
2401
 
#  define STRLOWER(str1, str2) \
2402
 
   { \
2403
 
       char  *p, *q; \
2404
 
       p = (char *)(str1) - 1; \
2405
 
       q = (char *)(str2); \
2406
 
       while (*++p) \
2407
 
           *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
2408
 
       *q = '\0'; \
2409
 
   }
2410
 
#endif
2411
 
/*
2412
 
 *  NOTES:  This macro makes no assumptions about the characteristics of
2413
 
 *    the tolower() function or macro (beyond its existence), nor does it
2414
 
 *    make assumptions about the structure of the character set (i.e., it
2415
 
 *    should work on EBCDIC machines, too).  The fact that either or both
2416
 
 *    of isupper() and tolower() may be macros has been taken into account;
2417
 
 *    watch out for "side effects" (in the C sense) when modifying this
2418
 
 *    macro.
2419
 
 */
2420
 
 
2421
 
#ifndef foreign
2422
 
#  define foreign(c)  (c)
2423
 
#endif
2424
 
 
2425
 
#ifndef native
2426
 
#  define native(c)   (c)
2427
 
#  define A_TO_N(str1)
2428
 
#else
2429
 
#  ifndef NATIVE
2430
 
#    define NATIVE     "native chars"
2431
 
#  endif
2432
 
#  define A_TO_N(str1) {register uch *p;\
2433
 
     for (p=(uch *)(str1); *p; p++) *p=native(*p);}
2434
 
#endif
2435
 
/*
2436
 
 *  Translate the zero-terminated string in str1 from ASCII to the native
2437
 
 *  character set. The translation is performed in-place and uses the
2438
 
 *  "native" macro to translate each character.
2439
 
 *
2440
 
 *  NOTE:  Using the "native" macro means that is it the only part of unzip
2441
 
 *    which knows which translation table (if any) is actually in use to
2442
 
 *    produce the native character set.  This makes adding new character set
2443
 
 *    translation tables easy, insofar as all that is needed is an appropriate
2444
 
 *    "native" macro definition and the translation table itself.  Currently,
2445
 
 *    the only non-ASCII native character set implemented is EBCDIC, but this
2446
 
 *    may not always be so.
2447
 
 */
2448
 
 
2449
 
 
2450
 
/* default setup for internal codepage: assume ISO 8859-1 compatibility!! */
2451
 
#if (!defined(NATIVE) && !defined(CRTL_CP_IS_ISO) && !defined(CRTL_CP_IS_OEM))
2452
 
#  define CRTL_CP_IS_ISO
2453
 
#endif
2454
 
 
2455
 
 
2456
 
/*  Translate "extended ASCII" chars (OEM coding for DOS and OS/2; else
2457
 
 *  ISO-8859-1 [ISO Latin 1, Win Ansi,...]) into the internal "native"
2458
 
 *  code page.  As with A_TO_N(), conversion is done in place.
2459
 
 */
2460
 
#ifndef _ISO_INTERN
2461
 
#  ifdef CRTL_CP_IS_OEM
2462
 
#    ifndef IZ_ISO2OEM_ARRAY
2463
 
#      define IZ_ISO2OEM_ARRAY
2464
 
#    endif
2465
 
#    define _ISO_INTERN(str1) {register uch *p;\
2466
 
       for (p=(uch *)(str1); *p; p++)\
2467
 
         *p = native((*p & 0x80) ? iso2oem[*p & 0x7f] : *p);}
2468
 
#  else
2469
 
#    define _ISO_INTERN(str1)   A_TO_N(str1)
2470
 
#  endif
2471
 
#endif
2472
 
 
2473
 
#ifndef _OEM_INTERN
2474
 
#  ifdef CRTL_CP_IS_OEM
2475
 
#    define _OEM_INTERN(str1)   A_TO_N(str1)
2476
 
#  else
2477
 
#    ifndef IZ_OEM2ISO_ARRAY
2478
 
#      define IZ_OEM2ISO_ARRAY
2479
 
#    endif
2480
 
#    define _OEM_INTERN(str1) {register uch *p;\
2481
 
       for (p=(uch *)(str1); *p; p++)\
2482
 
         *p = native((*p & 0x80) ? oem2iso[*p & 0x7f] : *p);}
2483
 
#  endif
2484
 
#endif
2485
 
 
2486
 
#ifndef STR_TO_ISO
2487
 
#  ifdef CRTL_CP_IS_ISO
2488
 
#    define STR_TO_ISO          strcpy
2489
 
#  else
2490
 
#    define STR_TO_ISO          str2iso
2491
 
#    define NEED_STR2ISO
2492
 
#  endif
2493
 
#endif
2494
 
 
2495
 
#ifndef STR_TO_OEM
2496
 
#  ifdef CRTL_CP_IS_OEM
2497
 
#    define STR_TO_OEM          strcpy
2498
 
#  else
2499
 
#    define STR_TO_OEM          str2oem
2500
 
#    define NEED_STR2OEM
2501
 
#  endif
2502
 
#endif
2503
 
 
2504
 
#if (!defined(INTERN_TO_ISO) && !defined(ASCII2ISO))
2505
 
#  ifdef CRTL_CP_IS_OEM
2506
 
     /* know: "ASCII" is "OEM" */
2507
 
#    define ASCII2ISO(c) (((c) & 0x80) ? oem2iso[(c) & 0x7f] : (c))
2508
 
#    if (defined(NEED_STR2ISO) && !defined(CRYP_USES_OEM2ISO))
2509
 
#      define CRYP_USES_OEM2ISO
2510
 
#    endif
2511
 
#  else
2512
 
     /* assume: "ASCII" is "ISO-ANSI" */
2513
 
#    define ASCII2ISO(c) (c)
2514
 
#  endif
2515
 
#endif
2516
 
 
2517
 
#if (!defined(INTERN_TO_OEM) && !defined(ASCII2OEM))
2518
 
#  ifdef CRTL_CP_IS_OEM
2519
 
     /* know: "ASCII" is "OEM" */
2520
 
#    define ASCII2OEM(c) (c)
2521
 
#  else
2522
 
     /* assume: "ASCII" is "ISO-ANSI" */
2523
 
#    define ASCII2OEM(c) (((c) & 0x80) ? iso2oem[(c) & 0x7f] : (c))
2524
 
#    if (defined(NEED_STR2OEM) && !defined(CRYP_USES_ISO2OEM))
2525
 
#      define CRYP_USES_ISO2OEM
2526
 
#    endif
2527
 
#  endif
2528
 
#endif
2529
 
 
2530
 
/* codepage conversion setup for testp() in crypt.c */
2531
 
#ifdef CRTL_CP_IS_ISO
2532
 
#  ifndef STR_TO_CP2
2533
 
#    define STR_TO_CP2  STR_TO_OEM
2534
 
#  endif
2535
 
#else
2536
 
#  ifdef CRTL_CP_IS_OEM
2537
 
#    ifndef STR_TO_CP2
2538
 
#      define STR_TO_CP2  STR_TO_ISO
2539
 
#    endif
2540
 
#  else /* native internal CP is neither ISO nor OEM */
2541
 
#    ifndef STR_TO_CP1
2542
 
#      define STR_TO_CP1  STR_TO_ISO
2543
 
#    endif
2544
 
#    ifndef STR_TO_CP2
2545
 
#      define STR_TO_CP2  STR_TO_OEM
2546
 
#    endif
2547
 
#  endif
2548
 
#endif
2549
 
 
2550
 
 
2551
 
/* Convert filename (and file comment string) into "internal" charset.
2552
 
 * This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
2553
 
 * codepage when made on
2554
 
 *  -> DOS (this includes 16-bit Windows 3.1)  (FS_FAT_)
2555
 
 *  -> OS/2                                    (FS_HPFS_)
2556
 
 *  -> Win95/WinNT with Nico Mak's WinZip      (FS_NTFS_ && hostver == "5.0")
2557
 
 * EXCEPTIONS:
2558
 
 *  PKZIP for Windows 2.5, 2.6, and 4.0 flag their entries as "FS_FAT_", but
2559
 
 *  the filename stored in the local header is coded in Windows ANSI (CP 1252
2560
 
 *  resp. ISO 8859-1 on US and western Europe locale settings).
2561
 
 *  Likewise, PKZIP for UNIX 2.51 flags its entries as "FS_FAT_", but the
2562
 
 *  filenames stored in BOTH the local and the central header are coded
2563
 
 *  in the local system's codepage (usually ANSI codings like ISO 8859-1).
2564
 
 *
2565
 
 * All other ports are assumed to code zip entry filenames in ISO 8859-1.
2566
 
 */
2567
 
#ifndef Ext_ASCII_TO_Native
2568
 
#  define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
2569
 
    if (((hostnum) == FS_FAT_ && \
2570
 
         !(((islochdr) || (isuxatt)) && \
2571
 
           ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
2572
 
        (hostnum) == FS_HPFS_ || \
2573
 
        ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
2574
 
        _OEM_INTERN((string)); \
2575
 
    } else { \
2576
 
        _ISO_INTERN((string)); \
2577
 
    }
2578
 
#endif
2579
 
 
2580
 
 
2581
 
 
2582
 
/**********************/
2583
 
/*  Global constants  */
2584
 
/**********************/
2585
 
 
2586
 
   extern ZCONST unsigned near mask_bits[17];
2587
 
   extern ZCONST char *fnames[2];
2588
 
 
2589
 
#ifdef EBCDIC
2590
 
   extern ZCONST uch ebcdic[];
2591
 
#endif
2592
 
#ifdef IZ_ISO2OEM_ARRAY
2593
 
   extern ZCONST uch Far iso2oem[];
2594
 
#endif
2595
 
#ifdef IZ_OEM2ISO_ARRAY
2596
 
   extern ZCONST uch Far oem2iso[];
2597
 
#endif
2598
 
 
2599
 
   extern ZCONST char Far  VersionDate[];
2600
 
   extern ZCONST char Far  CentSigMsg[];
2601
 
#ifndef SFX
2602
 
   extern ZCONST char Far  EndSigMsg[];
2603
 
#endif
2604
 
   extern ZCONST char Far  SeekMsg[];
2605
 
   extern ZCONST char Far  FilenameNotMatched[];
2606
 
   extern ZCONST char Far  ExclFilenameNotMatched[];
2607
 
   extern ZCONST char Far  ReportMsg[];
2608
 
 
2609
 
#ifndef SFX
2610
 
   extern ZCONST char Far  Zipnfo[];
2611
 
   extern ZCONST char Far  CompiledWith[];
2612
 
#endif /* !SFX */
2613
 
 
2614
 
 
2615
 
 
2616
 
/***********************************/
2617
 
/*  Global (shared?) RTL variables */
2618
 
/***********************************/
2619
 
 
2620
 
#ifdef DECLARE_ERRNO
2621
 
   extern int             errno;
2622
 
#endif
2623
 
 
2624
 
 
2625
 
#endif /* !__unzpriv_h */