splice returns EINVAL if (loff_t)(len + out.pos) is negative number.
This was the case on aarch64 and x86_64.
Change-Id: Ic52d08efce3fca555a83319c8161c3656b553cc1
ssize_t s;
_Bool copied_data = 0;
- const ssize_t max_splice = SSIZE_MAX;
+ ssize_t max_splice = SSIZE_MAX;
do {
s = splice(in, NULL, out, NULL, max_splice, SPLICE_F_MOVE);
+ // output file position + len must not exceed the loff_t type limit,
+ // that's why we reduce len in every iteration
+ max_splice -= s;
+
// We can try to fallback to simple copy only if first splice failed
// (ie. we have not consumed any data yet)
if (!copied_data && s > 0)