Make WARNS=6 safe, mainly by casting to intmax_t and printing with %ju

where needed.  Also, fix bad indentation on lines already affected by the
above changes.

Tested with:	make universe
This commit is contained in:
Gavin Atkinson 2010-06-28 12:00:20 +00:00
parent 84f70ae360
commit ddcdd26ef6
2 changed files with 17 additions and 16 deletions

View File

@ -3,6 +3,4 @@
PROG= tcopy
WARNS?= 1
.include <bsd.prog.mk>

View File

@ -87,6 +87,7 @@ main(int argc, char *argv[])
msg = stdout;
guesslen = 1;
outp = -1;
while ((ch = getopt(argc, argv, "cs:vx")) != -1)
switch((char)ch) {
case 'c':
@ -157,16 +158,16 @@ main(int argc, char *argv[])
if (nread >= 0)
goto r1;
}
err(1, "read error, file %d, record %qu", filen, record);
err(1, "read error, file %d, record %ju", filen, (intmax_t)record);
} else if (nread != lastnread) {
if (lastnread != 0 && lastnread != NOCOUNT) {
if (lastrec == 0 && nread == 0)
fprintf(msg, "%qu records\n", record);
fprintf(msg, "%ju records\n", (intmax_t)record);
else if (record - lastrec > 1)
fprintf(msg, "records %qu to %qu\n",
lastrec, record);
fprintf(msg, "records %ju to %ju\n",
(intmax_t)lastrec, (intmax_t)record);
else
fprintf(msg, "record %qu\n", lastrec);
fprintf(msg, "record %ju\n", (intmax_t)lastrec);
}
if (nread != 0)
fprintf(msg, "file %d: block size %d: ",
@ -184,10 +185,12 @@ r1: guesslen = 0;
nw = write(outp, buff, nread);
if (nw != nread) {
if (nw == -1) {
warn("write error, file %d, record %qu", filen, record);
warn("write error, file %d, record %ju", filen,
(intmax_t)record);
} else {
warnx("write error, file %d, record %qu", filen, record);
warnx("write (%d) != read (%d)", nw, nread);
warnx("write error, file %d, record %ju", filen,
(intmax_t)record);
warnx("write (%d) != read (%d)", nw, nread);
}
errx(5, "copy aborted");
}
@ -200,8 +203,8 @@ r1: guesslen = 0;
break;
}
fprintf(msg,
"file %d: eof after %qu records: %qu bytes\n",
filen, record, size);
"file %d: eof after %ju records: %ju bytes\n",
filen, (intmax_t)record, (intmax_t)size);
needeof = 1;
filen++;
tsize += size;
@ -210,7 +213,7 @@ r1: guesslen = 0;
}
lastnread = nread;
}
fprintf(msg, "total length: %qu bytes\n", tsize);
fprintf(msg, "total length: %ju bytes\n", (intmax_t)tsize);
(void)signal(SIGINT, oldsig);
if (op == COPY || op == COPYVERIFY) {
writeop(outp, MTWEOF);
@ -281,11 +284,11 @@ intr(int signo __unused)
{
if (record) {
if (record - lastrec > 1)
fprintf(msg, "records %qu to %qu\n", lastrec, record);
fprintf(msg, "records %ju to %ju\n", (intmax_t)lastrec, (intmax_t)record);
else
fprintf(msg, "record %qu\n", lastrec);
fprintf(msg, "record %ju\n", (intmax_t)lastrec);
}
fprintf(msg, "interrupt at file %d: record %qu\n", filen, record);
fprintf(msg, "interrupt at file %d: record %ju\n", filen, (intmax_t)record);
fprintf(msg, "total length: %ju bytes\n", (uintmax_t)(tsize + size));
exit(1);
}