mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Fix bugs with cli flags in gzip.com
This commit is contained in:
parent
1c2da3a55a
commit
bf6459e324
1 changed files with 8 additions and 7 deletions
|
@ -137,13 +137,8 @@ void Compress(const char *inpath) {
|
||||||
int rc, n, errnum;
|
int rc, n, errnum;
|
||||||
const char *outpath;
|
const char *outpath;
|
||||||
char *p, openflags[5];
|
char *p, openflags[5];
|
||||||
outpath = 0;
|
if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) {
|
||||||
if (inpath) {
|
|
||||||
input = fopen(inpath, "rb");
|
|
||||||
} else if (opt_usestdout && (opt_force || !isatty(1))) {
|
|
||||||
opt_usestdout = true;
|
opt_usestdout = true;
|
||||||
inpath = "/dev/stdin";
|
|
||||||
input = stdin;
|
|
||||||
} else {
|
} else {
|
||||||
fputs(prog, stderr);
|
fputs(prog, stderr);
|
||||||
fputs(": compressed data not written to a terminal."
|
fputs(": compressed data not written to a terminal."
|
||||||
|
@ -151,6 +146,12 @@ void Compress(const char *inpath) {
|
||||||
stderr);
|
stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (inpath) {
|
||||||
|
input = fopen(inpath, "rb");
|
||||||
|
} else {
|
||||||
|
inpath = "/dev/stdin";
|
||||||
|
input = stdin;
|
||||||
|
}
|
||||||
p = openflags;
|
p = openflags;
|
||||||
*p++ = opt_append ? 'a' : 'w';
|
*p++ = opt_append ? 'a' : 'w';
|
||||||
*p++ = 'b';
|
*p++ = 'b';
|
||||||
|
@ -160,7 +161,7 @@ void Compress(const char *inpath) {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
if (opt_usestdout) {
|
if (opt_usestdout) {
|
||||||
outpath = "/dev/stdout";
|
outpath = "/dev/stdout";
|
||||||
output = gzdopen(0, openflags);
|
output = gzdopen(1, openflags);
|
||||||
} else {
|
} else {
|
||||||
if (strlen(inpath) + 3 + 1 > PATH_MAX) _Exit(2);
|
if (strlen(inpath) + 3 + 1 > PATH_MAX) _Exit(2);
|
||||||
stpcpy(stpcpy(pathbuf, inpath), ".gz");
|
stpcpy(stpcpy(pathbuf, inpath), ".gz");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue