From c0bb071b4bc47c74e229ef84cdbaf374e1c2a581 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 22 Oct 2019 16:04:55 -0700 Subject: macOS: implement posix_fallocate(). --- lib/portability.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/portability.c') 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: -- cgit v1.2.3