lib: Use iov_advance in write_data_iov
authorVolker Lendecke <vl@samba.org>
Sat, 27 Dec 2014 16:48:55 +0000 (16:48 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 29 Dec 2014 23:25:08 +0000 (00:25 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/sys_rw_data.c

index 353dbe75c2db9deb0bd43d7827c0ed76b2cc0584..88e5085ac696743e72885d473094c4333fdec786 100644 (file)
@@ -63,22 +63,12 @@ ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
        iov = iov_copy;
 
        while (sent < to_send) {
-               /*
-                * We have to discard "thistime" bytes from the beginning
-                * iov array, "thistime" contains the number of bytes sent
-                * via writev last.
-                */
-               while (thistime > 0) {
-                       if (thistime < iov[0].iov_len) {
-                               char *new_base =
-                                       (char *)iov[0].iov_base + thistime;
-                               iov[0].iov_base = (void *)new_base;
-                               iov[0].iov_len -= thistime;
-                               break;
-                       }
-                       thistime -= iov[0].iov_len;
-                       iov += 1;
-                       iovcnt -= 1;
+               bool ok;
+
+               ok = iov_advance(&iov, &iovcnt, thistime);
+               if (!ok) {
+                       errno = EIO;
+                       return -1;
                }
 
                thistime = sys_writev(fd, iov, iovcnt);