2
This is version 1999-Oct-05 of the Info-ZIP copyright and license.
3
The definitive version of this document should be available at
4
ftp://ftp.cdrom.com/pub/infozip/license.html indefinitely.
7
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
9
For the purposes of this copyright and license, "Info-ZIP" is defined as
10
the following set of individuals:
12
Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
13
Jean-loup Gailly, Hunter Goatley, Ian Gorman, Chris Herborth, Dirk Haase,
14
Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz, David Kirschbaum,
15
Johnny Lee, Onno van der Linden, Igor Mandrichenko, Steve P. Miller,
16
Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs, Kai Uwe Rommel,
17
Steve Salisbury, Dave Smith, Christian Spieler, Antoine Verheijen,
18
Paul von Behren, Rich Wales, Mike White
20
This software is provided "as is," without warranty of any kind, express
21
or implied. In no event shall Info-ZIP or its contributors be held liable
22
for any direct, indirect, incidental, special or consequential damages
23
arising out of the use of or inability to use this software.
25
Permission is granted to anyone to use this software for any purpose,
26
including commercial applications, and to alter it and redistribute it
27
freely, subject to the following restrictions:
29
1. Redistributions of source code must retain the above copyright notice,
30
definition, disclaimer, and this list of conditions.
32
2. Redistributions in binary form must reproduce the above copyright
33
notice, definition, disclaimer, and this list of conditions in
34
documentation and/or other materials provided with the distribution.
36
3. Altered versions--including, but not limited to, ports to new operating
37
systems, existing ports with new graphical interfaces, and dynamic,
38
shared, or static library versions--must be plainly marked as such
39
and must not be misrepresented as being the original source. Such
40
altered versions also must not be misrepresented as being Info-ZIP
41
releases--including, but not limited to, labeling of the altered
42
versions with the names "Info-ZIP" (or any variation thereof, including,
43
but not limited to, different capitalizations), "Pocket UnZip," "WiZ"
44
or "MacZip" without the explicit permission of Info-ZIP. Such altered
45
versions are further prohibited from misrepresentative use of the
46
Zip-Bugs or Info-ZIP e-mail addresses or of the Info-ZIP URL(s).
48
4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
49
"WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its own source and
59
#define ZIP /* for crypt.c: include zip password functions, not unzip */
61
/* Set up portability */
70
/* The minimum and maximum match lengths */
73
# define WSIZE (0x8000)
75
/* Maximum window size = 32K. If you are really short of memory, compile
76
* with a smaller WSIZE but this reduces the compression ratio for files
77
* of size > WSIZE. WSIZE must be a power of two in the current implementation.
80
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
81
/* Minimum amount of lookahead, except at the end of the input file.
82
* See deflate.c for comments about the MIN_MATCH+1.
85
#define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
86
/* In order to simplify the code, particularly on 16 bit machines, match
87
* distances are limited to MAX_DIST instead of WSIZE.
90
/* Forget FILENAME_MAX (incorrectly = 14 on some System V) */
98
# define MATCH dosmatch /* Default for pattern matching: UNIX style */
101
/* Types centralized here for easy modification */
102
#define local static /* More meaningful outside functions */
105
typedef unsigned char uch; /* unsigned 8-bit value */
106
typedef unsigned short ush; /* unsigned 16-bit value */
107
typedef unsigned long ulg; /* unsigned 32-bit value */
110
/* Structure carrying extended timestamp information */
111
typedef struct iztimes {
112
time_t atime; /* new access time */
113
time_t mtime; /* new modification time */
114
time_t ctime; /* new creation time (!= Unix st.ctime) */
117
/* Lengths of headers after signatures in bytes */
122
/* Structures for in-memory file information */
124
/* See central header in zipfile.c for what vem..off are */
125
ush vem, ver, flg, how;
126
ulg tim, crc, siz, len;
127
extent nam, ext, cext, com; /* offset of ext must be >= LOCHEAD */
128
ush dsk, att, lflg; /* offset of lflg must be >= LOCHEAD */
130
char *name; /* File name in zip file */
131
char *extra; /* Extra field (set only if ext != 0) */
132
char *cextra; /* Extra in central (set only if cext != 0) */
133
char *comment; /* Comment (set only if com != 0) */
134
char *iname; /* Internal file name after cleanup */
135
char *zname; /* External version of internal name */
136
int mark; /* Marker for files to operate on */
137
int trash; /* Marker for files to delete */
138
int dosflag; /* Set to force MSDOS file attributes */
139
struct zlist far *nxt; /* Pointer to next header in list */
142
char *name; /* Raw internal file name */
143
char *iname; /* Internal file name after cleanup */
144
char *zname; /* External version of internal name */
145
int dosflag; /* Set to force MSDOS file attributes */
146
struct flist far *far *lst; /* Pointer to link pointing here */
147
struct flist far *nxt; /* Link to next name */
150
char *zname; /* External version of internal name */
151
int select; /* Selection flag ('i' or 'x') */
154
/* internal file attribute */
160
/* extra field definitions */
161
#define EF_VMCMS 0x4704 /* VM/CMS Extra Field ID ("G")*/
162
#define EF_MVS 0x470f /* MVS Extra Field ID ("G") */
163
#define EF_IZUNIX 0x5855 /* UNIX Extra Field ID ("UX") */
164
#define EF_IZUNIX2 0x7855 /* Info-ZIP's new Unix ("Ux") */
165
#define EF_TIME 0x5455 /* universal timestamp ("UT") */
166
#define EF_OS2EA 0x0009 /* OS/2 Extra Field ID (extended attributes) */
167
#define EF_ACL 0x4C41 /* ACL Extra Field ID (access control list, "AL") */
168
#define EF_NTSD 0x4453 /* NT Security Descriptor Extra Field ID, ("SD") */
169
#define EF_BEOS 0x6542 /* BeOS Extra Field ID ("Be") */
170
#define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
171
#define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
172
#define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
173
#define EF_THEOS 0x6854 /* THEOS ("Th") */
174
#define EF_TANDEM 0x4154 /* Tandem NSK ("TA") */
176
/* Definitions for extra field handling: */
177
#define EF_SIZE_MAX ((unsigned)0xFFFF) /* hard limit of total e.f. length */
178
#define EB_HEADSIZE 4 /* length of a extra field block header */
179
#define EB_ID 0 /* offset of block ID in header */
180
#define EB_LEN 2 /* offset of data length field in header */
182
#define EB_UX_MINLEN 8 /* minimal "UX" field contains atime, mtime */
183
#define EB_UX_ATIME 0 /* offset of atime in "UX" extra field data */
184
#define EB_UX_MTIME 4 /* offset of mtime in "UX" extra field data */
186
#define EB_UX_FULLSIZE 12 /* full "UX" field (atime, mtime, uid, gid) */
187
#define EB_UX_UID 8 /* byte offset of UID in "UX" field data */
188
#define EB_UX_GID 10 /* byte offset of GID in "UX" field data */
190
#define EB_UT_MINLEN 1 /* minimal UT field contains Flags byte */
191
#define EB_UT_FLAGS 0 /* byte offset of Flags field */
192
#define EB_UT_TIME1 1 /* byte offset of 1st time value */
193
#define EB_UT_FL_MTIME (1 << 0) /* mtime present */
194
#define EB_UT_FL_ATIME (1 << 1) /* atime present */
195
#define EB_UT_FL_CTIME (1 << 2) /* ctime present */
196
#define EB_UT_LEN(n) (EB_UT_MINLEN + 4 * (n))
198
#define EB_UX2_MINLEN 4 /* minimal Ux field contains UID/GID */
199
#define EB_UX2_UID 0 /* byte offset of UID in "Ux" field data */
200
#define EB_UX2_GID 2 /* byte offset of GID in "Ux" field data */
201
#define EB_UX2_VALID (1 << 8) /* UID/GID present */
203
/* ASCII definitions for line terminators in text files: */
204
#define LF 10 /* '\n' on ASCII machines; must be 10 due to EBCDIC */
205
#define CR 13 /* '\r' on ASCII machines; must be 13 due to EBCDIC */
206
#define CTRLZ 26 /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
208
/* return codes of password fetches (negative: user abort; positive: error) */
209
#define IZ_PW_ENTERED 0 /* got some PWD string, use/try it */
210
#define IZ_PW_CANCEL -1 /* no password available (for this entry) */
211
#define IZ_PW_CANCELALL -2 /* no password, skip any further PWD request */
212
#define IZ_PW_ERROR 5 /* = PK_MEM2 : failure (no mem, no tty, ...) */
213
#define IZ_PW_SKIPVERIFY IZ_PW_CANCEL /* skip encrypt. passwd verification */
215
/* mode flag values of password prompting function */
216
#define ZP_PW_ENTER 0 /* request for encryption password */
217
#define ZP_PW_VERIFY 1 /* request for reentering password */
219
/* Error return codes and PERR macro */
222
#if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
223
# define CRCVAL_INITIAL crc32(0L, (uch *)NULL, 0)
225
# define CRCVAL_INITIAL 0L
228
#define DOSTIME_MINIMUM ((ulg)0x00210000L)
229
#define DOSTIME_2038_01_18 ((ulg)0x74320000L)
233
extern uch upper[256]; /* Country dependent case map table */
234
extern uch lower[256];
236
extern ZCONST uch ascii[256]; /* EBCDIC <--> ASCII translation tables */
237
extern ZCONST uch ebcdic[256];
239
#ifdef IZ_ISO2OEM_ARRAY /* ISO 8859-1 (Win CP 1252) --> OEM CP 850 */
240
extern ZCONST uch Far iso2oem[128];
242
#ifdef IZ_OEM2ISO_ARRAY /* OEM CP 850 --> ISO 8859-1 (Win CP 1252) */
243
extern ZCONST uch Far oem2iso[128];
245
extern char errbuf[FNMAX+81]; /* Handy place to build error messages */
246
extern int recurse; /* Recurse into directories encountered */
247
extern int dispose; /* Remove files after put in zip file */
248
extern int pathput; /* Store path with name */
251
extern int scanimage; /* Scan through image files */
254
#define BEST -1 /* Use best method (deflation or store) */
255
#define STORE 0 /* Store method */
256
#define DEFLATE 8 /* Deflation method*/
257
extern int method; /* Restriction on compression method */
259
extern int dosify; /* Make new entries look like MSDOS */
260
extern char *special; /* Don't compress special suffixes */
261
extern int verbose; /* Report oddities in zip file structure */
262
extern int fix; /* Fix the zip file */
263
extern int adjust; /* Adjust the unzipsfx'd zip file */
264
extern int level; /* Compression level */
265
extern int translate_eol; /* Translate end-of-line LF -> CR LF */
267
extern int vmsver; /* Append VMS version number to file names */
268
extern int vms_native; /* Store in VMS format */
270
#if defined(OS2) || defined(WIN32)
271
extern int use_longname_ea; /* use the .LONGNAME EA as the file's name */
273
#if defined (QDOS) || defined(QLZIP)
276
extern int hidden_files; /* process hidden and system files */
277
extern int volume_label; /* add volume label */
278
extern int dirnames; /* include directory names */
279
extern int linkput; /* Store symbolic links as such */
280
extern int noisy; /* False for quiet operation */
281
extern int extra_fields; /* do not create extra fields */
283
extern int use_privileges; /* use security privilege overrides */
285
extern char *key; /* Scramble password or NULL */
286
extern char *tempath; /* Path for temporary files */
287
extern FILE *mesg; /* Where informational output goes */
288
extern char *zipfile; /* New or existing zip archive (zip file) */
289
extern ulg zipbeg; /* Starting offset of zip structures */
290
extern ulg cenbeg; /* Starting offset of central directory */
291
extern struct zlist far *zfiles;/* Pointer to list of files in zip file */
292
extern extent zcount; /* Number of files in zip file */
293
extern extent zcomlen; /* Length of zip file comment */
294
extern char *zcomment; /* Zip file comment (not zero-terminated) */
295
extern struct zlist far **zsort;/* List of files sorted by name */
296
extern ulg tempzn; /* Count of bytes written to output zip file */
297
extern struct flist far *found; /* List of names found */
298
extern struct flist far *far *fnxt; /* Where to put next in found list */
299
extern extent fcount; /* Count of names in found list */
301
extern struct plist *patterns; /* List of patterns to be matched */
302
extern unsigned pcount; /* number of patterns */
303
extern unsigned icount; /* number of include only patterns */
306
extern int zp_tz_is_valid; /* signals "timezone info is available" */
308
#if (defined(MACOS) || defined(WINDLL))
309
extern int zipstate; /* flag "zipfile has been stat()'ed */
312
/* Diagnostic functions */
316
# define stderr stdout
318
# define diag(where) fprintf(stderr, "zip diagnostic: %s\n", where)
319
# define Assert(cond,msg) {if(!(cond)) error(msg);}
321
# define Trace(x) _fprintf x
322
# define Tracev(x) {if (verbose) _fprintf x ;}
323
# define Tracevv(x) {if (verbose>1) _fprintf x ;}
324
# define Tracec(c,x) {if (verbose && (c)) _fprintf x ;}
325
# define Tracecv(c,x) {if (verbose>1 && (c)) _fprintf x ;}
327
# define Trace(x) fprintf x
328
# define Tracev(x) {if (verbose) fprintf x ;}
329
# define Tracevv(x) {if (verbose>1) fprintf x ;}
330
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
331
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
335
# define Assert(cond,msg)
340
# define Tracecv(c,x)
344
# define free(x) { int *v;Free(x); v=x;*v=0xdeadbeef;x=(void *)0xdeadbeef; }
347
/* Public function prototypes */
351
//int zip_main OF((int, char **));
352
int zip_main(int argc, char** argv);
354
//int main OF((int, char **));
355
//#endif /* USE_ZIPMAIN */
364
void zipwarn OF((char *, char *));
365
int ziperr OF((int, char *));
367
# define error(msg) ziperr(ZE_LOGIC, msg)
369
void error OF((char *));
371
void help OF((void));
373
int encr_passwd OF((int, char *, int, ZCONST char *));
378
int percent OF((ulg, ulg));
379
int zipup OF((struct zlist far *, FILE *));
381
void zl_deflate_free OF((void));
383
void flush_outbuf OF((char *, unsigned *));
384
int seekable OF((void));
385
extern unsigned (*read_buf) OF((char *, unsigned int));
386
# endif /* !USE_ZLIB */
387
# ifdef ZP_NEED_MEMCOMPR
388
ulg memcompress OF((char *, ulg, char *, ulg));
394
struct zlist far *zsearch OF((ZCONST char *));
395
# ifdef USE_EF_UT_TIME
396
int get_ef_ut_ztime OF((struct zlist far *, iztimes *));
397
# endif /* USE_EF_UT_TIME */
398
int trash OF((void));
400
char *ziptyp OF((char *));
401
int readzipfile OF((void));
402
int putlocal OF((struct zlist far *, FILE *));
403
int putextended OF((struct zlist far *, FILE *));
404
int putcentral OF((struct zlist far *, FILE *));
405
int putend OF((int, ulg, ulg, extent, char *, FILE *));
406
int zipcopy OF((struct zlist far *, FILE *, FILE *));
410
char *getnam OF((char *, FILE *));
411
struct flist far *fexpel OF((struct flist far *));
412
char *last OF((char *, int));
413
char *msname OF((char *));
414
int check_dup OF((void));
415
int filter OF((char *, int));
416
int newname OF((char *, int, int));
418
#if (!defined(UTIL) || defined(W32_STATROOT_FIX))
419
time_t dos2unixtime OF((ulg));
422
ulg dostime OF((int, int, int, int, int, int));
423
ulg unix2dostime OF((time_t *));
424
int issymlnk OF((ulg a));
426
# define rdsymlnk(p,b,n) readlink(p,b,n)
427
/* extern int readlink OF((char *, char *, int)); */
428
# else /* !S_IFLNK */
429
# define rdsymlnk(p,b,n) (0)
430
# endif /* !S_IFLNK */
433
int destroy OF((char *));
434
int replace OF((char *, char *));
435
int getfileattr OF((char *));
436
int setfileattr OF((char *, int));
437
char *tempname OF((char *));
438
int fcopy OF((FILE *, FILE *, ulg));
446
char *memset OF((char *, int, unsigned int));
447
char *memcpy OF((char *, char *, unsigned int));
448
int memcmp OF((char *, char *, unsigned int));
451
/* in system dependent fileio code (<system>.c) */
454
int wild OF((char *));
456
char *in2ex OF((char *));
457
char *ex2in OF((char *, int, int *));
458
int procname OF((char *, int));
459
void stamp OF((char *, ulg));
460
ulg filetime OF((char *, ulg *, long *, iztimes *));
461
#if !(defined(VMS) && defined(VMS_PK_EXTRA))
462
int set_extra_field OF((struct zlist far *, iztimes *));
463
#endif /* ?(VMS && VMS_PK_EXTRA) */
464
int deletedir OF((char *));
466
zvoid far *zcalloc OF((unsigned int, unsigned int));
467
zvoid zcfree OF((zvoid far *));
468
#endif /* MY_ZCALLOC */
470
void version_local OF((void));
474
int fseekable OF((FILE *));
475
char *isshexp OF((char *));
476
int shmatch OF((ZCONST char *, ZCONST char *, int));
477
#if defined(DOS) || defined(WIN32)
478
int dosmatch OF((ZCONST char *, ZCONST char *, int));
479
#endif /* DOS || WIN32 */
481
void init_upper OF((void));
482
int namecmp OF((ZCONST char *string1, ZCONST char *string2));
485
char *strtoasc OF((char *str1, ZCONST char *str2));
486
char *strtoebc OF((char *str1, ZCONST char *str2));
487
char *memtoasc OF((char *mem1, ZCONST char *mem2, unsigned len));
488
char *memtoebc OF((char *mem1, ZCONST char *mem2, unsigned len));
490
#ifdef IZ_ISO2OEM_ARRAY
491
char *str_iso_to_oem OF((char *dst, ZCONST char *src));
493
#ifdef IZ_OEM2ISO_ARRAY
494
char *str_oem_to_iso OF((char *dst, ZCONST char *src));
497
zvoid far **search OF((ZCONST zvoid *, ZCONST zvoid far **, extent,
498
int (*)(ZCONST zvoid *, ZCONST zvoid far *)));
499
void envargs OF((int *, char ***, char *, char *));
500
void expand_args OF((int *, char ***));
505
ulg crc32 OF((ulg, ZCONST uch *, extent));
509
ZCONST ulg near *get_crc_table_boinc OF((void));
510
#ifdef DYNALLOC_CRCTAB
511
void free_crc_table OF((void));
513
#endif /* !USE_ZLIB */
518
void lm_init OF((int, ush *));
519
void lm_free OF((void));
520
ulg deflate_boinc OF((void));
523
void ct_init OF((ush *, int *));
524
int ct_tally OF((int, int));
525
ulg flush_block OF((char far *, ulg, int));
526
void bi_init OF((char *, unsigned int, int));
527
#endif /* !USE_ZLIB */
530
/* in system specific assembler code, replacing C code in trees.c */
531
#if defined(ASMV) && defined(RISCOS)
532
void send_bits OF((int, int));
533
unsigned bi_reverse OF((unsigned int, int));
534
#endif /* ASMV && RISCOS */
536
/*---------------------------------------------------------------------------
538
---------------------------------------------------------------------------*/
540
int vms_stat OF((char *, stat_t *)); /* vms.c */
541
void vms_exit OF((int)); /* vms.c */
544
ulg vms_zip_cmdline OF((int *, char ***)); /* cmdline.c */
545
void VMSCLI_help OF((void)); /* cmdline.c */
551
/*---------------------------------------------------------------------------
552
WIN32-only functions:
553
---------------------------------------------------------------------------*/
555
int ZipIsWinNT OF((void)); /* win32.c */
558
#if (defined(WINDLL) || defined(DLL_ZIPAPI))
559
/*---------------------------------------------------------------------------
560
Prototypes for public Zip API (DLL) functions.
561
---------------------------------------------------------------------------*/
563
#endif /* WINDLL || DLL_ZIPAPI */
565
#endif /* !__zip_h */