-
Notifications
You must be signed in to change notification settings - Fork 1
/
unzpriv.h
2150 lines (1832 loc) · 75.9 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:https://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.
---------------------------------------------------------------------------*/
#pragma once
/* First thing: Signal all following code that we compile UnZip utilities! */
#ifndef UNZIP
# define UNZIP
#endif
#if (defined(USE_ZLIB) && !defined(HAVE_ZL_INFLAT64) && !defined(NO_DEFLATE64))
/* zlib does not (yet?) provide Deflate64(tm) support */
# define NO_DEFLATE64
#endif
#if (defined(NO_VMS_TEXT_CONV) || defined(VMS))
# ifdef VMS_TEXT_CONV
# undef VMS_TEXT_CONV
# endif
#else
# if (!defined(VMS_TEXT_CONV))
# 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(DYNAMIC_CRC_TABLE))
# define DYNAMIC_CRC_TABLE
#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(pG, c)
# define REDIRECTPRINT(buf,size) varmessage(pG, buf, size)
# define FINISH_REDIRECT() finish_REXX_redirect(pG)
# else
# define REDIRECTC(c)
# define REDIRECTPRINT(buf,size) 0
# define FINISH_REDIRECT() close_redirect(pG)
# endif
#endif
/*---------------------------------------------------------------------------
MS-DOS, OS/2, FLEXOS section:
---------------------------------------------------------------------------*/
#ifdef WINDLL
# ifdef MORE
# undef MORE
# endif
#endif
#if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
# ifndef MSC
# define MSC /* This should work for older MSC, too! */
# endif
#endif
/*---------------------------------------------------------------------------
Unix section:
---------------------------------------------------------------------------*/
#ifdef UNIX
# include "unix/unxcfg.h"
#endif /* UNIX */
/*---------------------------------------------------------------------------
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
# include <stdio.h>
#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
# include <limits.h> /* MAX/MIN constant symbols for system types... */
/* this include must be down here for SysV.4, for some reason... */
#include <signal.h> /* used in unzip.c, fileio.c */
# include <stddef.h>
# include <stdlib.h> /* standard library prototypes, malloc(), etc. */
typedef size_t extent;
/*************/
/* Defines */
/*************/
#define UNZIP_BZ2VERS 46
# ifdef USE_BZIP2
# define UNZIP_VERSION UNZIP_BZ2VERS
# else
# define UNZIP_VERSION 45
# endif
#define VMS_UNZIP_VERSION 42 /* if OS-needed-to-extract is VMS: can do */
#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
/* 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((*(Uz_Globs *)pG).zipfd)
#endif
#ifndef RETURN
# define RETURN return /* only used in main() */
#endif
#ifndef EXIT
# define EXIT exit
#endif
#ifndef USAGE
# define USAGE(ret) usage(pG, (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
/* 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 */
# define DIR_BLKSIZ 16384 /* use more memory, to reduce long-range seeks */
#ifndef WSIZE
# define WSIZE 65536L /* window size--must be a power of two, and */
/* at least 64K for PKZip's deflate64 method */
/* window size--must be a power of two, and */
/* at least 32K for zip's deflate method */
#endif
#if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
# undef DYNALLOC_CRCTAB
#endif
#if (defined(DYNALLOC_CRCTAB))
# 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
#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
# define LoadFarString(x) (char *)(x)
# define LoadFarStringSmall(x) (char *)(x)
# define LoadFarStringSmall2(x) (char *)(x)
# define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
# define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
typedef int shrint; /* for efficiency/speed, we hope... */
# define RAWBUFSIZ OUTBUFSIZ
#ifndef Cdecl
# define Cdecl
#endif
/* user may have defined both by accident... NOTIMESTAMP takes precedence */
#if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
# undef TIMESTAMP
#endif
#if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
# define COPYRIGHT_CLEAN
#endif
/* The LZW patent is expired worldwide since 2004-Jul-07, so USE_UNSHRINK
* is now enabled by default. See unshrink.c.
*/
#if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
# define USE_UNSHRINK
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifndef PIPE_ERROR
# ifndef EPIPE
# define EPIPE -1
# endif
# define PIPE_ERROR (errno == EPIPE)
#endif
/* Defaults when nothing special has been defined previously. */
# ifndef FOPR
# define FOPR "rb"
# endif
# ifndef FOPM
# define FOPM "r+b"
# endif
# ifndef FOPW
# define FOPW "wb"
# endif
# ifndef FOPWT
# define FOPWT "wt"
# endif
# ifndef FOPWR
# define FOPWR "w+b"
# endif
/*
* If <limits.h> exists on most systems, should include that, since it may
* define some or all of the following: NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
* _POSIX_PATH_MAX.
*/
#ifdef DOS_FLX_NLM_OS2_W32
# include <limits.h>
#endif
#ifndef PATH_MAX
# ifdef MAXPATHLEN
# define PATH_MAX MAXPATHLEN /* in <sys/param.h> on some systems */
# else
# ifdef _MAX_PATH
# define PATH_MAX _MAX_PATH
# else
# if FILENAME_MAX > 255
# define PATH_MAX FILENAME_MAX /* used like PATH_MAX on some systems */
# else
# define PATH_MAX 1024
# endif
# endif /* ?_MAX_PATH */
# endif /* ?MAXPATHLEN */
#endif /* !PATH_MAX */
/*
* buffer size required to hold the longest legal local filepath
* (including the trailing '\0')
*/
#define FILNAMSIZ PATH_MAX
#ifdef UNICODE_SUPPORT
# if !(defined(UTF8_MAYBE_NATIVE) || defined(UNICODE_WCHAR))
# undef UNICODE_SUPPORT
# endif
#endif
/* 2007-09-18 SMS.
* Include <locale.h> here if it will be needed later for Unicode.
* Otherwise, SETLOCALE may be defined here, and then defined again
* (differently) when <locale.h> is read later.
*/
#ifdef UNICODE_SUPPORT
# ifdef UNICODE_WCHAR
# if !(defined(_WIN32_WCE) || defined(POCKET_UNZIP))
# include <wchar.h>
# endif
# endif
# ifndef _MBCS /* no need to include <locale.h> twice, see below */
# include <locale.h>
# ifndef SETLOCALE
# define SETLOCALE(category, locale) setlocale(category, locale)
# endif
# endif
#endif /* UNICODE_SUPPORT */
/* DBCS support for Info-ZIP (mainly for japanese (-: )
* by Yoshioka Tsuneo ([email protected],[email protected])
*/
#ifdef _MBCS
# include <locale.h>
/* Multi Byte Character Set */
# define ___MBS_TMP_DEF char *___tmp_ptr;
# define ___TMP_PTR ___tmp_ptr
# ifndef CLEN
# define NEED_UZMBCLEN
# define CLEN(ptr) (int)uzmbclen((const unsigned char *)(ptr))
# endif
# ifndef PREINCSTR
# define PREINCSTR(ptr) (ptr += CLEN(ptr))
# endif
# define POSTINCSTR(ptr) (___TMP_PTR=(char *)(ptr), PREINCSTR(ptr),___TMP_PTR)
char *plastchar OF((const char *ptr, extent len));
# define lastchar(ptr, len) ((int)(unsigned)*plastchar(ptr, len))
# ifndef MBSCHR
# define NEED_UZMBSCHR
# define MBSCHR(str,c) (char *)uzmbschr((const unsigned char *)(str), c)
# endif
# ifndef MBSRCHR
# define NEED_UZMBSRCHR
# define MBSRCHR(str,c) (char *)uzmbsrchr((const unsigned char *)(str), c)
# endif
# ifndef SETLOCALE
# define SETLOCALE(category, locale) setlocale(category, locale)
# endif
#else /* !_MBCS */
# define ___MBS_TMP_DEF
# define ___TMP_PTR
# define CLEN(ptr) 1
# define PREINCSTR(ptr) (++(ptr))
# define POSTINCSTR(ptr) ((ptr)++)
# define plastchar(ptr, len) (&ptr[(len)-1])
# define lastchar(ptr, len) (ptr[(len)-1])
# define MBSCHR(str, c) strchr(str, c)
# define MBSRCHR(str, c) strrchr(str, c)
# ifndef SETLOCALE
# define SETLOCALE(category, locale)
# endif
#endif /* ?_MBCS */
#define INCSTR(ptr) PREINCSTR(ptr)
# define memzero(dest,len) memset(dest,0,len)
#ifndef TRUE
# define TRUE 1 /* sort of obvious */
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifndef SEEK_SET
# define SEEK_SET 0
# define SEEK_CUR 1
# define SEEK_END 2
#endif
#if (!defined(S_IEXEC) && defined(S_IXUSR))
# define S_IEXEC S_IXUSR
#endif
#if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
# define SYMLINKS
# ifndef S_ISLNK
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
# endif
#endif /* UNIX && S_IFLNK && !MTS */
#ifndef S_ISDIR
# ifdef CMS_MVS
# define S_ISDIR(m) (FALSE)
# else
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# endif
#endif
#ifndef IS_VOLID
# define IS_VOLID(m) ((m) & 0x08)
#endif
/***********************************/
/* LARGE_FILE_SUPPORT */
/***********************************/
/* This whole section lifted from Zip 3b tailor.h
* Types are in OS dependent headers (eg, w32cfg.h)
*
* LARGE_FILE_SUPPORT and ZIP64_SUPPORT are automatically
* set in OS dependent headers (for some ports) based on the port and compiler.
*
* Function prototypes are below as OF is defined earlier in this file
* but after OS dependent header is included.
*
* E. Gordon 9/21/2003
* Updated 1/28/2004
* Lifted and placed here 6/7/2004 - Myles Bennett
*/
/* 64-bit Large File Support */
/* ---------------------------- */
# if defined(UNIX)
/* 64-bit stat functions */
# define zstat stat
# define zfstat fstat
/* 64-bit fseeko */
# define zlseek lseek
# define zfseeko fseeko
/* 64-bit ftello */
# define zftello ftello
/* 64-bit fopen */
# define zfopen fopen
# define zfdopen fdopen
# endif /* UNIX */
/* ---------------------------- */
# ifdef WIN32
# if defined(_MSC_VER) || defined(__MINGW32__) || defined(__LCC__)
/* MS C (VC), MinGW GCC port and LCC-32 use the MS C Runtime lib */
/* 64-bit stat functions */
# define zstat _stati64
# define zfstat _fstati64
/* 64-bit lseek */
# define zlseek _lseeki64
# if defined(_MSC_VER) && (_MSC_VER >= 1400)
/* Beginning with VS 8.0 (Visual Studio 2005, MSC 14), the Microsoft
C rtl publishes its (previously internal) implmentations of
"fseeko" and "ftello" for 64-bit file offsets. */
/* 64-bit fseeko */
# define zfseeko _fseeki64
/* 64-bit ftello */
# define zftello _ftelli64
# else /* not (defined(_MSC_VER) && (_MSC_VER >= 1400)) */
# if defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ >= 0x800)
/* Up-to-date versions of MinGW define the macro __MSVCRT_VERSION__
to denote the version of the MS C rtl dll used for linking. When
configured to link against the runtime of MS Visual Studio 8 (or
newer), the built-in 64-bit fseek/ftell functions are available. */
/* 64-bit fseeko */
# define zfseeko _fseeki64
/* 64-bit ftello */
# define zftello _ftelli64
# else /* !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__>=0x800)) */
/* The version of the C runtime is lower than MSC 14 or unknown. */
/* The newest MinGW port contains built-in extensions to the MSC rtl
that provide fseeko and ftello, but our implementations will do
for now. */
/* 64-bit fseeko */
int zfseeko OF((FILE *, zoff_t, int));
/* 64-bit ftello */
zoff_t zftello OF((FILE *));
# endif /* ? (__MSVCRT_VERSION__ >= 0x800) */
# endif /* ? (_MSC_VER >= 1400) */
/* 64-bit fopen */
# define zfopen fopen
# define zfdopen fdopen
# endif /* _MSC_VER || __MINGW__ || __LCC__ */
# ifdef __CYGWIN__
/* CYGWIN GCC Posix emulator on Windows
(configuration not yet finished/tested) */
/* 64-bit stat functions */
# define zstat _stati64
# define zfstat _fstati64
/* 64-bit lseek */
# define zlseek _lseeki64
/* 64-bit fseeko */
# define zfseeko fseeko
/* 64-bit ftello */
# define zftello ftello
/* 64-bit fopen */
# define zfopen fopen
# define zfdopen fdopen
# endif
# endif /* WIN32 */
#ifndef SSTAT
# ifdef WILD_STAT_BUG
# define SSTAT(path,pbuf) (iswild(path) || zstat(path,pbuf))
# else
# define SSTAT zstat
# endif
#endif
/* Default fzofft() format selection. */
#ifndef FZOFFT_FMT
# define FZOFFT_FMT "ll"
# define FZOFFT_HEX_WID_VALUE "16"
#endif /* ndef FZOFFT_FMT */
#define FZOFFT_HEX_WID ((char *) -1)
#define FZOFFT_HEX_DOT_WID ((char *) -2)
#define FZOFFT_NUM 4 /* Number of chambers. */
#define FZOFFT_LEN 24 /* Number of characters/chamber. */
#ifdef SHORT_SYMS /* Mark Williams C, ...? */
# define extract_or_test_files xtr_or_tst_files
# define extract_or_test_member xtr_or_tst_member
#endif
#ifndef S_TIME_T_MAX /* max value of signed (>= 32-bit) time_t */
# define S_TIME_T_MAX ((time_t)(ulg)0x7fffffffL)
#endif
#ifndef U_TIME_T_MAX /* max value of unsigned (>= 32-bit) time_t */
# define U_TIME_T_MAX ((time_t)(ulg)0xffffffffL)
#endif
#ifdef DOSTIME_MINIMUM /* min DOSTIME value (1980-01-01) */
# undef DOSTIME_MINIMUM
#endif
#define DOSTIME_MINIMUM ((ulg)0x00210000L)
#ifdef DOSTIME_2038_01_18 /* approximate DOSTIME equivalent of */
# undef DOSTIME_2038_01_18 /* the signed-32-bit time_t limit */
#endif
#define DOSTIME_2038_01_18 ((ulg)0x74320000L)
# define ZSUFX ".zip"
# define ALT_ZSUFX ".ZIP" /* Unix-only so far (only case-sensitive fs) */
#define CENTRAL_HDR_SIG "\001\002" /* the infamous "PK" signature bytes, */
#define LOCAL_HDR_SIG "\003\004" /* w/o "PK" (so unzip executable not */
#define END_CENTRAL_SIG "\005\006" /* mistaken for zipfile itself) */
#define EXTD_LOCAL_SIG "\007\010" /* [ASCII "\113" == EBCDIC "\080" ??] */
/** internal-only return codes **/
#define IZ_DIR 76 /* potential zipfile is a directory */
/* special return codes for mapname() */
#define MPN_OK 0 /* mapname successful */
#define MPN_INF_TRUNC (1<<8) /* caution - filename truncated */
#define MPN_INF_SKIP (2<<8) /* info - skipped because nothing to do */
#define MPN_ERR_SKIP (3<<8) /* error - entry skipped */
#define MPN_ERR_TOOLONG (4<<8) /* error - path too long */
#define MPN_NOMEM (10<<8) /* error - out of memory, file skipped */
#define MPN_CREATED_DIR (16<<8) /* directory created: set time & permission */
#define MPN_VOL_LABEL (17<<8) /* volume label, but can't set on hard disk */
#define MPN_INVALID (99<<8) /* internal logic error, should never reach */
/* mask for internal mapname&checkdir return codes */
#define MPN_MASK 0x7F00
/* error code for extracting/testing extra field blocks */
#define IZ_EF_TRUNC 79 /* local extra field truncated (PKZIP'd) */
/* choice of activities for do_string() */
#define SKIP 0 /* skip header block */
#define DISPLAY 1 /* display archive comment (ASCII) */
#define DISPL_8 5 /* display file comment (ext. ASCII) */
#define DS_FN 2 /* read filename (ext. ASCII, chead) */
#define DS_FN_C 2 /* read filename from central header */
#define DS_FN_L 6 /* read filename from local header */
#define EXTRA_FIELD 3 /* copy extra field into buffer */
#define DS_EF 3
#define DOES_NOT_EXIST -1 /* return values for check_for_newer() */
#define EXISTS_AND_OLDER 0
#define EXISTS_AND_NEWER 1
#define OVERWRT_QUERY 0 /* status values for (*(Uz_Globs *)pG).overwrite_mode */
#define OVERWRT_ALWAYS 1
#define OVERWRT_NEVER 2
#define IS_OVERWRT_ALL ((*(Uz_Globs *)pG).overwrite_mode == OVERWRT_ALWAYS)
#define IS_OVERWRT_NONE ((*(Uz_Globs *)pG).overwrite_mode == OVERWRT_NEVER)
#define ROOT 0 /* checkdir() extract-to path: called once */
#define INIT 1 /* allocate buildpath: called once per member */
#define APPEND_DIR 2 /* append a dir comp.: many times per member */
#define APPEND_NAME 3 /* append actual filename: once per member */
#define GETPATH 4 /* retrieve the complete path and free it */
#define END 5 /* free root path prior to exiting program */
/* version_made_by codes (central dir): make sure these */
/* are not defined on their respective systems!! */
#define FS_FAT_ 0 /* filesystem used by MS-DOS, OS/2, Win32 */
#define AMIGA_ 1
#define VMS_ 2
#define UNIX_ 3
#define VM_CMS_ 4
#define ATARI_ 5 /* what if it's a minix filesystem? [cjh] */
#define FS_HPFS_ 6 /* filesystem used by OS/2 (and NT 3.x) */
#define MAC_ 7 /* HFS filesystem used by MacOS */
#define Z_SYSTEM_ 8
#define CPM_ 9
#define TOPS20_ 10
#define FS_NTFS_ 11 /* filesystem used by Windows NT */
#define QDOS_ 12
#define ACORN_ 13 /* Archimedes Acorn RISC OS */
#define FS_VFAT_ 14 /* filesystem used by Windows 95, NT */
#define MVS_ 15
#define BEOS_ 16 /* hybrid POSIX/database filesystem */
#define TANDEM_ 17 /* Tandem NSK */
#define THEOS_ 18 /* THEOS */
#define MAC_OSX_ 19 /* Mac OS/X (Darwin) */
#define ATHEOS_ 30 /* AtheOS */
#define NUM_HOSTS 31 /* index of last system + 1 */
/* don't forget to update zipinfo.c appropiately if NUM_HOSTS changes! */
#define STORED 0 /* compression methods */
#define SHRUNK 1
#define REDUCED1 2
#define REDUCED2 3
#define REDUCED3 4
#define REDUCED4 5
#define IMPLODED 6
#define TOKENIZED 7
#define DEFLATED 8
#define ENHDEFLATED 9
#define DCLIMPLODED 10
#define BZIPPED 12
#define LZMAED 14
#define IBMTERSED 18
#define IBMLZ77ED 19
#define WAVPACKED 97
#define PPMDED 98
#define NUM_METHODS 17 /* number of known method IDs */
/* don't forget to update list.c (list_files()), extract.c and zipinfo.c
* appropriately if NUM_METHODS changes */
/* (the PK-class error codes are public and have been moved into unzip.h) */
#define DF_MDY 0 /* date format 10/26/91 (USA only) */
#define DF_DMY 1 /* date format 26/10/91 (most of the world) */
#define DF_YMD 2 /* date format 91/10/26 (a few countries) */
/*---------------------------------------------------------------------------
Extra-field block ID values and offset info.
---------------------------------------------------------------------------*/
/* extra-field ID values, all little-endian: */
#define EF_PKSZ64 0x0001 /* PKWARE's 64-bit filesize extensions */
#define EF_AV 0x0007 /* PKWARE's authenticity verification */
#define EF_EFS 0x0008 /* PKWARE's extended language encoding */
#define EF_OS2 0x0009 /* OS/2 extended attributes */
#define EF_PKW32 0x000a /* PKWARE's Win95/98/WinNT filetimes */
#define EF_PKVMS 0x000c /* PKWARE's VMS */
#define EF_PKUNIX 0x000d /* PKWARE's Unix */
#define EF_PKFORK 0x000e /* PKWARE's future stream/fork descriptors */
#define EF_PKPATCH 0x000f /* PKWARE's patch descriptor */
#define EF_PKPKCS7 0x0014 /* PKWARE's PKCS#7 store for X.509 Certs */
#define EF_PKFX509 0x0015 /* PKWARE's file X.509 Cert&Signature ID */
#define EF_PKCX509 0x0016 /* PKWARE's central dir X.509 Cert ID */
#define EF_PKENCRHD 0x0017 /* PKWARE's Strong Encryption header */
#define EF_PKRMCTL 0x0018 /* PKWARE's Record Management Controls*/
#define EF_PKLSTCS7 0x0019 /* PKWARE's PKCS#7 Encr. Recipient Cert List */
#define EF_PKIBM 0x0065 /* PKWARE's IBM S/390 & AS/400 attributes */
#define EF_PKIBM2 0x0066 /* PKWARE's IBM S/390 & AS/400 compr. attribs */
#define EF_IZVMS 0x4d49 /* Info-ZIP's VMS ("IM") */
#define EF_IZUNIX 0x5855 /* Info-ZIP's first Unix[1] ("UX") */
#define EF_IZUNIX2 0x7855 /* Info-ZIP's second Unix[2] ("Ux") */
#define EF_IZUNIX3 0x7875 /* Info-ZIP's newest Unix[3] ("ux") */
#define EF_TIME 0x5455 /* universal timestamp ("UT") */
#define EF_UNIPATH 0x7075 /* Info-ZIP Unicode Path ("up") */
#define EF_UNICOMNT 0x6375 /* Info-ZIP Unicode Comment ("uc") */
#define EF_MAC3 0x334d /* Info-ZIP's new Macintosh (= "M3") */
#define EF_JLMAC 0x07c8 /* Johnny Lee's old Macintosh (= 1992) */
#define EF_ZIPIT 0x2605 /* Thomas Brown's Macintosh (ZipIt) */
#define EF_ZIPIT2 0x2705 /* T. Brown's Mac (ZipIt) v 1.3.8 and newer ? */
#define EF_SMARTZIP 0x4d63 /* Mac SmartZip by Marco Bambini */
#define EF_VMCMS 0x4704 /* Info-ZIP's VM/CMS ("\004G") */
#define EF_MVS 0x470f /* Info-ZIP's MVS ("\017G") */
#define EF_ACL 0x4c41 /* (OS/2) access control list ("AL") */
#define EF_NTSD 0x4453 /* NT security descriptor ("SD") */
#define EF_ATHEOS 0x7441 /* AtheOS ("At") */
#define EF_BEOS 0x6542 /* BeOS ("Be") */
#define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
#define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
#define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
#define EF_TANDEM 0x4154 /* Tandem NSK ("TA") */
#define EF_THEOS 0x6854 /* Jean-Michel Dubois' Theos "Th" */
#define EF_THEOSO 0x4854 /* old Theos port */
#define EF_MD5 0x4b46 /* Fred Kantor's MD5 ("FK") */
#define EF_ASIUNIX 0x756e /* ASi's Unix ("nu") */