Reimport zip into third party

This commit is contained in:
Justine Tunney 2022-10-16 13:39:41 -07:00
parent 60cb435cb4
commit 648bf6555c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
22 changed files with 1555 additions and 569 deletions

View file

@ -59,7 +59,7 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex) {
t = gettid(); t = gettid();
// we allow unlocking an initialized lock that wasn't locked, but we // we allow unlocking an initialized lock that wasn't locked, but we
// don't allow unlocking a lock held by another thread, on unlocking // don't allow unlocking a lock held by another thread, or unlocking
// recursive locks from a forked child, since it should be re-init'd // recursive locks from a forked child, since it should be re-init'd
if (mutex->_owner && (mutex->_owner != t || mutex->_pid != __pid)) { if (mutex->_owner && (mutex->_owner != t || mutex->_pid != __pid)) {
return EPERM; return EPERM;

View file

@ -1,64 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigset.h"
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/stdio/posix_spawn.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/testlib.h"
char testlib_enable_tmp_setup_teardown;
TEST(posix_spawn, torture) {
int ws, pid;
short flags;
sigset_t allsig;
posix_spawnattr_t attr;
posix_spawn_file_actions_t fa;
sigfillset(&allsig);
testlib_extract("/zip/echo.com", "echo.com", 0755);
// XXX: NetBSD doesn't seem to let us set the scheduler to itself ;_;
ASSERT_EQ(0, posix_spawnattr_init(&attr));
ASSERT_EQ(0, posix_spawnattr_setflags(
&attr, POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETSIGDEF |
POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETPGROUP |
POSIX_SPAWN_SETSIGMASK |
(IsNetbsd() ? 0 : POSIX_SPAWN_SETSCHEDULER)));
ASSERT_EQ(0, posix_spawnattr_setsigmask(&attr, &allsig));
ASSERT_EQ(0, posix_spawnattr_setsigdefault(&attr, &allsig));
ASSERT_EQ(0, posix_spawn_file_actions_init(&fa));
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, 0));
ASSERT_EQ(
0, posix_spawn_file_actions_addopen(&fa, 1, "/dev/null", O_WRONLY, 0644));
ASSERT_EQ(0, posix_spawn_file_actions_adddup2(&fa, 1, 0));
for (int i = 0; i < 15; ++i) {
char *volatile zzz = malloc(13);
char *args[] = {"./echo.com", NULL};
char *envs[] = {NULL};
ASSERT_EQ(0, posix_spawn(&pid, "./echo.com", &fa, &attr, args, envs));
ASSERT_NE(-1, waitpid(pid, &ws, 0));
ASSERT_TRUE(WIFEXITED(ws));
ASSERT_EQ(0, WEXITSTATUS(ws));
free(zzz);
}
ASSERT_EQ(0, posix_spawn_file_actions_destroy(&fa));
ASSERT_EQ(0, posix_spawnattr_destroy(&attr));
}

View file

@ -1,7 +1,14 @@
zip utility from Info-ZIP: DESCRIPTION
http://infozip.sourceforge.net/Zip.html zip utility from Info-ZIP
source code obtained as zip30.tar.gz from: ORIGIN
https://sourceforge.net/projects/infozip/files/ source code obtained as zip30.tar.gz
http://infozip.sourceforge.net/Zip.html
https://sourceforge.net/projects/infozip/files/
LOCAL CHANGES
- Use Cosmopolitan's PCLMUL optimized CRC32
- Improve find_next_signature() performance using unlocked stdio

54
third_party/zip/api.h vendored
View file

@ -1,11 +1,59 @@
// clang-format off
/*
api.h - Zip 3
Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2007-Mar-4 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/* Only the Windows DLL is currently supported */
#ifndef _ZIPAPI_H #ifndef _ZIPAPI_H
#define _ZIPAPI_H #define _ZIPAPI_H
#include "third_party/zip/zip.h"
/* clang-format off */
#define MAXPATH 1024 #include "third_party/zip/zip.h"
#ifdef WIN32
# ifndef PATH_MAX
# define PATH_MAX 260
# endif
#else
# ifndef PATH_MAX
# define PATH_MAX 128
# endif
#endif
#if defined(WINDLL) || defined(API) #if defined(WINDLL) || defined(API)
#include "libc/nt/accounting.h"
#include "libc/nt/automation.h"
#include "libc/nt/console.h"
#include "libc/nt/debug.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/keyaccess.h"
#include "libc/nt/enum/regtype.h"
#include "libc/nt/errors.h"
#include "libc/nt/events.h"
#include "libc/nt/files.h"
#include "libc/nt/ipc.h"
#include "libc/nt/memory.h"
#include "libc/nt/paint.h"
#include "libc/nt/process.h"
#include "libc/nt/registry.h"
#include "libc/nt/synchronization.h"
#include "libc/nt/thread.h"
#include "libc/nt/windows.h"
#include "libc/nt/winsock.h"
/* Porting definations between Win 3.1x and Win32 */
#ifdef WIN32
# define far
# define _far
# define __far
# define near
# define _near
# define __near
#endif
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
Prototypes for public Zip API (DLL) functions. Prototypes for public Zip API (DLL) functions.

View file

@ -1,7 +1,23 @@
// clang-format off
/*
Copyright (c) 1990-2008 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/* crc32.h -- compute the CRC-32 of a data stream
* Copyright (C) 1995 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifndef __crc32_h #ifndef __crc32_h
#define __crc32_h #define __crc32_h /* identifies this source module */
#include "third_party/zip/zip.h"
/* clang-format off */ /* This header should be read AFTER zip.h resp. unzip.h
* (the latter with UNZIP_INTERNAL defined...).
*/
#ifndef OF #ifndef OF
# define OF(a) a # define OF(a) a

View file

@ -1,9 +1,4 @@
/* clang-format off */ // clang-format off
#define ZCRYPT_INTERNAL
#include "third_party/zip/zip.h"
#include "third_party/zip/crypt.h"
#include "third_party/zip/ttyio.h"
#include "libc/stdio/rand.h"
/* /*
Copyright (c) 1990-2008 Info-ZIP. All rights reserved. Copyright (c) 1990-2008 Info-ZIP. All rights reserved.
@ -35,6 +30,11 @@
version without encryption capabilities). version without encryption capabilities).
*/ */
#define ZCRYPT_INTERNAL
#include "third_party/zip/zip.h"
#include "third_party/zip/crypt.h"
#include "third_party/zip/ttyio.h"
#if CRYPT #if CRYPT
#ifndef FALSE #ifndef FALSE
@ -75,7 +75,14 @@
as a fallback to allow successful compilation in "beta state" as a fallback to allow successful compilation in "beta state"
environments. environments.
*/ */
#include "libc/time/time.h" /* time() function supplies first part of crypt seed */ #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/sched.h"
#include "libc/sysv/consts/timer.h"
#include "libc/time/struct/tm.h"
#include "libc/time/time.h" /* time() function supplies first part of crypt seed */
/* "last resort" source for second part of crypt seed pattern */ /* "last resort" source for second part of crypt seed pattern */
# ifndef ZCR_SEED2 # ifndef ZCR_SEED2
# define ZCR_SEED2 (unsigned)3141592654L /* use PI as default pattern */ # define ZCR_SEED2 (unsigned)3141592654L /* use PI as default pattern */

View file

@ -1,8 +1,58 @@
#ifndef __crypt_h /* don't include more than once */ // clang-format off
#define __crypt_h /*
/* clang-format off */ Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
#define CRYPT 1 /* full version for zip and main unzip */ See the accompanying file LICENSE, version 2007-Mar-4 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*
crypt.h (full version) by Info-ZIP. Last revised: [see CR_VERSION_DATE]
The main encryption/decryption source code for Info-Zip software was
originally written in Europe. To the best of our knowledge, it can
be freely distributed in both source and object forms from any country,
including the USA under License Exception TSU of the U.S. Export
Administration Regulations (section 740.13(e)) of 6 June 2002.
NOTE on copyright history:
Previous versions of this source package (up to version 2.8) were
not copyrighted and put in the public domain. If you cannot comply
with the Info-Zip LICENSE, you may want to look for one of those
public domain versions.
*/
#ifndef __crypt_h /* don't include more than once */
#define __crypt_h
#ifdef CRYPT
# undef CRYPT
#endif
/*
Logic of selecting "full crypt" code:
a) default behaviour:
- dummy crypt code when compiling UnZipSFX stub, to minimize size
- full crypt code when used to compile Zip, UnZip and fUnZip
b) USE_CRYPT defined:
- always full crypt code
c) NO_CRYPT defined:
- never full crypt code
NO_CRYPT takes precedence over USE_CRYPT
*/
#if defined(NO_CRYPT)
# define CRYPT 0 /* dummy version */
#else
#if defined(USE_CRYPT)
# define CRYPT 1 /* full version */
#else
#if !defined(SFX)
# define CRYPT 1 /* full version for zip and main unzip */
#else
# define CRYPT 0 /* dummy version for unzip sfx */
#endif
#endif /* ?USE_CRYPT */
#endif /* ?NO_CRYPT */
#if CRYPT #if CRYPT
/* full version */ /* full version */
@ -80,22 +130,23 @@
/* decode byte c in place */ /* decode byte c in place */
#define zdecode(c) update_keys(__G__ c ^= decrypt_byte(__G)) #define zdecode(c) update_keys(__G__ c ^= decrypt_byte(__G))
int decrypt_byte (__GPRO); int decrypt_byte OF((__GPRO));
int update_keys (__GPRO__ int c); int update_keys OF((__GPRO__ int c));
void init_keys (__GPRO__ ZCONST char *passwd); void init_keys OF((__GPRO__ ZCONST char *passwd));
#ifdef ZIP #ifdef ZIP
void crypthead (ZCONST char *, ulg); void crypthead OF((ZCONST char *, ulg));
# ifdef UTIL # ifdef UTIL
int zipcloak (struct zlist far *, ZCONST char *); int zipcloak OF((struct zlist far *, ZCONST char *));
int zipbare (struct zlist far *, ZCONST char *); int zipbare OF((struct zlist far *, ZCONST char *));
# else # else
unsigned zfwrite (zvoid *, extent, extent); unsigned zfwrite OF((zvoid *, extent, extent));
extern char *key;
# endif # endif
#endif /* ZIP */ #endif /* ZIP */
#if (defined(UNZIP) && !defined(FUNZIP)) #if (defined(UNZIP) && !defined(FUNZIP))
int decrypt (__GPRO__ ZCONST char *passwrd); int decrypt OF((__GPRO__ ZCONST char *passwrd));
#endif #endif
#ifdef FUNZIP #ifdef FUNZIP

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
fileio.c - Zip 3 fileio.c - Zip 3
@ -15,15 +15,24 @@
#define __FILEIO_C #define __FILEIO_C
#include "third_party/zip/zip.h" #include "third_party/zip/zip.h"
#include "libc/calls/struct/stat.macros.h"
#include "third_party/zip/crc32.h" #include "third_party/zip/crc32.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/alg.h" #ifdef MACOS
#include "libc/stdio/temp.h" // MISSING #include "helpers.h"
#include "libc/time/time.h" #endif
#ifdef VMS
// MISSING #include "vms/vms.h"
#endif /* def VMS */
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/sched.h"
#include "libc/sysv/consts/timer.h"
#include "libc/time/struct/tm.h" #include "libc/time/struct/tm.h"
#include "libc/sysv/consts/s.h" #include "libc/time/time.h"
#include "libc/limits.h"
#ifdef NO_MKTIME #ifdef NO_MKTIME
time_t mktime OF((struct tm *)); time_t mktime OF((struct tm *));
@ -1175,6 +1184,7 @@ ulg dostime; /* DOS time to convert */
#endif /* ZP_NEED_GEN_D2U_TIME */ #endif /* ZP_NEED_GEN_D2U_TIME */
#ifndef MACOS
int destroy(f) int destroy(f)
char *f; /* file to delete */ char *f; /* file to delete */
/* Delete the file *f, returning non-zero on failure. */ /* Delete the file *f, returning non-zero on failure. */
@ -1191,32 +1201,69 @@ char *d, *s; /* destination and source file names */
*/ */
{ {
z_stat t; /* results of stat() */ z_stat t; /* results of stat() */
#if defined(CMS_MVS)
/* cmsmvs.h defines FOPW_TEMP as memory(hiperspace). Since memory is
* lost at end of run, always do copy instead of rename.
*/
int copy = 1;
#else
int copy = 0; int copy = 0;
#endif
int d_exists; int d_exists;
#if defined(VMS) || defined(CMS_MVS)
/* stat() is broken on VMS remote files (accessed through Decnet).
* This patch allows creation of remote zip files, but is not sufficient
* to update them or compress remote files */
unlink(d);
#else /* !(VMS || CMS_MVS) */
d_exists = (LSTAT(d, &t) == 0); d_exists = (LSTAT(d, &t) == 0);
if (d_exists) if (d_exists)
{ {
/* /*
* respect existing soft and hard links! * respect existing soft and hard links!
*/ */
if (t.st_nlink > 1 || (t.st_mode & S_IFMT) == S_IFLNK) if (t.st_nlink > 1
# ifdef S_IFLNK
|| (t.st_mode & S_IFMT) == S_IFLNK
# endif
)
copy = 1; copy = 1;
else if (unlink(d)) else if (unlink(d))
return ZE_CREAT; /* Can't erase zip file--give up */ return ZE_CREAT; /* Can't erase zip file--give up */
} }
#endif /* ?(VMS || CMS_MVS) */
#ifndef CMS_MVS
if (!copy) { if (!copy) {
if (rename(s, d)) { /* Just move s on top of d */ if (rename(s, d)) { /* Just move s on top of d */
copy = 1; /* failed ? */ copy = 1; /* failed ? */
if (errno != EXDEV) #if !defined(VMS) && !defined(ATARI) && !defined(AZTEC_C)
return ZE_CREAT; #if !defined(CMS_MVS) && !defined(RISCOS) && !defined(QDOS)
/* For VMS, ATARI, AMIGA Aztec, VM_CMS, MVS, RISCOS,
always assume that failure is EXDEV */
if (errno != EXDEV
# ifdef THEOS
&& errno != EEXIST
# else
# ifdef ENOTSAM
&& errno != ENOTSAM /* Used at least on Turbo C */
# endif
# endif
) return ZE_CREAT;
#endif /* !CMS_MVS && !RISCOS */
#endif /* !VMS && !ATARI && !AZTEC_C */
} }
} }
#endif /* !CMS_MVS */
if (copy) { if (copy) {
FILE *f, *g; /* source and destination files */ FILE *f, *g; /* source and destination files */
int r; /* temporary variable */ int r; /* temporary variable */
#ifdef RISCOS
if (SWI_OS_FSControl_26(s,d,0xA1)!=NULL) {
#endif
/* Use zfopen for almost all opens where fopen is used. For /* Use zfopen for almost all opens where fopen is used. For
most OS that support large files we use the 64-bit file most OS that support large files we use the 64-bit file
environment and zfopen maps to fopen, but this allows environment and zfopen maps to fopen, but this allows
@ -1239,9 +1286,13 @@ char *d, *s; /* destination and source file names */
return r ? (r == ZE_TEMP ? ZE_WRITE : r) : ZE_WRITE; return r ? (r == ZE_TEMP ? ZE_WRITE : r) : ZE_WRITE;
} }
unlink(s); unlink(s);
#ifdef RISCOS
}
#endif
} }
return ZE_OK; return ZE_OK;
} }
#endif /* !MACOS */
int getfileattr(f) int getfileattr(f)
@ -1884,6 +1935,87 @@ int bfcopy(n)
} }
#ifdef NO_RENAME
int rename(from, to)
ZCONST char *from;
ZCONST char *to;
{
unlink(to);
if (link(from, to) == -1)
return -1;
if (unlink(from) == -1)
return -1;
return 0;
}
#endif /* NO_RENAME */
#ifdef ZMEM
/************************/
/* Function memset() */
/************************/
/*
* memset - for systems without it
* bill davidsen - March 1990
*/
char *
memset(buf, init, len)
register char *buf; /* buffer loc */
register int init; /* initializer */
register unsigned int len; /* length of the buffer */
{
char *start;
start = buf;
while (len--) *(buf++) = init;
return(start);
}
/************************/
/* Function memcpy() */
/************************/
char *
memcpy(dst,src,len) /* v2.0f */
register char *dst, *src;
register unsigned int len;
{
char *start;
start = dst;
while (len--)
*dst++ = *src++;
return(start);
}
/************************/
/* Function memcmp() */
/************************/
int
memcmp(b1,b2,len) /* jpd@usl.edu -- 11/16/90 */
register char *b1, *b2;
register unsigned int len;
{
if (len) do { /* examine each byte (if any) */
if (*b1++ != *b2++)
return (*((uch *)b1-1) - *((uch *)b2-1)); /* exit when miscompare */
} while (--len);
return(0); /* no miscompares, yield 0 result */
}
#endif /* ZMEM */
/*------------------------------------------------------------------ /*------------------------------------------------------------------
* Split archives * Split archives
*/ */

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
unix/osdep.h - Zip 3 unix/osdep.h - Zip 3
@ -10,6 +10,12 @@
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/ */
#ifdef NO_LARGE_FILE_SUPPORT
# ifdef LARGE_FILE_SUPPORT
# undef LARGE_FILE_SUPPORT
# endif
#endif
#ifdef LARGE_FILE_SUPPORT #ifdef LARGE_FILE_SUPPORT
/* 64-bit Large File Support */ /* 64-bit Large File Support */
@ -22,9 +28,22 @@
# define _LARGE_FILES /* some OSes need this for 64-bit off_t */ # define _LARGE_FILES /* some OSes need this for 64-bit off_t */
#endif #endif
#include "libc/calls/makedev.h"
#include "libc/calls/weirdtypes.h" #include "libc/calls/weirdtypes.h"
#include "libc/thread/thread.h"
#include "libc/calls/typedef/u.h"
#include "libc/calls/weirdtypes.h"
#include "libc/intrin/newbie.h"
#include "libc/sock/select.h"
#include "libc/sysv/consts/endian.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/stat.macros.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/s.h" #include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/utime.h"
#include "libc/time/time.h"
/* printf format size prefix for zoff_t values */ /* printf format size prefix for zoff_t values */
#ifdef LARGE_FILE_SUPPORT #ifdef LARGE_FILE_SUPPORT

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
tailor.h - Zip 3 tailor.h - Zip 3
@ -9,6 +9,9 @@
If, for some reason, all these files are missing, the Info-ZIP license If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/ */
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/stat.macros.h"
#include "libc/calls/weirdtypes.h"
/* Some compiler distributions for Win32/i386 systems try to emulate /* Some compiler distributions for Win32/i386 systems try to emulate
* a Unix (POSIX-compatible) environment. * a Unix (POSIX-compatible) environment.
@ -36,10 +39,83 @@
# endif # endif
#endif #endif
#include "libc/str/str.h"
#include "libc/calls/struct/stat.h" #ifdef AMIGA
#include "libc/runtime/runtime.h" // MISSING #include "amiga/osdep.h"
#include "third_party/zip/osdep.h" #endif
#ifdef AOSVS
// MISSING #include "aosvs/osdep.h"
#endif
#ifdef ATARI
// MISSING #include "atari/osdep.h"
#endif
#ifdef __ATHEOS__
// MISSING #include "atheos/osdep.h"
#endif
#ifdef __BEOS__
// MISSING #include "beos/osdep.h"
#endif
#ifdef DOS
// MISSING #include "msdos/osdep.h"
#endif
#ifdef __human68k__
// MISSING #include "human68k/osdep.h"
#endif
#if ((defined(__MWERKS__) && defined(macintosh)) || defined(MACOS))
// MISSING #include "macos/osdep.h"
#endif
#ifdef NLM
// MISSING #include "novell/osdep.h"
#endif
#ifdef OS2
// MISSING #include "os2/osdep.h"
#endif
#ifdef __riscos
// MISSING #include "acorn/osdep.h"
#endif
#ifdef QDOS
// MISSING #include "qdos/osdep.h"
#endif
#ifdef __TANDEM
// MISSING #include "tandem.h"
// MISSING #include "tanzip.h"
#endif
#ifdef UNIX
// MISSING #include "unix/osdep.h"
#endif
#if defined(__COMPILER_KCC__) || defined(TOPS20)
// MISSING #include "tops20/osdep.h"
#endif
#if defined(VMS) || defined(__VMS)
// MISSING #include "vms/osdep.h"
#endif
#if defined(__VM__) || defined(VM_CMS) || defined(MVS)
// MISSING #include "cmsmvs.h"
#endif
#ifdef WIN32
// MISSING #include "win32/osdep.h"
#endif
#ifdef THEOS
// MISSING #include "theos/osdep.h"
#endif
/* generic LARGE_FILE_SUPPORT defines /* generic LARGE_FILE_SUPPORT defines
@ -136,38 +212,82 @@
* to_up is used to force upper case even on Unix (for dosify option). * to_up is used to force upper case even on Unix (for dosify option).
*/ */
#ifdef USE_CASE_MAP #ifdef USE_CASE_MAP
# define case_map(c) kToUpper[(c) & 0xff] # define case_map(c) upper[(c) & 0xff]
# define to_up(c) kToLower[(c) & 0xff] # define to_up(c) upper[(c) & 0xff]
#else #else
# define case_map(c) (c) # define case_map(c) (c)
# define to_up(c) ((c) >= 'a' && (c) <= 'z' ? (c)-'a'+'A' : (c)) # define to_up(c) ((c) >= 'a' && (c) <= 'z' ? (c)-'a'+'A' : (c))
#endif /* USE_CASE_MAP */ #endif /* USE_CASE_MAP */
/* Define void, zvoid, and extent (size_t) */ /* Define void, zvoid, and extent (size_t) */
#include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/calls/weirdtypes.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/fmt.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/stdio/temp.h"
#include "third_party/musl/tempnam.h"
#ifndef NO_STDDEF_H #ifndef NO_STDDEF_H
// # include <stddef.h>
#endif /* !NO_STDDEF_H */ #endif /* !NO_STDDEF_H */
#ifndef NO_STDLIB_H #ifndef NO_STDLIB_H
#include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/calls/termios.h"
#include "libc/fmt/conv.h"
#include "libc/limits.h"
#include "libc/mem/alg.h"
#include "libc/mem/mem.h" #include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.h"
#include "third_party/musl/crypt.h"
#include "third_party/musl/rand48.h"
#endif /* !NO_STDLIB_H */ #endif /* !NO_STDLIB_H */
#ifndef NO_UNISTD_H #ifndef NO_UNISTD_H
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h" #include "libc/calls/weirdtypes.h"
#include "libc/runtime/pathconf.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/ok.h"
#include "libc/time/time.h"
#include "third_party/getopt/getopt.h"
#include "third_party/musl/crypt.h"
#include "third_party/musl/lockf.h" /* usually defines _POSIX_VERSION */
#endif /* !NO_UNISTD_H */ #endif /* !NO_UNISTD_H */
#ifndef NO_FCNTL_H #ifndef NO_FCNTL_H
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/struct/flock.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/f.h" #include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/posix.h"
#include "libc/sysv/consts/s.h"
#endif /* !NO_FNCTL_H */ #endif /* !NO_FNCTL_H */
#ifndef NO_STRING_H
#include "libc/mem/alg.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#else
#include "libc/str/locale.h"
#include "libc/str/str.h"
#include "libc/nexgen32e/ffs.h"
#endif /* NO_STRING_H */
#ifdef NO_VOID #ifdef NO_VOID
# define void int # define void int
@ -261,12 +381,21 @@ IZ_IMP char *mktemp();
#ifdef UNICODE_SUPPORT #ifdef UNICODE_SUPPORT
# if defined( UNIX) || defined( VMS) # if defined( UNIX) || defined( VMS)
#include "libc/str/locale.h" #include "libc/str/locale.h"
#include "libc/str/unicode.h"
# endif /* defined( UNIX) || defined( VMS) */ # endif /* defined( UNIX) || defined( VMS) */
#include "libc/fmt/conv.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/unicode.h"
#include "libc/time/time.h"
#include "libc/calls/calls.h"
#include "libc/fmt/conv.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#endif /* def UNICODE_SUPPORT */ #endif /* def UNICODE_SUPPORT */
#ifdef _MBCS #ifdef _MBCS
# include <locale.h> #include "libc/str/locale.h"
#include "libc/str/unicode.h"
/* Multi Byte Character Set */ /* Multi Byte Character Set */
extern char *___tmp_ptr; extern char *___tmp_ptr;

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
ttyio.c - Zip 3 ttyio.c - Zip 3
@ -108,17 +108,33 @@
# endif # endif
#endif #endif
#if (defined(UNZIP) && !defined(FUNZIP) && defined(UNIX) && defined(MORE))
#include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/winsize.h"
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/fio.h"
#include "libc/sysv/consts/modem.h"
#include "libc/sysv/consts/pty.h"
#include "libc/sysv/consts/sio.h"
#include "libc/sysv/consts/termios.h"
# define GOT_IOCTL_H
/* int ioctl OF((int, int, zvoid *)); GRR: may need for some systems */
#endif
#ifndef HAVE_WORKING_GETCH #ifndef HAVE_WORKING_GETCH
/* include system support for switching of console echo */ /* include system support for switching of console echo */
# ifdef VMS # ifdef VMS
# include <descrip.h> // MISSING #include <descrip.h>
# include <iodef.h> // MISSING #include <iodef.h>
# include <ttdef.h> // MISSING #include <ttdef.h>
# include <starlet.h> // MISSING #include <starlet.h>
# include <ssdef.h> // MISSING #include <ssdef.h>
# else /* !VMS */ # else /* !VMS */
# ifdef HAVE_TERMIOS_H # ifdef HAVE_TERMIOS_H
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/baud.h"
#include "libc/sysv/consts/termios.h" #include "libc/sysv/consts/termios.h"
# define sgttyb termios # define sgttyb termios
# define sg_flags c_lflag # define sg_flags c_lflag
@ -127,14 +143,14 @@
# else /* !HAVE_TERMIOS_H */ # else /* !HAVE_TERMIOS_H */
# ifdef USE_SYSV_TERMIO /* Amdahl, Cray, all SysV? */ # ifdef USE_SYSV_TERMIO /* Amdahl, Cray, all SysV? */
# ifdef HAVE_TERMIO_H # ifdef HAVE_TERMIO_H
# include <termio.h> // MISSING #include <termio.h>
# endif # endif
# ifdef HAVE_SYS_TERMIO_H # ifdef HAVE_SYS_TERMIO_H
# include <sys/termio.h> // MISSING #include <sys/termio.h>
# endif # endif
# ifdef NEED_PTEM # ifdef NEED_PTEM
# include <sys/stream.h> // MISSING #include <sys/stream.h>
# include <sys/ptem.h> // MISSING #include <sys/ptem.h>
# endif # endif
# define sgttyb termio # define sgttyb termio
# define sg_flags c_lflag # define sg_flags c_lflag
@ -143,9 +159,17 @@
# else /* !USE_SYSV_TERMIO */ # else /* !USE_SYSV_TERMIO */
# ifndef CMS_MVS # ifndef CMS_MVS
# if (!defined(MINIX) && !defined(GOT_IOCTL_H)) # if (!defined(MINIX) && !defined(GOT_IOCTL_H))
# include <sys/ioctl.h> #include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/winsize.h"
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/fio.h"
#include "libc/sysv/consts/modem.h"
#include "libc/sysv/consts/pty.h"
#include "libc/sysv/consts/sio.h"
#include "libc/sysv/consts/termios.h"
# endif # endif
# include <sgtty.h> // MISSING #include <sgtty.h>
# define GTTY gtty # define GTTY gtty
# define STTY stty # define STTY stty
# ifdef UNZIP # ifdef UNZIP
@ -164,8 +188,14 @@
# ifndef NO_FCNTL_H # ifndef NO_FCNTL_H
# ifndef UNZIP # ifndef UNZIP
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/struct/flock.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/f.h" #include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/posix.h"
#include "libc/sysv/consts/s.h"
# endif # endif
# else # else
char *ttyname OF((int)); char *ttyname OF((int));

