fallocate(int fd, long new_size)
{
#ifdef HAVE_POSIX_FALLOCATE
- return posix_fallocate(fd, 0, new_size);
-#else
+ const int posix_fallocate_err = posix_fallocate(fd, 0, new_size);
+ if (posix_fallocate_err == 0 || posix_fallocate_err != EINVAL) {
+ return posix_fallocate_err;
+ }
+ // the underlying filesystem does not support the operation so fallback to
+ // lseeks
+#endif
off_t saved_pos = lseek(fd, 0, SEEK_END);
off_t old_size = lseek(fd, 0, SEEK_END);
if (old_size == -1) {
lseek(fd, saved_pos, SEEK_SET);
free(buf);
return err;
-#endif
}
std::string