From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH v5] tools/libxc: Implement writev_exact() in the same style as write_exact() Date: Thu, 19 Feb 2015 16:39:40 +0000 Message-ID: <1424363980.30924.125.camel@citrix.com> References: <1424346333-13716-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1424346333-13716-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Wei Liu , Ian Jackson , Xen-devel List-Id: xen-devel@lists.xenproject.org On Thu, 2015-02-19 at 11:45 +0000, Andrew Cooper wrote: > + while ( iov_idx < iovcnt ) > + { > + /* Skip over iov[] entries with 0 length. */ > + while ( iov[iov_idx].iov_len == 0 ) > + if ( ++iov_idx == iovcnt ) > + goto out; Is this required for some reason or just an optimisation? > + > + len = writev(fd, &iov[iov_idx], min(iovcnt - iov_idx, IOV_MAX)); > + saved_errno = errno; > + > + if ( (len == -1) && (errno == EINTR) ) > + continue; > + if ( len <= 0 ) > + { > + rc = -1; > + goto out; > + } > + > + /* Check iov[] to see whether we had a partial or complete write. */ > + while ( len > 0 && (iov_idx < iovcnt) ) > + { > + if ( len >= iov[iov_idx].iov_len ) > + len -= iov[iov_idx++].iov_len; > + else > + { > + /* Partial write of iov[iov_idx]. Copy iov so we can adjust > + * element iov_idx and resubmit the rest. */ I suppose we can't / don't want to just declare that the input is non-const and potentially corrupted? > + if ( !local_iov ) > + { > + local_iov = malloc(iovcnt * sizeof(*iov)); > + if ( !local_iov ) > + { > + saved_errno = ENOMEM; > + goto out; What is rc at this point? I think it is 0, but I think you want it to be -1? It might be better to drop the inialiser of rc and set it in the one or two places which would then need it (the goto out in the skip-0-length loop and just before the out label AFAICT).