View file

@ -1,15 +1,4 @@
/* clang-format off */ // clang-format off
#include "libc/calls/struct/dirent.h"
#include "libc/calls/calls.h"
#include "libc/sysv/consts/s.h"
#include "third_party/zip/zip.h"
#include "libc/time/time.h"
#include "libc/calls/struct/stat.macros.h"
#include "libc/calls/calls.h"
#include "third_party/zip/osdep.h"
#include "libc/time/struct/utimbuf.h"
#include "libc/sysv/consts/dt.h"
/* /*
unix/unix.c - Zip 3 unix/unix.c - Zip 3
@ -20,14 +9,64 @@
If, for some reason, all these files are missing, the Info-ZIP license If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/ */
#include "third_party/zip/osdep.h"
#include "third_party/zip/zip.h"
#ifndef UTIL /* the companion #endif is a bit of ways down ... */ #ifndef UTIL /* the companion #endif is a bit of ways down ... */
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/sched.h"
#include "libc/sysv/consts/timer.h"
#include "libc/time/struct/tm.h"
#include "libc/time/time.h"
#if defined(MINIX) || defined(__mpexl)
# ifdef S_IWRITE
# undef S_IWRITE
# endif /* S_IWRITE */
# define S_IWRITE S_IWUSR
#endif /* MINIX */
#if (!defined(S_IWRITE) && defined(S_IWUSR))
# define S_IWRITE S_IWUSR
#endif
#if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
#include "libc/calls/calls.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/dt.h"
#else /* !HAVE_DIRENT_H */
# ifdef HAVE_NDIR_H
// MISSING #include <ndir.h>
# endif /* HAVE_NDIR_H */
# ifdef HAVE_SYS_NDIR_H
// MISSING #include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
#include "libc/calls/calls.h"
#include "libc/sysv/consts/dt.h"
# endif /* HAVE_SYS_DIR_H */
# ifndef dirent
# define dirent direct
# endif
#endif /* HAVE_DIRENT_H || _POSIX_VERSION */
#define PAD 0 #define PAD 0
#define PATH_END '/' #define PATH_END '/'
/* Library functions not in (most) header files */ /* Library functions not in (most) header files */
#ifdef _POSIX_VERSION
#include "libc/time/struct/utimbuf.h"
#include "libc/time/time.h"
#else
int utime OF((char *, time_t *));
#endif
extern char *label; extern char *label;
local ulg label_time = 0; local ulg label_time = 0;
local ulg label_mode = 0; local ulg label_mode = 0;
@ -663,9 +702,21 @@ char *d; /* directory to delete */
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__386BSD__) || \ #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__386BSD__) || \
defined(__OpenBSD__) || defined(__bsdi__) defined(__OpenBSD__) || defined(__bsdi__)
#include "libc/intrin/newbie.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/sysparam.h"
#include "libc/calls/weirdtypes.h"
#include "libc/limits.h"
#include "libc/sysv/consts/endian.h"
#include "libc/sysv/consts/prio.h"
#include "libc/sysv/consts/rlim.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/consts/rusage.h" /* for the BSD define */
/* if we have something newer than NET/2 we'll use uname(3) */ /* if we have something newer than NET/2 we'll use uname(3) */
#if (BSD > 199103) #if (BSD > 199103)
#include "libc/calls/calls.h" #include "libc/calls/struct/utsname.h"
#endif /* BSD > 199103 */ #endif /* BSD > 199103 */
#endif /* __{Net,Free,Open,386}BSD__ || __bsdi__ */ #endif /* __{Net,Free,Open,386}BSD__ || __bsdi__ */
@ -972,3 +1023,4 @@ void version_local()
COMPILER_NAME, OS_NAME, COMPILE_DATE); COMPILER_NAME, OS_NAME, COMPILE_DATE);
} /* end function version_local() */ } /* end function version_local() */

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
util.c util.c
@ -15,10 +15,19 @@
#define __UTIL_C #define __UTIL_C
#include "third_party/zip/zip.h" #include "third_party/zip/zip.h"
// MISSING #include "ebcdic.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/fmt/fmt.h"
#include "libc/runtime/runtime.h" #ifdef MSDOS16
#include "libc/fmt/conv.h" // MISSING #include <dos.h>
#endif
#ifdef NO_MKTIME
# ifndef IZ_MKTIME_ONLY
# define IZ_MKTIME_ONLY /* only mktime() related code is pulled in */
# endif
#include "third_party/zip/timezone.c"
#endif
uch upper[256], lower[256]; uch upper[256], lower[256];
/* Country-dependent case map table */ /* Country-dependent case map table */
@ -587,6 +596,72 @@ int (*cmp) OF((ZCONST zvoid *, ZCONST zvoid far *)); /* comparison function */
#endif /* !UTIL */ #endif /* !UTIL */
#ifdef MSDOS16
local unsigned ident(unsigned chr)
{
return chr; /* in al */
}
void init_upper()
{
static struct country {
uch ignore[18];
int (far *casemap)(int);
uch filler[16];
} country_info;
struct country far *info = &country_info;
union REGS regs;
struct SREGS sregs;
unsigned int c;
regs.x.ax = 0x3800; /* get country info */
regs.x.dx = FP_OFF(info);
sregs.ds = FP_SEG(info);
intdosx(&regs, &regs, &sregs);
for (c = 0; c < 128; c++) {
upper[c] = (uch) toupper(c);
lower[c] = (uch) c;
}
for (; c < sizeof(upper); c++) {
upper[c] = (uch) (*country_info.casemap)(ident(c));
/* ident() required because casemap takes its parameter in al */
lower[c] = (uch) c;
}
for (c = 0; c < sizeof(upper); c++ ) {
unsigned int u = upper[c];
if (u != c && lower[u] == (uch) u) {
lower[u] = (uch)c;
}
}
for (c = 'A'; c <= 'Z'; c++) {
lower[c] = (uch) (c - 'A' + 'a');
}
}
#else /* !MSDOS16 */
# ifndef OS2
void init_upper()
{
unsigned int c;
#if defined(ATARI) || defined(CMS_MVS)
#include "libc/str/str.h"
/* this should be valid for all other platforms too. (HD 11/11/95) */
for (c = 0; c< sizeof(upper); c++) {
upper[c] = islower(c) ? toupper(c) : c;
lower[c] = isupper(c) ? tolower(c) : c;
}
#else
for (c = 0; c < sizeof(upper); c++) upper[c] = lower[c] = (uch)c;
for (c = 'a'; c <= 'z'; c++) upper[c] = (uch)(c - 'a' + 'A');
for (c = 'A'; c <= 'Z'; c++) lower[c] = (uch)(c - 'A' + 'a');
#endif
}
# endif /* !OS2 */
#endif /* ?MSDOS16 */
int namecmp(string1, string2) int namecmp(string1, string2)
ZCONST char *string1, *string2; ZCONST char *string1, *string2;
/* Compare the two strings ignoring case, and correctly taking into /* Compare the two strings ignoring case, and correctly taking into

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
Copyright (c) 1990-2008 Info-ZIP. All rights reserved. Copyright (c) 1990-2008 Info-ZIP. All rights reserved.
@ -30,9 +30,19 @@
#define __ZBZ2ERR_C /* identifies this source module */ #define __ZBZ2ERR_C /* identifies this source module */
#include "libc/fmt/fmt.h"
#include "third_party/zip/zip.h" #include "third_party/zip/zip.h"
#include "third_party/bzip2/bzlib.h"
#ifdef BZIP2_SUPPORT
# ifdef BZIP2_USEBZIP2DIR
// MISSING #include "bzip2/bzlib.h"
# else
/* If IZ_BZIP2 is defined as the location of the bzip2 files then
assume the location has been added to include path. For Unix
this is done by the configure script. */
/* Also do not need path for bzip2 include if OS includes support
for bzip2 library. */
// MISSING #include "bzlib.h"
# endif
/**********************************/ /**********************************/
/* Function bz_internal_error() */ /* Function bz_internal_error() */
@ -48,3 +58,5 @@ void bz_internal_error(errcode)
sprintf(errbuf, "fatal error (code %d) in bzip2 library", errcode); sprintf(errbuf, "fatal error (code %d) in bzip2 library", errcode);
ziperr(ZE_LOGIC, errbuf); ziperr(ZE_LOGIC, errbuf);
} /* end function bz_internal_error() */ } /* end function bz_internal_error() */
#endif /* def BZIP2_SUPPORT */

