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;
|
||||
const char *outpath;
|
||||
char *p, openflags[5];
|
||||
outpath = 0;
|
||||
if (inpath) {
|
||||
input = fopen(inpath, "rb");
|
||||
} else if (opt_usestdout && (opt_force || !isatty(1))) {
|
||||
if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) {
|
||||
opt_usestdout = true;
|
||||
inpath = "/dev/stdin";
|
||||
input = stdin;
|
||||
} else {
|
||||
fputs(prog, stderr);
|
||||
fputs(": compressed data not written to a terminal."
|
||||
|
@ -151,6 +146,12 @@ void Compress(const char *inpath) {
|
|||
stderr);
|
||||
exit(1);
|
||||
}
|
||||
if (inpath) {
|
||||
input = fopen(inpath, "rb");
|
||||
} else {
|
||||
inpath = "/dev/stdin";
|
||||
input = stdin;
|
||||
}
|
||||
p = openflags;
|
||||
*p++ = opt_append ? 'a' : 'w';
|
||||
*p++ = 'b';
|
||||
|
@ -160,7 +161,7 @@ void Compress(const char *inpath) {
|
|||
*p = 0;
|
||||
if (opt_usestdout) {
|
||||
outpath = "/dev/stdout";
|
||||
output = gzdopen(0, openflags);
|
||||
output = gzdopen(1, openflags);
|
||||
} else {
|
||||
if (strlen(inpath) + 3 + 1 > PATH_MAX) _Exit(2);
|
||||
stpcpy(stpcpy(pathbuf, inpath), ".gz");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue