The "ret < n" was done as an unsigned comparison, so it didn't work as
expected when ret was negative.
Simplest fix is to do an equals comparison everywhere, which is also
slightly stricter.
} else {
ssize_t ret;
ret = pwrite(tdb->fd, buf, len, off);
- if (ret < len) {
+ if (ret != len) {
/* This shouldn't happen: we avoid sparse files. */
if (ret >= 0)
errno = ENOSPC;
while (len) {
size_t n = len > size ? size : len;
ssize_t ret = pwrite(tdb->fd, buf, n, off);
- if (ret < n) {
+ if (ret != n) {
if (ret >= 0)
errno = ENOSPC;