Several style fixes as prompted by bde@.

While I'm there, loosen the st_nlink check and fix grammar for 1 extra
links.
This commit is contained in:
Xin LI 2010-06-10 20:59:28 +00:00
parent 2bc3bd71de
commit 08b300a1b7

View File

@ -65,10 +65,6 @@ __RCSID("$FreeBSD$");
#include <getopt.h> #include <getopt.h>
#include <time.h> #include <time.h>
#ifndef PRIdOFF
#define PRIdOFF PRId64
#endif
/* what type of file are we dealing with */ /* what type of file are we dealing with */
enum filetype { enum filetype {
FT_GZIP, FT_GZIP,
@ -1221,46 +1217,46 @@ file_compress(char *file, char *outfile, size_t outsize)
in = open(file, O_RDONLY); in = open(file, O_RDONLY);
if (in == -1) { if (in == -1) {
maybe_warn("can't open %s", file); maybe_warn("can't open %s", file);
return -1; return (-1);
} }
#ifndef SMALL #ifndef SMALL
if (fstat(in, &isb) != 0) { if (fstat(in, &isb) != 0) {
maybe_warn("couldn't stat: %s", file); maybe_warn("couldn't stat: %s", file);
close(in); close(in);
return -1; return (-1);
} }
#endif #endif
if (cflag == 0) { if (cflag == 0) {
#ifndef SMALL #ifndef SMALL
if (isb.st_nlink != 1 && fflag == 0) { if (isb.st_nlink > 1 && fflag == 0) {
maybe_warnx("%s has %d other link%s -- " maybe_warnx("%s has %d other link%s -- skipping",
"skipping", file, isb.st_nlink - 1, file, isb.st_nlink - 1,
isb.st_nlink == 1 ? "" : "s"); (isb.st_nlink - 1) == 1 ? "" : "s");
close(in); close(in);
return -1; return (-1);
} }
if (fflag == 0 && (suff = check_suffix(file, 0)) if (fflag == 0 && (suff = check_suffix(file, 0)) &&
&& suff->zipped[0] != 0) { suff->zipped[0] != 0) {
maybe_warnx("%s already has %s suffix -- unchanged", maybe_warnx("%s already has %s suffix -- unchanged",
file, suff->zipped); file, suff->zipped);
close(in); close(in);
return -1; return (-1);
} }
#endif #endif
/* Add (usually) .gz to filename */ /* Add (usually) .gz to filename */
if ((size_t)snprintf(outfile, outsize, "%s%s", 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, memcpy(outfile + outsize - suffixes[0].ziplen - 1,
suffixes[0].zipped, suffixes[0].ziplen + 1); suffixes[0].zipped, suffixes[0].ziplen + 1);
#ifndef SMALL #ifndef SMALL
if (check_outfile(outfile) == 0) { if (check_outfile(outfile) == 0) {
close(in); close(in);
return -1; return (-1);
} }
#endif #endif
} }
@ -1270,7 +1266,7 @@ file_compress(char *file, char *outfile, size_t outsize)
if (out == -1) { if (out == -1) {
maybe_warn("could not create output: %s", outfile); maybe_warn("could not create output: %s", outfile);
fclose(stdin); fclose(stdin);
return -1; return (-1);
} }
#ifndef SMALL #ifndef SMALL
remove_file = outfile; remove_file = outfile;
@ -1290,7 +1286,7 @@ file_compress(char *file, char *outfile, size_t outsize)
* has the expected size. * has the expected size.
*/ */
if (cflag != 0) if (cflag != 0)
return insize == -1 ? -1 : size; return (insize == -1 ? -1 : size);
#ifndef SMALL #ifndef SMALL
if (fstat(out, &osb) != 0) { if (fstat(out, &osb) != 0) {
@ -1299,9 +1295,8 @@ file_compress(char *file, char *outfile, size_t outsize)
} }
if (osb.st_size != size) { if (osb.st_size != size) {
maybe_warnx("output file: %s wrong size (%" PRIdOFF maybe_warnx("output file: %s wrong size (%ju != %ju), deleting",
" != %" PRIdOFF "), deleting", outfile, (uintmax_t)osb.st_size, (uintmax_t)size);
outfile, osb.st_size, size);
goto bad_outfile; goto bad_outfile;
} }
@ -1313,7 +1308,7 @@ file_compress(char *file, char *outfile, size_t outsize)
/* output is good, ok to delete input */ /* output is good, ok to delete input */
unlink_input(file, &isb); unlink_input(file, &isb);
return size; return (size);
#ifndef SMALL #ifndef SMALL
bad_outfile: bad_outfile:
@ -1322,7 +1317,7 @@ file_compress(char *file, char *outfile, size_t outsize)
maybe_warnx("leaving original %s", file); maybe_warnx("leaving original %s", file);
unlink(outfile); unlink(outfile);
return size; return (size);
#endif #endif
} }
@ -1570,9 +1565,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
return -1; return -1;
} }
if (osb.st_size != size) { if (osb.st_size != size) {
maybe_warnx("stat gave different size: %" PRIdOFF maybe_warnx("stat gave different size: %ju != %ju (leaving original)",
" != %" PRIdOFF " (leaving original)", (uintmax_t)size, (uintmax_t)osb.st_size);
size, osb.st_size);
close(ofd); close(ofd);
unlink(outfile); unlink(outfile);
return -1; return -1;