diff options
author | green <green@FreeBSD.org> | 2000-07-01 05:36:25 +0000 |
---|---|---|
committer | green <green@FreeBSD.org> | 2000-07-01 05:36:25 +0000 |
commit | 5f788961ba48b35c324803f25cdd9c5d46dcf9e7 (patch) | |
tree | e2bd810d05c1625f1047f5ab6bcc21828825df0b /bin/dd/dd.c | |
parent | d65ba30aafb85a96c9826a26c7794d0a5dd9ea22 (diff) | |
download | FreeBSD-src-5f788961ba48b35c324803f25cdd9c5d46dcf9e7.zip FreeBSD-src-5f788961ba48b35c324803f25cdd9c5d46dcf9e7.tar.gz |
Various cleanups are made to reduce warnings and make code prettier :)
Also, check for ftruncate() return value and die on failure, but only
try to ftruncate() when the file is a regular file.
Diffstat (limited to 'bin/dd/dd.c')
-rw-r--r-- | bin/dd/dd.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/bin/dd/dd.c b/bin/dd/dd.c index 937379f..2ce90df 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -70,6 +70,7 @@ static const char rcsid[] = static void dd_close __P((void)); static void dd_in __P((void)); +int main __P((int, char *[])); static void getfdtype __P((IO *)); static void setup __P((void)); @@ -171,8 +172,10 @@ setup() * Truncate the output file; ignore errors because it fails on some * kinds of output files, tapes, for example. */ - if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK)) - (void)ftruncate(out.fd, out.offset * out.dbsz); + if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK) && + out.flags & ISTRUNC) + if (ftruncate(out.fd, out.offset * out.dbsz) == -1) + err(1, "truncating %s", out.name); /* * If converting case at the same time as another conversion, build a @@ -191,10 +194,10 @@ setup() } else { if (ddflags & C_LCASE) { for (cnt = 0; cnt <= 0377; ++cnt) - casetab[cnt] = tolower(cnt); + casetab[cnt] = tolower((int)cnt); } else { for (cnt = 0; cnt <= 0377; ++cnt) - casetab[cnt] = toupper(cnt); + casetab[cnt] = toupper((int)cnt); } } ctab = casetab; @@ -213,6 +216,8 @@ getfdtype(io) if (fstat(io->fd, &sb) == -1) err(1, "%s", io->name); + if (S_ISREG(sb.st_mode)) + io->flags |= ISTRUNC; if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) { if (ioctl(io->fd, FIODTYPE, &type) == -1) { err(1, "%s", io->name); @@ -251,7 +256,7 @@ dd_in() case 0: break; default: - if (st.in_full + st.in_part >= cpy_cnt) + if (st.in_full + st.in_part >= (u_quad_t)cpy_cnt) return; break; } @@ -303,7 +308,7 @@ dd_in() ++st.in_full; /* Handle full input blocks. */ - } else if (n == in.dbsz) { + } else if ((size_t)n == in.dbsz) { in.dbcnt += in.dbrcnt = n; ++st.in_full; @@ -334,7 +339,7 @@ dd_in() ++st.swab; --n; } - swab(in.dbp, in.dbp, n); + swab(in.dbp, in.dbp, (size_t)n); } in.dbp += in.dbrcnt; @@ -434,7 +439,7 @@ dd_out(force) } outp += nw; st.bytes += nw; - if (nw == n) { + if ((size_t)nw == n) { if (n != out.dbsz) ++st.out_part; else @@ -442,7 +447,7 @@ dd_out(force) break; } ++st.out_part; - if (nw == cnt) + if ((size_t)nw == cnt) break; if (out.flags & ISTAPE) errx(1, "%s: short write on tape device", |