826
third_party/zip/zip.c vendored
View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
zip.c - Zip 3 zip.c - Zip 3
@ -15,30 +15,102 @@
#define __ZIP_C #define __ZIP_C
#include "third_party/zip/zip.h" #include "third_party/zip/zip.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/sched.h"
#include "libc/sysv/consts/timer.h"
#include "libc/time/struct/tm.h"
#include "libc/time/time.h" /* for tzset() declaration */ #include "libc/time/time.h" /* for tzset() declaration */
#if defined(WIN32) || defined(WINDLL)
# define WIN32_LEAN_AND_MEAN
#include "libc/nt/accounting.h"
#include "libc/nt/automation.h"
#include "libc/nt/console.h"
#include "libc/nt/debug.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/keyaccess.h"
#include "libc/nt/enum/regtype.h"
#include "libc/nt/errors.h"
#include "libc/nt/events.h"
#include "libc/nt/files.h"
#include "libc/nt/ipc.h"
#include "libc/nt/memory.h"
#include "libc/nt/paint.h"
#include "libc/nt/process.h"
#include "libc/nt/registry.h"
#include "libc/nt/synchronization.h"
#include "libc/nt/thread.h"
#include "libc/nt/windows.h"
#include "libc/nt/winsock.h"
#endif
#ifdef WINDLL
#include "libc/runtime/runtime.h"
// MISSING #include "windll/windll.h"
#endif
#define DEFCPYRT /* main module: enable copyright string defines! */ #define DEFCPYRT /* main module: enable copyright string defines! */
#include "third_party/zip/revision.h" #include "third_party/zip/revision.h"
#include "third_party/zip/crc32.h" #include "third_party/zip/crc32.h"
#include "third_party/zip/crypt.h" #include "third_party/zip/crypt.h"
#include "third_party/zip/ttyio.h" #include "third_party/zip/ttyio.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/log/log.h"
#include "libc/dce.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/sysv/consts/sig.h"
#include "libc/calls/calls.h"
#include "libc/calls/calls.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/calls/calls.h"
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/temp.h"
#include "libc/runtime/runtime.h"
#include "third_party/bzip2/bzlib.h" #include "third_party/bzip2/bzlib.h"
#ifdef VMS
// MISSING #include <stsdef.h>
// MISSING #include "vms/vmsmunch.h"
// MISSING #include "vms/vms.h"
#endif
#ifdef MACOS
// MISSING #include "macglob.h"
extern MacZipGlobals MacZip;
extern int error_level;
#endif
#if (defined(MSDOS) && !defined(__GO32__)) || defined(__human68k__)
// MISSING #include <process.h>
# if (!defined(P_WAIT) && defined(_P_WAIT))
# define P_WAIT _P_WAIT
# endif
#endif
#include "libc/calls/calls.h"
#include "libc/calls/sigtimedwait.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/ss.h"
#include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/calls/weirdtypes.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/fmt.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/temp.h"
#include "third_party/musl/tempnam.h"
#ifdef UNICODE_TEST
# ifdef WIN32
// MISSING #include <direct.h>
# endif
#endif
#ifdef BZIP2_SUPPORT
/* If IZ_BZIP2 is defined as the location of the bzip2 files then
assume the location has been added to include path. For Unix
this is done by the configure script. */
/* Also do not need path for bzip2 include if OS includes support
for bzip2 library. */
// MISSING #include "bzlib.h"
#endif
#define MAXCOM 256 /* Maximum one-line comment size */ #define MAXCOM 256 /* Maximum one-line comment size */
/* Local option flags */ /* Local option flags */
#ifndef DELETE #ifndef DELETE
#define DELETE 0 #define DELETE 0
@ -413,14 +485,24 @@ void error(h)
ziperr(ZE_LOGIC, h); ziperr(ZE_LOGIC, h);
} }
#if (!defined(MACOS) && !defined(WINDLL))
local void handler(s) local void handler(s)
int s; /* signal number (ignored) */ int s; /* signal number (ignored) */
/* Upon getting a user interrupt, turn echo back on for tty and abort /* Upon getting a user interrupt, turn echo back on for tty and abort
cleanly using ziperr(). */ cleanly using ziperr(). */
{ {
#if defined(AMIGA) && defined(__SASC)
_abort();
#else
#if !defined(MSDOS) && !defined(__human68k__) && !defined(RISCOS)
echon();
putc('\n', mesg);
#endif /* !MSDOS */
#endif /* AMIGA && __SASC */
ziperr(ZE_ABORT, "aborting"); ziperr(ZE_ABORT, "aborting");
s++; /* keep some compilers happy */ s++; /* keep some compilers happy */
} }
#endif /* !MACOS && !WINDLL */
void zipmessage_nl(a, nl) void zipmessage_nl(a, nl)
ZCONST char *a; /* message string to output */ ZCONST char *a; /* message string to output */
@ -654,331 +736,345 @@ local void help_extended()
#endif #endif
/* Print extended help to stdout. */ /* Print extended help to stdout. */
{ {
__paginate(1, "\n\ extent i; /* counter for help array */
Extended Help for Zip\n\
\n\ /* help array */
See the Zip Manual for more detailed help\n\ static ZCONST char *text[] = {
\n\ "",
\n\ "Extended Help for Zip",
Zip stores files in zip archives. The default action is to add or replace\n\ "",
zipfile entries.\n\ "See the Zip Manual for more detailed help",
\n\ "",
Basic command line:\n\ "",
zip options archive_name file file ...\n\ "Zip stores files in zip archives. The default action is to add or replace",
\n\ "zipfile entries.",
Some examples:\n\ "",
Add file.txt to z.zip (create z if needed): zip z file.txt\n\ "Basic command line:",
Zip all files in current dir: zip z *\n\ " zip options archive_name file file ...",
Zip files in current dir and subdirs also: zip -r z .\n\ "",
\n\ "Some examples:",
Basic modes:\n\ " Add file.txt to z.zip (create z if needed): zip z file.txt",
External modes (selects files from file system):\n\ " Zip all files in current dir: zip z *",
add - add new files/update existing files in archive (default)\n\ " Zip files in current dir and subdirs also: zip -r z .",
-u update - add new files/update existing files only if later date\n\ "",
-f freshen - update existing files only (no files added)\n\ "Basic modes:",
-FS filesync - update if date or size changed, delete if no OS match\n\ " External modes (selects files from file system):",
Internal modes (selects entries in archive):\n\ " add - add new files/update existing files in archive (default)",
-d delete - delete files from archive (see below)\n\ " -u update - add new files/update existing files only if later date",
-U copy - select files in archive to copy (use with --out)\n\ " -f freshen - update existing files only (no files added)",
\n\ " -FS filesync - update if date or size changed, delete if no OS match",
Basic options:\n\ " Internal modes (selects entries in archive):",
-r recurse into directories (see Recursion below)\n\ " -d delete - delete files from archive (see below)",
-m after archive created, delete original files (move into archive)\n\ " -U copy - select files in archive to copy (use with --out)",
-j junk directory names (store just file names)\n\ "",
-q quiet operation\n\ "Basic options:",
-v verbose operation (just \"zip -v\" shows version information)\n\ " -r recurse into directories (see Recursion below)",
-c prompt for one-line comment for each entry\n\ " -m after archive created, delete original files (move into archive)",
-z prompt for comment for archive (end with just \".\" line or EOF)\n\ " -j junk directory names (store just file names)",
-@ read names to zip from stdin (one path per line)\n\ " -q quiet operation",
-o make zipfile as old as latest entry\n\ " -v verbose operation (just \"zip -v\" shows version information)",
\n\ " -c prompt for one-line comment for each entry",
\n\ " -z prompt for comment for archive (end with just \".\" line or EOF)",
Syntax:\n\ " -@ read names to zip from stdin (one path per line)",
The full command line syntax is:\n\ " -o make zipfile as old as latest entry",
\n\ "",
zip [-shortopts ...] [--longopt ...] [zipfile [path path ...]] [-xi list]\n\ "",
\n\ "Syntax:",
Any number of short option and long option arguments are allowed\n\ " The full command line syntax is:",
(within limits) as well as any number of path arguments for files\n\ "",
to zip up. If zipfile exists, the archive is read in. If zipfile\n\ " zip [-shortopts ...] [--longopt ...] [zipfile [path path ...]] [-xi list]",
is \"-\", stream to stdout. If any path is \"-\", zip stdin.\n\ "",
\n\ " Any number of short option and long option arguments are allowed",
Options and Values:\n\ " (within limits) as well as any number of path arguments for files",
For short options that take values, use -ovalue or -o value or -o=value\n\ " to zip up. If zipfile exists, the archive is read in. If zipfile",
For long option values, use either --longoption=value or --longoption value\n\ " is \"-\", stream to stdout. If any path is \"-\", zip stdin.",
For example:\n\ "",
zip -ds 10 --temp-dir=path zipfile path1 path2 --exclude pattern pattern\n\ "Options and Values:",
Avoid -ovalue (no space between) to avoid confusion\n\ " For short options that take values, use -ovalue or -o value or -o=value",
In particular, be aware of 2-character options. For example:\n\ " For long option values, use either --longoption=value or --longoption value",
-d -s is (delete, split size) while -ds is (dot size)\n\ " For example:",
Usually better to break short options across multiple arguments by function\n\ " zip -ds 10 --temp-dir=path zipfile path1 path2 --exclude pattern pattern",
zip -r -dbdcds 10m -lilalf logfile archive input_directory -ll\n\ " Avoid -ovalue (no space between) to avoid confusion",
\n\ " In particular, be aware of 2-character options. For example:",
All args after just \"--\" arg are read verbatim as paths and not options.\n\ " -d -s is (delete, split size) while -ds is (dot size)",
zip zipfile path path ... -- verbatimpath verbatimpath ...\n\ " Usually better to break short options across multiple arguments by function",
Use -nw to also disable wildcards, so paths are read literally:\n\ " zip -r -dbdcds 10m -lilalf logfile archive input_directory -ll",
zip zipfile -nw -- \"-leadingdashpath\" \"a[path].c\" \"path*withwildcard\"\n\ "",
You may still have to escape or quote arguments to avoid shell expansion\n\ " All args after just \"--\" arg are read verbatim as paths and not options.",
\n\ " zip zipfile path path ... -- verbatimpath verbatimpath ...",
Wildcards:\n\ " Use -nw to also disable wildcards, so paths are read literally:",
Internally zip supports the following wildcards:\n\ " zip zipfile -nw -- \"-leadingdashpath\" \"a[path].c\" \"path*withwildcard\"",
? (or %% or #, depending on OS) matches any single character\n\ " You may still have to escape or quote arguments to avoid shell expansion",
* matches any number of characters, including zero\n\ "",
[list] matches char in list (regex), can do range [ac-f], all but [!bf]\n\ "Wildcards:",
If port supports [], must escape [ as [[] or use -nw to turn off wildcards\n\ " Internally zip supports the following wildcards:",
For shells that expand wildcards, escape (\\* or \"*\") so zip can recurse\n\ " ? (or %% or #, depending on OS) matches any single character",
zip zipfile -r . -i \"*.h\"\n\ " * matches any number of characters, including zero",
\n\ " [list] matches char in list (regex), can do range [ac-f], all but [!bf]",
Normally * crosses dir bounds in path, e.g. 'a*b' can match 'ac/db'. If\n\ " If port supports [], must escape [ as [[] or use -nw to turn off wildcards",
-ws option used, * does not cross dir bounds but ** does\n\ " For shells that expand wildcards, escape (\\* or \"*\") so zip can recurse",
\n\ " zip zipfile -r . -i \"*.h\"",
For DOS and Windows, [list] is now disabled unless the new option\n\ "",
-RE enable [list] (regular expression) matching\n\ " Normally * crosses dir bounds in path, e.g. 'a*b' can match 'ac/db'. If",
is used to avoid problems with file paths containing \"[\" and \"]\":\n\ " -ws option used, * does not cross dir bounds but ** does",
zip files_ending_with_number -RE foo[0-9].c\n\ "",
\n\ " For DOS and Windows, [list] is now disabled unless the new option",
Include and Exclude:\n\ " -RE enable [list] (regular expression) matching",
-i pattern pattern ... include files that match a pattern\n\ " is used to avoid problems with file paths containing \"[\" and \"]\":",
-x pattern pattern ... exclude files that match a pattern\n\ " zip files_ending_with_number -RE foo[0-9].c",
Patterns are paths with optional wildcards and match paths as stored in\n\ "",
archive. Exclude and include lists end at next option, @, or end of line.\n\ "Include and Exclude:",
zip -x pattern pattern @ zipfile path path ...\n\ " -i pattern pattern ... include files that match a pattern",
\n\ " -x pattern pattern ... exclude files that match a pattern",
Case matching:\n\ " Patterns are paths with optional wildcards and match paths as stored in",
On most OS the case of patterns must match the case in the archive, unless\n\ " archive. Exclude and include lists end at next option, @, or end of line.",
the -ic option is used.\n\ " zip -x pattern pattern @ zipfile path path ...",
-ic ignore case of archive entries\n\ "",
This option not available on case-sensitive file systems. On others, case\n\ "Case matching:",
ignored when matching files on file system but matching against archive\n\ " On most OS the case of patterns must match the case in the archive, unless",
entries remains case sensitive for modes -f (freshen), -U (archive copy),\n\ " the -ic option is used.",
and -d (delete) because archive paths are always case sensitive. With\n\ " -ic ignore case of archive entries",
-ic, all matching ignores case, but it's then possible multiple archive\n\ " This option not available on case-sensitive file systems. On others, case",
entries that differ only in case will match.\n\ " ignored when matching files on file system but matching against archive",
\n\ " entries remains case sensitive for modes -f (freshen), -U (archive copy),",
End Of Line Translation (text files only):\n\ " and -d (delete) because archive paths are always case sensitive. With",
-l change CR or LF (depending on OS) line end to CR LF (Unix->Win)\n\ " -ic, all matching ignores case, but it's then possible multiple archive",
-ll change CR LF to CR or LF (depending on OS) line end (Win->Unix)\n\ " entries that differ only in case will match.",
If first buffer read from file contains binary the translation is skipped\n\ "",
\n\ "End Of Line Translation (text files only):",
Recursion:\n\ " -l change CR or LF (depending on OS) line end to CR LF (Unix->Win)",
-r recurse paths, include files in subdirs: zip -r a path path ...\n\ " -ll change CR LF to CR or LF (depending on OS) line end (Win->Unix)",
-R recurse current dir and match patterns: zip -R a ptn ptn ...\n\ " If first buffer read from file contains binary the translation is skipped",
Use -i and -x with either to include or exclude paths\n\ "",
Path root in archive starts at current dir, so if /a/b/c/file and\n\ "Recursion:",
current dir is /a/b, 'zip -r archive .' puts c/file in archive\n\ " -r recurse paths, include files in subdirs: zip -r a path path ...",
\n\ " -R recurse current dir and match patterns: zip -R a ptn ptn ...",
Date filtering:\n\ " Use -i and -x with either to include or exclude paths",
-t date exclude before (include files modified on this date and later)\n\ " Path root in archive starts at current dir, so if /a/b/c/file and",
-tt date include before (include files modified before date)\n\ " current dir is /a/b, 'zip -r archive .' puts c/file in archive",
Can use both at same time to set a date range\n\ "",
Dates are mmddyyyy or yyyy-mm-dd\n\ "Date filtering:",
\n\ " -t date exclude before (include files modified on this date and later)",
Deletion, File Sync:\n\ " -tt date include before (include files modified before date)",
-d delete files\n\ " Can use both at same time to set a date range",
Delete archive entries matching internal archive paths in list\n\ " Dates are mmddyyyy or yyyy-mm-dd",
zip archive -d pattern pattern ...\n\ "",
Can use -t and -tt to select files in archive, but NOT -x or -i, so\n\ "Deletion, File Sync:",
zip archive -d \"*\" -t 2005-12-27\n\ " -d delete files",
deletes all files from archive.zip with date of 27 Dec 2005 and later\n\ " Delete archive entries matching internal archive paths in list",
Note the * (escape as \"*\" on Unix) to select all files in archive\n\ " zip archive -d pattern pattern ...",
\n\ " Can use -t and -tt to select files in archive, but NOT -x or -i, so",
-FS file sync\n\ " zip archive -d \"*\" -t 2005-12-27",
Similar to update, but files updated if date or size of entry does not\n\ " deletes all files from archive.zip with date of 27 Dec 2005 and later",
match file on OS. Also deletes entry from archive if no matching file\n\ " Note the * (escape as \"*\" on Unix) to select all files in archive",
on OS.\n\ "",
zip archive_to_update -FS -r dir_used_before\n\ " -FS file sync",
Result generally same as creating new archive, but unchanged entries\n\ " Similar to update, but files updated if date or size of entry does not",
are copied instead of being read and compressed so can be faster.\n\ " match file on OS. Also deletes entry from archive if no matching file",
WARNING: -FS deletes entries so make backup copy of archive first\n\ " on OS.",
\n\ " zip archive_to_update -FS -r dir_used_before",
Compression:\n\ " Result generally same as creating new archive, but unchanged entries",
-0 store files (no compression)\n\ " are copied instead of being read and compressed so can be faster.",
-1 to -9 compress fastest to compress best (default is 6)\n\ " WARNING: -FS deletes entries so make backup copy of archive first",
-Z cm set compression method to cm:\n\ "",
store - store without compression, same as option -0\n\ "Compression:",
deflate - original zip deflate, same as -1 to -9 (default)\n\ " -0 store files (no compression)",
bzip2 - use bzip2 compression (need modern unzip)\n\ " -1 to -9 compress fastest to compress best (default is 6)",
\n\ " -Z cm set compression method to cm:",
Encryption:\n\ " store - store without compression, same as option -0",
-e use standard (weak) PKZip 2.0 encryption, prompt for password\n\ " deflate - original zip deflate, same as -1 to -9 (default)",
-P pswd use standard encryption, password is pswd\n\ " if bzip2 is enabled:",
\n\ " bzip2 - use bzip2 compression (need modern unzip)",
Splits (archives created as a set of split files):\n\ "",
-s ssize create split archive with splits of size ssize, where ssize nm\n\ "Encryption:",
n number and m multiplier (kmgt, default m), 100k -> 100 kB\n\ " -e use standard (weak) PKZip 2.0 encryption, prompt for password",
-sp pause after each split closed to allow changing disks\n\ " -P pswd use standard encryption, password is pswd",
WARNING: Archives created with -sp use data descriptors and should\n\ "",
work with most unzips but may not work with some\n\ "Splits (archives created as a set of split files):",
-sb ring bell when pause\n\ " -s ssize create split archive with splits of size ssize, where ssize nm",
-sv be verbose about creating splits\n\ " n number and m multiplier (kmgt, default m), 100k -> 100 kB",
Split archives CANNOT be updated, but see --out and Copy Mode below\n\ " -sp pause after each split closed to allow changing disks",
\n\ " WARNING: Archives created with -sp use data descriptors and should",
Using --out (output to new archive):\n\ " work with most unzips but may not work with some",
--out oa output to new archive oa\n\ " -sb ring bell when pause",
Instead of updating input archive, create new output archive oa.\n\ " -sv be verbose about creating splits",
Result is same as without --out but in new archive. Input archive\n\ " Split archives CANNOT be updated, but see --out and Copy Mode below",
unchanged.\n\ "",
WARNING: --out ALWAYS overwrites any existing output file\n\ "Using --out (output to new archive):",
For example, to create new_archive like old_archive but add newfile1\n\ " --out oa output to new archive oa",
and newfile2:\n\ " Instead of updating input archive, create new output archive oa.",
zip old_archive newfile1 newfile2 --out new_archive\n\ " Result is same as without --out but in new archive. Input archive",
Cannot update split archive, so use --out to out new archive:\n\ " unchanged.",
zip in_split_archive newfile1 newfile2 --out out_split_archive\n\ " WARNING: --out ALWAYS overwrites any existing output file",
If input is split, output will default to same split size\n\ " For example, to create new_archive like old_archive but add newfile1",
Use -s=0 or -s- to turn off splitting to convert split to single file:\n\ " and newfile2:",
zip in_split_archive -s 0 --out out_single_file_archive\n\ " zip old_archive newfile1 newfile2 --out new_archive",
WARNING: If overwriting old split archive but need less splits,\n\ " Cannot update split archive, so use --out to out new archive:",
old splits not overwritten are not needed but remain\n\ " zip in_split_archive newfile1 newfile2 --out out_split_archive",
\n\ " If input is split, output will default to same split size",
Copy Mode (copying from archive to archive):\n\ " Use -s=0 or -s- to turn off splitting to convert split to single file:",
-U (also --copy) select entries in archive to copy (reverse delete)\n\ " zip in_split_archive -s 0 --out out_single_file_archive",
Copy Mode copies entries from old to new archive with --out and is used by\n\ " WARNING: If overwriting old split archive but need less splits,",
zip when either no input files on command line or -U (--copy) used.\n\ " old splits not overwritten are not needed but remain",
zip inarchive --copy pattern pattern ... --out outarchive\n\ "",
To copy only files matching *.c into new archive, excluding foo.c:\n\ "Copy Mode (copying from archive to archive):",
zip old_archive --copy \"*.c\" --out new_archive -x foo.c\n\ " -U (also --copy) select entries in archive to copy (reverse delete)",
If no input files and --out, copy all entries in old archive:\n\ " Copy Mode copies entries from old to new archive with --out and is used by",
zip old_archive --out new_archive\n\ " zip when either no input files on command line or -U (--copy) used.",
\n\ " zip inarchive --copy pattern pattern ... --out outarchive",
Streaming and FIFOs:\n\ " To copy only files matching *.c into new archive, excluding foo.c:",
prog1 | zip -ll z - zip output of prog1 to zipfile z, converting CR LF\n\ " zip old_archive --copy \"*.c\" --out new_archive -x foo.c",
zip - -R \"*.c\" | prog2 zip *.c files in current dir and stream to prog2 \n\ " If no input files and --out, copy all entries in old archive:",
prog1 | zip | prog2 zip in pipe with no in or out acts like zip - -\n\ " zip old_archive --out new_archive",
If Zip is Zip64 enabled, streaming stdin creates Zip64 archives by default\n\ "",
that need PKZip 4.5 unzipper like UnZip 6.0\n\ "Streaming and FIFOs:",
WARNING: Some archives created with streaming use data descriptors and\n\ " prog1 | zip -ll z - zip output of prog1 to zipfile z, converting CR LF",
should work with most unzips but may not work with some\n\ " zip - -R \"*.c\" | prog2 zip *.c files in current dir and stream to prog2 ",
Can use -fz- to turn off Zip64 if input not large (< 4 GB):\n\ " prog1 | zip | prog2 zip in pipe with no in or out acts like zip - -",
prog_with_small_output | zip archive -fz-\n\ " If Zip is Zip64 enabled, streaming stdin creates Zip64 archives by default",
\n\ " that need PKZip 4.5 unzipper like UnZip 6.0",
Zip now can read Unix FIFO (named pipes). Off by default to prevent zip\n\ " WARNING: Some archives created with streaming use data descriptors and",
from stopping unexpectedly on unfed pipe, use -FI to enable:\n\ " should work with most unzips but may not work with some",
zip -FI archive fifo\n\ " Can use -fz- to turn off Zip64 if input not large (< 4 GB):",
\n\ " prog_with_small_output | zip archive -fz-",
Dots, counts:\n\ "",
-db display running count of bytes processed and bytes to go\n\ " Zip now can read Unix FIFO (named pipes). Off by default to prevent zip",
(uncompressed size, except delete and copy show stored size)\n\ " from stopping unexpectedly on unfed pipe, use -FI to enable:",
-dc display running count of entries done and entries to go\n\ " zip -FI archive fifo",
-dd display dots every 10 MB (or dot size) while processing files\n\ "",
-dg display dots globally for archive instead of for each file\n\ "Dots, counts:",
zip -qdgds 10m will turn off most output except dots every 10 MB\n\ " -db display running count of bytes processed and bytes to go",
-ds siz each dot is siz processed where siz is nm as splits (0 no dots)\n\ " (uncompressed size, except delete and copy show stored size)",
-du display original uncompressed size for each entry as added\n\ " -dc display running count of entries done and entries to go",
-dv display volume (disk) number in format in_disk>out_disk\n\ " -dd display dots every 10 MB (or dot size) while processing files",
Dot size is approximate, especially for dot sizes less than 1 MB\n\ " -dg display dots globally for archive instead of for each file",
Dot options don't apply to Scanning files dots (dot/2sec) (-q turns off)\n\ " zip -qdgds 10m will turn off most output except dots every 10 MB",
\n\ " -ds siz each dot is siz processed where siz is nm as splits (0 no dots)",
Logging:\n\ " -du display original uncompressed size for each entry as added",
-lf path open file at path as logfile (overwrite existing file)\n\ " -dv display volume (disk) number in format in_disk>out_disk",
-la append to existing logfile\n\ " Dot size is approximate, especially for dot sizes less than 1 MB",
-li include info messages (default just warnings and errors)\n\ " Dot options don't apply to Scanning files dots (dot/2sec) (-q turns off)",
\n\ "",
Testing archives:\n\ "Logging:",
-T test completed temp archive with unzip before updating archive\n\ " -lf path open file at path as logfile (overwrite existing file)",
-TT cmd use command cmd instead of 'unzip -tqq' to test archive\n\ " -la append to existing logfile",
On Unix, to use unzip in current directory, could use:\n\ " -li include info messages (default just warnings and errors)",
zip archive file1 file2 -T -TT \"./unzip -tqq\"\n\ "",
In cmd, {} replaced by temp archive path, else temp appended.\n\ "Testing archives:",
The return code is checked for success (0 on Unix)\n\ " -T test completed temp archive with unzip before updating archive",
\n\ " -TT cmd use command cmd instead of 'unzip -tqq' to test archive",
Fixing archives:\n\ " On Unix, to use unzip in current directory, could use:",
-F attempt to fix a mostly intact archive (try this first)\n\ " zip archive file1 file2 -T -TT \"./unzip -tqq\"",
-FF try to salvage what can (may get more but less reliable)\n\ " In cmd, {} replaced by temp archive path, else temp appended.",
Fix options copy entries from potentially bad archive to new archive.\n\ " The return code is checked for success (0 on Unix)",
-F tries to read archive normally and copy only intact entries, while\n\ "",
-FF tries to salvage what can and may result in incomplete entries.\n\ "Fixing archives:",
Must use --out option to specify output archive:\n\ " -F attempt to fix a mostly intact archive (try this first)",
zip -F bad.zip --out fixed.zip\n\ " -FF try to salvage what can (may get more but less reliable)",
Use -v (verbose) with -FF to see details:\n\ " Fix options copy entries from potentially bad archive to new archive.",
zip reallybad.zip -FF -v --out fixed.zip\n\ " -F tries to read archive normally and copy only intact entries, while",
Currently neither option fixes bad entries, as from text mode ftp get.\n\ " -FF tries to salvage what can and may result in incomplete entries.",
\n\ " Must use --out option to specify output archive:",
Difference mode:\n\ " zip -F bad.zip --out fixed.zip",
-DF (also --dif) only include files that have changed or are\n\ " Use -v (verbose) with -FF to see details:",
new as compared to the input archive\n\ " zip reallybad.zip -FF -v --out fixed.zip",
Difference mode can be used to create incremental backups. For example:\n\ " Currently neither option fixes bad entries, as from text mode ftp get.",
zip --dif full_backup.zip -r somedir --out diff.zip\n\ "",
will store all new files, as well as any files in full_backup.zip where\n\ "Difference mode:",
either file time or size have changed from that in full_backup.zip,\n\ " -DF (also --dif) only include files that have changed or are",
in new diff.zip. Output archive not excluded automatically if exists,\n\ " new as compared to the input archive",
so either use -x to exclude it or put outside what is being zipped.\n\ " Difference mode can be used to create incremental backups. For example:",
\n\ " zip --dif full_backup.zip -r somedir --out diff.zip",
DOS Archive bit (Windows only):\n\ " will store all new files, as well as any files in full_backup.zip where",
-AS include only files with the DOS Archive bit set\n\ " either file time or size have changed from that in full_backup.zip,",
-AC after archive created, clear archive bit of included files\n\ " in new diff.zip. Output archive not excluded automatically if exists,",
WARNING: Once the archive bits are cleared they are cleared\n\ " so either use -x to exclude it or put outside what is being zipped.",
Use -T to test the archive before the bits are cleared\n\ "",
Can also use -sf to save file list before zipping files\n\ "DOS Archive bit (Windows only):",
\n\ " -AS include only files with the DOS Archive bit set",
Show files:\n\ " -AC after archive created, clear archive bit of included files",
-sf show files to operate on and exit (-sf- logfile only)\n\ " WARNING: Once the archive bits are cleared they are cleared",
-su as -sf but show escaped UTF-8 Unicode names also if exist\n\ " Use -T to test the archive before the bits are cleared",
-sU as -sf but show escaped UTF-8 Unicode names instead\n\ " Can also use -sf to save file list before zipping files",
Any character not in the current locale is escaped as #Uxxxx, where x\n\ "",
is hex digit, if 16-bit code is sufficient, or #Lxxxxxx if 24-bits\n\ "Show files:",
are needed. If add -UN=e, Zip escapes all non-ASCII characters.\n\ " -sf show files to operate on and exit (-sf- logfile only)",
\n\ " -su as -sf but show escaped UTF-8 Unicode names also if exist",
Unicode:\n\ " -sU as -sf but show escaped UTF-8 Unicode names instead",
If compiled with Unicode support, Zip stores UTF-8 path of entries.\n\ " Any character not in the current locale is escaped as #Uxxxx, where x",
This is backward compatible. Unicode paths allow better conversion\n\ " is hex digit, if 16-bit code is sufficient, or #Lxxxxxx if 24-bits",
of entry names between different character sets.\n\ " are needed. If add -UN=e, Zip escapes all non-ASCII characters.",
\n\ "",
New Unicode extra field includes checksum to verify Unicode path\n\ "Unicode:",
goes with standard path for that entry (as utilities like ZipNote\n\ " If compiled with Unicode support, Zip stores UTF-8 path of entries.",
can rename entries). If these do not match, use below options to\n\ " This is backward compatible. Unicode paths allow better conversion",
set what Zip does:\n\ " of entry names between different character sets.",
-UN=Quit - if mismatch, exit with error\n\ "",
-UN=Warn - if mismatch, warn, ignore UTF-8 (default)\n\ " New Unicode extra field includes checksum to verify Unicode path",
-UN=Ignore - if mismatch, quietly ignore UTF-8\n\ " goes with standard path for that entry (as utilities like ZipNote",
-UN=No - ignore any UTF-8 paths, use standard paths for all\n\ " can rename entries). If these do not match, use below options to",
An exception to -UN=N are entries with new UTF-8 bit set (instead\n\ " set what Zip does:",
of using extra fields). These are always handled as Unicode.\n\ " -UN=Quit - if mismatch, exit with error",
\n\ " -UN=Warn - if mismatch, warn, ignore UTF-8 (default)",
Normally Zip escapes all chars outside current char set, but leaves\n\ " -UN=Ignore - if mismatch, quietly ignore UTF-8",
as is supported chars, which may not be OK in path names. -UN=Escape\n\ " -UN=No - ignore any UTF-8 paths, use standard paths for all",
escapes any character not ASCII:\n\ " An exception to -UN=N are entries with new UTF-8 bit set (instead",
zip -sU -UN=e archive\n\ " of using extra fields). These are always handled as Unicode.",
Can use either normal path or escaped Unicode path on command line\n\ "",
to match files in archive.\n\ " Normally Zip escapes all chars outside current char set, but leaves",
\n\ " as is supported chars, which may not be OK in path names. -UN=Escape",
Zip now stores UTF-8 in entry path and comment fields on systems\n\ " escapes any character not ASCII:",
where UTF-8 char set is default, such as most modern Unix, and\n\ " zip -sU -UN=e archive",
and on other systems in new extra fields with escaped versions in\n\ " Can use either normal path or escaped Unicode path on command line",
entry path and comment fields for backward compatibility.\n\ " to match files in archive.",
Option -UN=UTF8 will force storing UTF-8 in entry path and comment\n\ "",
fields:\n\ " Zip now stores UTF-8 in entry path and comment fields on systems",
-UN=UTF8 - store UTF-8 in entry path and comment fields\n\ " where UTF-8 char set is default, such as most modern Unix, and",
This option can be useful for multi-byte char sets on Windows where\n\ " and on other systems in new extra fields with escaped versions in",
escaped paths and comments can be too long to be valid as the UTF-8\n\ " entry path and comment fields for backward compatibility.",
versions tend to be shorter.\n\ " Option -UN=UTF8 will force storing UTF-8 in entry path and comment",
\n\ " fields:",
Only UTF-8 comments on UTF-8 native systems supported. UTF-8 comments\n\ " -UN=UTF8 - store UTF-8 in entry path and comment fields",
for other systems planned in next release.\n\ " This option can be useful for multi-byte char sets on Windows where",
\n\ " escaped paths and comments can be too long to be valid as the UTF-8",
Self extractor:\n\ " versions tend to be shorter.",
-A Adjust offsets - a self extractor is created by prepending\n\ "",
the extractor executable to archive, but internal offsets\n\ " Only UTF-8 comments on UTF-8 native systems supported. UTF-8 comments",
are then off. Use -A to fix offsets.\n\ " for other systems planned in next release.",
-J Junk sfx - removes prepended extractor executable from\n\ "",
self extractor, leaving a plain zip archive.\n\ "Self extractor:",
\n\ " -A Adjust offsets - a self extractor is created by prepending",
More option highlights (see manual for additional options and details):\n\ " the extractor executable to archive, but internal offsets",
-b dir when creating or updating archive, create the temp archive in\n\ " are then off. Use -A to fix offsets.",
dir, which allows using seekable temp file when writing to a\n\ " -J Junk sfx - removes prepended extractor executable from",
write once CD, such archives compatible with more unzips\n\ " self extractor, leaving a plain zip archive.",
(could require additional file copy if on another device)\n\ "",
-MM input patterns must match at least one file and matched files\n\ "More option highlights (see manual for additional options and details):",
must be readable or exit with OPEN error and abort archive\n\ " -b dir when creating or updating archive, create the temp archive in",
(without -MM, both are warnings only, and if unreadable files\n\ " dir, which allows using seekable temp file when writing to a",
are skipped OPEN error (18) returned after archive created)\n\ " write once CD, such archives compatible with more unzips",
-nw no wildcards (wildcards are like any other character)\n\ " (could require additional file copy if on another device)",
-sc show command line arguments as processed and exit\n\ " -MM input patterns must match at least one file and matched files",
-sd show debugging as Zip does each step\n\ " must be readable or exit with OPEN error and abort archive",
-so show all available options on this system\n\ " (without -MM, both are warnings only, and if unreadable files",
-X default=strip old extra fields, -X- keep old, -X strip most\n\ " are skipped OPEN error (18) returned after archive created)",
-ws wildcards don't span directory boundaries in paths\n\ " -nw no wildcards (wildcards are like any other character)",
"); " -sc show command line arguments as processed and exit",
exit(0); " -sd show debugging as Zip does each step",
" -so show all available options on this system",
" -X default=strip old extra fields, -X- keep old, -X strip most",
" -ws wildcards don't span directory boundaries in paths",
""
};
for (i = 0; i < sizeof(text)/sizeof(char *); i++)
{
printf(text[i]);
putchar('\n');
}
#ifdef DOS
check_for_windows("Zip");
#endif
} }
/* /*
@ -1372,7 +1468,7 @@ local void check_zipfile(zipname, zippath)
int result; int result;
/* Tell picky compilers to shut up about unused variables */ /* Tell picky compilers to shut up about unused variables */
(void)zippath; zippath = zippath;
if (unzip_path) { if (unzip_path) {
/* user gave us a path to some unzip (may not be UnZip) */ /* user gave us a path to some unzip (may not be UnZip) */
@ -1737,7 +1833,7 @@ ZCONST char *zfn;
char *prompt; char *prompt;
/* Tell picky compilers to shut up about unused variables */ /* Tell picky compilers to shut up about unused variables */
(void)zfn; zfn = zfn;
prompt = (modeflag == ZP_PW_VERIFY) ? prompt = (modeflag == ZP_PW_VERIFY) ?
"Verify password: " : "Enter password: "; "Verify password: " : "Enter password: ";
@ -1756,7 +1852,7 @@ int size;
ZCONST char *zfn; ZCONST char *zfn;
{ {
/* Tell picky compilers to shut up about unused variables */ /* Tell picky compilers to shut up about unused variables */
(void)modeflag; (void)pwbuf; (void)size; (void)zfn; modeflag = modeflag; pwbuf = pwbuf; size = size; zfn = zfn;
return ZE_LOGIC; /* This function should never be called! */ return ZE_LOGIC; /* This function should never be called! */
} }
@ -2132,6 +2228,7 @@ char **argv; /* command line tokens */
char **args = NULL; /* could be wide argv */ char **args = NULL; /* could be wide argv */
#ifdef THEOS #ifdef THEOS
/* the argument expansion from the standard library is full of bugs */ /* the argument expansion from the standard library is full of bugs */
/* use mine instead */ /* use mine instead */
@ -2197,6 +2294,15 @@ char **argv; /* command line tokens */
} }
#endif #endif
#ifdef RISCOS
set_prefix();
#endif
#ifdef __human68k__
fflush(stderr);
setbuf(stderr, NULL);
#endif
/* Re-initialize global variables to make the zip dll re-entrant. It is /* Re-initialize global variables to make the zip dll re-entrant. It is
* possible that we could get away with not re-initializing all of these * possible that we could get away with not re-initializing all of these
* but better safe than sorry. * but better safe than sorry.
@ -2415,6 +2521,8 @@ char **argv; /* command line tokens */
mesg = (FILE *) stdout; /* cannot be made at link time for VMS */ mesg = (FILE *) stdout; /* cannot be made at link time for VMS */
comment_stream = (FILE *)stdin; comment_stream = (FILE *)stdin;
init_upper(); /* build case map table */
#ifdef LARGE_FILE_SUPPORT #ifdef LARGE_FILE_SUPPORT
/* test if we can support large files - 9/29/04 */ /* test if we can support large files - 9/29/04 */
if (sizeof(zoff_t) < 8) { if (sizeof(zoff_t) < 8) {
@ -2533,8 +2641,6 @@ char **argv; /* command line tokens */
NLMsignals(); NLMsignals();
#endif #endif
if (!IsTiny()) ShowCrashReports();
#if defined(UNICODE_SUPPORT) && defined(WIN32) #if defined(UNICODE_SUPPORT) && defined(WIN32)
/* check if this Win32 OS has support for wide character calls */ /* check if this Win32 OS has support for wide character calls */
@ -2575,6 +2681,25 @@ char **argv; /* command line tokens */
{ {
switch (option) switch (option)
{ {
#ifdef EBCDIC
case 'a':
aflag = ASCII;
printf("Translating to ASCII...\n");
break;
#endif /* EBCDIC */
#ifdef CMS_MVS
case 'B':
bflag = 1;
printf("Using binary mode...\n");
break;
#endif /* CMS_MVS */
#ifdef TANDEM
case 'B':
nskformatopt(value);
free(value);
break;
#endif
case '0': case '0':
method = STORE; level = 0; break; method = STORE; level = 0; break;
case '1': case '2': case '3': case '4': case '1': case '2': case '3': case '4':
@ -2610,6 +2735,11 @@ char **argv; /* command line tokens */
} }
action = DELETE; action = DELETE;
break; break;
#ifdef MACOS
case o_df:
MacZip.DataForkOnly = true;
break;
#endif /* MACOS */
case o_db: case o_db:
if (negated) if (negated)
display_bytes = 0; display_bytes = 0;
@ -3566,6 +3696,14 @@ char **argv; /* command line tokens */
filterlist_to_patterns(); filterlist_to_patterns();
} }
#if (defined(MSDOS) || defined(OS2)) && !defined(WIN32)
if ((kk == 3 || kk == 4) && volume_label == 1) {
/* read volume label */
PROCNAME(NULL);
kk = 4;
}
#endif
if (have_out && kk == 3) { if (have_out && kk == 3) {
copy_only = 1; copy_only = 1;
action = ARCHIVE; action = ARCHIVE;
@ -4646,9 +4784,7 @@ char **argv; /* command line tokens */
#if CRYPT #if CRYPT
/* Initialize the crc_32_tab pointer, when encryption was requested. */ /* Initialize the crc_32_tab pointer, when encryption was requested. */
if (key != NULL) { if (key != NULL) {
#ifndef USE_ZLIB
crc_32_tab = get_crc_table(); crc_32_tab = get_crc_table();
#endif
#ifdef EBCDIC #ifdef EBCDIC
/* convert encryption key to ASCII (ISO variant for 8-bit ASCII chars) */ /* convert encryption key to ASCII (ISO variant for 8-bit ASCII chars) */
strtoasc(key, key); strtoasc(key, key);

92
third_party/zip/zip.h vendored
View file

@ -1,6 +1,81 @@
// clang-format off
/*
zip.h - Zip 3
/---------------------------------------------------------------------/
Info-ZIP Licence
This is version 2007-Mar-4 of the Info-ZIP license.
The definitive version of this document should be available at
ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely and
a copy at http://www.info-zip.org/pub/infozip/license.html.
Copyright (c) 1990-2008 Info-ZIP. All rights reserved.
For the purposes of this copyright and license, "Info-ZIP" is defined as
the following set of individuals:
Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
Jean-loup Gailly, Hunter Goatley, Ed Gordon, Ian Gorman, Chris Herborth,
Dirk Haase, Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz,
David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko,
Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs,
Kai Uwe Rommel, Steve Salisbury, Dave Smith, Steven M. Schweda,
Christian Spieler, Cosmin Truta, Antoine Verheijen, Paul von Behren,
Rich Wales, Mike White.
This software is provided "as is," without warranty of any kind, express
or implied. In no event shall Info-ZIP or its contributors be held liable
for any direct, indirect, incidental, special or consequential damages
arising out of the use of or inability to use this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the above disclaimer and the following restrictions:
1. Redistributions of source code (in whole or in part) must retain
the above copyright notice, definition, disclaimer, and this list
of conditions.
2. Redistributions in binary form (compiled executables and libraries)
must reproduce the above copyright notice, definition, disclaimer,
and this list of conditions in documentation and/or other materials
provided with the distribution. The sole exception to this condition
is redistribution of a standard UnZipSFX binary (including SFXWiz) as
part of a self-extracting archive; that is permitted without inclusion
of this license, as long as the normal SFX banner has not been removed
from the binary or disabled.
3. Altered versions--including, but not limited to, ports to new operating
systems, existing ports with new graphical interfaces, versions with
modified or added functionality, and dynamic, shared, or static library
versions not from Info-ZIP--must be plainly marked as such and must not
be misrepresented as being the original source or, if binaries,
compiled from the original source. Such altered versions also must not
be misrepresented as being Info-ZIP releases--including, but not
limited to, labeling of the altered versions with the names "Info-ZIP"
(or any variation thereof, including, but not limited to, different
capitalizations), "Pocket UnZip," "WiZ" or "MacZip" without the
explicit permission of Info-ZIP. Such altered versions are further
prohibited from misrepresentative use of the Zip-Bugs or Info-ZIP
e-mail addresses or the Info-ZIP URL(s), such as to imply Info-ZIP
will provide support for the altered versions.
4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
"UnZipSFX," "WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its
own source and binary releases.
/---------------------------------------------------------------------/
*/
/*
* zip.h by Mark Adler
*/
#ifndef __zip_h #ifndef __zip_h
#define __zip_h 1 #define __zip_h 1
/* clang-format off */
#define ZIP /* for crypt.c: include zip password functions, not unzip */ #define ZIP /* for crypt.c: include zip password functions, not unzip */
@ -13,8 +88,9 @@ typedef unsigned long ulg; /* unsigned 32-bit value */
/* Set up portability */ /* Set up portability */
#include "third_party/zip/tailor.h" #include "third_party/zip/tailor.h"
/* Error return codes and PERR macro */ #ifdef USE_ZLIB
#include "third_party/zip/ziperr.h" #include "third_party/zlib/zlib.h"
#endif
/* In the utilities, the crc32() function is only used for UNICODE_SUPPORT. */ /* In the utilities, the crc32() function is only used for UNICODE_SUPPORT. */
#if defined(UTIL) && !defined(UNICODE_SUPPORT) #if defined(UTIL) && !defined(UNICODE_SUPPORT)
@ -201,6 +277,9 @@ struct plist {
#define ZP_PW_ENTER 0 /* request for encryption password */ #define ZP_PW_ENTER 0 /* request for encryption password */
#define ZP_PW_VERIFY 1 /* request for reentering password */ #define ZP_PW_VERIFY 1 /* request for reentering password */
/* Error return codes and PERR macro */
#include "third_party/zip/ziperr.h"
#if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */ #if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
# define CRCVAL_INITIAL crc32(0L, (uch *)NULL, 0) # define CRCVAL_INITIAL crc32(0L, (uch *)NULL, 0)
# if 00 /* not used, should be removed !! */ # if 00 /* not used, should be removed !! */
@ -795,6 +874,13 @@ void bi_init OF((char *, unsigned int, int));
# endif # endif
#endif /* WIN32 */ #endif /* WIN32 */
#if (defined(WINDLL) || defined(DLL_ZIPAPI))
/*---------------------------------------------------------------------------
Prototypes for public Zip API (DLL) functions.
---------------------------------------------------------------------------*/
#include "third_party/zip/api.h"
#endif /* WINDLL || DLL_ZIPAPI */
/* WIN32_OEM */ /* WIN32_OEM */
#ifdef WIN32 #ifdef WIN32

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
zipcloak.c - Zip 3 zipcloak.c - Zip 3
@ -29,12 +29,29 @@
#include "third_party/zip/crypt.h" #include "third_party/zip/crypt.h"
#include "third_party/zip/ttyio.h" #include "third_party/zip/ttyio.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/log/log.h" #include "libc/calls/sigtimedwait.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/sysv/consts/sig.h" #include "libc/calls/struct/siginfo.h"
#include "libc/stdio/temp.h" #include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/ss.h"
#ifndef NO_STDLIB_H #ifndef NO_STDLIB_H
#include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/calls/termios.h"
#include "libc/fmt/conv.h"
#include "libc/limits.h"
#include "libc/mem/alg.h"
#include "libc/mem/mem.h" #include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.h"
#include "third_party/musl/crypt.h"
#include "third_party/musl/rand48.h"
#endif #endif
#if CRYPT /* defined (as TRUE or FALSE) in crypt.h */ #if CRYPT /* defined (as TRUE or FALSE) in crypt.h */
@ -388,10 +405,10 @@ int main(argc, argv)
/* Informational messages are written to stdout. */ /* Informational messages are written to stdout. */
mesg = stdout; mesg = stdout;
#ifndef USE_ZLIB init_upper(); /* build case map table */
crc_32_tab = get_crc_table(); crc_32_tab = get_crc_table();
/* initialize crc table for crypt */ /* initialize crc table for crypt */
#endif
/* Go through args */ /* Go through args */
zipfile = tempzip = NULL; zipfile = tempzip = NULL;

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
zipfile.c - Zip 3 zipfile.c - Zip 3
@ -17,21 +17,60 @@
#include "third_party/zip/zip.h" #include "third_party/zip/zip.h"
#include "third_party/zip/revision.h" #include "third_party/zip/revision.h"
#ifdef UNICODE_SUPPORT #ifdef UNICODE_SUPPORT
#include "libc/stdio/lock.internal.h" #include "libc/assert.h"
#include "third_party/zip/crc32.h" #include "third_party/zip/crc32.h"
#endif #endif
/* for realloc 2/6/2005 EG */ /* for realloc 2/6/2005 EG */
#include "libc/mem/mem.h" #include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/calls/termios.h"
#include "libc/fmt/conv.h"
#include "libc/limits.h"
#include "libc/mem/alg.h" #include "libc/mem/alg.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/gdtoa/gdtoa.h"
#include "third_party/getopt/getopt.h"
#include "third_party/musl/crypt.h"
#include "third_party/musl/rand48.h"
#include "libc/errno.h" #include "libc/errno.h"
/* for toupper() */ /* for toupper() */
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/fmt/fmt.h"
#if defined(__GNUC__) && !defined(__llvm__) #ifdef VMS
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // MISSING #include "vms/vms.h"
// MISSING #include "vms/vmsmunch.h"
// MISSING #include "vms/vmsdefs.h"
#endif
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
#include "libc/nt/accounting.h"
#include "libc/nt/automation.h"
#include "libc/nt/console.h"
#include "libc/nt/debug.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/keyaccess.h"
#include "libc/nt/enum/regtype.h"
#include "libc/nt/errors.h"
#include "libc/nt/events.h"
#include "libc/nt/files.h"
#include "libc/nt/ipc.h"
#include "libc/nt/memory.h"
#include "libc/nt/paint.h"
#include "libc/nt/process.h"
#include "libc/nt/registry.h"
#include "libc/nt/synchronization.h"
#include "libc/nt/thread.h"
#include "libc/nt/windows.h"
#include "libc/nt/winsock.h"
#endif #endif
/* /*
@ -3210,7 +3249,7 @@ local int scanzipf_fixnew()
int r = 0; /* zipcopy return */ int r = 0; /* zipcopy return */
uzoff_t s; /* size of data, start of central */ uzoff_t s; /* size of data, start of central */
struct zlist far * far *x; /* pointer last entry's link */ struct zlist far * far *x=0; /* pointer last entry's link */
struct zlist far *z; /* current zip entry structure */ struct zlist far *z; /* current zip entry structure */
int plen; int plen;
char *in_path_ext; char *in_path_ext;
@ -3631,6 +3670,7 @@ local int scanzipf_fixnew()
/* first link */ /* first link */
x = &zfiles; x = &zfiles;
/* Link into list */ /* Link into list */
assert(x != NULL);
*x = z; *x = z;
z->nxt = NULL; z->nxt = NULL;
x = &z->nxt; x = &z->nxt;
@ -4042,7 +4082,7 @@ local int scanzipf_regnew()
int skipped_disk = 0; /* 1 if skipped start disk and start offset is useless */ int skipped_disk = 0; /* 1 if skipped start disk and start offset is useless */
uzoff_t s; /* size of data, start of central */ uzoff_t s; /* size of data, start of central */
struct zlist far * far *x; /* pointer last entry's link */ struct zlist far * far *x=0; /* pointer last entry's link */
struct zlist far *z; /* current zip entry structure */ struct zlist far *z; /* current zip entry structure */
@ -4070,7 +4110,6 @@ local int scanzipf_regnew()
bytes (=65557 bytes) from the end of the file. bytes (=65557 bytes) from the end of the file.
We back up 128k, to allow some junk being appended to a Zip file. We back up 128k, to allow some junk being appended to a Zip file.
*/ */
int e = errno;
if ((zfseeko(in_file, -0x20000L, SEEK_END) != 0) || if ((zfseeko(in_file, -0x20000L, SEEK_END) != 0) ||
/* Some fseek() implementations (e.g. MSC 8.0 16-bit) fail to signal /* Some fseek() implementations (e.g. MSC 8.0 16-bit) fail to signal
an error when seeking before the beginning of the file. an error when seeking before the beginning of the file.
@ -4078,7 +4117,6 @@ local int scanzipf_regnew()
for the error value -1. for the error value -1.
*/ */
(zftello(in_file) == (zoff_t)-1L)) { (zftello(in_file) == (zoff_t)-1L)) {
errno = e;
/* file is less than 128 KB so back up to beginning */ /* file is less than 128 KB so back up to beginning */
if (zfseeko(in_file, 0L, SEEK_SET) != 0) { if (zfseeko(in_file, 0L, SEEK_SET) != 0) {
fclose(in_file); fclose(in_file);
@ -5052,6 +5090,7 @@ local int scanzipf_regnew()
#endif #endif
/* Link into list */ /* Link into list */
assert(x != NULL);
*x = z; *x = z;
z->nxt = NULL; z->nxt = NULL;
x = &z->nxt; x = &z->nxt;
@ -5122,12 +5161,28 @@ int readzipfile()
zipfile_exists = 0; zipfile_exists = 0;
/* If zip file exists, read headers and check structure */ /* If zip file exists, read headers and check structure */
#ifdef VMS
if (zipfile == NULL || !(*zipfile) || !strcmp(zipfile, "-"))
return ZE_OK;
{
int rtype;
if ((VMSmunch(zipfile, GET_RTYPE, (char *)&rtype) == RMS$_NORMAL) &&
(rtype == FAT$C_VARIABLE)) {
fprintf(mesg,
"\n Error: zipfile is in variable-length record format. Please\n\
run \"bilf b %s\" to convert the zipfile to fixed-length\n\
record format.\n\n", zipfile);
return ZE_FORM;
}
}
readable = ((f = zfopen(zipfile, FOPR)) != NULL);
#else /* !VMS */
readable = (zipfile != NULL && *zipfile && strcmp(zipfile, "-")); readable = (zipfile != NULL && *zipfile && strcmp(zipfile, "-"));
if (readable) { if (readable) {
int e = errno;
readable = ((f = zfopen(zipfile, FOPR)) != NULL); readable = ((f = zfopen(zipfile, FOPR)) != NULL);
errno = e;
} }
#endif /* ?VMS */
/* skip check if streaming */ /* skip check if streaming */
if (!readable) { if (!readable) {
@ -5142,9 +5197,63 @@ int readzipfile()
zipfile_exists = 1; zipfile_exists = 1;
} }
#ifdef MVS
/* Very nasty special case for MVS. Just because the zipfile has been
* opened for reading does not mean that we can actually read the data.
* Typical JCL to create a zipfile is
*
* //ZIPFILE DD DISP=(NEW,CATLG),DSN=prefix.ZIP,
* // SPACE=(CYL,(10,10))
*
* That creates a VTOC entry with an end of file marker (DS1LSTAR) of zero.
* Alas the VTOC end of file marker is only used when the file is opened in
* append mode. When a file is opened in read mode, the "other" end of file
* marker is used, a zero length data block signals end of file when reading.
* With a brand new file which has not been written to yet, it is undefined
* what you read off the disk. In fact you read whatever data was in the same
* disk tracks before the zipfile was allocated. You would be amazed at the
* number of application programmers who still do not understand this. Makes
* for interesting and semi-random errors, GIGO.
*
* Newer versions of SMS will automatically write a zero length block when a
* file is allocated. However not all sites run SMS or they run older levels
* so we cannot rely on that. The only safe thing to do is close the file,
* open in append mode (we already know that the file exists), close it again,
* reopen in read mode and try to read a data block. Opening and closing in
* append mode will write a zero length block where DS1LSTAR points, making
* sure that the VTOC and internal end of file markers are in sync. Then it
* is safe to read data. If we cannot read one byte of data after all that,
* it is a brand new zipfile and must not be read.
*/
if (readable)
{
char c;
fclose(f);
/* append mode */
if ((f = zfopen(zipfile, "ab")) == NULL) {
ZIPERR(ZE_OPEN, zipfile);
}
fclose(f);
/* read mode again */
if ((f = zfopen(zipfile, FOPR)) == NULL) {
ZIPERR(ZE_OPEN, zipfile);
}
if (fread(&c, 1, 1, f) != 1) {
/* no actual data */
readable = 0;
fclose(f);
}
else{
fseek(f, 0, SEEK_SET); /* at least one byte in zipfile, back to the start */
}
}
#endif /* MVS */
/* ------------------------ */ /* ------------------------ */
/* new file read */ /* new file read */
#ifndef UTIL #ifndef UTIL
if (fix == 2) { if (fix == 2) {
scanzipf_fixnew(); scanzipf_fixnew();

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
zipnote.c - Zip 3 zipnote.c - Zip 3
@ -21,13 +21,12 @@
#define DEFCPYRT /* main module: enable copyright string defines! */ #define DEFCPYRT /* main module: enable copyright string defines! */
#include "third_party/zip/revision.h" #include "third_party/zip/revision.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/fmt/fmt.h" #include "libc/calls/sigtimedwait.h"
#include "libc/fmt/conv.h"
#include "libc/mem/alg.h"
#include "libc/log/log.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/sysv/consts/sig.h" #include "libc/calls/struct/siginfo.h"
#include "libc/stdio/temp.h" #include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/ss.h"
/* Calculate size of static line buffer used in write (-w) mode. */ /* Calculate size of static line buffer used in write (-w) mode. */
#define WRBUFSIZ 2047 #define WRBUFSIZ 2047
@ -73,6 +72,10 @@ void zipnoteerr(int c, ZCONST char *h);
void zipnotewarn(ZCONST char *a, ZCONST char *b); void zipnotewarn(ZCONST char *a, ZCONST char *b);
#endif #endif
#ifdef QDOS
#define exit(p1) QDOSexit()
#endif
int set_filetype(out_path) int set_filetype(out_path)
char *out_path; char *out_path;
{ {
@ -454,6 +457,8 @@ char **argv; /* command line tokens */
/* Direct info messages to stderr; stdout is used for data output. */ /* Direct info messages to stderr; stdout is used for data output. */
mesg = stderr; mesg = stderr;
init_upper(); /* build case map table */
/* Go through args */ /* Go through args */
zipfile = tempzip = NULL; zipfile = tempzip = NULL;
tempzf = NULL; tempzf = NULL;

View file

@ -1,4 +1,4 @@
/* clang-format off */ // clang-format off
/* /*
zipsplit.c - Zip 3 zipsplit.c - Zip 3
@ -21,12 +21,12 @@
#define DEFCPYRT /* main module: enable copyright string defines! */ #define DEFCPYRT /* main module: enable copyright string defines! */
#include "third_party/zip/revision.h" #include "third_party/zip/revision.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/fmt/fmt.h" #include "libc/calls/sigtimedwait.h"
#include "libc/fmt/conv.h"
#include "libc/mem/alg.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/sysv/consts/sig.h" #include "libc/calls/struct/siginfo.h"
#include "libc/log/log.h" #include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/ss.h"
#define DEFSIZ 36000L /* Default split size (change in help() too) */ #define DEFSIZ 36000L /* Default split size (change in help() too) */
#ifdef MSDOS #ifdef MSDOS
@ -41,6 +41,11 @@
# define ZPATH_SEP '.' # define ZPATH_SEP '.'
#else #else
#ifdef QDOS #ifdef QDOS
# define ZPATH_SEP '_'
# define INDEX "zipsplit_idx" /* Name of index file */
# define TEMPL_FMT "%%0%dld_zip"
# define TEMPL_SIZ 17
# define exit(p1) QDOSexit()
#else #else
#ifdef VM_CMS #ifdef VM_CMS
# define INDEX "zipsplit.idx" /* Name of index file */ # define INDEX "zipsplit.idx" /* Name of index file */
@ -586,6 +591,8 @@ char **argv; /* command line tokens */
/* Informational messages are written to stdout. */ /* Informational messages are written to stdout. */
mesg = stdout; mesg = stdout;
init_upper(); /* build case map table */
/* Go through args */ /* Go through args */
signal(SIGINT, handler); signal(SIGINT, handler);
#ifdef SIGTERM /* Amiga has no SIGTERM */ #ifdef SIGTERM /* Amiga has no SIGTERM */

View file

@ -1,5 +1,4 @@
// -*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*- // clang-format off
/* clang-format off */
/* /*
zipup.c - Zip 3 zipup.c - Zip 3
@ -21,26 +20,134 @@
different sizes and needless to say leads to segmentation faults. Putting different sizes and needless to say leads to segmentation faults. Putting
zip.h first seems to fix this. 8/14/04 EG */ zip.h first seems to fix this. 8/14/04 EG */
#include "third_party/zip/zip.h" #include "third_party/zip/zip.h"
#include "libc/errno.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/log/log.h" #include "third_party/zip/zipup.h"
#include "libc/sysv/consts/prot.h" #include "third_party/bzip2/bzlib.h"
#include "libc/fmt/fmt.h" #include "libc/calls/typedef/u.h"
#include "libc/stdio/stdio.h" #include "third_party/zlib/zconf.h"
#include "libc/runtime/sysconf.h" #include "libc/runtime/sysconf.h"
#include "libc/runtime/sysconf.h" #include "libc/errno.h"
#include "libc/runtime/runtime.h"
#ifndef UTIL /* This module contains no code for Zip Utilities */ #ifndef UTIL /* This module contains no code for Zip Utilities */
#include "third_party/zip/revision.h" #include "third_party/zip/revision.h"
#include "third_party/zip/crc32.h" #include "third_party/zip/crc32.h"
#include "third_party/zip/crypt.h" #include "third_party/zip/crypt.h"
#include "third_party/bzip2/bzlib.h" #ifdef USE_ZLIB
// MISSING #include "zlib.h"
#endif
#ifdef BZIP2_SUPPORT
# ifdef BZIP2_USEBZIP2DIR
// MISSING #include "bzip2/bzlib.h"
# else
// MISSING #include "bzlib.h"
# endif
#endif
#ifdef OS2
// MISSING #include "os2/os2zip.h"
#endif
#if defined(MMAP)
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/mlock.h"
#include "libc/sysv/consts/msync.h"
#include "libc/sysv/consts/posix.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/mfd.h"
#include "libc/sysv/consts/mremap.h" #include "libc/sysv/consts/mremap.h"
# ifndef PAGESIZE /* used to be SYSV, what about pagesize on SVR3 ? */
# define PAGESIZE getpagesize()
# endif
# if defined(NO_VALLOC) && !defined(valloc)
# define valloc malloc
# endif
#endif
/* Use the raw functions for MSDOS and Unix to save on buffer space.
They're not used for VMS since it doesn't work (raw is weird on VMS).
*/
#ifdef AMIGA
// MISSING #include "amiga/zipup.h"
#endif /* AMIGA */
#ifdef AOSVS
// MISSING #include "aosvs/zipup.h"
#endif /* AOSVS */
#ifdef ATARI
// MISSING #include "atari/zipup.h"
#endif
#ifdef __BEOS__
// MISSING #include "beos/zipup.h"
#endif
#ifdef __ATHEOS__
// MISSING #include "atheos/zipup.h"
#endif /* __ATHEOS__ */
#ifdef __human68k__
// MISSING #include "human68k/zipup.h"
#endif /* __human68k__ */
#ifdef MACOS
// MISSING #include "macos/zipup.h"
#endif
#ifdef DOS
// MISSING #include "msdos/zipup.h"
#endif /* DOS */
#ifdef NLM
// MISSING #include "novell/zipup.h"
// MISSING #include <nwfattr.h>
#endif
#ifdef OS2
// MISSING #include "os2/zipup.h"
#endif /* OS2 */
#ifdef RISCOS
// MISSING #include "acorn/zipup.h"
#endif
#ifdef TOPS20
// MISSING #include "tops20/zipup.h"
#endif
#ifdef UNIX
// MISSING #include "unix/zipup.h"
#endif
#ifdef CMS_MVS
#include "third_party/zip/zipup.h" #include "third_party/zip/zipup.h"
#endif /* CMS_MVS */
#ifdef TANDEM
#include "third_party/zip/zipup.h"
#endif /* TANDEM */
#ifdef VMS
// MISSING #include "vms/zipup.h"
#endif /* VMS */
#ifdef QDOS
// MISSING #include "qdos/zipup.h"
#endif /* QDOS */
#ifdef WIN32
// MISSING #include "win32/zipup.h"
#endif
#ifdef THEOS
// MISSING #include "theos/zipup.h"
#endif
/* Local functions */ /* Local functions */
#ifndef RISCOS #ifndef RISCOS
@ -539,17 +646,17 @@ struct zlist far *z; /* zip entry to compress */
if (window != NULL) if (window != NULL)
free(window); /* window can't be a mapped file here */ free(window); /* window can't be a mapped file here */
window_size = (ulg)q + MIN_LOOKAHEAD; window_size = (ulg)q + MIN_LOOKAHEAD;
remain = window_size & (sysconf(_SC_PAGESIZE)-1); remain = window_size & (PAGESIZE-1);
/* If we can't touch the page beyond the end of file, we must /* If we can't touch the page beyond the end of file, we must
* allocate an extra page. * allocate an extra page.
*/ */
if (remain > MIN_LOOKAHEAD) { if (remain > MIN_LOOKAHEAD) {
window = (uch*)mmap(0, window_size, PROT_READ, MAP_PRIVATE, ifile, 0); window = (uch*)mmap(0, window_size, PROT_READ, MAP_PRIVATE, ifile, 0);
} else { } else {
window = (uch*)pvalloc(window_size - remain + sysconf(_SC_PAGESIZE)); window = (uch*)valloc(window_size - remain + PAGESIZE);
if (window != NULL) { if (window != NULL) {
window = (uch*)mmap((char*)window, window_size - remain, PROT_READ, window = (uch*)mmap((char*)window, window_size - remain, PROT_READ,
MAP_PRIVATE | MAP_FIXED, ifile, 0); MAP_PRIVATE | MAP_FIXED, ifile, 0);
} else { } else {
window = (uch*)(-1); window = (uch*)(-1);
} }
@ -837,7 +944,7 @@ struct zlist far *z; /* zip entry to compress */
zclose(ifile); zclose(ifile);
#ifdef MMAP #ifdef MMAP
if (remain != (ulg)-1L) { if (remain != (ulg)-1L) {
munmap((void*) window, window_size); munmap((caddr_t) window, window_size);
window = NULL; window = NULL;
} }
#endif /*MMAP */ #endif /*MMAP */
@ -1446,8 +1553,8 @@ local zoff_t filecompress(z_entry, cmpr_method)
do { do {
err = deflate(&zstrm, Z_FINISH); err = deflate(&zstrm, Z_FINISH);
if (maybe_stored) { if (maybe_stored) {
if (err == Z_STREAM_END && zstrm.total_out >= zstrm.total_in/* && */ if (err == Z_STREAM_END && zstrm.total_out >= zstrm.total_in &&
/* fseekable(y) */) { fseekable(zipfile)) {
/* deflation does not reduce size, switch to STORE method */ /* deflation does not reduce size, switch to STORE method */
unsigned len_out = (unsigned)zstrm.total_in; unsigned len_out = (unsigned)zstrm.total_in;
if (zfwrite(f_ibuf, 1, len_out) != len_out) { if (zfwrite(f_ibuf, 1, len_out) != len_out) {
@ -1677,16 +1784,16 @@ int *cmpr_method;
} else } else
#endif /* MMAP || BIG_MEM */ #endif /* MMAP || BIG_MEM */
{ {
bstrm.next_in = f_ibuf; bstrm.next_in = (char *)f_ibuf;
} }
bstrm.avail_in = file_read((char *)bstrm.next_in, ibuf_sz); bstrm.avail_in = file_read(bstrm.next_in, ibuf_sz);
if (file_binary_final == 0) { if (file_binary_final == 0) {
/* check for binary as library does not */ /* check for binary as library does not */
if (!is_text_buf((char *)bstrm.next_in, ibuf_sz)) if (!is_text_buf(bstrm.next_in, ibuf_sz))
file_binary_final = 1; file_binary_final = 1;
} }
if (bstrm.avail_in < ibuf_sz) { if (bstrm.avail_in < ibuf_sz) {
unsigned more = file_read((char *)(bstrm.next_in + bstrm.avail_in), unsigned more = file_read(bstrm.next_in + bstrm.avail_in,
(ibuf_sz - bstrm.avail_in)); (ibuf_sz - bstrm.avail_in));
if (more == (unsigned) EOF || more == 0) { if (more == (unsigned) EOF || more == 0) {
maybe_stored = TRUE; maybe_stored = TRUE;
@ -1694,7 +1801,7 @@ int *cmpr_method;
bstrm.avail_in += more; bstrm.avail_in += more;
} }
} }
bstrm.next_out = (void *)f_obuf; bstrm.next_out = (char *)f_obuf;
bstrm.avail_out = OBUF_SZ; bstrm.avail_out = OBUF_SZ;
if (!maybe_stored) { if (!maybe_stored) {
@ -1708,7 +1815,7 @@ int *cmpr_method;
if (zfwrite(f_obuf, 1, OBUF_SZ) != OBUF_SZ) { if (zfwrite(f_obuf, 1, OBUF_SZ) != OBUF_SZ) {
ziperr(ZE_TEMP, "error writing to zipfile"); ziperr(ZE_TEMP, "error writing to zipfile");
} }
bstrm.next_out = f_obuf; bstrm.next_out = (char *)f_obuf;
bstrm.avail_out = OBUF_SZ; bstrm.avail_out = OBUF_SZ;
} }
/* $TODO what about high 32-bits of total-in??? */ /* $TODO what about high 32-bits of total-in??? */
@ -1750,14 +1857,14 @@ int *cmpr_method;
} }
#if defined(MMAP) || defined(BIG_MEM) #if defined(MMAP) || defined(BIG_MEM)
if (remain == (ulg)-1L) if (remain == (ulg)-1L)
bstrm.next_in = f_ibuf; bstrm.next_in = (char *)f_ibuf;
#else #else
bstrm.next_in = (char *)f_ibuf; bstrm.next_in = (char *)f_ibuf;
#endif #endif
bstrm.avail_in = file_read((char *)bstrm.next_in, ibuf_sz); bstrm.avail_in = file_read(bstrm.next_in, ibuf_sz);
if (file_binary_final == 0) { if (file_binary_final == 0) {
/* check for binary as library does not */ /* check for binary as library does not */
if (!is_text_buf((char *)bstrm.next_in, ibuf_sz)) if (!is_text_buf(bstrm.next_in, ibuf_sz))
file_binary_final = 1; file_binary_final = 1;
} }
} }
@ -1802,7 +1909,7 @@ int *cmpr_method;
if (zfwrite(f_obuf, 1, len_out) != len_out) { if (zfwrite(f_obuf, 1, len_out) != len_out) {
ziperr(ZE_TEMP, "error writing to zipfile"); ziperr(ZE_TEMP, "error writing to zipfile");
} }
bstrm.next_out = f_obuf; bstrm.next_out = (char *)f_obuf;
bstrm.avail_out = OBUF_SZ; bstrm.avail_out = OBUF_SZ;
} }
} while (err == BZ_FINISH_OK); } while (err == BZ_FINISH_OK);

View file

@ -1,20 +1,25 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_INFOZIP_ZIP_UNIX_ZIPUP_H_ // clang-format off
#define COSMOPOLITAN_THIRD_PARTY_INFOZIP_ZIP_UNIX_ZIPUP_H_ /*
#include "libc/calls/calls.h" unix/zipup.h - Zip 3
#include "libc/sysv/consts/o.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define fhow O_RDONLY Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
#define fbad (-1)
#define zopen(n, p) open(n, p)
#define zread(f, b, n) read(f, b, n)
#define zclose(f) close(f)
#define zerr(f) (k == (extent)(-1L))
#define zstdin 0
See the accompanying file LICENSE, version 2005-Feb-10 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#ifndef O_RDONLY
# define O_RDONLY 0
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
#define fhow (O_RDONLY|O_BINARY)
#define fbad (-1)
typedef int ftype; typedef int ftype;
#define zopen(n,p) open(n,p)
COSMOPOLITAN_C_END_ #define zread(f,b,n) read(f,b,n)
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #define zclose(f) close(f)
#endif /* COSMOPOLITAN_THIRD_PARTY_INFOZIP_ZIP_UNIX_ZIPUP_H_ */ #define zerr(f) (k == (extent)(-1L))
#define zstdin 0