[PATCH 04/11] memcpy cmd: Do not expect to read/write the whole chunk at once

Peter Korsgaard jacmet at sunsite.dk
Fri Jun 25 03:17:44 EDT 2010


>>>>> "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()?

-- 
Bye, Peter Korsgaard



More information about the barebox mailing list