[PATCH 04/11] memcpy cmd: Do not expect to read/write the whole chunk at once
Sascha Hauer
s.hauer at pengutronix.de
Mon Jun 28 04:37:46 EDT 2010
On Fri, Jun 25, 2010 at 09:17:44AM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:
>
> Hi,
>
> Sascha> read() does not necessarily return the number of bytes
> Sascha> we want to read, so deal with less bytes.
>
> Sascha> - if ((w = write(destfd, rw_buf, r)) < 0) {
> Sascha> - perror("write");
> Sascha> - goto out;
> Sascha> - }
> Sascha> -
> Sascha> - if (r < now)
> Sascha> + if (!r)
> Sascha> break;
>
> Sascha> - if (w < r)
> Sascha> - break;
> Sascha> + tmp = 0;
> Sascha> + now = r;
> Sascha> + while (now) {
> Sascha> + w = write(destfd, rw_buf + tmp, now);
> Sascha> + if (w < 0) {
> Sascha> + perror("write");
> Sascha> + goto out;
> Sascha> + }
> Sascha> + if (!w)
> Sascha> + break;
>
> Sascha> - count -= now;
> Sascha> + now -= w;
> Sascha> + tmp += w;
> Sascha> + }
> Sascha> +
>
> This is probably not the only place we need this. What about moving this
> to a helper function like busybox' full_write()?
I merged this for now, but I'll remember it for next time I implement
such a loop.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list