aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/portability.c17
-rw-r--r--lib/portability.h3
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/portability.c b/lib/portability.c
index d48a3b4d..0b5677cc 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -396,6 +396,23 @@ int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev)
if (fchdir(old_dirfd) == -1) perror_exit("mknodat couldn't return");
return result;
}
+
+// As of 10.15, macOS offers an fcntl F_PREALLOCATE rather than fallocate()
+// or posix_fallocate() calls.
+int posix_fallocate(int fd, off_t offset, off_t length)
+{
+ int e = errno, result;
+ fstore_t f;
+
+ f.fst_flags = F_ALLOCATEALL;
+ f.fst_posmode = F_PEOFPOSMODE;
+ f.fst_offset = offset;
+ f.fst_length = length;
+ if (fcntl(fd, F_PREALLOCATE, &f) == -1) result = errno;
+ else result = ftruncate(fd, length);
+ errno = e;
+ return result;
+}
#endif
// Signals required by POSIX 2008:
diff --git a/lib/portability.h b/lib/portability.h
index fb4e0383..896fba34 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -201,9 +201,10 @@ ssize_t xattr_lset(const char*, const char*, const void*, size_t, int);
ssize_t xattr_fset(int, const char*, const void*, size_t, int);
#endif
-// macOS doesn't have mknodat, but we can fake it.
+// macOS doesn't have these functions, but we can fake them.
#ifdef __APPLE__
int mknodat(int, const char*, mode_t, dev_t);
+int posix_fallocate(int, off_t, off_t);
#endif
// Android is missing some headers and functions