- /*
- * The usual case is success (__sfvwrite returns 0);
- * skip the divide if this happens, since divides are
- * generally slow and since this occurs whenever size==0.
- */
- if (__sfvwrite(fp, &uio) != 0)
- count = (n - uio.uio_resid) / size;
+
+ for (resid = n; resid > 0; buf += s, resid -= s) {
+ s = resid > INT_MAX ? MAXWRITE : (int)resid;
+ iov.iov_base = (void *)buf;
+ uio.uio_resid = iov.iov_len = s;
+
+ /*
+ * The usual case is success (__sfvwrite returns 0);
+ * skip the divide if this happens, since divides are
+ * generally slow and since this occurs whenever size==0.
+ */
+ if (__sfvwrite(fp, &uio) != 0) {
+ count = (n - resid + s - uio.uio_resid) / size;
+ break;
+ }
+ }