- // For now, there are some cases where we just give up if the
- // values are too large, but we could try to break up the relevant
- // operations into chunks.
-
- // Deal with preceding zeros. Just make them sparse, along with
- // any leading zeros in buf, even if the region's not >= min,
- // since the alternative is a potentially extra small write.
- if (prev_sparse_len)
- {
- const unsigned long long zeros = count_leading_zeros(buf, buf_len);
- unsigned long long new_sparse_len = 0;
- if (!uadd(&new_sparse_len, prev_sparse_len, zeros))
- return PyErr_Format (PyExc_OverflowError, "sparse region too large");
- if (zeros == buf_len)
- return PyLong_FromUnsignedLongLong(new_sparse_len);
-
- off_t new_off;
- if (!INTEGRAL_ASSIGNMENT_FITS(&new_off, new_sparse_len))
- return PyErr_Format(PyExc_OverflowError,
- "sparse region too large for seek");
- const off_t off = lseek(fd, new_off, SEEK_CUR);
- if (off == -1)
- return PyErr_SetFromErrno(PyExc_IOError);
- buf += zeros;
- buf_len -= zeros;
- }
-
+ // The value of zeros_read indicates the number of zeros read from
+ // buf that haven't been accounted for yet (with respect to cur),
+ // while zeros indicates the total number of pending zeros, which
+ // could be larger in the first iteration if prev_sparse_len
+ // wasn't zero.