summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2010-06-12 05:22:55 +0000
committerdelphij <delphij@FreeBSD.org>2010-06-12 05:22:55 +0000
commitaa0fc0028504d7985b1cf7c1dfd8aebe1aba07c4 (patch)
treec4d7bc3f293422bf4d95e617765062b7de31c3e4 /usr.bin
parent2b4920d05f55f6e6d79794be2b9d00c3001823e5 (diff)
downloadFreeBSD-src-aa0fc0028504d7985b1cf7c1dfd8aebe1aba07c4.zip
FreeBSD-src-aa0fc0028504d7985b1cf7c1dfd8aebe1aba07c4.tar.gz
MFC r208888,208889,209017:
- make sure that initialize isb with fstat() on input file before using it. (bin/147275) - Fix grammar for st_nlink. - Style changes. PR: bin/147275 Approved by: re (kensmith)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/gzip/gzip.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c
index f465ef9..441724f 100644
--- a/usr.bin/gzip/gzip.c
+++ b/usr.bin/gzip/gzip.c
@@ -65,10 +65,6 @@ __RCSID("$FreeBSD$");
#include <getopt.h>
#include <time.h>
-#ifndef PRIdOFF
-#define PRIdOFF PRId64
-#endif
-
/* what type of file are we dealing with */
enum filetype {
FT_GZIP,
@@ -1221,40 +1217,46 @@ file_compress(char *file, char *outfile, size_t outsize)
in = open(file, O_RDONLY);
if (in == -1) {
maybe_warn("can't open %s", file);
- return -1;
+ return (-1);
}
+#ifndef SMALL
+ if (fstat(in, &isb) != 0) {
+ maybe_warn("couldn't stat: %s", file);
+ close(in);
+ return (-1);
+ }
+#endif
+
if (cflag == 0) {
#ifndef SMALL
- if (fstat(in, &isb) == 0) {
- if (isb.st_nlink > 1 && fflag == 0) {
- maybe_warnx("%s has %d other link%s -- "
- "skipping", file, isb.st_nlink - 1,
- isb.st_nlink == 1 ? "" : "s");
- close(in);
- return -1;
- }
+ if (isb.st_nlink > 1 && fflag == 0) {
+ maybe_warnx("%s has %d other link%s -- skipping",
+ file, isb.st_nlink - 1,
+ (isb.st_nlink - 1) == 1 ? "" : "s");
+ close(in);
+ return (-1);
}
- if (fflag == 0 && (suff = check_suffix(file, 0))
- && suff->zipped[0] != 0) {
+ if (fflag == 0 && (suff = check_suffix(file, 0)) &&
+ suff->zipped[0] != 0) {
maybe_warnx("%s already has %s suffix -- unchanged",
- file, suff->zipped);
+ file, suff->zipped);
close(in);
- return -1;
+ return (-1);
}
#endif
/* Add (usually) .gz to filename */
if ((size_t)snprintf(outfile, outsize, "%s%s",
- file, suffixes[0].zipped) >= outsize)
+ file, suffixes[0].zipped) >= outsize)
memcpy(outfile + outsize - suffixes[0].ziplen - 1,
- suffixes[0].zipped, suffixes[0].ziplen + 1);
+ suffixes[0].zipped, suffixes[0].ziplen + 1);
#ifndef SMALL
if (check_outfile(outfile) == 0) {
close(in);
- return -1;
+ return (-1);
}
#endif
}
@@ -1264,7 +1266,7 @@ file_compress(char *file, char *outfile, size_t outsize)
if (out == -1) {
maybe_warn("could not create output: %s", outfile);
fclose(stdin);
- return -1;
+ return (-1);
}
#ifndef SMALL
remove_file = outfile;
@@ -1284,7 +1286,7 @@ file_compress(char *file, char *outfile, size_t outsize)
* has the expected size.
*/
if (cflag != 0)
- return insize == -1 ? -1 : size;
+ return (insize == -1 ? -1 : size);
#ifndef SMALL
if (fstat(out, &osb) != 0) {
@@ -1293,9 +1295,8 @@ file_compress(char *file, char *outfile, size_t outsize)
}
if (osb.st_size != size) {
- maybe_warnx("output file: %s wrong size (%" PRIdOFF
- " != %" PRIdOFF "), deleting",
- outfile, osb.st_size, size);
+ maybe_warnx("output file: %s wrong size (%ju != %ju), deleting",
+ outfile, (uintmax_t)osb.st_size, (uintmax_t)size);
goto bad_outfile;
}
@@ -1307,7 +1308,7 @@ file_compress(char *file, char *outfile, size_t outsize)
/* output is good, ok to delete input */
unlink_input(file, &isb);
- return size;
+ return (size);
#ifndef SMALL
bad_outfile:
@@ -1316,7 +1317,7 @@ file_compress(char *file, char *outfile, size_t outsize)
maybe_warnx("leaving original %s", file);
unlink(outfile);
- return size;
+ return (size);
#endif
}
@@ -1564,9 +1565,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
return -1;
}
if (osb.st_size != size) {
- maybe_warnx("stat gave different size: %" PRIdOFF
- " != %" PRIdOFF " (leaving original)",
- size, osb.st_size);
+ maybe_warnx("stat gave different size: %ju != %ju (leaving original)",
+ (uintmax_t)size, (uintmax_t)osb.st_size);
close(ofd);
unlink(outfile);
return -1;
OpenPOWER on IntegriCloud