Skip to content

Commit 98acba1

Browse files
authored
Merge pull request #671 from evoskuil/master
Implement fallocate for win32, revert to ftruncate for xcode.
2 parents a981ad3 + 3f2c376 commit 98acba1

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/memory/map.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,13 @@ bool map::remap_(size_t size) NOEXCEPT
557557
// disk_full: space is set but no code is set with false return.
558558
bool map::resize_(size_t size) NOEXCEPT
559559
{
560-
// Disk full detection is platform common, any other failure is an abort.
560+
// Disk full detection, any other failure is an abort.
561+
#if defined(HAVE_APPLE)
562+
// TODO: implement fallocate for macOS (open and write a byte per block).
563+
if (::ftruncate(opened_, size) == fail)
564+
#else
561565
if (::fallocate(opened_, 0, capacity_, size - capacity_) == fail)
566+
#endif
562567
{
563568
// Disk full is the only restartable store failure (leave mapped).
564569
if (errno == ENOSPC)

src/memory/mman-win32/mman.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ int fsync(int fd) noexcept
223223
return 0;
224224
}
225225

226+
int fallocate(int fd, int mode, oft__ offset, oft__ size) noexcept
227+
{
228+
return ftruncate(fd, offset + size);
229+
}
230+
226231
int ftruncate(int fd, oft__ size) noexcept
227232
{
228233
LARGE_INTEGER big{};

src/memory/mman-win32/mman.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ int msync(void* addr, size_t len, int flags) noexcept;
4040
int mlock(const void* addr, size_t len) noexcept;
4141
int munlock(const void* addr, size_t len) noexcept;
4242
int fsync(int fd) noexcept;
43+
int fallocate(int fd, int mode, oft__ offset, oft__ size) noexcept;
4344
int ftruncate(int fd, oft__ size) noexcept;
4445

4546
#endif // _WIN32

0 commit comments

Comments
 (0)