diff --git a/tool/build/gzip.c b/tool/build/gzip.c index e99102f4e..14f00a463 100644 --- a/tool/build/gzip.c +++ b/tool/build/gzip.c @@ -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");