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