svn commit: branches/busybox_scratch/coreutils
aldot at busybox.net
aldot at busybox.net
Sun Aug 20 11:17:23 UTC 2006
Author: aldot
Date: 2006-08-20 04:17:22 -0700 (Sun, 20 Aug 2006)
New Revision: 15837
Log:
- shrink and cleanup dd: Help optimizers by using explicit gotos for
outfile errors.
text data bss dec hex filename
2123 0 16 2139 85b coreutils/dd.o.01b
1793 0 16 1809 711 coreutils/dd.o.01c
Modified:
branches/busybox_scratch/coreutils/dd.c
Changeset:
Modified: branches/busybox_scratch/coreutils/dd.c
===================================================================
--- branches/busybox_scratch/coreutils/dd.c 2006-08-20 11:14:15 UTC (rev 15836)
+++ branches/busybox_scratch/coreutils/dd.c 2006-08-20 11:17:22 UTC (rev 15837)
@@ -101,12 +101,14 @@
}
ibuf = xmalloc(ibs);
- if (flags & twobufs_flag) obuf = xmalloc(obs);
- else obuf = ibuf;
+ if (flags & twobufs_flag)
+ obuf = xmalloc(obs);
+ else
+ obuf = ibuf;
- if (infile != NULL) {
+ if (infile != NULL)
ifd = bb_xopen(infile, O_RDONLY);
- } else {
+ else {
ifd = STDIN_FILENO;
infile = bb_msg_standard_input;
}
@@ -114,9 +116,8 @@
if (outfile != NULL) {
oflag = O_WRONLY | O_CREAT;
- if (!seek && (flags & trunc_flag)) {
+ if (!seek && (flags & trunc_flag))
oflag |= O_TRUNC;
- }
ofd = bb_xopen3(outfile, oflag, 0666);
@@ -124,10 +125,9 @@
if (ftruncate(ofd, seek * obs) < 0) {
struct stat st;
- if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) ||
- S_ISDIR (st.st_mode)) {
- bb_perror_msg_and_die("%s", outfile);
- }
+ if (fstat(ofd, &st) < 0 || S_ISREG(st.st_mode) ||
+ S_ISDIR(st.st_mode))
+ goto die_outfile;
}
}
} else {
@@ -148,9 +148,8 @@
}
if (seek) {
- if (lseek(ofd, seek * obs, SEEK_CUR) < 0) {
- bb_perror_msg_and_die("%s", outfile);
- }
+ if (lseek(ofd, seek * obs, SEEK_CUR) < 0)
+ goto die_outfile;
}
while (in_full + in_part != count) {
@@ -167,13 +166,12 @@
if (flags & noerror) {
n = ibs;
bb_perror_msg("%s", infile);
- } else {
+ } else
bb_perror_msg_and_die("%s", infile);
- }
}
- if ((size_t)n == ibs) {
+ if ((size_t)n == ibs)
in_full++;
- } else {
+ else {
in_part++;
if (sync_flag) {
memset(ibuf + n, '\0', ibs - n);
@@ -185,39 +183,39 @@
while (n) {
size_t d = obs - oc;
- if (d > n) d = n;
+ if (d > n)
+ d = n;
memcpy(obuf + oc, tmp, d);
n -= d;
tmp += d;
oc += d;
if (oc == obs) {
- if (bb_full_write(ofd, obuf, obs) < 0) {
- bb_perror_msg_and_die("%s", outfile);
- }
+ if (bb_full_write(ofd, obuf, obs) < 0)
+ goto die_outfile;
out_full++;
oc = 0;
}
}
} else {
- if ((n = bb_full_write(ofd, ibuf, n)) < 0) {
- bb_perror_msg_and_die("%s", outfile);
- }
- if (n == ibs) out_full++;
- else out_part++;
+ if ((n = bb_full_write(ofd, ibuf, n)) < 0)
+ goto die_outfile;
+ if (n == ibs)
+ out_full++;
+ else
+ out_part++;
}
}
-
+
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
- if (bb_full_write(ofd, obuf, oc) < 0) {
- bb_perror_msg_and_die("%s", outfile);
- }
+ if (bb_full_write(ofd, obuf, oc) < 0)
+ goto die_outfile;
out_part++;
}
- if (close (ifd) < 0) {
+ if (close(ifd) < 0)
bb_perror_msg_and_die("%s", infile);
- }
- if (close (ofd) < 0) {
+ if (close(ofd) < 0) {
+die_outfile:
bb_perror_msg_and_die("%s", outfile);
}
More information about the busybox-cvs
mailing list