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