-
Notifications
You must be signed in to change notification settings - Fork 1
/
unzpriv.h
3123 lines (2719 loc) · 107 KB
/
unzpriv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2009-Jan-02 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
unzpriv.h
This header file contains private (internal) macros, typedefs, prototypes
and global-variable declarations used by all of the UnZip source files.
In a prior life it was part of the main unzip.h header, but now it is only
included by that header if UNZIP_INTERNAL is defined.
---------------------------------------------------------------------------*/
#ifndef __unzpriv_h /* prevent multiple inclusions */
#define __unzpriv_h
/* First thing: Signal all following code that we compile UnZip utilities! */
#ifndef UNZIP
# define UNZIP
#endif
/* GRR 960204: MORE defined here in preparation for removal altogether */
#ifndef MORE
# ifndef RISCOS
# define MORE
# endif
#endif
/* fUnZip should never need to be reentrant */
#ifdef FUNZIP
# ifdef REENTRANT
# undef REENTRANT
# endif
# ifdef DLL
# undef DLL
# endif
# ifdef SFX /* fUnZip is NOT the sfx stub! */
# undef SFX
# endif
# ifdef USE_BZIP2 /* fUnZip does not support bzip2 decompression */
# undef USE_BZIP2
# endif
#endif
#if (defined(USE_ZLIB) && !defined(HAVE_ZL_INFLAT64) && !defined(NO_DEFLATE64))
/* zlib does not (yet?) provide Deflate64(tm) support */
# define NO_DEFLATE64
#endif
#ifdef NO_DEFLATE64
/* disable support for Deflate64(tm) */
# ifdef USE_DEFLATE64
# undef USE_DEFLATE64
# endif
#else
/* enable Deflate64(tm) support unless compiling for SFX stub */
# if (!defined(USE_DEFLATE64) && !defined(SFX))
# define USE_DEFLATE64
# endif
#endif
/* disable bzip2 support for SFX stub, unless explicitly requested */
#if (defined(SFX) && !defined(BZIP2_SFX) && defined(USE_BZIP2))
# undef USE_BZIP2
#endif
#if (defined(NO_VMS_TEXT_CONV) || defined(VMS))
# ifdef VMS_TEXT_CONV
# undef VMS_TEXT_CONV
# endif
#else
# if (!defined(VMS_TEXT_CONV) && !defined(SFX))
# define VMS_TEXT_CONV
# endif
#endif
/* Enable -B option per default on specific systems, to allow backing up
* files that would be overwritten.
* (This list of systems must be kept in sync with the list of systems
* that add the B_flag to the UzpOpts structure, see unzip.h.)
*/
#if (!defined(NO_UNIXBACKUP) && !defined(UNIXBACKUP))
# if defined(UNIX) || defined(OS2) || defined(WIN32)
# define UNIXBACKUP
# endif
#endif
#if (defined(DLL) && !defined(REENTRANT))
# define REENTRANT
#endif
#if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
# define DYNAMIC_CRC_TABLE
#endif
#if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
# ifndef DYNALLOC_CRCTAB
# define DYNALLOC_CRCTAB
# endif
#endif
/*---------------------------------------------------------------------------
OS-dependent configuration for UnZip internals
---------------------------------------------------------------------------*/
/* Some compiler distributions for Win32/i386 systems try to emulate
* a Unix (POSIX-compatible) environment.
*/
#if (defined(WIN32) && defined(UNIX))
/* UnZip does not support merging both ports in a single executable. */
# if (defined(FORCE_WIN32_OVER_UNIX) && defined(FORCE_UNIX_OVER_WIN32))
/* conflicting choice requests -> we prefer the Win32 environment */
# undef FORCE_UNIX_OVER_WIN32
# endif
# ifdef FORCE_WIN32_OVER_UNIX
/* native Win32 support was explicitly requested... */
# undef UNIX
# else
/* use the POSIX (Unix) emulation features by default... */
# undef WIN32
# endif
#endif
/* bad or (occasionally?) missing stddef.h: */
#if (defined(M_XENIX) || defined(DNIX))
# define NO_STDDEF_H
#endif
#if (defined(M_XENIX) && !defined(M_UNIX)) /* SCO Xenix only, not SCO Unix */
# define SCO_XENIX
# define NO_LIMITS_H /* no limits.h, but MODERN defined */
# define NO_UID_GID /* no uid_t/gid_t */
# define size_t int
#endif
#ifdef realix /* Modcomp Real/IX, real-time SysV.3 variant */
# define SYSV
# define NO_UID_GID /* no uid_t/gid_t */
#endif
#if (defined(_AIX) && !defined(_ALL_SOURCE))
# define _ALL_SOURCE
#endif
#if defined(apollo) /* defines __STDC__ */
# define NO_STDLIB_H
#endif
#ifdef DNIX
# define SYSV
# define SHORT_NAMES /* 14-char limitation on path components */
/* # define FILENAME_MAX 14 */
# define FILENAME_MAX NAME_MAX /* GRR: experiment */
#endif
#if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
# ifndef SYSV
# define SYSV
# endif
#endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
#if (defined(M_SYSV) || defined(M_SYS5))
# ifndef SYSV
# define SYSV
# endif
#endif /* M_SYSV || M_SYS5 */
/* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
#if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
# ifndef SYSV
# define SYSV
# endif
#endif /* __SVR4 || __svr4__ || sgi || __hpux */
#if (defined(LINUX) || defined(__QNX__))
# ifndef SYSV
# define SYSV
# endif
#endif /* LINUX || __QNX__ */
#if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
# if (!defined(BSD) && !defined(SYSV))
# define BSD
# endif
#endif /* ultrix || __ultrix || bsd4_2 */
#if (defined(sun) || defined(pyr) || defined(CONVEX))
# if (!defined(BSD) && !defined(SYSV))
# define BSD
# endif
#endif /* sun || pyr || CONVEX */
#ifdef pyr /* Pyramid: has BSD and AT&T "universes" */
# ifdef BSD
# define pyr_bsd
# define USE_STRINGS_H /* instead of more common string.h */
# define ZMEM /* ZMEM now uses bcopy/bzero: not in AT&T universe */
# endif /* (AT&T memcpy claimed to be very slow, though) */
# define DECLARE_ERRNO
#endif /* pyr */
/* stat() bug for Borland, VAX C RTL, and Atari ST MiNT on TOS
* filesystems: returns 0 for wildcards! (returns 0xffffffff on Minix
* filesystem or `U:' drive under Atari MiNT.) Watcom C was previously
* included on this list; it would be good to know what version the problem
* was fixed at, if it did exist. */
#if (defined(__TURBOC__) && !defined(WIN32))
/*# define WILD_STAT_BUG*/
#endif
#if (defined(VMS) || defined(__MINT__))
# define WILD_STAT_BUG
#endif
/*---------------------------------------------------------------------------
OS-dependent includes
---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
API (DLL) section:
---------------------------------------------------------------------------*/
#ifdef DLL
# define MAIN UZ_EXP UzpMain /* was UzpUnzip */
# ifdef OS2DLL
# undef Info
# define REDIRECTC(c) varputchar(__G__ c)
# define REDIRECTPRINT(buf,size) varmessage(__G__ buf, size)
# define FINISH_REDIRECT() finish_REXX_redirect(__G)
# else
# define REDIRECTC(c)
# define REDIRECTPRINT(buf,size) 0
# define FINISH_REDIRECT() close_redirect(__G)
# endif
#endif
/*---------------------------------------------------------------------------
Acorn RISCOS section:
---------------------------------------------------------------------------*/
#ifdef RISCOS
# include "acorn/riscos.h"
#endif
/*---------------------------------------------------------------------------
Amiga section:
---------------------------------------------------------------------------*/
#ifdef AMIGA
# include "amiga/amiga.h"
#endif
/*---------------------------------------------------------------------------
AOS/VS section (somewhat similar to Unix, apparently):
---------------------------------------------------------------------------*/
#ifdef AOS_VS
# ifdef __FILEIO_C
# include "aosvs/aosvs.h"
# endif
#endif
/*---------------------------------------------------------------------------
Atari ST section:
---------------------------------------------------------------------------*/
#ifdef ATARI
# include <time.h>
# include <stat.h>
# include <fcntl.h>
# include <limits.h>
# define SYMLINKS
# define EXE_EXTENSION ".tos"
# ifndef DATE_FORMAT
# define DATE_FORMAT DF_DMY
# endif
# define DIR_END '/'
# define INT_SPRINTF
# define timezone _timezone
# define lenEOL 2
# define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
# undef SHORT_NAMES
# if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
# define TIMESTAMP
# endif
#endif
/*---------------------------------------------------------------------------
AtheOS section:
---------------------------------------------------------------------------*/
#ifdef __ATHEOS__
# include "atheos/athcfg.h"
#endif
/*---------------------------------------------------------------------------
BeOS section:
---------------------------------------------------------------------------*/
#ifdef __BEOS__
# include "beos/beocfg.h"
#endif
/*---------------------------------------------------------------------------
Human68k/X680x0 section:
---------------------------------------------------------------------------*/
#ifdef __human68k__
/* DO NOT DEFINE DOS_OS2 HERE! If Human68k is so much */
/* like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
# if (!defined(_MBCS) && !defined(NO_MBCS))
/* enable MBCS support by default for this system */
# define _MBCS
# endif
# if (defined(_MBCS) && defined(NO_MBCS))
/* disable MBCS support when explicitely requested */
# undef _MBCS
# endif
# include <time.h>
# include <fcntl.h>
# include <io.h>
# include <conio.h>
# include <sys/stat.h>
# ifdef HAVE_MBSTRING_H
# include <mbstring.h>
# endif
# ifdef HAVE_MBCTYPE_H
# include <mbctype.h>
# else
# ifndef _ismbblead
# define _ismbblead(c) (0x80 <= (c) && ((c) < 0xa0 || 0xe0 <= (c)))
# endif
# endif
# ifndef DATE_FORMAT
# define DATE_FORMAT DF_YMD /* Japanese standard */
# endif
# define lenEOL 1
# define PutNativeEOL *q++ = native(LF);
# define INT_SPRINTF
# define SYMLINKS
# ifdef SFX
# define MAIN main_sfx
# endif
#endif
/*---------------------------------------------------------------------------
Mac section:
---------------------------------------------------------------------------*/
#ifdef MACOS
# include "maccfg.h"
#endif /* MACOS */
/*---------------------------------------------------------------------------
MS-DOS, OS/2, FLEXOS section:
---------------------------------------------------------------------------*/
#ifdef WINDLL
# ifdef MORE
# undef MORE
# endif
# ifdef OS2_EAS
# undef OS2_EAS
# endif
#endif
#if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
# ifndef MSC
# define MSC /* This should work for older MSC, too! */
# endif
#endif
#if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
# include <sys/types.h> /* off_t, time_t, dev_t, ... */
# include <sys/stat.h>
# include <io.h> /* lseek(), open(), setftime(), dup(), creat() */
# include <time.h> /* localtime() */
# include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
# ifdef OS2 /* defined for all OS/2 compilers */
# include "os2/os2cfg.h"
# else
# ifdef FLEXOS
# include "flexos/flxcfg.h"
# else
# include "msdos/doscfg.h"
# endif
# endif
# if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
/*
* ARGH. MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
* 1970 Jan 1 00:00. So we have to diddle time_t's appropriately: add or
* subtract 70 years' worth of seconds; i.e., number of days times 86400;
* i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
* (25550 + 17 + 1) * 86400 == 2209075200 seconds. We know time_t is an
* unsigned long (ulg) on the only system with this bug.
*/
# define TIMET_TO_NATIVE(x) (x) += (ulg)2209075200L;
# define NATIVE_TO_TIMET(x) (x) -= (ulg)2209075200L;
# endif
# if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
# define timezone _timezone
# endif
# if (defined(__GO32__) || defined(FLEXOS))
# define DIR_END '/'
# else
# define DIR_END '\\' /* OS uses '\\' as directory separator */
# define DIR_END2 '/' /* also check for '/' (RTL may convert) */
# endif
# ifdef DATE_FORMAT
# undef DATE_FORMAT
# endif
# define DATE_FORMAT dateformat()
# define lenEOL 2
# define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
# if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
# define USE_EF_UT_TIME
# endif
#endif /* MSDOS || OS2 || FLEXOS */
/*---------------------------------------------------------------------------
MTS section (piggybacks UNIX, I think):
---------------------------------------------------------------------------*/
#ifdef MTS
# include <sys/types.h> /* off_t, time_t, dev_t, ... */
# include <sys/stat.h>
# include <sys/file.h> /* MTS uses this instead of fcntl.h */
# include <timeb.h>
# include <time.h>
# include <unix.h> /* some important non-ANSI routines */
# define mkdir(s,n) (-1) /* no "make directory" capability */
# define EBCDIC /* set EBCDIC conversion on */
# define NO_STRNICMP /* unzip's is as good the one in MTS */
# define USE_FWRITE
# define close_outfile() fclose(G.outfile) /* can't set time on files */
# define umask(n) /* don't have umask() on MTS */
# define FOPWT "w" /* open file for writing in TEXT mode */
# ifndef DATE_FORMAT
# define DATE_FORMAT DF_MDY
# endif
# define lenEOL 1
# define PutNativeEOL *q++ = native(LF);
#endif /* MTS */
/*---------------------------------------------------------------------------
Novell Netware NLM section
---------------------------------------------------------------------------*/
#ifdef NLM
# include "netware/nlmcfg.h"
#endif
/*---------------------------------------------------------------------------
QDOS section
---------------------------------------------------------------------------*/
#ifdef QDOS
# define DIRENT
# include <fcntl.h>
# include <unistd.h>
# include <sys/stat.h>
# include <time.h>
# include "qdos/izqdos.h"
# ifndef DATE_FORMAT
# define DATE_FORMAT DF_MDY
# endif
# define lenEOL 1
# define PutNativeEOL *q++ = native(LF);
# define DIR_END '_'
# define RETURN QReturn
# undef PATH_MAX
# define PATH_MAX 36
# if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
# define TIMESTAMP
# endif
# define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
# define SCREENWIDTH 80
#endif
/*---------------------------------------------------------------------------
Tandem NSK section:
---------------------------------------------------------------------------*/
#ifdef TANDEM
# include "tandem.h"
# include <fcntl.h>
# ifndef __INT32
/* We are compiling with non-WIDE memory model, int = 16 bits */
# ifndef INT_16BIT
# define INT_16BIT /* report "int" size is 16-bit to inflate setup */
# endif
# ifdef USE_DEFLATE64
/* Following required for 64k WSIZE of Deflate64 support */
# define MED_MEM /* else OUTBUFSIZ is 64K and fails in do_string */
# define INBUFSIZ 8192 /* but larger buffer for real OSes */
# endif
# endif
/* use a single LF delimiter so that writes to 101 text files work */
# define PutNativeEOL *q++ = native(LF);
# define lenEOL 1
# ifndef DATE_FORMAT
# define DATE_FORMAT DF_DMY
# endif
# define SCREENLINES 25
/* USE_EF_UT_TIME is set in tandem.h */
# define RESTORE_UIDGID
# define NO_STRNICMP
#endif
/*---------------------------------------------------------------------------
THEOS section:
---------------------------------------------------------------------------*/
#ifdef THEOS
# include "theos/thscfg.h"
#endif
/*---------------------------------------------------------------------------
TOPS-20 section:
---------------------------------------------------------------------------*/
#ifdef TOPS20
# include <sys/types.h> /* off_t, time_t, dev_t, ... */
# include <sys/stat.h>
# include <sys/param.h>
# include <sys/time.h>
# include <sys/timeb.h>
# include <sys/file.h>
# include <timex.h>
# include <monsym.h> /* get amazing monsym() macro */
extern int open(), close(), read();
extern int stat(), unlink(), jsys(), fcntl();
extern long lseek(), dup(), creat();
# define strchr index /* GRR: necessary? */
# define strrchr rindex
# define REALLY_SHORT_SYMS
# define NO_MKDIR
# ifndef HAVE_STRNICMP
# define NO_STRNICMP /* probably not provided by TOPS20 C RTL */
# endif
# define DIR_BEG '<'
# define DIR_END '>'
# define DIR_EXT ".directory"
# ifndef DATE_FORMAT
# define DATE_FORMAT DF_MDY
# endif
# define EXE_EXTENSION ".exe" /* just a guess... */
#endif /* TOPS20 */
/*---------------------------------------------------------------------------
Unix section:
---------------------------------------------------------------------------*/
#ifdef UNIX
# include "unix/unxcfg.h"
#endif /* UNIX */
/*---------------------------------------------------------------------------
VM/CMS and MVS section:
---------------------------------------------------------------------------*/
#ifdef CMS_MVS
# include "vmmvs.h"
# define CLOSE_INFILE() close_infile(__G)
#endif
/*---------------------------------------------------------------------------
VMS section:
---------------------------------------------------------------------------*/
#ifdef VMS
# include "vms/vmscfg.h"
#endif /* VMS */
/*---------------------------------------------------------------------------
Win32 (Windows 95/NT) section:
---------------------------------------------------------------------------*/
#if (defined(WIN32) && !defined(POCKET_UNZIP) && !defined(_WIN32_WCE))
# include "win32/w32cfg.h"
#endif
/*---------------------------------------------------------------------------
Win32 Windows CE section (also POCKET_UNZIP)
---------------------------------------------------------------------------*/
#if (defined(_WIN32_WCE) || defined(POCKET_UNZIP))
# include "wince/wcecfg.h"
#endif
/* ----------------------------------------------------------------------------
MUST BE AFTER LARGE FILE INCLUDES
---------------------------------------------------------------------------- */
/* This stuff calls in types and messes up large file includes. It needs to
go after large file defines in local includes.
I am guessing that moving them here probably broke some ports, but hey.
10/31/2004 EG */
/* ----------------------------------------------------------------------------
Common includes
---------------------------------------------------------------------------- */
/* Some ports apply specific adjustments which must be in effect before
reading the "standard" include headers.
*/
#ifdef EFT
# define Z_OFF_T off_t /* Amdahl UTS nonsense ("extended file types") */
#else
#if (defined(UNIX) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
# define Z_OFF_T off_t /* 64bit offsets to support 2GB < zipfile size < 4GB */
#else
# define Z_OFF_T long
#endif
#endif
#ifndef ZOFF_T_DEFINED
typedef Z_OFF_T zoff_t;
# define ZOFF_T_DEFINED
#endif
#ifndef Z_STAT_DEFINED
typedef struct stat z_stat;
# define Z_STAT_DEFINED
#endif
#ifndef MINIX /* Minix needs it after all the other includes (?) */
# include <stdio.h>
#endif
#include <ctype.h> /* skip for VMS, to use tolower() function? */
#include <errno.h> /* used in mapname() */
#ifdef USE_STRINGS_H
# include <strings.h> /* strcpy, strcmp, memcpy, index/rindex, etc. */
#else
# include <string.h> /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
#endif
#if (defined(MODERN) && !defined(NO_LIMITS_H))
# include <limits.h> /* MAX/MIN constant symbols for system types... */
#endif
/* this include must be down here for SysV.4, for some reason... */
#include <signal.h> /* used in unzip.c, fileio.c */
#ifdef MODERN
# ifndef NO_STDDEF_H
# include <stddef.h>
# endif
# ifndef NO_STDLIB_H
# include <stdlib.h> /* standard library prototypes, malloc(), etc. */
# endif
typedef size_t extent;
#else /* !MODERN */
# ifndef AOS_VS /* mostly modern? */
Z_OFF_T lseek();
# ifdef VAXC /* not fully modern, but has stdlib.h and void */
# include <stdlib.h>
# else
char *malloc();
# endif /* ?VAXC */
# endif /* !AOS_VS */
typedef unsigned int extent;
#endif /* ?MODERN */
/*************/
/* Defines */
/*************/
#define UNZIP_BZ2VERS 46
#ifdef ZIP64_SUPPORT
# ifdef USE_BZIP2
# define UNZIP_VERSION UNZIP_BZ2VERS
# else
# define UNZIP_VERSION 45
# endif
#else
#ifdef USE_DEFLATE64
# define UNZIP_VERSION 21 /* compatible with PKUNZIP 4.0 */
#else
# define UNZIP_VERSION 20 /* compatible with PKUNZIP 2.0 */
#endif
#endif
#define VMS_UNZIP_VERSION 42 /* if OS-needed-to-extract is VMS: can do */
#if (defined(MSDOS) || defined(OS2))
# define DOS_OS2
#endif
#if (defined(OS2) || defined(WIN32))
# define OS2_W32
#endif
#if (defined(DOS_OS2) || defined(WIN32))
# define DOS_OS2_W32
# define DOS_W32_OS2 /* historical: don't use */
#endif
#if (defined(DOS_OS2_W32) || defined(__human68k__))
# define DOS_H68_OS2_W32
#endif
#if (defined(DOS_OS2) || defined(FLEXOS))
# define DOS_FLX_OS2
#endif
#if (defined(DOS_OS2_W32) || defined(FLEXOS))
# define DOS_FLX_OS2_W32
#endif
#if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
# define DOS_FLX_H68_OS2_W32
#endif
#if (defined(DOS_FLX_OS2) || defined(NLM))
# define DOS_FLX_NLM_OS2
#endif
#if (defined(DOS_FLX_OS2_W32) || defined(NLM))
# define DOS_FLX_NLM_OS2_W32
#endif
#if (defined(DOS_FLX_H68_OS2_W32) || defined(NLM))
# define DOS_FLX_H68_NLM_OS2_W32
#endif
#if (defined(TOPS20) || defined(VMS))
# define T20_VMS
#endif
#if (defined(MSDOS) || defined(T20_VMS))
# define DOS_T20_VMS
#endif
#if (defined(__ATHEOS__) || defined(__BEOS__))
# define ATH_BEO
#endif
#if (defined(ATH_BEO) || defined(UNIX))
# define ATH_BEO_UNX
#endif
#if (defined(ATH_BEO_UNX) || defined(THEOS))
# define ATH_BEO_THS_UNX
#endif
/* clean up with a few defaults */
#ifndef DIR_END
# define DIR_END '/' /* last char before program name or filename */
#endif
#ifndef DATE_FORMAT
# ifdef DATEFMT_ISO_DEFAULT
# define DATE_FORMAT DF_YMD /* defaults to invariant ISO-style */
# else
# define DATE_FORMAT DF_MDY /* defaults to US convention */
# endif
#endif
#ifndef DATE_SEPCHAR
# define DATE_SEPCHAR '-'
#endif
#ifndef CLOSE_INFILE
# define CLOSE_INFILE() close(G.zipfd)
#endif
#ifndef RETURN
# define RETURN return /* only used in main() */
#endif
#ifndef EXIT
# define EXIT exit
#endif
#ifndef USAGE
# define USAGE(ret) usage(__G__ (ret)) /* used in unzip.c, zipinfo.c */
#endif
#ifndef TIMET_TO_NATIVE /* everybody but MSC 7.0 and Macintosh */
# define TIMET_TO_NATIVE(x)
# define NATIVE_TO_TIMET(x)
#endif
#ifndef STRNICMP
# ifdef NO_STRNICMP
# define STRNICMP zstrnicmp
# else
# define STRNICMP strnicmp
# endif
#endif
#if (defined(DOS_FLX_NLM_OS2_W32) || defined(ATH_BEO_UNX) || defined(RISCOS))
# ifndef HAVE_UNLINK
# define HAVE_UNLINK
# endif
#endif
#if (defined(AOS_VS) || defined(ATARI)) /* GRR: others? */
# ifndef HAVE_UNLINK
# define HAVE_UNLINK
# endif
#endif
/* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
#if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
# if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
# define INT_SPRINTF /* sprintf() returns int: SysVish/Posix */
# endif
# if (defined(DOS_FLX_NLM_OS2_W32) || defined(VMS) || defined(AMIGA))
# define INT_SPRINTF /* sprintf() returns int: ANSI */
# endif
# if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
# if (defined(POSIX) || defined(__POSIX))
# define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
# endif
# ifdef __GNUC__
# define PCHAR_SPRINTF /* undetermined actual return value */
# endif
# endif
# if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS) || defined(THEOS))
# define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
# endif
# if defined(sun)
# define PCHAR_SPRINTF /* sprintf() returns char *: SunOS cc *and* gcc */
# endif
#endif
/* defaults that we hope will take care of most machines in the future */
#if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
# ifdef __STDC__
# define INT_SPRINTF /* sprintf() returns int: ANSI */
# endif
# ifndef INT_SPRINTF
# define PCHAR_SPRINTF /* sprintf() returns char *: BSDish */
# endif
#endif
#define MSG_STDERR(f) (f & 1) /* bit 0: 0 = stdout, 1 = stderr */
#define MSG_INFO(f) ((f & 6) == 0) /* bits 1 and 2: 0 = info */
#define MSG_WARN(f) ((f & 6) == 2) /* bits 1 and 2: 1 = warning */
#define MSG_ERROR(f) ((f & 6) == 4) /* bits 1 and 2: 2 = error */
#define MSG_FATAL(f) ((f & 6) == 6) /* bits 1 and 2: (3 = fatal error) */
#define MSG_ZFN(f) (f & 0x0008) /* bit 3: 1 = print zipfile name */
#define MSG_FN(f) (f & 0x0010) /* bit 4: 1 = print filename */
#define MSG_LNEWLN(f) (f & 0x0020) /* bit 5: 1 = leading newline if !SOL */
#define MSG_TNEWLN(f) (f & 0x0040) /* bit 6: 1 = trailing newline if !SOL */
#define MSG_MNEWLN(f) (f & 0x0080) /* bit 7: 1 = trailing NL for prompts */
/* the following are subject to change */
#define MSG_NO_WGUI(f) (f & 0x0100) /* bit 8: 1 = skip if Windows GUI */
#define MSG_NO_AGUI(f) (f & 0x0200) /* bit 9: 1 = skip if Acorn GUI */
#define MSG_NO_DLL2(f) (f & 0x0400) /* bit 10: 1 = skip if OS/2 DLL */
#define MSG_NO_NDLL(f) (f & 0x0800) /* bit 11: 1 = skip if WIN32 DLL */
#define MSG_NO_WDLL(f) (f & 0x1000) /* bit 12: 1 = skip if Windows DLL */
#if (defined(MORE) && !defined(SCREENLINES))
# ifdef DOS_FLX_NLM_OS2_W32
# define SCREENLINES 25 /* can be (should be) a function instead */
# else
# define SCREENLINES 24 /* VT-100s are assumed to be minimal hardware */
# endif
#endif
#if (defined(MORE) && !defined(SCREENSIZE))
# ifndef SCREENWIDTH
# define SCREENSIZE(scrrows, scrcols) { \
if ((scrrows) != NULL) *(scrrows) = SCREENLINES; }
# else
# define SCREENSIZE(scrrows, scrcols) { \
if ((scrrows) != NULL) *(scrrows) = SCREENLINES; \
if ((scrcols) != NULL) *(scrcols) = SCREENWIDTH; }
# endif
#endif
#if (defined(__16BIT__) || defined(MED_MEM) || defined(SMALL_MEM))
# define DIR_BLKSIZ 64 /* number of directory entries per block
* (should fit in 4096 bytes, usually) */
#else
# define DIR_BLKSIZ 16384 /* use more memory, to reduce long-range seeks */
#endif
#ifndef WSIZE
# ifdef USE_DEFLATE64
# define WSIZE 65536L /* window size--must be a power of two, and */
# else /* at least 64K for PKZip's deflate64 method */
# define WSIZE 0x8000 /* window size--must be a power of two, and */
# endif /* at least 32K for zip's deflate method */
#endif
#ifdef __16BIT__
# ifndef INT_16BIT
# define INT_16BIT /* on 16-bit systems int size is 16 bits */
# endif
#else
# define nearmalloc malloc
# define nearfree free
# if (!defined(__IBMC__) || !defined(OS2))
# ifndef near
# define near
# endif
# ifndef far
# define far
# endif
# endif
#endif
#if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
# undef DYNALLOC_CRCTAB
#endif
#if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
# undef DYNALLOC_CRCTAB /* not safe with reentrant code */
#endif
#if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
# ifdef DYNALLOC_CRCTAB
# undef DYNALLOC_CRCTAB
# endif
#endif
#if (defined(USE_ZLIB) && defined(ASM_CRC))
# undef ASM_CRC
#endif
#ifdef USE_ZLIB
# ifdef IZ_CRC_BE_OPTIMIZ
# undef IZ_CRC_BE_OPTIMIZ
# endif
# ifdef IZ_CRC_LE_OPTIMIZ
# undef IZ_CRC_LE_OPTIMIZ
# endif
#endif
#if (!defined(IZ_CRC_BE_OPTIMIZ) && !defined(IZ_CRC_LE_OPTIMIZ))
# ifdef IZ_CRCOPTIM_UNFOLDTBL
# undef IZ_CRCOPTIM_UNFOLDTBL
# endif
#endif
#ifndef INBUFSIZ
# if (defined(MED_MEM) || defined(SMALL_MEM))
# define INBUFSIZ 2048 /* works for MS-DOS small model */
# else
# define INBUFSIZ 8192 /* larger buffers for real OSes */
# endif
#endif
#if (defined(INT_16BIT) && (defined(USE_DEFLATE64) || lenEOL > 1))
/* For environments using 16-bit integers OUTBUFSIZ must be limited to
* less than 64k (do_string() uses "unsigned" in calculations involving
* OUTBUFSIZ). This is achieved by defining MED_MEM when WSIZE = 64k (aka
* Deflate64 support enabled) or EOL markers contain multiple characters.
* (The rule gets applied AFTER the default rule for INBUFSIZ because it
* is not neccessary to reduce INBUFSIZE in this case.)
*/
# if (!defined(SMALL_MEM) && !defined(MED_MEM))
# define MED_MEM
# endif
#endif
/* Logic for case of small memory, length of EOL > 1: if OUTBUFSIZ == 2048,
* OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
* and transbuf 1040 bytes. Have room for 32 extra EOL chars; 1008/32 == 31.5
* chars/line, smaller than estimated 35-70 characters per line for C source
* and normal text. Hence difference is sufficient for most "average" files.
* (Argument scales for larger OUTBUFSIZ.)
*/
#ifdef SMALL_MEM /* i.e., 16-bit OSes: MS-DOS, OS/2 1.x, etc. */
# define LoadFarString(x) fLoadFarString(__G__ (x))
# define LoadFarStringSmall(x) fLoadFarStringSmall(__G__ (x))
# define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
# if (defined(_MSC_VER) && (_MSC_VER >= 600))
# define zfstrcpy(dest, src) _fstrcpy((dest), (src))
# define zfstrcmp(s1, s2) _fstrcmp((s1), (s2))
# endif
# if !(defined(SFX) || defined(FUNZIP))
# if (defined(_MSC_VER))
# define zfmalloc(sz) _fmalloc((sz))
# define zffree(x) _ffree(x)
# endif
# if (defined(__TURBOC__))
# include <alloc.h>
# define zfmalloc(sz) farmalloc((unsigned long)(sz))
# define zffree(x) farfree(x)
# endif
# endif /* !(SFX || FUNZIP) */
# ifndef Far
# define Far far /* __far only works for MSC 6.00, not 6.0a or Borland */
# endif
# define OUTBUFSIZ INBUFSIZ
# if (lenEOL == 1)
# define RAWBUFSIZ (OUTBUFSIZ>>1)
# else
# define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
# endif
# define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
typedef short shrint; /* short/int or "shrink int" (unshrink) */
#else
# define zfstrcpy(dest, src) strcpy((dest), (src))