Skip to content

Commit 4e06516

Browse files
committed
Fix macos build break.
1 parent 3c5133c commit 4e06516

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

src/memory/map.cpp

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include <bitcoin/database/error.hpp>
3838
#include <bitcoin/database/file/file.hpp>
3939

40+
#if defined(HAVE_APPLE)
41+
int fallocate(int fd, int, off_t offset, off_t len) NOEXCEPT;
42+
#endif
43+
4044
namespace libbitcoin {
4145
namespace database {
4246

@@ -554,47 +558,6 @@ bool map::remap_(size_t size) NOEXCEPT
554558
return finalize_(size);
555559
}
556560

557-
#if defined(HAVE_APPLE)
558-
// ::fallocate is not defined on macOS, so implement. Ignores mode (linux).
559-
int fallocate(int fd, int, size_t offset, size_t len) NOEXCEPT
560-
{
561-
fstore_t store
562-
{
563-
// Prefer contiguous allocation
564-
.fst_flags = F_ALLOCATECONTIG,
565-
566-
// Allocate from EOF
567-
.fst_posmode = F_PEOFPOSMODE,
568-
569-
// Start from current capacity
570-
.fst_offset = offset,
571-
572-
// Delta size
573-
.fst_length = len,
574-
575-
// Output: actual bytes allocated
576-
.fst_bytesalloc = 0
577-
};
578-
579-
// Try contiguous allocation.
580-
auto result = ::fcntl(fd, F_PREALLOCATE, &store);
581-
582-
// Fallback to non-contiguous.
583-
if ((result == fail) && (errno != ENOSPC))
584-
{
585-
store.fst_flags = F_ALLOCATEALL;
586-
result = ::fcntl(fd, F_PREALLOCATE, &store);
587-
}
588-
589-
if (result == fail)
590-
return fail;
591-
592-
// Extend file to new size (required for mmap). This is not required on
593-
// Linux because fallocate(2) automatically extends file's logical size.
594-
return ::ftruncate(fd, offset + len);
595-
}
596-
#endif // HAVE_APPLE
597-
598561
// disk_full: space is set but no code is set with false return.
599562
bool map::resize_(size_t size) NOEXCEPT
600563
{
@@ -681,3 +644,44 @@ BC_POP_WARNING()
681644

682645
} // namespace database
683646
} // namespace libbitcoin
647+
648+
#if defined(HAVE_APPLE)
649+
// ::fallocate is not defined on macOS, so implement. Ignores mode (linux).
650+
int fallocate(int fd, int, off_t offset, off_t len) NOEXCEPT
651+
{
652+
fstore_t store
653+
{
654+
// Prefer contiguous allocation
655+
.fst_flags = F_ALLOCATECONTIG,
656+
657+
// Allocate from EOF
658+
.fst_posmode = F_PEOFPOSMODE,
659+
660+
// Start from current capacity
661+
.fst_offset = offset,
662+
663+
// Delta size
664+
.fst_length = len,
665+
666+
// Output: actual bytes allocated
667+
.fst_bytesalloc = 0
668+
};
669+
670+
// Try contiguous allocation.
671+
auto result = ::fcntl(fd, F_PREALLOCATE, &store);
672+
673+
// Fallback to non-contiguous.
674+
if ((result == fail) && (errno != ENOSPC))
675+
{
676+
store.fst_flags = F_ALLOCATEALL;
677+
result = ::fcntl(fd, F_PREALLOCATE, &store);
678+
}
679+
680+
if (result == fail)
681+
return fail;
682+
683+
// Extend file to new size (required for mmap). This is not required on
684+
// Linux because fallocate(2) automatically extends file's logical size.
685+
return ::ftruncate(fd, offset + len);
686+
}
687+
#endif // HAVE_APPLE

0 commit comments

Comments
 (0)