version 1.101, 2022/08/29 19:42:01 |
version 1.102, 2022/10/22 14:41:27 |
|
|
|
|
enum program_mode pmode; |
enum program_mode pmode; |
|
|
int cat, decomp, pipin, force, verbose, testmode, list, recurse, storename; |
static int cat, decomp, kflag, pipin, force, verbose, testmode, list, recurse; |
int kflag; |
static int storename; |
|
static char suffix[16]; |
extern char *__progname; |
extern char *__progname; |
|
|
const struct compressor { |
const struct compressor { |
|
|
zwrite, |
zwrite, |
z_close |
z_close |
}, |
}, |
|
#define M_UNZIP (&c_table[2]) |
|
{ |
|
"unzip", |
|
".zip", |
|
"PK", |
|
NULL, |
|
"cfhkLlNno:qrtVv", |
|
"fhqr", |
|
zip_ropen, |
|
zip_read, |
|
NULL, |
|
NULL, |
|
zip_close |
|
}, |
#endif /* SMALL */ |
#endif /* SMALL */ |
{ NULL } |
{ NULL } |
}; |
}; |
|
|
const struct compressor *method; |
const struct compressor *method; |
const char *optstr, *s; |
const char *optstr, *s; |
char *p, *infile; |
char *p, *infile; |
char outfile[PATH_MAX], _infile[PATH_MAX], suffix[16]; |
char outfile[PATH_MAX], _infile[PATH_MAX]; |
int bits, ch, error, rc, cflag, oflag; |
int bits, ch, error, rc, cflag, oflag; |
|
|
if (pledge("stdio rpath wpath cpath fattr chown", NULL) == -1) |
if (pledge("stdio rpath wpath cpath fattr chown", NULL) == -1) |
|
|
if (optarg[0] != '.') |
if (optarg[0] != '.') |
*p++ = '.'; |
*p++ = '.'; |
strlcpy(p, optarg, sizeof(suffix) - (p - suffix)); |
strlcpy(p, optarg, sizeof(suffix) - (p - suffix)); |
p = optarg; |
|
break; |
break; |
case 't': |
case 't': |
testmode = 1; |
testmode = 1; |
|
|
} |
} |
} |
} |
ofd = open(out, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR); |
ofd = open(out, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR); |
|
if (ofd != -1) |
|
oreg = 1; |
} |
} |
if (ofd == -1) { |
if (ofd == -1) { |
if (verbose >= 0) |
if (verbose >= 0) |
|
|
error = errno == EINVAL ? WARNING : FAILURE; |
error = errno == EINVAL ? WARNING : FAILURE; |
} |
} |
|
|
if (method->close(cookie, &info, NULL, NULL)) { |
if (method->close(cookie, &info, NULL, NULL) && !error) { |
if (!error && verbose >= 0) |
#ifdef M_UNZIP |
warnx("%s", in); |
if (errno == EEXIST) { |
error = FAILURE; |
if (verbose >= 0) { |
|
warnx("more than one entry in %s: %s", in, |
|
cat ? "ignoring the rest" : "unchanged"); |
|
} |
|
error = cat ? WARNING : FAILURE; |
|
} else |
|
#endif |
|
{ |
|
if (verbose >= 0) |
|
warn("%s", in); |
|
error = FAILURE; |
|
} |
} |
} |
if (storename && !cat) { |
if (storename && !cat) { |
if (info.mtime != 0) { |
if (info.mtime != 0) { |
|
|
sb->st_atimespec.tv_sec = info.mtime; |
sb->st_atimespec.tv_sec = info.mtime; |
sb->st_mtimespec.tv_nsec = |
sb->st_mtimespec.tv_nsec = |
sb->st_atimespec.tv_nsec = 0; |
sb->st_atimespec.tv_nsec = 0; |
} else |
} |
storename = 0; /* no timestamp to restore */ |
|
} |
} |
if (error == SUCCESS) |
if (error != FAILURE) |
setfile(out, ofd, sb); |
setfile(out, ofd, sb); |
|
|
if (ofd != -1 && close(ofd)) { |
if (ofd != -1 && close(ofd)) { |
|
|
error = FAILURE; |
error = FAILURE; |
} |
} |
|
|
if (!error) { |
if (error != FAILURE) { |
if (list) { |
if (list) { |
if (info.mtime == 0) |
if (info.mtime == 0) |
info.mtime = (u_int32_t)sb->st_mtime; |
info.mtime = (u_int32_t)sb->st_mtime; |
|
|
} |
} |
|
|
/* On error, clean up the file we created but preserve errno. */ |
/* On error, clean up the file we created but preserve errno. */ |
if (error && oreg) |
if (error == FAILURE && oreg) |
unlink(out); |
unlink(out); |
|
|
return (error); |
return (error); |
|
|
check_suffix(const char *infile) |
check_suffix(const char *infile) |
{ |
{ |
int i; |
int i; |
char *suf, *sep, *separators = ".-_"; |
const char *suf, *sep; |
static char *suffixes[] = { "Z", "gz", "z", "tgz", "taz", NULL }; |
const char separators[] = ".-_"; |
|
const char *suffixes[] = { "Z", "gz", "z", "tgz", "taz", NULL }; |
|
|
for (sep = separators; *sep != '\0'; sep++) { |
for (sep = separators; *sep != '\0'; sep++) { |
if ((suf = strrchr(infile, *sep)) == NULL) |
if ((suf = strrchr(infile, *sep)) == NULL) |
continue; |
continue; |
suf++; |
suf++; |
|
|
|
if (strcmp(suf, suffix + 1) == 0) |
|
return (suf - 1); |
for (i = 0; suffixes[i] != NULL; i++) { |
for (i = 0; suffixes[i] != NULL; i++) { |
if (strcmp(suf, suffixes[i]) == 0) |
if (strcmp(suf, suffixes[i]) == 0) |
return (suf - 1); |
return (suf - 1); |