basic/io-util: invert return value from IOVEC_INCREMENT()

We would try to return a value that could be nonzero only if the kernel
reported writing more bytes than we gave to it, hopefully a rare occurence.
Instead, assert that this doesn't happen.

Instead, return true if we got to the end of the iovec array. The caller
can use this information to know that the whole iovec array was written.
This allows one loop to be dropped in write_to_syslog().

Also drop _unlikely_: this function is called with very short arrays, and
it *is* likely that we trigger this condition. Let's just let the compiler
generate normal code without giving it a potentially false hint.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-05-04 14:57:49 +02:00
parent 0f6bb1ed05
commit 32f65484d7
2 changed files with 14 additions and 9 deletions
+3 -3
View File
@@ -491,11 +491,11 @@ static int write_to_syslog(
if (n < 0)
return -errno;
if (!syslog_is_stream ||
(size_t) n >= IOVEC_TOTAL_SIZE(iovec, ELEMENTSOF(iovec)))
if (!syslog_is_stream)
break;
IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n);
if (IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n))
break;
}
return 1;