Skip to content

Commit 01753c5

Browse files
committed
fix FreeBSD build, lacking fsync_range()
1 parent 9c8bb8f commit 01753c5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

include/libtorrent/config.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ see LICENSE file.
9191
|| defined __FreeBSD_kernel__
9292
#define TORRENT_BSD
9393

94+
#ifdef __NetBSD__
95+
#define TORRENT_HAS_FSYNC_RANGE 1
96+
#endif
97+
9498
#if defined __APPLE__
9599

96100
#include <AvailabilityMacros.h>
@@ -560,6 +564,10 @@ see LICENSE file.
560564
#define TORRENT_HAS_COPYFILE 0
561565
#endif
562566

567+
#ifndef TORRENT_HAS_FSYNC_RANGE
568+
#define TORRENT_HAS_FSYNC_RANGE 0
569+
#endif
570+
563571
// debug builds have asserts enabled by default, release
564572
// builds have asserts if they are explicitly enabled by
565573
// the release_asserts macro.

src/pread_storage.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ see LICENSE file.
4141
#include <fcntl.h> // for sync_file_range
4242
#elif defined TORRENT_WINDOWS
4343
#include "libtorrent/aux_/windows.hpp" // for FlushFileBuffers
44-
#elif defined TORRENT_BSD && ! defined __APPLE__
44+
#elif TORRENT_HAS_FSYNC_RANGE
4545
#include <unistd.h> // for fsync_range
4646
#else
4747
#include <unistd.h> // for fsync
@@ -72,8 +72,8 @@ namespace {
7272
::FlushFileBuffers(handle);
7373
TORRENT_UNUSED(offset);
7474
TORRENT_UNUSED(len);
75-
#elif defined TORRENT_BSD && ! defined __APPLE__
76-
::fsync_range(handle, FFILESYNC, offset, len);
75+
#elif TORRENT_HAS_FSYNC_RANGE
76+
::fsync_range(handle, FDATASYNC, offset, len);
7777
#else
7878
::fsync(handle);
7979
TORRENT_UNUSED(offset);
@@ -634,8 +634,6 @@ namespace {
634634
ph.update(scratch_buffer);
635635
if (flags & disk_interface::volatile_read)
636636
advise_dont_need(handle->fd(), file_offset, buf.size());
637-
if (flags & disk_interface::flush_piece)
638-
sync_file(handle->fd(), file_offset, buf.size());
639637
}
640638

641639
return ret;
@@ -688,8 +686,6 @@ namespace {
688686
ph.update(b);
689687
if (flags & disk_interface::volatile_read)
690688
advise_dont_need(handle->fd(), file_offset, len);
691-
if (flags & disk_interface::flush_piece)
692-
sync_file(handle->fd(), file_offset, len);
693689

694690
return static_cast<int>(len);
695691
}

0 commit comments

Comments
 (0)