[BusyBox] confused by copyfd.c
Rainer Weikusat
rainer.weikusat at sncag.com
Thu Jun 16 07:31:11 UTC 2005
Paul Fox <pgf at brightstareng.com> writes:
> we run (mostly) busybox-1.00 on our product, and i just hit the
> problem where cp won't fail properly if a disk is full.
[...]
> looking at copyfd.c, i'm a little confused. the routine in
> question is short, so i'll include it here:
>
> (note that it's possible that i'm hitting at least some of these
> errors because i've been building busybox with -O3 rather than
> the default -Os.)
Nope. While this is certainly unintentional, the code appears to
actually be C.
A mentally sane person would do this roughly like that:
static ssize_t copy_fd(int from, int to)
{
char buf[4096]; /* pick whatever you like */
ssize_t rc, total;
total = 0;
do {
rc = read(from, buf, sizeof(buf));
if (rc > 0) {
total += rc;
rc = bb_full_write(to, buf, rc);
}
} while (rc > 0);
return rc ? rc : total;
}
[uncompiled/ may not be compatible]
More information about the busybox
mailing list