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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Sascha" == Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> 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

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox


[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux