diff --git a/src/memory/map.cpp b/src/memory/map.cpp index b7fdef966..151e15b8e 100644 --- a/src/memory/map.cpp +++ b/src/memory/map.cpp @@ -557,8 +557,13 @@ bool map::remap_(size_t size) NOEXCEPT // disk_full: space is set but no code is set with false return. bool map::resize_(size_t size) NOEXCEPT { - // Disk full detection is platform common, any other failure is an abort. + // Disk full detection, any other failure is an abort. +#if defined(HAVE_APPLE) + // TODO: implement fallocate for macOS (open and write a byte per block). + if (::ftruncate(opened_, size) == fail) +#else if (::fallocate(opened_, 0, capacity_, size - capacity_) == fail) +#endif { // Disk full is the only restartable store failure (leave mapped). if (errno == ENOSPC) diff --git a/src/memory/mman-win32/mman.cpp b/src/memory/mman-win32/mman.cpp index 50df00402..1e06a5f07 100644 --- a/src/memory/mman-win32/mman.cpp +++ b/src/memory/mman-win32/mman.cpp @@ -223,6 +223,11 @@ int fsync(int fd) noexcept return 0; } +int fallocate(int fd, int mode, oft__ offset, oft__ size) noexcept +{ + return ftruncate(fd, offset + size); +} + int ftruncate(int fd, oft__ size) noexcept { LARGE_INTEGER big{}; diff --git a/src/memory/mman-win32/mman.hpp b/src/memory/mman-win32/mman.hpp index b34839b39..bd00401b3 100644 --- a/src/memory/mman-win32/mman.hpp +++ b/src/memory/mman-win32/mman.hpp @@ -40,6 +40,7 @@ int msync(void* addr, size_t len, int flags) noexcept; int mlock(const void* addr, size_t len) noexcept; int munlock(const void* addr, size_t len) noexcept; int fsync(int fd) noexcept; +int fallocate(int fd, int mode, oft__ offset, oft__ size) noexcept; int ftruncate(int fd, oft__ size) noexcept; #endif // _WIN32