aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cursor/os-compatibility.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/cursor/os-compatibility.c b/cursor/os-compatibility.c
index 9008755..6f5b39f 100644
--- a/cursor/os-compatibility.c
+++ b/cursor/os-compatibility.c
@@ -156,19 +156,24 @@ os_create_anonymous_file(off_t size)
}
#ifdef HAVE_POSIX_FALLOCATE
+ /*
+ * Filesystems that do support fallocate will return EOPNOTSUPP.
+ * In this case we need to fall back to ftruncate
+ */
ret = posix_fallocate(fd, 0, size);
- if (ret != 0) {
+ if (ret == 0) {
+ return fd;
+ } else if (ret != EOPNOTSUPP) {
close(fd);
errno = ret;
return -1;
}
-#else
+#endif
ret = ftruncate(fd, size);
if (ret < 0) {
close(fd);
return -1;
}
-#endif
return fd;
}