~ubuntu-branches/ubuntu/quantal/unzip/quantal-proposed

« back to all changes in this revision

Viewing changes to .pc/05-unzip60-alt-iconv-utf8/unzpriv.h

  • Committer: Package Import Robot
  • Author(s): Logan Rosen
  • Date: 2012-08-05 21:31:45 UTC
  • mfrom: (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20120805213145-yjn97p3843amjk91
Tags: 6.0-7ubuntu1
* Merge from Debian unstable. Remaining change:
  - Added patch from archlinux which adds the -O option allowing a charset
  to be specified for the proper unzipping of non-latin and non-unicode
  filenames.
* Merge adds Multi-Arch: foreign. (LP: #1010450)

Show diffs side-by-side

added added

removed removed

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